-
1. Re: NoClassDefFoundError: org/infinispan/query/dsl/Query
anistor Jun 27, 2017 4:50 PM (in response to sea_shankar)RemoteCache.retrieveEntriesByQuery takes a Query parameter. That class comes from query-dsl module, which you do not have in your hot rod client's classpath (neither infinispan-spring4-remote nor infinsipan-spring-boot-starter do not contain it). Even if that class is missing everything should work nicely with the RemoteCache until you invoke a query related operation, which you don't. But ... since you are creating a mock object using the @Mock annotation, your mocking framework will try to proxy that method using bytecode engineering which fails due to the missing class. You can fix this by adding infinispan-query-dsl.jar to your class path.
-
2. Re: NoClassDefFoundError: org/infinispan/query/dsl/Query
sea_shankar Jun 27, 2017 5:08 PM (in response to anistor)Ahhh that makes sense why it's only happening in my test case and not the normal code. Am I mocking RemoteCache wrong then? I would like to avoid adding jars to the project that I am not using, just for test cases?
I also have this issue where this keeps throwing NullPointer:
RemoteCache<Object, Object> remote = Mockito.mock(RemoteCache.class);
when(remote.withFlags(any(Flag.class)).putIfAbsent(anyObject(), anyObject())).thenReturn("hello");
but this works.
RemoteCache<Object, Object> remote = Mockito.mock(RemoteCache.class);
when(remote.putIfAbsent(anyObject(), anyObject())).thenReturn("hello");
Any ideas?
-
3. Re: NoClassDefFoundError: org/infinispan/query/dsl/Query
sea_shankar Jun 27, 2017 5:14 PM (in response to anistor)I also tried with this same NullPointer:
when(remote.withFlags(Flag.FORCE_RETURN_VALUE).putIfAbsent(anyObject(), anyObject())).thenReturn("hello");
-
4. Re: NoClassDefFoundError: org/infinispan/query/dsl/Query
sebastian.laskawiec Jun 28, 2017 2:09 AM (in response to sea_shankar)Even though you are mocking, the JVM needs to load full class. This is why you're seeing the NoClassDefFoundError.
Using #withFlags is very tricky since it returns RemoteCache instance. The default Mockito behavior with the absence of mock definitions is that it returns null. This results in NullPointerException in your code. You also need to mock #withFlags methods to ensure it returns a valid, mocked RemoteCache.
-
5. Re: NoClassDefFoundError: org/infinispan/query/dsl/Query
sea_shankar Jun 28, 2017 9:14 AM (in response to sebastian.laskawiec)Thanks a lot, got it to work with mocking withFlags as well!