Hi Quintin,

Sorry I for the delay in responding to your other mails. I've picked up your
latest code and it runs perfectly on my machine now - thanks for that. I'll
have play around with this some more when I get home this evening.

Jon



On Mon, Sep 28, 2009 at 11:21 AM, Quintin Beukes <[email protected]>wrote:

> Uploaded another one. Accidentally left the spring dependencies of my
> project in the POM (like I mentioned it comes from my project).
>
> Quintin Beukes
>
>
>
> On Mon, Sep 28, 2009 at 12:16 PM, Quintin Beukes <[email protected]>
> wrote:
> > I'm not sure how to remove files from JIRA, so both are still there.
> > Just check the upload times or the SNAPSHOT version number (which is a
> > date/time).
> >
> > Quintin Beukes
> >
> >
> >
> > On Mon, Sep 28, 2009 at 12:14 PM, Quintin Beukes <[email protected]>
> wrote:
> >> OK. Stupid little bug. To fix it, change in the class
> >> 'src/main/org/apache/openejb/junit/context/OpenEjbTestContext.java
> >> line 125, change
> >>      if (config.containsKey(REALM_PROPERTY_KEY))
> >>      {
> >>        String loginConfig =
> >>
> OpenEjbTestContext.class.getResource(LOGIN_CONFIG_RESOURCE).toExternalForm();
> >>        System.out.println("Got the property : " + loginConfig);
> >>        System.setProperty("java.security.auth.login.config",
> >> URLDecoder.decode(loginConfig));
> >>      }
> >>
> >> To:
> >>      String loginConfig =
> >>
> OpenEjbTestContext.class.getResource(LOGIN_CONFIG_RESOURCE).toExternalForm();
> >>      System.setProperty("java.security.auth.login.config",
> >> URLDecoder.decode(loginConfig));
> >>
> >> I uploaded a new one to the same JIRA which has this fix applied. So
> >> you could alternatively just download the new one.
> >>
> >> The problem was that the system property was not set when OpenEJB
> >> started up, due to some minor difference in ordering I suppose? I
> >> assume at the time the first InitialContext was created, the role
> >> wasn't specified yet.
> >>
> >> My bad. Curious that JDK6u11 runs it perfectly fine on both my machines.
> >>
> >> Though I still don't feel right doing it this way :/
> >>
> >> Quintin Beukes
> >>
> >>
> >>
> >> On Mon, Sep 28, 2009 at 11:32 AM, Quintin Beukes <[email protected]>
> wrote:
> >>> Hey,
> >>>
> >>> I just download the tarball from the JIRA onto my office machine. Then
> >>> I extracted it and ran mvn install, this is what I got:
> >>>
> >>> quin...@quintin-desktop openejb-junit $ mvn install
> >>> [INFO] Scanning for projects...
> >>> [INFO]
> ------------------------------------------------------------------------
> >>> [INFO] Building openejb-junit
> >>> [INFO]    task-segment: [install]
> >>> [INFO]
> ------------------------------------------------------------------------
> >>> [INFO] [resources:resources {execution: default-resources}]
> >>> [WARNING] Using platform encoding (UTF-8 actually) to copy filtered
> >>> resources, i.e. build is platform dependent!
> >>> [INFO] Copying 2 resources
> >>> [INFO] [compiler:compile {execution: default-compile}]
> >>> [INFO] Compiling 12 source files to
> >>> /home/quintin/dev/openejb/openejb-junit/target/classes
> >>> [INFO] [resources:testResources {execution: default-testResources}]
> >>> [WARNING] Using platform encoding (UTF-8 actually) to copy filtered
> >>> resources, i.e. build is platform dependent!
> >>> [INFO] Copying 3 resources
> >>> [INFO] [compiler:testCompile {execution: default-testCompile}]
> >>> [INFO] Compiling 15 source files to
> >>> /home/quintin/dev/openejb/openejb-junit/target/test-classes
> >>> [INFO] [surefire:test {execution: default-test}]
> >>> [INFO] Surefire report directory:
> >>> /home/quintin/dev/openejb/openejb-junit/target/surefire-reports
> >>>
> >>> -------------------------------------------------------
> >>>  T E S T S
> >>> -------------------------------------------------------
> >>> Running org.apache.openejb.junit.TestEjbSecurity
> >>> Apache OpenEJB 3.1.2-SNAPSHOT    build: 20090827-09:05
> >>> http://openejb.apache.org/
> >>> INFO - openejb.home = /home/quintin/dev/openejb/openejb-junit
> >>> INFO - openejb.base = /home/quintin/dev/openejb/openejb-junit
> >>> INFO - Configuring Service(id=Default Security Service,
> >>> type=SecurityService, provider-id=Default Security Service)
> >>> INFO - Configuring Service(id=Default Transaction Manager,
> >>> type=TransactionManager, provider-id=Default Transaction Manager)
> >>> INFO - Found EjbModule in classpath:
> >>> /home/quintin/dev/openejb/openejb-junit/target/test-classes
> >>> INFO - Beginning load:
> >>> /home/quintin/dev/openejb/openejb-junit/target/test-classes
> >>> INFO - Configuring enterprise application: classpath.ear
> >>> INFO - Configuring Service(id=Default Stateless Container,
> >>> type=Container, provider-id=Default Stateless Container)
> >>> INFO - Auto-creating a container for bean SecuredEjb:
> >>> Container(type=STATELESS, id=Default Stateless Container)
> >>> INFO - Enterprise application "classpath.ear" loaded.
> >>> INFO - Assembling app: classpath.ear
> >>> INFO - Jndi(name=SecuredEjbLocal) --> Ejb(deployment-id=SecuredEjb)
> >>> INFO - Jndi(name=BasicEjbLocal) --> Ejb(deployment-id=BasicEjb)
> >>> INFO - Created Ejb(deployment-id=SecuredEjb, ejb-name=SecuredEjb,
> >>> container=Default Stateless Container)
> >>> INFO - Created Ejb(deployment-id=BasicEjb, ejb-name=BasicEjb,
> >>> container=Default Stateless Container)
> >>> INFO - Deployed Application(path=classpath.ear)
> >>> INFO - Logging in
> >>> INFO - Logging in
> >>> INFO - Logging in
> >>> Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.791
> sec
> >>> Running org.apache.openejb.junit.context.ContextWrapperStatementTest
> >>> Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.027
> sec
> >>> Running org.apache.openejb.junit.TestEjbBasic
> >>> Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.006
> sec
> >>> Running org.apache.openejb.junit.TestMethodConfigProperties
> >>> Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.006
> sec
> >>> Running org.apache.openejb.junit.TestClassConfigFileAndProperties
> >>> Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.002
> sec
> >>> Running org.apache.openejb.junit.TestClassConfigFile
> >>> Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.003
> sec
> >>> Running org.apache.openejb.junit.TestDualConfigOverride
> >>> Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.004
> sec
> >>> Running org.apache.openejb.junit.TestRunner
> >>> Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.003
> sec
> >>> Running org.apache.openejb.junit.TestMethodConfigFile
> >>> Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.002
> sec
> >>> Running org.apache.openejb.junit.context.UtilTest
> >>> Tests run: 10, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.011
> sec
> >>> Running org.apache.openejb.junit.TestClassConfigProperties
> >>> Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.002
> sec
> >>>
> >>> Results :
> >>>
> >>> Tests run: 33, Failures: 0, Errors: 0, Skipped: 0
> >>>
> >>> [INFO] [jar:jar {execution: default-jar}]
> >>> [INFO] Building jar:
> >>>
> /home/quintin/dev/openejb/openejb-junit/target/openejb-junit-0.1-SNAPSHOT.jar
> >>> [INFO] [install:install {execution: default-install}]
> >>> [INFO] Installing
> >>>
> /home/quintin/dev/openejb/openejb-junit/target/openejb-junit-0.1-SNAPSHOT.jar
> >>> to
> /home/quintin/.m2/repository/org/apache/openejb/openejb-junit/0.1-SNAPSHOT/openejb-junit-0.1-SNAPSHOT.jar
> >>> [INFO]
> ------------------------------------------------------------------------
> >>> [INFO] BUILD SUCCESSFUL
> >>> [INFO]
> ------------------------------------------------------------------------
> >>> [INFO] Total time: 1 minute 9 seconds
> >>> [INFO] Finished at: Mon Sep 28 11:22:52 SAST 2009
> >>>
> >>> Can you perhaps send me your full output.
> >>>
> >>> And, are you perhaps running in JDK5? I haven't tested it in JDK5. I
> >>> just did so an found I get the same error. I will be updating it for
> >>> JDK5 today, which should probably fix the error. Thanks for the input.
> >>>
> >>> Quintin Beukes
> >>>
> >>>
> >>>
> >>> On Mon, Sep 28, 2009 at 12:55 AM, Jonathan Gallimore
> >>> <[email protected]> wrote:
> >>>> Just had a quick play with this, it  looks really nice. Thanks for a
> great
> >>>> contribution. I think it would be good to get this added to subversion
> and
> >>>> some info up on the website. I'm happy to get this in, anyone got any
> >>>> thoughts about where it goes (under openejb3 or somewhere else)?
> >>>>
> >>>> One problem I did run into was this error running the TestEjbSecurity
> test
> >>>> case:
> >>>>
> >>>> java.lang.RuntimeException: Failed to configure object.
> >>>>    at
> >>>>
> org.apache.openejb.junit.context.OpenEjbTestContext.configureTest(OpenEjbTestContext.java:109)
> >>>>    at
> >>>>
> org.apache.openejb.junit.context.ContextWrapperStatement.evaluate(ContextWrapperStatement.java:44)
> >>>>    at
> >>>>
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
> >>>>    at
> >>>>
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
> >>>>    at
> org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
> >>>>    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
> >>>>    at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
> >>>>    at
> >>>>
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
> >>>>    at
> >>>>
> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
> >>>>    at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
> >>>>    at
> org.apache.openejb.junit.OpenEjbRunner.run(OpenEjbRunner.java:133)
> >>>>    at
> >>>>
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
> >>>>    at
> >>>>
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> >>>>    at
> >>>>
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
> >>>>    at
> >>>>
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
> >>>>    at
> >>>>
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
> >>>>    at
> >>>>
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
> >>>> Caused by: javax.naming.AuthenticationException: User could not be
> >>>> authenticated: RoleA [Root exception is
> >>>> javax.security.auth.login.LoginException: No LoginModules configured
> for
> >>>> OpenEjbJunitSecurityRealm]
> >>>>    at
> >>>>
> org.apache.openejb.client.LocalInitialContext.login(LocalInitialContext.java:127)
> >>>>    at
> >>>>
> org.apache.openejb.client.LocalInitialContext.<init>(LocalInitialContext.java:77)
> >>>>    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
> Method)
> >>>>    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown
> Source)
> >>>>    at
> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown
> >>>> Source)
> >>>>    at java.lang.reflect.Constructor.newInstance(Unknown Source)
> >>>>    at
> >>>>
> org.apache.openejb.client.LocalInitialContextFactory.getLocalInitialContext(LocalInitialContextFactory.java:86)
> >>>>    at
> >>>>
> org.apache.openejb.client.LocalInitialContextFactory.getInitialContext(LocalInitialContextFactory.java:43)
> >>>>    at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
> >>>>    at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
> >>>>    at javax.naming.InitialContext.init(Unknown Source)
> >>>>    at javax.naming.InitialContext.<init>(Unknown Source)
> >>>>    at
> >>>>
> org.apache.openejb.junit.context.OpenEjbTestContext.getInitialContext(OpenEjbTestContext.java:130)
> >>>>    at
> >>>>
> org.apache.openejb.junit.context.OpenEjbTestContext.configureTest(OpenEjbTestContext.java:97)
> >>>>    ... 16 more
> >>>> Caused by: javax.security.auth.login.LoginException: No LoginModules
> >>>> configured for OpenEjbJunitSecurityRealm
> >>>>    at javax.security.auth.login.LoginContext.init(Unknown Source)
> >>>>    at javax.security.auth.login.LoginContext.<init>(Unknown Source)
> >>>>    at
> >>>>
> org.apache.openejb.core.security.SecurityServiceImpl.login(SecurityServiceImpl.java:74)
> >>>>    at
> >>>>
> org.apache.openejb.core.security.SecurityServiceImpl.login(SecurityServiceImpl.java:35)
> >>>>    at
> >>>>
> org.apache.openejb.client.LocalInitialContext.login(LocalInitialContext.java:123)
> >>>>    ... 29 more
> >>>>
> >>>>
> >>>> I guess there's something extra I need in my setup, any thoughts? (I
> admit I
> >>>> haven't tried particularly hard to troubleshoot it yet - its getting
> late,
> >>>> but I'll have another go tomorrow!),
> >>>>
> >>>> Cheers
> >>>>
> >>>> Jon
> >>>>
> >>>> On Sun, Sep 27, 2009 at 8:16 PM, Quintin Beukes <[email protected]>
> wrote:
> >>>>
> >>>>> Hey,
> >>>>>
> >>>>> The previous runner I started modifying extensively to customize for
> >>>>> our company's tests. I already had a small testing framework for the
> >>>>> tests, which used Spring to initial OpenEJB and do the lookups. I
> >>>>> changed this to use the runner technique.
> >>>>>
> >>>>> Then over the weekend I decided to extract the runner code into an
> >>>>> openejb-junit project, and make it extensible so I could use the
> >>>>> library's code and only extend to give our tests the same
> >>>>> functionality.
> >>>>>
> >>>>> This is what I came up with:
> >>>>> https://issues.apache.org/jira/browse/OPENEJB-1078
> >>>>>
> >>>>> The JUnit tests demonstrate it's behaviour. These 3 tests are the
> best
> >>>>> examples:
> >>>>> org.apache.openejb.junit.TestEjbBasic
> >>>>> org.apache.openejb.junit.TestEjbSecurity
> >>>>> org.apache.openejb.junit.TestDualConfigOverride
> >>>>>
> >>>>> It supports class level configuration of the InitialContext, and then
> >>>>> method specific configurations. You can configure the InitialContext
> >>>>> from a file, or by directly specifying properties. You can have
> >>>>> OpenEJB do any of it's supported injections, or you can have the
> >>>>> runner inject the InitialContext (or it's initialization Properties
> >>>>> object) and do your own lookups. You can specify as which role to
> load
> >>>>> the InitialContext (basically a RunAs).
> >>>>>
> >>>>> I'm planning on doing resource configurations, such as datasources.
> >>>>> Any other suggestions, please throw them my way. And please send me
> >>>>> feedback. So far it's working very well for my tests. I have yet to
> >>>>> complete the spring modification, but for those tests which don't
> >>>>> require it, it works very well. Especially the role tests.
> >>>>>
> >>>>> Not that it still doesn't support JUnit 3. If you require JUnit 3,
> let
> >>>>> me know and I'll prioritize implementing JUnit 3 support.
> >>>>>
> >>>>> An basic example would be the following:
> >>>>> @RunWith(OpenEjbRunner.class)
> >>>>> @ContextConfig(
> >>>>>  properties={
> >>>>>
> >>>>>
>  
> @Property("java.naming.factory.initial=org.apache.openejb.client.LocalInitialContextFactory")
> >>>>>  }
> >>>>> )
> >>>>> @LocalClient
> >>>>> public class TestEjbSecurity
> >>>>> {
> >>>>>  @EJB
> >>>>>  private MyBusinessBean myBean;
> >>>>>
> >>>>>  @TestResource
> >>>>>  private InitialContext currentInitialContext;
> >>>>>
> >>>>>  @Test
> >>>>>  @ContextConfig(
> >>>>>    securityRole="Admin"
> >>>>>  )
> >>>>>  public void testAsAdmin()
> >>>>>  {
> >>>>>    myBean.someMethod();
> >>>>>    currentInitialContext.lookup("some/custom/lookup");
> >>>>>  }
> >>>>>
> >>>>>  @Test
> >>>>>  @ContextConfig(
> >>>>>    propertiesFile="/META-INF/employee-context.properties",
> >>>>>    securityRole="Employe"
> >>>>>  )
> >>>>>  public void testAsEmployee()
> >>>>>  {
> >>>>>    myBean.someMethod();
> >>>>>  }
> >>>>> }
> >>>>>
> >>>>> Quintin Beukes
> >>>>>
> >>>>
> >>>
> >>
> >
>

Reply via email to