I need some pax exam help.
I get a ClassNotFoundException I don't know how to fix.
I can access the bean Account for use in asserts without errors.
But once I use stream, filter and findFirst to find a particular account
I get ClassNotFoundException on the account.
I have the following pax exam test:
https://github.com/steinarb/liquibase-karaf-feature/blob/master/liquibase-integration-test/karaf.liquibase.tests/src/test/java/no/priv/bang/karaf/liquibase/tests/LiquibaseKarafFeatureIntegrationTest.java#L55
Here I access beans of type Account in the pax exam test.
However if I try searching for a bean using stream and filter, like this:
@Test
public void testLoadFeature() throws Exception { // NOSONAR this test has an assert, just not an assert sonar recognizes
installAndAssertFeature("karaf-liquibase-sample-datasource-receiver");
var service = getOsgiService(SampleLiquibaseDatasourceReceiverService.class);
var initialAccounts = service.accounts();
assertEquals(1, initialAccounts.size());
var initialAccount = initialAccounts.get(0);
assertEquals("jod", initialAccount.getUsername());
var newAccount = Account.with().username("jad").build();
var accountsAfterAdd = service.addAccount(newAccount);
assertEquals(2, accountsAfterAdd.size());
var addedAccount = accountsAfterAdd.stream().filter(a -> "jad".equals(a.getUsername())).findFirst().orElseThrow();
assertEquals(initialAccount.getId() + 1, addedAccount.getId());
assertEquals("jad", addedAccount.getUsername());
}
Then I get the following error:
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 6.93 s <<< FAILURE! - in no.priv.bang.karaf.liquibase.tests.LiquibaseKarafFeatureIntegrationTest
[ERROR] testLoadFeature(no.priv.bang.karaf.liquibase.tests.LiquibaseKarafFeatureIntegrationTest) Time elapsed: 0.061 s <<< ERROR!
java.lang.ClassNotFoundException: no.priv.bang.karaf.liquibase.sample.services.Account not found by PAXEXAM-PROBE-37daa15f-5c4f-4a37-b284-8ef8ac7cb232 [77]
I googled the error message and found this:
https://stackoverflow.com/a/43009600
I have tried adding a probeConfiguration to the test, by adding this
method to the test:
@ProbeBuilder
public TestProbeBuilder probeConfiguration(TestProbeBuilder probe) {
probe.setHeader(Constants.IMPORT_PACKAGE, "*,no.priv.bang.karaf.liquibase.sample.services.*");
return probe;
}
But that just gave me a different error message:
ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 13.32 s <<< FAILURE! - in no.priv.bang.karaf.liquibase.tests.LiquibaseKarafFeatureIntegrationTest
[ERROR] no.priv.bang.karaf.liquibase.tests.LiquibaseKarafFeatureIntegrationTest Time elapsed: 11.865 s <<< ERROR!
java.lang.RuntimeException: Bundle cannot be installed
Caused by: org.osgi.framework.BundleException: Unable to resolve PAXEXAM-PROBE-20d166e8-9d0f-41f0-86b8-79228ed20833 [77](R 77.0): missing requirement [PAXEXAM-PROBE-20d166e8-9d0f-41f0-86b8-79228ed20833 [77](R 77.0)] osgi.wiring.package; (osgi.wiring.package=no.priv.bang.karaf.liquibase.sample.services.*) Unresolved requirements: [[PAXEXAM-PROBE-20d166e8-9d0f-41f0-86b8-79228ed20833 [77](R 77.0)] osgi.wiring.package; (osgi.wiring.package=no.priv.bang.karaf.liquibase.sample.services.*)]
Does anyone know why I get the ClassNotFoundException when I use the
stream, but not when accessing the Account variables in the asserts?
Does anyone know what to do to fix this?
Thanks!