EOModels not loaded for projects in Java Build Path during unit tests

From: Denis Frolov (de..emax.ru)
Date: Thu Aug 03 2006 - 08:01:13 EDT

  • Next message: Ian McDougall: "Re: EOModels not loaded for projects in Java Build Path during unit tests"

    Hi,

    I have two projects in Eclipse: MyProject and MyProjectBusinessLogic.
    MyProjectBusinessLogic is specified in Projects tab of Java Build Path
    section in MyProject's Properties.

    I have one unit test extending ERXTestCasa with the following code:

        public void setUp() throws Exception {
            super.setUp();
            WOApplication.primeApplication(null,
    NSBundle.mainBundle().bundlePathURL(), null);
        }

        public void testCustomerValidates() {
            Customer customer = (Customer)
    EOUtilities.createAndInsertInstance(editingContext(), "Customer");
            assertValidates(false, customer);
        }

    Customer is an entity of model in MyProjectBusinessLogic

    When I run the unit test via Eclipse Junit launcher I get the following
    error and exception:

    ERROR (ERXEntityClassDescription.java:321) - Entity Customer not found in
    the default model group!

    java.lang.NullPointerException at
    er.extensions.ERXEntityClassDescription$Factory.registerDescriptionForEntity
    (ERXEntityClassDescription.java:516) at
    er.extensions.ERXEntityClassDescription$Factory.classDescriptionNeededForEnt
    ityName(ERXEntityClassDescription.java:322) at
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
    ) at
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
    .java:25) at java.lang.reflect.Method.invoke(Method.java:324) at
    com.webobjects.foundation.NSSelector._safeInvokeMethod(NSSelector.java:120)
    at
    com.webobjects.foundation.NSNotificationCenter$_Entry.invokeMethod(NSNotific
    ationCenter.java:601) at
    com.webobjects.foundation.NSNotificationCenter.postNotification(NSNotificati
    onCenter.java:545) at
    com.webobjects.foundation.NSNotificationCenter.postNotification(NSNotificati
    onCenter.java:559) at
    com.webobjects.eocontrol.EOClassDescription.classDescriptionForEntityName(EO
    ClassDescription.java:297) at
    com.webobjects.eoaccess.EOUtilities.createAndInsertInstance(EOUtilities.java
    :814) at
    dm.inmega.tests.SimpleTest.testCustomerValidates(SimpleTest.java:30) at
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
    ) at
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
    .java:25) at java.lang.reflect.Method.invoke(Method.java:324) at
    junit.framework.TestCase.runTest(TestCase.java:154) at
    er.testrunner.ERXTestCase.runBare(ERXTestCase.java:95) at
    junit.framework.TestResult$1.protect(TestResult.java:106) at
    junit.framework.TestResult.runProtected(TestResult.java:124) at
    junit.framework.TestResult.run(TestResult.java:109) at
    junit.framework.TestCase.run(TestCase.java:118) at
    junit.framework.TestSuite.runTest(TestSuite.java:208) at
    junit.framework.TestSuite.run(TestSuite.java:203) at
    org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3T
    estReference.java:128) at
    org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:3
    8) at
    org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRu
    nner.java:460) at
    org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRu
    nner.java:673) at
    org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.
    java:386) at
    org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner
    .java:196) If I load the model manually by calling:

            EOModelGroup.defaultGroup().addModelWithPathURL(new
    File(pathToModel).toURL());

    I get the same error and another exception:

     ERROR (ERXEntityClassDescription.java:321) - Entity Customer not found in
    the default model group! at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:141) at
    com.webobjects.foundation._NSUtilities._classWithPartialName(_NSUtilities.ja
    va:307) at
    com.webobjects.foundation._NSUtilities.classWithName(_NSUtilities.java:291)
    at
    com.webobjects.eoaccess.EOModel._setEntityForEntityNameClassName(EOModel.jav
    a:1242) at
    com.webobjects.eoaccess.EOModel._addFakeEntityWithPropertyList(EOModel.java:
    1280) at
    com.webobjects.eoaccess.EOModel._initWithTableOfContentsPropertyListPathURL(
    EOModel.java:1092) at
    com.webobjects.eoaccess.EOModel.<init>(EOModel.java:802) at
    com.webobjects.eoaccess.EOModelGroup.addModelWithPathURL(EOModelGroup.java:4
    98) at
    dm.inmega.tests.SimpleTest.testCustomerValidates(SimpleTest.java:32) at
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
    ) at
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
    .java:25) at java.lang.reflect.Method.invoke(Method.java:324) at
    junit.framework.TestCase.runTest(TestCase.java:154) at
    er.testrunner.ERXTestCase.runBare(ERXTestCase.java:95) at
    junit.framework.TestResult$1.protect(TestResult.java:106) at
    junit.framework.TestResult.runProtected(TestResult.java:124) at
    junit.framework.TestResult.run(TestResult.java:109) at
    junit.framework.TestCase.run(TestCase.java:118) at
    junit.framework.TestSuite.runTest(TestSuite.java:208) at
    junit.framework.TestSuite.run(TestSuite.java:203) at
    org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3T
    estReference.java:128) at
    org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:3
    8) at
    org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRu
    nner.java:460) at
    org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRu
    nner.java:673) at
    org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.
    java:386) at
    org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner
    .java:196) Caused by: java.lang.ClassCastException at
    dm.inmega.Administrator.<clinit>(Administrator.java:34) ... 28 more

    Administrator is also an entity in MyProjectBusinessLogic and line 34 is:

        public static AdministratorClazz clazz =
    (AdministratorClazz)EOEnterpriseObjectClazz.clazzForEntityNamed("Administrat
    or"); Is there a solution to this problem other that removing
    MyProjectBusinessLogic from Projects in Java Build Path of MyProject? There
    should be since to my mind this setup is pretty common.

    ---
    Denis Frolov
    Media Agency Design Maximum
    

    Tel: +7 863 2648211 Fax: +7 863 2645229 Web: http://www.designmaximum.com



    This archive was generated by hypermail 2.0.0 : Thu Aug 03 2006 - 08:01:22 EDT