@Test
public void saveResourceOnlyOnePerAPI() {

     thrown.expect(BadRequestException.class);
     thrown.expectMessage("Only one resource per api");
     Api resApi = new Api();
     resApi.setId(10L);
     Resource resData = new Resource();
     resData.setApi(resApi);
     Mockito.when(apiRepository.findOne(1L)).thenReturn(api);
     Mockito.when(resourceRepository.findByApiIdAndName(1L, "Local Resource")).thenReturn(resData);
     Mockito.when(resourceRepository.save(Mockito.any(Resource.class))).thenReturn(resource);
     Resource saved = resourceService.save(1L, resource);
     assertEquals(saved.getId(), resource.getId());
}