Cleanup and documentation

This commit is contained in:
René Pfeuffer
2018-06-06 16:24:59 +02:00
parent ff8c6ea014
commit a8c61a9bfd
20 changed files with 244 additions and 64 deletions

View File

@@ -60,7 +60,7 @@ public class JsonMarshallingResponseFilterTest {
public void testFilter() {
when(responseContext.hasEntity()).thenReturn(Boolean.TRUE);
when(responseContext.getEntity()).thenReturn(new JsonMarshallingResponseFilterTest.Sample("one-two-three"));
when(responseContext.getMediaType()).thenReturn(VndMediaType.jsonType("sample"));
when(responseContext.getMediaType()).thenReturn(MediaType.valueOf(VndMediaType.USER));
filter.filter(requestContext, responseContext);
@@ -81,7 +81,7 @@ public class JsonMarshallingResponseFilterTest {
when(responseContext.hasEntity()).thenReturn(Boolean.TRUE);
when(responseContext.getEntity()).thenReturn(new JsonMarshallingResponseFilterTest.Sample("one-two-three"));
when(responseContext.getMediaType()).thenReturn(VndMediaType.jsonType("sample"));
when(responseContext.getMediaType()).thenReturn(MediaType.valueOf(VndMediaType.USER));
filter.filter(requestContext, responseContext);

View File

@@ -45,28 +45,28 @@ public class UserCollection2DtoMapperTest {
@Test
public void shouldSetPageNumber() {
PageResult<User> pageResult = mockPageResult(true, "Hannes");
UserCollectionDto userCollectionDto = mapper.userCollectionToUserDto(uriInfo, 1, 1, pageResult);
UserCollectionDto userCollectionDto = mapper.userCollectionToDto(uriInfo, 1, 1, pageResult);
assertEquals(1, userCollectionDto.getPage());
}
@Test
public void shouldHaveSelfLink() {
PageResult<User> pageResult = mockPageResult(true, "Hannes");
UserCollectionDto userCollectionDto = mapper.userCollectionToUserDto(uriInfo, 1, 1, pageResult);
UserCollectionDto userCollectionDto = mapper.userCollectionToDto(uriInfo, 1, 1, pageResult);
assertTrue(userCollectionDto.getLinks().getLinkBy("self").get().getHref().startsWith(expectedBaseUri.toString()));
}
@Test
public void shouldCreateNextPageLink_whenHasMore() {
PageResult<User> pageResult = mockPageResult(true, "Hannes");
UserCollectionDto userCollectionDto = mapper.userCollectionToUserDto(uriInfo, 1, 1, pageResult);
UserCollectionDto userCollectionDto = mapper.userCollectionToDto(uriInfo, 1, 1, pageResult);
assertTrue(userCollectionDto.getLinks().getLinkBy("next").get().getHref().contains("page=2"));
}
@Test
public void shouldNotCreateNextPageLink_whenNoMore() {
PageResult<User> pageResult = mockPageResult(false, "Hannes");
UserCollectionDto userCollectionDto = mapper.userCollectionToUserDto(uriInfo, 1, 1, pageResult);
UserCollectionDto userCollectionDto = mapper.userCollectionToDto(uriInfo, 1, 1, pageResult);
assertFalse(userCollectionDto.getLinks().stream().anyMatch(link -> link.getHref().contains("page=2")));
}
@@ -75,7 +75,7 @@ public class UserCollection2DtoMapperTest {
PageResult<User> pageResult = mockPageResult(false, "Hannes");
when(subject.isPermitted("user:create")).thenReturn(true);
UserCollectionDto userCollectionDto = mapper.userCollectionToUserDto(uriInfo, 1, 1, pageResult);
UserCollectionDto userCollectionDto = mapper.userCollectionToDto(uriInfo, 1, 1, pageResult);
assertTrue(userCollectionDto.getLinks().getLinkBy("create").isPresent());
}
@@ -85,7 +85,7 @@ public class UserCollection2DtoMapperTest {
PageResult<User> pageResult = mockPageResult(false, "Hannes");
when(subject.isPermitted("user:create")).thenReturn(false);
UserCollectionDto userCollectionDto = mapper.userCollectionToUserDto(uriInfo, 1, 1, pageResult);
UserCollectionDto userCollectionDto = mapper.userCollectionToDto(uriInfo, 1, 1, pageResult);
assertFalse(userCollectionDto.getLinks().getLinkBy("create").isPresent());
}
@@ -93,7 +93,7 @@ public class UserCollection2DtoMapperTest {
@Test
public void shouldMapUsers() {
PageResult<User> pageResult = mockPageResult(false, "Hannes", "Wurst");
UserCollectionDto userCollectionDto = mapper.userCollectionToUserDto(uriInfo, 1, 2, pageResult);
UserCollectionDto userCollectionDto = mapper.userCollectionToDto(uriInfo, 1, 2, pageResult);
List<HalRepresentation> users = userCollectionDto.getEmbedded().getItemsBy("users");
assertEquals(2, users.size());
assertEquals("Hannes", ((UserDto) users.get(0)).getName());