cancel
Showing results for 
Search instead for 
Did you mean: 

bizarre ClassCastException in JUnit test.

Former Member
0 Kudos
 @RunWith(HybrisJUnit4ClassRunner.class)
 @IntegrationTest
 @Transactional(noRollback = false)
 public class ProductConsolidationServiceTest extends ServicelayerTransactionalTest {
     @test
     public void test() {
         CatalogModel productCatalog = modelService.create(CatalogModel.class);
         MyProductModel p = modelService.create(MyProductModel.class);
     }
 }

The line that creates the CatalogModel works fine. The line that creates the MyProductModel throws a ClassCastException: java.lang.ClassCastException: de.hybris.platform.core.model.product.ProductModel cannot be cast to com.my.generated.core.model.MyProductModel

This line works fine in Master tenant, just not in JUnit tests.

Why is this happening?

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Chao,

As you mentioned, test runs fine in Ant but not in Ee, If this is the case, you probably do not have all configured extensions of your localextensions.xml file registered at the classpath of the Ee JUnit test configuration. Please try the following steps:

Open the Run menu -> click Run Configurations to open Run Configurations dialog box.

In the Run Configurations dialog box, select your test configuration.

Navigate to the Classpath tab.

Select the platform folder.

Click the Add Projects button. In the Project Selection dialog box, select all extensions you have configured in the localextensions.xml file.

Regards,

Reena

Answers (6)

Answers (6)

Former Member
0 Kudos
  • have you run ant junitinit or updated the junit tenant from the hac? I understand the test passes with ant but I'm questioning that pnyway because the symptom is similar to what you get with a non existing MyProductModel itemtype in the database. Or is ee using the same database as ant?

  • do you have warnings in the logs of the junit test execution containing MyProductModel keyword?

0 Kudos

Hi Chao I reproduced the exact same thing on my platform, everything seems ok and the test runs with out any problems.

Regards

Former Member
0 Kudos

Also in DefaultModelService's converterRegistry doesn't contain MyProductModel...is that a problem? This causes my DefaultModelService.create method to return a ProductModel instead of a MyProductModel

Former Member
0 Kudos

The test runs fine with with Ant, just not in Ee. Any ideas?

0 Kudos

Hi Will you refresh your platform project and search for MyProductModel.class? is it created? Regards

Former Member
0 Kudos

The model is there. However that is a good point, let me try to run this with Ant instead of Ee.

0 Kudos

Hu Can you send me your item.xml file?

Regards

Former Member
0 Kudos

here:

itemtype code="MyProduct" extends="Product" autocreate="true" generate="true"