Hi , Is it possible in Junits to lookup the DomainObjectContainer instance to set it in my isis service to query, persist and merge entities.
Actually my Usecase is that I have a Isis service whose method(upload) calls a component which unmarshall input excel file and performs bulk insert and bulk update into the database. For persisting this component requires DomainObjectContainer. When this application is run in jetty server, DomainObjectContainer instance is obtained by injecting it in my service class. But in Junits how can I obtain it. I tried with @Mock annotation for DomainObjectContainer and JunitRuleMockery2, but it seems that it requires some expectations before calling service upload. So it failed asking for expectations to be set on DomainObjectContainer as it is used in querying, persisting. Error is : java.lang.AssertionError: unexpected invocation: mockContainer.firstMatch(<org.apache.isis.applib.query.QueryDefault@789144>) no expectations specified: did you... - forget to start an expectation with a cardinality clause? - call a mocked method to specify the parameter of an expectation? what happened before this: nothing! Then I set the expectation on mockContainer for the method firstMatch: oneOf(mockContainer).firstMatch(new QueryDefault<MOrganisation>( MOrganisation.class, "fetch_orgnaisation_by_id", "orgId", consumptionProfile.getSiteId())); I got error: java.lang.AssertionError: unexpected invocation: mockContainer.firstMatch(<org.apache.isis.applib.query.QueryDefault@a8c488>) expectations: expected once, never invoked: mockContainer.firstMatch(<org.apache.isis.applib.query.QueryDefault@148cc8c>); returns a default value parameter 0 did not match: <org.apache.isis.applib.query.QueryDefault@148cc8c>, because was <org.apache.isis.applib.query.QueryDefault@a8c488> what happened before this: nothing! .. at org.apache.isis.applib.DomainObjectContainer$$EnhancerByCGLIB$$34b7a821.firstMatch(<generated>) at com.wipro.wess.upload.excel.dto.ExcelSheet.lookupOrganisation(ExcelSheet.java:273) at com.wipro.wess.upload.excel.dto.ExcelConsumptionProfile.process(ExcelConsumptionProfile.java:128) Error says it's never invoked. In fact its invoked at ExcelSheet.lookupOrganisation(ExcelSheet.java:273) I really don't understand this JunitMockery framework. I did not find the documentation part regarding this. So I wanted this to do without mockery framework. In this case I need DomainObjectContainer instance. Please help. BR Ranganath Varma The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email. www.wipro.com