title: Testing Katharsis JsonApi with MockMvc and Mockito
body: <p>I would like to test the behaviour configured by my Katharsis ResourceRepository (katharsis-spring 2.1.7):</p>
  
  <pre><code>import io.katharsis.queryParams.QueryParams;
  import io.katharsis.repository.ResourceRepository;
  import org.springframework.stereotype.Component;
  
  @Component
  public class UserResourceRepository implements ResourceRepository&lt;UserDTO, String&gt; {
  
      @Autowired
      private UserRepository databaseRepository;
  
      @Override
      public UserDTO findOne(String email, QueryParams queryParams) {
          return null;
      }
  
      @Override
      public Iterable&lt;UserDTO&gt; findAll(QueryParams queryParams) {
          return null;
      }
  
      @Override
      public Iterable&lt;UserDTO&gt; findAll(Iterable&lt;String&gt; iterable, QueryParams queryParams) {
          return null;
      }
  
      @Override
      public void delete(String email) {
      }
  
      @Override
      public UserDTO save(UserDTO s) {
          return null;
      }
  }
  </code></pre>
  
  <p>I would like to test it in a similar way as I do it with normal, Spring Controllers, using Mockito to mock database repository and using MockMvc:</p>
  
  <pre><code>import org.junit.Before;
  import org.junit.Test;
  import org.junit.runner.RunWith;
  import org.mockito.InjectMocks;
  import org.mockito.Mock;
  import org.mockito.runners.MockitoJUnitRunner;
  import org.springframework.test.web.servlet.MockMvc;
  import org.springframework.test.web.servlet.setup.MockMvcBuilders;
  
  import java.util.Optional;
  
  import static org.mockito.Mockito.when;
  import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
  import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
  
  @RunWith(MockitoJUnitRunner.class)
  public class UserJsonApiTest {
  
      @InjectMocks
      private UserResourceRepository resourceRepository;
  
      @Mock
      private UserRepository databaseRepository;
  
      private MockMvc mockMvc;
  
      @Before
      public void setup() {
          mockMvc = MockMvcBuilders.standaloneSetup(resourceRepository).build();
      }
  
      @Test
      public void first() throws Exception {
          Optional&lt;UserEntity&gt; user = Optional.of(new UserEntity().
                  id(1).
                  email("test@test").
                  firstName("test first name").
                  lastName("test last name").
                  pass("test pass"));
  
          when(
                  databaseRepository.
                          findOneByEmail(user.get().getEmail())).
                  thenReturn(user);
  
          mockMvc.perform(
                  get("/users/" + user.get().email())).
                  andExpect(status().isOk())
          ;
      }
  
  }
  </code></pre>
  
  <p>Obviously, this code doesn't work because my Katharsis UserResourceRepository is not really a Controller. So far I have learned (from logs) that it is actually using some filters mappings and class named io.katharsis.spring.<strong>KatharsisFilterV2</strong>.</p>
  
  <p>Is there any way to use MockMvc for such test? If not - is there any other way I could test it without starting the whole server (with mocking)?</p>