5 Replies Latest reply on Jun 28, 2017 9:14 AM by sea_shankar

    NoClassDefFoundError: org/infinispan/query/dsl/Query

    sea_shankar

      I was trying to create a unit test case and for some reason I get a class not found error for org/infinispan/query/dsl/Query when I did this:

       

      @Mock

      private RemoteCache<String, String> remote;

       

      What is this class, because I am not doing any sort of dsl query?  I have infinispan-spring4-remote and infinsipan-spring-boot-starter as a dependency. 

        • 1. Re: NoClassDefFoundError: org/infinispan/query/dsl/Query
          anistor

          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

            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

              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

                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

                  Thanks a lot, got it to work with mocking withFlags as well!