Accessing Jar resource issue (in Junit test)

Hi,
I have a package called my.test.example containing one class called Example1.class and a property file called MyProp.properties. I am trying to load the content of MyProp.properties with the following:
static {
    Properties Configuration = new Properties();
    try {
       URL url = Example1.class.getResource("/MyProp.properties");
       Configuration.load(url.openStream());
    } catch (IOException ex) {
        LOG.severe("Cannot load MyProp.properties :\n" + ex.toString());
}The url is systematically null. I have tried including the package name, to use '/' instead of '.', but it does not work. How should I proceed? I am looking for a solution that works wherever the .jar is installed. Is this possible?
Thanks.
P.S.: I am working under Vista and the static code is invoked in a Junit test. I don't know whether this has an impact on the issue (but I don't think so).

OK. Solved the issue with:
Configuration.load(Example1.class.getResourceAsStream("MyProp.properties"));I had to solve another 'hidden' bug in the code.

Similar Messages

  • Accessing JARred resource file

    Hi,
    My app uses an XML file. How might I construct the java.io.File so that when I JAR the app, it can be executed from any where on my file system? Currently, I have to hardcode the File absolute path which is very limiting and undesirable.
    e.g: private File configFile = new File("c:\dev\myproj\config\config.xml");
    works, bit I wish to have the resource file bundled in to the JAR, so the path must be relative i.e accessible to the app, no matter where the JAR is executed from. How can I achieve this please?
    thanks
    Paul.

    To find about more about a class, you can always look it up in the API: [http://java.sun.com/javase/6/docs/api/]
    For example, here is the constructor in question:
    [http://java.sun.com/javase/6/docs/api/java/io/InputStreamReader.html#InputStreamReader(java.io.InputStream,%20java.lang.String)]
    Click on the [charset |http://java.sun.com/javase/6/docs/api/java/nio/charset/Charset.html] link for more information about that string.

  • File.seperator fails accessing jar resource

    my code is like this:
    URL myURL = getClass().getResource("image" + System.getProperty("file.seperator") + imageName);
    It works perfectly when i run from my IDE. But when i package this into a JAR file, it fails with NullPointerException (it cant find the image in my JAR). When I look at what it is doing in the debugger, it seems to create the filename: "image%5c(imagename)" It uses %5c as a file seperator? escape code for "/" (windows environment) i presume??
    If i change my code to "image" + "/" + imageName it works perfect, but this is windows dependent and I dont want to do that.
    Has anyone come across this? what is a simple work around?

    It's not Windows-dependent. You are producing a URL
    there and they always, in all environments, use the /
    character to separate path elements. So yes, you DO
    want to do that.thank you. Why of course, it is a URL and URLs are always using "/".
    So I understand correctly ... if i reference actual FILES on my computer, i should STILL use System.getProperty(file.separator), though, right?

  • Root cause of error " Access denied. You do not have permission to perform this action or access this resource" - workflow - SharePoint 2013

    Good evening, technet community
    I hope you are doing well.
    When configuring my SharePoint workflow, I encounter the problem below:
    Problem Description:
    Let's say my domain is: test.com, my group user is: test\group , my user is: test\user1
    Except an admin account with full control at both "Web Application" and "Site Collection", all others account all have problem when creating a list item. After creating a list item, the workflow status is "cancelled" immediately
    with the following message:
    RequestorId: 262a35e4-99f4-40f0-929b-5d04b415f147. Details: System.ApplicationException: HTTP 401 {"Transfer-Encoding":["chunked"],"X-SharePointHealthScore":["0"],"SPClientServiceRequestDuration":["10"],"SPRequestGuid":["262a35e4-99f4-40f0-929b-5d04b415f147"],"request-id":["262a35e4-99f4-40f0-929b-5d04b415f147"],"X-FRAME-OPTIONS":["SAMEORIGIN"],"MicrosoftSharePointTeamServices":["15.0.0.4420"],"X-Content-Type-Options":["nosniff"],"X-MS-InvokeApp":["1;
    RequireReadOnly"],"Cache-Control":["max-age=0, private"],"Date":["Thu, 06 Nov 2014 12:14:28 GMT"],"Server":["Microsoft-IIS\/7.5"],"WWW-Authenticate":["NTLM"],"X-AspNet-Version":["4.0.30319"],"X-Powered-By":["ASP.NET"]}
    {"error":{"code":"-2147024891, System.UnauthorizedAccessException","message":{"lang":"en-US","value":"Access denied. You do not have permission to perform
    this action or access this resource."}}} at Microsoft.Activities.Hosting.Runtime.Subroutine.SubroutineChild.Execute(CodeActivityContext context) at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor,
    BookmarkManager bookmarkManager) at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)
    - The workflow is still fail even I assign "full control" to my users group "test\group" – at Site Collection level.
    Surprisingly, I have successfully found a solution for this error message. However, I still have some points that I do not clearly understand. Let's start with my solution first.
    Solution:
    *** i. Assign permission policy at Web Application level – Central Admin site ***
    1. Central Administration ==> Application management
    ==> Manage Web application 
    2. Go to "permission policy", then create a new permission level. This permission level contains all "edit item" permission.
    3. Select "user policy", then I assign it directly to my user account: test\user1.
    *** ii. Assign "edit item" permission at Site Collection level ***
    1. Site Setting ==> Site permission
    2. Assign "Edit" permission to my test\group.
    (Actually I removed all permissions of my user group at Site Collection level. It seem my group has inherited permission from Web Application level, is that correct? )
    *** iii. Create a new list item and workflow runs ……. ***
    ==> My question is:
    1. Why I cannot assign permission to my users group - "test\group" -
     at "Web Application" level? Instead I have to assign permission policy for each users, one by one?
    2. Could you please let me know how to collect full detail error message of workflow status?
    Thank you very much! Have a nice weekend.

    Thank you for your very detail response.
    Point 1: Yes my 2 service: user profile & profile sync service are running. I performed "full synchronization" as well. Actually i've tried 3 another action plans before coming up with the solution i posted:
    *** Actions completed ***
    1. Activate the feature: workflow can use app permissions.
    Site actions > Site Settings > Site features >activate the feature below:
     Workflows can use app permissions
    2.
    Refresh trusted security token services metadata feed
    Get-SPTimerJob
    "RefreshMetadataFeed"
    | Start-SPTimerJob
    - then restart the machine.
    3. Start full user profile synchronization.
    Point 2:
    - Yes my user had Edit permission at workflow task list + list affected by workflow.
    I have just remove all permissions of my user at "Site Collection" level. However, when i show my user permissions at my workflow task list and my users still have "Edit" Permission ( assigned at Web Application level. These permissions
    still exist even after my workflow task list stop inheriting permission).
    ==> the problems probably belongs to "permission" at "Site Collection level". It seems "permission level at my Site Collection does not work". All users accounts are also suffer from the same issues except farm admin account
    ( which has full control at Web Application level).
    I would appreciate if your guys can guide me how to make "permission" at my "Site Collection level" work again?
    Thank you very much.

  • JUNIT test failure-Configuration file bc4j.xcfg not found in the classpath

    Hi All,
    As part of an ESS project,Im having a model project containing a VO(parameters VO).This VO is configured to have Read-only access through SQL query and have only one transient attribute each.For the model projects containing the VO for pre merge checker compliance I had to create JUNIT Test projects containing new AMs for testing the parametersVO. While running the JUNIT tests I got an exception like
    “oracle.jbo.JboException: JBO-29000: Unexpected exception caught: oracle.jbo.ConfigException, msg=JBO-33001: Configuration file /oracle/apps/hcm/goals/core/dataMigration/publicEssModel/test/applicationModule/common/bc4j.xcfg is not found in the classpath.”.—even though this file is contained in both the src/classes folder of the project.
    When i try to run the TestAM I'm getting an exception like 'configuration tester.xcfg not found in the calsspath.
    While debugging this error, we found that we are able to successfully run the JUNIT tests if we make some changes in the adf-config.xml file of the Application. The change required is to comment out the mdsC:adf-mds-config tag in the xml file.
    After doing this change Im also able to run my AM without any exception.
    Is this a known issue?.
    Since modifying the adf-config.xml is not a recommended practice is there any workaround that we can get rid of this exception.
    Regards,
    Ajin.

    Just checked but could only find this thread Unable to run ADFBC JUNIT Test Classes with JDEV11G 11.1.1.6
    As it's also dealing with junit and 11.1.1.6.0 you might want to read it.
    Timo

  • Getting error while writing JUnit test case for RestFul Services

    Hi All,
    I have written Restful services in Netbean 6.8.
    It's running well...no issues.
    {color:#0000ff}While writing JUnit test cases for them, I am getting following error:
    {color}{color:#993300}Testcase: testGetAuthenticated(com.ct.services.LoginServicesTest): Caused an ERROR
    Implementing class{color}
    java.lang.IncompatibleClassChangeError: Implementing class
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:303)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:303)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
    at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:160)
    at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:65)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:52)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34)
    at com.ct.services.LoginServices.getAuthenticated(LoginServices.java:205)
    at com.ct.services.LoginServicesTest.testGetAuthenticated(LoginServicesTest.java:84)
    Test com.ct.services.LoginServicesTest FAILED
    F:\NetbeanProjectsWorkspace\DemoProject\nbproject\build-impl.xml:972: Some tests failed; see details above.
    BUILD FAILED (total time: 11 seconds)
    {color:#0000ff}Strange thing is that when I am commenting below lines and its related calls:
    {color}
    {color:#ff0000}EntityManagerFactory mEmf = Persistence.createEntityManagerFactory("AnyName");
    EntityManager mEm = mEmf.createEntityManager();
    {color}
    {color:#0000ff}from my code, JUnit test cases are working fine.
    {color}Anybody having any idea about this ?
    Thanks
    Avi
    Edited by: Avi007 on Aug 28, 2010 5:17 AM

    Hi All,
    [http://stackoverflow.com/questions/2778295/test-driven-development-problem]
    Please refer the above link for the solution
    Thanks
    Avi
    Edited by: Avi007 on Aug 30, 2010 12:33 AM

  • Exceptions trying to run Junit test thro Jdev. Test uses Application module

    Hi,
    my junit test works through the OraTst frame work. But I want to debug the code and If I try to run the same test through Jdev I am running into a following exception. Can somebody tell me how to fix this issue.
    I am a consumer of the Application module, I have not created it. I am using it by referencing it through the jar file provided by the owner.
    oracle.jbo.DMLException: JBO-27200: JNDI failure. Unable to lookup Data Source at context jdbc/EMReposDS
    at oracle.jbo.server.DBTransactionImpl.lookupDataSource(DBTransactionImpl.java:1414)
    at oracle.jbo.server.DBTransactionImpl2.connectToDataSource(DBTransactionImpl2.java:309)
    at oracle.jbo.common.ampool.DefaultConnectionStrategy.connect(DefaultConnectionStrategy.java:203)
    at oracle.jbo.server.ApplicationPoolMessageHandler.doPoolConnect(ApplicationPoolMessageHandler.java:553)
    at oracle.jbo.server.ApplicationPoolMessageHandler.doPoolMessage(ApplicationPoolMessageHandler.java:409)
    at oracle.jbo.server.ApplicationModuleImpl.doPoolMessage(ApplicationModuleImpl.java:8534)
    at oracle.jbo.common.ampool.ApplicationPoolImpl.sendPoolMessage(ApplicationPoolImpl.java:4392)
    at oracle.jbo.common.ampool.ApplicationPoolImpl.prepareApplicationModule(ApplicationPoolImpl.java:2388)
    at oracle.jbo.common.ampool.ApplicationPoolImpl.prepareResource(ApplicationPoolImpl.java:3621)
    at oracle.jbo.pool.ResourcePool.useResource(ResourcePool.java:344)
    at oracle.jbo.common.ampool.ApplicationPoolImpl.doCheckout(ApplicationPoolImpl.java:2200)
    at oracle.jbo.common.ampool.ApplicationPoolImpl.useApplicationModule(ApplicationPoolImpl.java:3088)
    at oracle.jbo.common.ampool.SessionCookieImpl.useApplicationModule(SessionCookieImpl.java:460)
    at oracle.jbo.common.ampool.SessionCookieImpl.useApplicationModule(SessionCookieImpl.java:431)
    at oracle.jbo.common.ampool.SessionCookieImpl.useApplicationModule(SessionCookieImpl.java:426)
    at oracle.jbo.client.Configuration.getApplicationModule(Configuration.java:1494)
    at oracle.jbo.client.Configuration.createRootApplicationModule(Configuration.java:1399)
    at oracle.jbo.client.Configuration.createRootApplicationModule(Configuration.java:1370)
    -Sidd

    Sidd,
    No idea what OraTst is, but based upon the name of your data source, I'd guess you are an Oracle employee using an internal framework. I understand that there are some internal Oracle forums that you can use.
    John

  • How to run a junit test?

    Hi,
    i have compliled a junit test class (MsgQueueTest extends TestCase). When i try to run it, i get:
    kostas@home:~/programming/java/SwarmTests/src$ java MsgQueueTest
    Exception in thread "main" java.lang.NoClassDefFoundError: junit/framework/TestCase
            at java.lang.ClassLoader.defineClass1(Native Method)
            at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
            at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
            at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
            at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
            at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
            at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)I have tried some parameters, but no luck so far. Any ideas?

    Append junit.jar to your CLASSPATH.

  • Portal failed to access remote resource due to network failures

    Hi,
    We have a portlet that allows users to upload files to a SQL Server database and make it available for other users to access. The portlet code is on our remote servers. Everything works fine in dev environment, but certain files fail in pre-prod and prod within the portal, but work fine when the code is executed outside the portal.
    I keep getting this error:
    Error - Portal failed to access remote resource due to network failures. Try again later or contact your portal administrator.     
    What could the problem be?
    Thank you for your help.
    Rad

    If the Studio service looks good on the remote server where Studio is installed (check that
    the service is started and look in the Studio logs for any warnings or errors), you should
    also verify the configuration settings in the Studio remote server object. Is it properly
    configured and pointing to the correct remote server?
    If so, check the portal servers access to the Studio server via the port specified in the remote
    server (default is 11935). You can test this by doing a telnet test on the portal server. In a cmd
    prompt (Windows) or on the CLI (Unix), type 'telnet [studioserver] 11935', where "<servername> is
    the name of your Studio remote server. The screen should just go blank, meaning that there is
    something accepting connections on that port on the given server. (We would hope it's the Studio
    app and not another service occupying that port.) If you get "Could not open connection to the host"
    or some such similar result, check that the network between the portal and the Studio remote server
    is open (ie, make sure there isn't any port blocking or a firewall in place that would hinder the
    communication between the two servers).

  • Access to Resources via Non-admin accounts

    Is there any way to provide access to resources so that they are accessible via
    non-admin accounts. For e.g. to Retrieve my JMSConnectionfactory i do a
    Environment env = new Environment();
    env.setProviderUrl(url);
    env.setSecurityPrincipal(username);
    env.setSecurityCredentials(password);
    Context ctx = env.getInitialContext();
    The username and password here is the admin account. This works fine but if i
    use a non-admin account(member of Operators group), i get exceptions on Domainloghandler
    runtime
    Problem: I need to register a mbean that needs to access JMS Resources. Since
    our deployment team doesnt want to provide us access to admin accounts, we use
    a "operators" group account to register our mbeans. if i do this, i get a
    Access not Allowed for subject:principals=[operator, Operators], on ResourceType:
    DomainLogHandlerRuntime Action: execute Target: registerToMe.
    This happens when my managed resource tries to access a JMS ConnectionFactory.
    Instead if i register my mbeans using the admin account, everything is fine and
    my managed resource works nice.
    This is on weblogic 81 SP1 on Solaris. Please let me know if you need more details.
    Any clues/hints/solutions greatly appreciated. There is not a lot of documentation
    on how to access/register mbeans using non-admin accounts.
    TIA
    Raj

    I have done some more debugging on this and have narrowed down the issue to the
    location where my initialcontext is being obtained.
    so if i register my mbean as a non-admin account and do an operation on the managed
    resource which fetches initial context, i get the below exception. This is how
    i get my initialcontext
    weblogic.jndi.Environment env = new weblogic.jndi.Environment();
    env.setProviderURL("t3://machine:8102,machine:8103");
    env.setSecurityPrincipal("operator");
    env.setSecurityCredentials("operator");
    Context ctx = env.getInitialContext();
    I am doing this from a mbean thats registered on a different managed server(t3://machine:8101)...
    Whats wrong with this?
    TIA
    Raj
    "Raj" <[email protected]> wrote:
    >
    Is there any way to provide access to resources so that they are accessible
    via
    non-admin accounts. For e.g. to Retrieve my JMSConnectionfactory i do
    a
    Environment env = new Environment();
    env.setProviderUrl(url);
    env.setSecurityPrincipal(username);
    env.setSecurityCredentials(password);
    Context ctx = env.getInitialContext();
    The username and password here is the admin account. This works fine
    but if i
    use a non-admin account(member of Operators group), i get exceptions
    on Domainloghandler
    runtime
    Problem: I need to register a mbean that needs to access JMS Resources.
    Since
    our deployment team doesnt want to provide us access to admin accounts,
    we use
    a "operators" group account to register our mbeans. if i do this, i get
    a
    Access not Allowed for subject:principals=[operator, Operators], on ResourceType:
    DomainLogHandlerRuntime Action: execute Target: registerToMe.
    This happens when my managed resource tries to access a JMS ConnectionFactory.
    Instead if i register my mbeans using the admin account, everything is
    fine and
    my managed resource works nice.
    This is on weblogic 81 SP1 on Solaris. Please let me know if you need
    more details.
    Any clues/hints/solutions greatly appreciated. There is not a lot of
    documentation
    on how to access/register mbeans using non-admin accounts.
    TIA
    Raj

  • Unable to run ADFBC JUNIT Test Classes with JDEV11G 11.1.1.6

    Dear All,
    I upgraded my project to the latest release JDEV 11G 11.1.1.6
    Previously we are on JDEV 11G 11.1.1.5
    I have a JUNIT class that I am running which test my ADFBC components.
    public class MyTestClass {
      @Test
      public void testVOAccess()
        //assertions
    }Unfortunately, I am hitting an error like this from the messages.
    Mar 9, 2012 1:28:07 PM oracle.adf.share.ADFContext getCurrent
    WARNING: Automatically initializing a DefaultContext for getCurrent.
    Caller should ensure that a DefaultContext is proper for this use.
    Memory leaks and/or unexpected behaviour may occur if the automatic initialization is performed improperly.
    This message may be avoided by performing initADFContext before using getCurrent().
    For more information please enable logging for oracle.adf.share.ADFContext at FINEST level.
    Mar 9, 2012 1:28:08 PM oracle.security.jps.internal.config.xml.XmlConfigurationFactory initDefaultConfiguration
    SEVERE: org.xml.sax.SAXParseException: Invalid encoding name "Cp1252".
    Mar 9, 2012 1:28:10 PM oracle.mds
    NOTIFICATION: PManager instance is created without multitenancy support as JVM flag "oracle.multitenant.enabled" is not set to enable multitenancy support.
    Mar 9, 2012 1:28:12 PM oracle.security.jps.internal.config.xml.XmlConfigurationFactory initDefaultConfiguration
    SEVERE: org.xml.sax.SAXParseException: Invalid encoding name "Cp1252".
    Mar 9, 2012 1:28:12 PM oracle.adf.share.jndi.ReferenceStoreHelper getReferencesMapEx
    WARNING: Incomplete connection reference object for connection:MYDATASOURCEAt the JUNIT Test Runner, I see this.
    java.lang.ExceptionInInitializerError: null
         java.lang.reflect.Constructor.newInstance(Constructor.java:513)
         org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:171)
         org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:216)
    Caused by: oracle.jbo.DMLException: JBO-26061: Error while opening JDBC connection.
         oracle.jbo.server.ConnectionPool.createConnection(ConnectionPool.java:207)
         oracle.jbo.server.ConnectionPool.instantiateResource(ConnectionPool.java:166)To validate the issue, I tried to run my same project using the older release which is JDEV 11G 11.1.1.5
    and I see that I am not hitting any error. All my test classes runs fine.
    Has anybody replicated this?
    Thanks

    Didier Laurent wrote:
    I logged the following bug for this issue:
    bug 14030895 - REGR: JDEVELOPER 11.1.1.6.0 JUNIT JBO-26061 ERROR WHILE OPENING JDBC CONNECTION
    Regards,
    Didier.So its really a bug..
    I abandon this already since I cannot find any solution to look up for this.
    On the other hand, I am maintaining two jdeveloper version just to get around this problem.
    When testing ADFBC, I used the 11.1.1.5 while for non-junit test I used the 11.1.1.6
    Hopefully this gets fixed on the next release as I am having a hard time swithcing between two JDev version.
    Thanks
    Edited by: Neliel on May 3, 2012 11:42 PM

  • Writing to file in JUnit test case? Not working?

    I have a singleton class called InstantLogger that internally uses a PrintWriter to write to file. It is very basic, has startLogger(String filename), log(String msg), and stopLogger(). startLogger just creates file, log write to file, and stopLogger closes file.
    When I use this class outside of the JUnit test suite it works fine.
    As soon as I use it in a JUnit test it does not write to file. It creates the file (this happens in the TestSuite), but will not write anything to it (when log is called from TestCase). I put a System.out in the log function and I see that, but still nothing writing to file. And I will say it again, it does work in non TestCase scenarios so I know it works.
    Is there something that could be preventing me from writing to file in JUnit TestCase? Could this be a Singleton Issue?
    Thanks,

    avalanche333 wrote:
    I have a singleton class called InstantLogger Ouch.
    that internally uses a PrintWriter to write to file. It is very basic, has startLogger(String filename), log(String msg), and stopLogger(). startLogger just creates file, log write to file, and stopLogger closes file.
    When I use this class outside of the JUnit test suite it works fine.Oh, brother.
    >
    As soon as I use it in a JUnit test it does not write to file. It creates the file (this happens in the TestSuite), but will not write anything to it (when log is called from TestCase). I put a System.out in the log function and I see that, but still nothing writing to file. And I will say it again, it does work in non TestCase scenarios so I know it works.
    Is there something that could be preventing me from writing to file in JUnit TestCase? Could this be a Singleton Issue?Um, no.
    Your code is wrong. You're assuming something that isn't correct. You're also making the assumption that just because it "works" in another context that it's right in all contexts. The two aren't the same, be it configuration or something else.
    Singleton? That GoF pattern has been voted off the island. Didn't you hear?
    http://code.google.com/p/google-singleton-detector/
    %

  • Re: junit test for entity beans ... ejb 3.0

    I'm confused. I'm trying to test my entity bean.
    I have:
    - an entity bean
    - a stateless session bean for accessing the entity bean (facade)
    - an interface for accessing the the stateless bean
    And I'm trying to write a JUnit test class to test this bean. However, I am uncertain as to how to test this (I'm new to EJB 3.0, JBoss and Eclipse).
    What would the JUnit test look like? I'm confused as to whether or not I should be injecting the interface/bean/what???
    I've tried several variations. I either get "NameNotFound" - not bound exceptions or Null pointer exceptions.
    What would the @EJB syntax look like or how would I do it through the context?
    For Example:
    @EJB private TestFacade myTest; //interface to stateless bean ?
    OR
    InitialContext ctx = new InitialContext();
    TestResultFacadeBean myTest = (TestResultFacadeBean) ctx.lookup("localTest");
    I'm confused at to which method I should be using and what object I should be accessing. If I could get either one to work, I'd be happy. :)
    How do I ensure my bean is deployed to the container? What do I need to do?
    If anyone has a simple example or explanation as to which method I should use and how to use it, I'd be very grateful.
    Thanks very much,
    LisaD

    OK, you need to have several layers of testing.
    Layer 0. Test the entity beans are deployable (more on this later). Basically, you need to know that all your annotations work. Things to watch out for are multiple @Id fields in one class or @EmbeddedID or @IdClass in conjuction with @ManyToOne, @ManyToMany, @OneToMany, @OneToOne and fun with @JoinTable, @JoinColumn and @JoinColumns. Once you know how these are supposed to work with the spec, it's not too bad to write it correctly each time. But there are some gotchas that will break things later on.
    Layer 1. Do the functions in the classes that don't depend on annotations work as expected. Typically, this is just going to be the getters and setters in your entity classes. Of course JUnit best practice says we don't bother testing functions that look like:
    public T getX() {
    return this.x;
    or
    public void setX(T x) {
    this.x = x;
    as there is nothing that can go wrong with them. So in that case, your level 1 tests will just be initial values specified from constructors and verifying that the non-get/set pairs work, and that the getters you have tagged @Transient work (because you've likely put some logic in them)
    Layer 2. Test the session bean methods that don't require injection to work.
    Layer 3. Test the session bean methods that require injection (Mock Objects). Simulate the injection for yourself, injecting Mock Objects for the entity manager. Then you can confirm that the correct methods are being called in the correct sequences, etc.
    [Note this may require some skill in designing the mock.  I'm working on developing my own entitymanager mock, and if it looks usefull I'll release it to the world.
    Layer 4. Test the session bean methods that require injection (Real entity manager) (See Layer 0)
    For this you will need an out of container persistence implementation.  Currently Hibernate and Glassfish provide beta versions.  You will need a different persistence.xml file that lists all the entities.  You will have to use reflection to inject the entity manager(s) that you create from an entity manager factory unless you provide a constructor that takes an EntityManager as a parameter.  You may need to use reflection to call any @PostConstruct method if you made it private.
    Layer 5. Navigate the relationships in the objects returned from Layer 4 using a database that has been loaded with test data.
    I am currently using Layers 0, 1, 2 & 4 to test my session beans and entity beans.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Unable to access local resources or RDP over VPN Connection

    Dear Tech People.
    I have a Windows 7 computer that I have created a VPN service through Windows on.  I am able to connect to the VPN from outside of my network with my Macbook Air.  However, I am unable to connect to the computer via RDP, nor can I ping my PC that
    I am VPN'd into (192.168.1.252).  When I am connected, the IP address that I am assigned, is 192.168.1.150.  When I run ipconfig /all, I can see the "RAS < Dial In> Interface for VPN, and it is setup with an ip address of 192.168.1.151
    with a /32 subnet mask.  There is no default gateway listed, which is why I believe that this is not working.  I cannot determine any way to make this change.
    Basically, I have a VPN connection that I can do nothing with.  I cannot access shared resources, nor can I start a remote desktop session.  The pass through is setup for PPTP with my router, which I believe is working, as I couldn't even connect
    prior to this.  Below is the full results of my ipconfig /all command on my Windows PC:
    C:\Users\Zach>ipconfig /all
    Windows IP Configuration
       Host Name . . . . . . . . . . . . : Serenity
       Primary Dns Suffix  . . . . . . . :
       Node Type . . . . . . . . . . . . : Hybrid
       IP Routing Enabled. . . . . . . . : Yes
       WINS Proxy Enabled. . . . . . . . : No
       DNS Suffix Search List. . . . . . : att.net
    PPP adapter RAS (Dial In) Interface:
       Connection-specific DNS Suffix  . :
       Description . . . . . . . . . . . : RAS (Dial In) Interface
       Physical Address. . . . . . . . . :
       DHCP Enabled. . . . . . . . . . . : No
       Autoconfiguration Enabled . . . . : Yes
       IPv4 Address. . . . . . . . . . . : 192.168.1.151(Preferred)
       Subnet Mask . . . . . . . . . . . : 255.255.255.255
       Default Gateway . . . . . . . . . :
       NetBIOS over Tcpip. . . . . . . . : Enabled
    Ethernet adapter Local Area Connection:
       Connection-specific DNS Suffix  . : att.net
       Description . . . . . . . . . . . : Broadcom NetLink (TM) Gigabit Ethernet
       Physical Address. . . . . . . . . : BC-5F-F4-85-5E-A8
       DHCP Enabled. . . . . . . . . . . : Yes
       Autoconfiguration Enabled . . . . : Yes
       IPv6 Address. . . . . . . . . . . : 2602:306:ce94:2570:3144:306c:cdae:d615(Pr
    eferred)
       Temporary IPv6 Address. . . . . . : 2602:306:ce94:2570:bd83:220:80a0:eb1e(Pre
    ferred)
       Link-local IPv6 Address . . . . . : fe80::3144:306c:cdae:d615%11(Preferred)
       IPv4 Address. . . . . . . . . . . : 192.168.1.252(Preferred)
       Subnet Mask . . . . . . . . . . . : 255.255.255.0
       Lease Obtained. . . . . . . . . . : Saturday, October 26, 2013 7:27:27 PM
       Lease Expires . . . . . . . . . . : Thursday, October 31, 2013 7:28:28 AM
       Default Gateway . . . . . . . . . : fe80::22e5:64ff:fe0c:5640%11
                                           192.168.1.254
       DHCP Server . . . . . . . . . . . : 192.168.1.254
       DHCPv6 IAID . . . . . . . . . . . : 247226356
       DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-19-2E-8E-B2-BC-5F-F4-85-5E-A8
       DNS Servers . . . . . . . . . . . : 192.168.1.254
       NetBIOS over Tcpip. . . . . . . . : Enabled
    Ethernet adapter VMware Network Adapter VMnet1:
       Connection-specific DNS Suffix  . :
       Description . . . . . . . . . . . : VMware Virtual Ethernet Adapter for VMnet
    1
       Physical Address. . . . . . . . . : 00-50-56-C0-00-01
       DHCP Enabled. . . . . . . . . . . : No
       Autoconfiguration Enabled . . . . : Yes
       Link-local IPv6 Address . . . . . : fe80::d906:32d3:7108:1227%15(Preferred)
       Autoconfiguration IPv4 Address. . : 169.254.18.39(Preferred)
       Subnet Mask . . . . . . . . . . . : 255.255.0.0
       Default Gateway . . . . . . . . . :
       DHCPv6 IAID . . . . . . . . . . . : 335564886
       DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-19-2E-8E-B2-BC-5F-F4-85-5E-A8
       DNS Servers . . . . . . . . . . . : fec0:0:0:ffff::1%1
                                           fec0:0:0:ffff::2%1
                                           fec0:0:0:ffff::3%1
       NetBIOS over Tcpip. . . . . . . . : Enabled
    Ethernet adapter VMware Network Adapter VMnet8:
       Connection-specific DNS Suffix  . :
       Description . . . . . . . . . . . : VMware Virtual Ethernet Adapter for VMnet
    8
       Physical Address. . . . . . . . . : 00-50-56-C0-00-08
       DHCP Enabled. . . . . . . . . . . : No
       Autoconfiguration Enabled . . . . : Yes
       Link-local IPv6 Address . . . . . : fe80::fc76:1de8:a7c3:27dd%16(Preferred)
       IPv4 Address. . . . . . . . . . . : 192.168.135.1(Preferred)
       Subnet Mask . . . . . . . . . . . : 255.255.255.0
       Default Gateway . . . . . . . . . :
       DHCPv6 IAID . . . . . . . . . . . : 352342102
       DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-19-2E-8E-B2-BC-5F-F4-85-5E-A8
       DNS Servers . . . . . . . . . . . : fec0:0:0:ffff::1%1
                                           fec0:0:0:ffff::2%1
                                           fec0:0:0:ffff::3%1
       NetBIOS over Tcpip. . . . . . . . : Enabled
    Tunnel adapter isatap.{6E06F030-7526-11D2-BAF4-00600815A4BD}:
       Media State . . . . . . . . . . . : Media disconnected
       Connection-specific DNS Suffix  . :
       Description . . . . . . . . . . . : Microsoft ISATAP Adapter
       Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
       DHCP Enabled. . . . . . . . . . . : No
       Autoconfiguration Enabled . . . . : Yes
    Tunnel adapter Teredo Tunneling Pseudo-Interface:
       Media State . . . . . . . . . . . : Media disconnected
       Connection-specific DNS Suffix  . :
       Description . . . . . . . . . . . : Teredo Tunneling Pseudo-Interface
       Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
       DHCP Enabled. . . . . . . . . . . : No
       Autoconfiguration Enabled . . . . : Yes
    Tunnel adapter isatap.att.net:
       Media State . . . . . . . . . . . : Media disconnected
       Connection-specific DNS Suffix  . : att.net
       Description . . . . . . . . . . . : Microsoft ISATAP Adapter #2
       Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
       DHCP Enabled. . . . . . . . . . . : No
       Autoconfiguration Enabled . . . . : Yes
    Tunnel adapter isatap.{20B8F51C-F852-41EF-9F9B-1D0107550D1E}:
       Media State . . . . . . . . . . . : Media disconnected
       Connection-specific DNS Suffix  . :
       Description . . . . . . . . . . . : Microsoft ISATAP Adapter #3
       Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
       DHCP Enabled. . . . . . . . . . . : No
       Autoconfiguration Enabled . . . . : Yes
    Tunnel adapter isatap.{8CCEC9EC-0685-4C6A-A87A-CED27B6C93E5}:
       Media State . . . . . . . . . . . : Media disconnected
       Connection-specific DNS Suffix  . :
       Description . . . . . . . . . . . : Microsoft ISATAP Adapter #4
       Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
       DHCP Enabled. . . . . . . . . . . : No
       Autoconfiguration Enabled . . . . : Yes
    Any thoughts or help would be greatly appreciated.

    Hi,
    I'm so glad you have solved the issue in this way.
    And thanks for your sharing, your solution shared here will provie other people in this forum with a great help!
    Regards,
    Ada Liu
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • Hybrid Remote App Unable to Access this resource

    I am having a difficult time getting my Hybrid remote app to authenticate properly. Configuration is as follows:
    Hybrid Remote App collection with S2S VPN between remote app VNet and Azure VNet following the guide:
    http://blogs.msdn.com/b/rds/archive/2014/07/21/how-to-link-azure-remoteapp-to-an-existing-vnet.aspx
    Client Server model Application with the Client installed on custom remote app image and server side on azure Vnet along with a cloud DC
    DC Syncing with Azure AD using AAD Sync Services and utilizing the mail attribute for AAD Login ID
    Remote App deploys successfully and joins to the domain (I can see the computer objects in the specified OU). I am able to publish my apps an assign user access. I am also able login through the azure remote app application and see my published apps. 
    However once I try to launch the remote app it prompts me once again to login, which I do, then it hangs for a while before erroring out with the following message
    "An error occurred while remote desktop connection was accessing this resource. Retry the connection or contact your system administrator."
    Since this is a hybrid deployment I am able to login to the session host OS.  Whenever I do I am logged in with a temporary profile (I am not sure if this is normal or not).  I see very little in the event logs on the session host, nor the DC.
    I have verified connectivity between the remote app and the DC through ping both ways. The S2S VPN is up and functioning properly.  The session host and the DC have access to other domain resources and the web.  I have also seen documentation
    on a "'Known Issue" with this error related to large profile disks but this does not apply as I have never been able to successfully launch the app.  Any assistance with be greatly appreciated I am at my wits end. Please let me know
    if I can add any additional information that would help solve the issue.

    Hi,
    Do you have the User Principal Name (UPN) suffix that you are using configured in your Active Directory?  For example, say you use
    [email protected] for the initial sign on to Azure RemoteApp, and when you launch an application you also enter
    [email protected] in the second authentication prompt.  Is
    [email protected] a valid UPN in your cloud Active Directory--the AD that is hosted on your DCs?
    -TP

Maybe you are looking for

  • Comparing SQL data in the same table for two different dates

    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 Hello, We have a batch scheduling tool that automatically runs Oracle jobs and when it runs the jobs it stores a record from the instance in a table. I am trying to write a query that pulls up

  • Why are my PDF file icons/files missing from Docs?

    Using Windows Vista 7 -a few years old but never had any problems... I'm writing a film script on an old version of Final Draft (5) -it was working great until a few weeks ago. Suddenly, all the PDF icons were gone when I went to look for saved PDF f

  • How to save to data into another file in the Report Generation Toolkit

    I read a doc template and wirte many data and bmp into it. I want to create a new doc file with my own name, But in my test, data will be writen into my template. If user don't notice it, my template will be overriden. Can I save to a new file in my

  • How i remove the stand from an Intel iMac 17"  ???

    Please help...is it possible to remove the stand from an intel based imac 17" . If yes how i do it? Thank you

  • FCP User Manual viewer

    OK, this seems like it wouldn't be a FCP question, but hopefully someone has the answer: I needed to look something up in the manual, so I went Help --> User Manual and it opened up in Adobe Reader. It used to open up in Preview. Preview has a much f