Skip to content
Snippets Groups Projects
Commit 9a5b67de authored by OZGCloud's avatar OZGCloud
Browse files

OZG-6477 OZG-6439 Implement CollaborationController.getById()

parent 0ae2d11a
No related branches found
No related tags found
No related merge requests found
Showing
with 317 additions and 97 deletions
......@@ -2,6 +2,8 @@ package de.ozgcloud.alfa.collaboration;
public interface Collaboration {
String getId();
String getVorgangId();
String getCollaborationVorgangId();
......
package de.ozgcloud.alfa.collaboration;
import java.util.Optional;
import org.springframework.hateoas.CollectionModel;
import org.springframework.hateoas.EntityModel;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -17,10 +20,26 @@ public class CollaborationController {
private final CollaborationModelAssembler assembler;
private final CollaborationService service;
static final String PATH = "/api/vorgangs"; // NOSONAR
static final String PATH = "/api/collaborations"; // NOSONAR
@GetMapping("/{collaborationId}")
public ResponseEntity<EntityModel<Collaboration>> getById(@PathVariable String collaborationId) {
return ResponseEntity.of(Optional.of(service.getById(collaborationId)).map(assembler::toModel));
}
@RestController
@RequestMapping(CollaborationByVorgangController.PATH)
@RequiredArgsConstructor
public static class CollaborationByVorgangController {
static final String PATH = "/api/vorgangs";
private final CollaborationModelAssembler assembler;
private final CollaborationService service;
@GetMapping("/{vorgangId}/collaborations")
public CollectionModel<EntityModel<Collaboration>> getAllByVorgangId(@PathVariable String vorgangId) {
return assembler.toCollectionModel(service.getCollaborations(vorgangId), vorgangId);
}
}
}
......@@ -11,6 +11,8 @@ import org.springframework.hateoas.LinkRelation;
import org.springframework.hateoas.server.RepresentationModelAssembler;
import org.springframework.stereotype.Component;
import de.ozgcloud.alfa.collaboration.CollaborationController.CollaborationByVorgangController;
import de.ozgcloud.alfa.common.CollectionModelBuilder;
import de.ozgcloud.alfa.common.ModelBuilder;
import de.ozgcloud.alfa.common.command.CommandController;
import de.ozgcloud.alfa.vorgang.VorgangController;
......@@ -26,17 +28,23 @@ class CollaborationModelAssembler implements RepresentationModelAssembler<Collab
@Override
public EntityModel<Collaboration> toModel(Collaboration collaboration) {
var selfLink = linkTo(methodOn(CollaborationController.class).getById(collaboration.getId())).withSelfRel();
return ModelBuilder.fromEntity(collaboration)
// TODO: Wenn Schnittstelle zum laden der Collaboration existiert, muss self
// link ergänzt werden
.addLink(selfLink)
.buildModel();
}
public CollectionModel<EntityModel<Collaboration>> toCollectionModel(Stream<? extends Collaboration> entities, String vorgangId) {
var collectionModel = CollectionModel.of(entities.map(this::toModel).toList())
.add(linkTo(methodOn(CollaborationController.class).getAllByVorgangId(vorgangId)).withSelfRel());
return collectionModel
.addIf(collectionModel.getContent().isEmpty(), () -> buildCreateCollaborationRequestLink(vorgangId));
var entityModels = entities.map(this::toModel).toList();
var selfLink = linkTo(methodOn(CollaborationByVorgangController.class).getAllByVorgangId(vorgangId)).withSelfRel();
return CollectionModelBuilder.fromEntities(entityModels)
.addLink(selfLink)
.ifMatch(entityModels::isEmpty)
.addLink(() -> buildCreateCollaborationRequestLink(vorgangId))
.buildModel();
}
Link buildCreateCollaborationRequestLink(String vorgangId) {
......
......@@ -10,6 +10,7 @@ import de.ozgcloud.alfa.common.GrpcUtil;
import de.ozgcloud.collaboration.request.CollaborationRequestServiceGrpc.CollaborationRequestServiceBlockingStub;
import de.ozgcloud.collaboration.request.GrpcCollaborationRequest;
import de.ozgcloud.collaboration.request.GrpcFindRequestsRequest;
import de.ozgcloud.collaboration.request.GrpcGetRequestRequest;
import net.devh.boot.grpc.client.inject.GrpcClient;
@Service
......@@ -21,12 +22,20 @@ public class CollaborationRemoteService {
@Autowired
private CollaborationMapper collaborationMapper;
// public Collaboration getById(String collaborationId) {
// serviceStub.getRequest()
// }
public Stream<Collaboration> getCollaborations(String vorgangId) {
var toCollaboration = getCollaborationMapperForVorgang(vorgangId);
return serviceStub.findRequests(buildSearchRequest(vorgangId))
.getRequestsList().stream().map(toCollaboration);
}
GrpcGetRequestRequest buildGetRequest(String collaborationId) {
return GrpcGetRequestRequest.newBuilder().setId(collaborationId).build();
}
GrpcFindRequestsRequest buildSearchRequest(String vorgangId) {
return GrpcFindRequestsRequest.newBuilder().setVorgangId(vorgangId).build();
}
......
......@@ -12,6 +12,10 @@ class CollaborationService {
private final CollaborationRemoteService remoteService;
public Collaboration getById(String collaborationId) {
return null;
}
public Stream<Collaboration> getCollaborations(String vorgangId) {
return remoteService.getCollaborations(vorgangId);
}
......
......@@ -11,6 +11,7 @@ import org.springframework.hateoas.LinkRelation;
import org.springframework.hateoas.server.RepresentationModelProcessor;
import org.springframework.stereotype.Component;
import de.ozgcloud.alfa.collaboration.CollaborationController.CollaborationByVorgangController;
import de.ozgcloud.alfa.common.ModelBuilder;
import de.ozgcloud.alfa.common.user.CurrentUserService;
import de.ozgcloud.alfa.common.user.UserRole;
......@@ -40,7 +41,7 @@ class CollaborationVorgangProcessor implements RepresentationModelProcessor<Enti
return ModelBuilder.fromModel(model)
.ifMatch(() -> !collaborationService.hasCollaboration(vorgang.getId()))
.addLinks(buildSearchOrganisationsEinheitLink(), buildSearchFachstelleLink())
.addLink(linkTo(methodOn(CollaborationController.class).getAllByVorgangId(vorgang.getId())).withRel(REL_COLLABORATIONS))
.addLink(linkTo(methodOn(CollaborationByVorgangController.class).getAllByVorgangId(vorgang.getId())).withRel(REL_COLLABORATIONS))
.buildModel();
}
......
......@@ -14,6 +14,8 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor
public class FachstelleCollaboration implements Collaboration {
@JsonIgnore
private String id;
@JsonIgnore
private String vorgangId;
@JsonIgnore
......
......@@ -14,6 +14,8 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor
public class OrganisationsEinheitCollaboration implements Collaboration {
@JsonIgnore
private String id;
@JsonIgnore
private String vorgangId;
@JsonIgnore
......
......@@ -27,6 +27,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.function.BooleanSupplier;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Stream;
import org.springframework.hateoas.CollectionModel;
......@@ -82,5 +83,12 @@ public class CollectionModelBuilder<T> {
}
return CollectionModelBuilder.this;
}
public CollectionModelBuilder<T> addLink(Supplier<Link> linkSupplier) {
if (conditionFulfilled) {
links.add(linkSupplier.get());
}
return CollectionModelBuilder.this;
}
}
}
\ No newline at end of file
......@@ -38,7 +38,7 @@ import org.springframework.stereotype.Component;
import de.ozgcloud.alfa.bescheid.BescheidController;
import de.ozgcloud.alfa.bescheid.DocumentController;
import de.ozgcloud.alfa.collaboration.CollaborationController;
import de.ozgcloud.alfa.collaboration.CollaborationController.CollaborationByVorgangController;
import de.ozgcloud.alfa.common.ModelBuilder;
import de.ozgcloud.alfa.kommentar.KommentarController;
import de.ozgcloud.alfa.postfach.PostfachMailController;
......@@ -83,7 +83,7 @@ class CommandModelAssembler implements RepresentationModelAssembler<Command, Ent
case WIEDERVORLAGE -> linkTo(WiedervorlageController.class).slash(entity.getRelationId());
case BESCHEID -> linkTo(methodOn(BescheidController.class).getDraft(entity.getVorgangId()));
case DOCUMENT -> linkTo(DocumentController.class).slash(entity.getCreatedResource());
case COLLABORATION -> linkTo(methodOn(CollaborationController.class).getAllByVorgangId(entity.getVorgangId()));
case COLLABORATION -> linkTo(methodOn(CollaborationByVorgangController.class).getAllByVorgangId(entity.getVorgangId()));
case NONE -> throw new IllegalArgumentException("Unknown CommandOrder: " + entity.getOrder());
};
......
package de.ozgcloud.alfa.collaboration;
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.test.web.servlet.result.JsonPathResultMatchers;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.web.util.UriComponentsBuilder;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
class CollaborationAssertions {
private final boolean collectionModel;
void assertHasFields(ResultActions response) throws Exception {
response.andExpect(jsonPath("id").doesNotExist())
.andExpect(jsonPath("vorgangId").doesNotExist())
.andExpect(jsonPath("collaborationVorgangId").doesNotExist())
.andExpect(jsonPath("titel").value(OrganisationsEinheitCollaborationTestFactory.TITEL))
.andExpect(jsonPath("beschreibung").value(OrganisationsEinheitCollaborationTestFactory.BESCHREIBUNG))
.andExpect(jsonPath("collaborationLevel").value(OrganisationsEinheitCollaborationTestFactory.COLLABORATION_LEVEL));
}
void assertHasZustaendigeStelleLink(ResultActions response, String controllerPath, String zustaendigeStelle) throws Exception {
var expectedLink = UriComponentsBuilder
.fromUriString("http://localhost")
.path(controllerPath)
.pathSegment(zustaendigeStelle)
.build();
response.andExpect(jsonPath("zustaendigeStelle").value(expectedLink.toString()));
}
private JsonPathResultMatchers jsonPath(String expression, Object... args) {
return MockMvcResultMatchers.jsonPath(jsonPathPrefix() + expression, args);
}
private String jsonPathPrefix() {
var prefix = "$.";
if (collectionModel) {
prefix += "content[0].";
}
return prefix;
}
}
package de.ozgcloud.alfa.collaboration;
import static org.mockito.Mockito.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import java.util.Collections;
import java.util.stream.Stream;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.springframework.hateoas.CollectionModel;
import org.springframework.hateoas.EntityModel;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import de.ozgcloud.alfa.collaboration.CollaborationController.CollaborationByVorgangController;
import lombok.SneakyThrows;
class CollaborationByVorgangControllerTest {
@InjectMocks
private CollaborationByVorgangController controller;
@Mock
private CollaborationService service;
@Mock
private CollaborationModelAssembler assembler;
private MockMvc mockMvc;
private static final String VORGANG_ID = OrganisationsEinheitCollaborationTestFactory.VORGANG_ID;
@BeforeEach
void initTest() {
mockMvc = MockMvcBuilders.standaloneSetup(controller).build();
}
@Nested
class TestGetAllByVorgangId {
private final Collaboration collaboration = OrganisationsEinheitCollaborationTestFactory.create();
@Test
void shouldCallCollaborationService() {
performRequest();
verify(service).getCollaborations(VORGANG_ID);
}
@Nested
class TestOnExistingCollaboration {
private final CollaborationAssertions collaborationAssertions = new CollaborationAssertions(true);
private final Stream<Collaboration> collaborations = Stream.of(collaboration);
@BeforeEach
void mock() {
when(service.getCollaborations(VORGANG_ID)).thenReturn(collaborations);
when(assembler.toCollectionModel(collaborations, VORGANG_ID))
.thenReturn(CollectionModel.of(Collections.singletonList(EntityModel.of(collaboration))));
}
@Test
void shouldCallAssembler() {
performRequest();
verify(assembler).toCollectionModel(collaborations, VORGANG_ID);
}
@SneakyThrows
@Test
void shouldReturnStatusOk() {
var response = performRequest();
response.andExpect(status().isOk());
}
@SneakyThrows
@Test
void shouldHaveContentWithFields() {
var response = performRequest();
collaborationAssertions.assertHasFields(response);
}
@SneakyThrows
@Test
void shouldHaveContentWithLink() {
var response = performRequest();
collaborationAssertions.assertHasZustaendigeStelleLink(response, OrganisationsEinheitController.PATH,
OrganisationsEinheitCollaborationTestFactory.ZUSTAENDIGE_STELLE);
}
}
@SneakyThrows
private ResultActions performRequest() {
return mockMvc.perform(
get(CollaborationByVorgangController.PATH + "/" + VORGANG_ID + "/collaborations"));
}
}
}
......@@ -4,20 +4,15 @@ import static org.mockito.Mockito.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import java.util.Collections;
import java.util.stream.Stream;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.springframework.hateoas.CollectionModel;
import org.springframework.hateoas.EntityModel;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.util.UriComponentsBuilder;
import lombok.SneakyThrows;
......@@ -40,109 +35,92 @@ class CollaborationControllerTest {
}
@Nested
class TestGetAllByVorgangId {
class TestGetById {
private final CollaborationAssertions collaborationAssertions = new CollaborationAssertions(false);
@Nested
class OnOrganisationsEinheitCollaboration {
public static final String COLLABORATION_ID = OrganisationsEinheitCollaborationTestFactory.ID;
private final Collaboration collaboration = OrganisationsEinheitCollaborationTestFactory.create();
@SneakyThrows
@BeforeEach
void init() {
when(service.getById(OrganisationsEinheitCollaborationTestFactory.ID)).thenReturn(collaboration);
when(assembler.toModel(collaboration)).thenReturn(EntityModel.of(collaboration));
}
@Test
void shouldCallCollaborationService() {
performRequest();
verify(service).getCollaborations(OrganisationsEinheitCollaborationTestFactory.VORGANG_ID);
}
@Nested
class TestOnExistingCollaboration {
private final Stream<Collaboration> collaborations = Stream.of(collaboration);
@BeforeEach
void mock() {
when(service.getCollaborations(OrganisationsEinheitCollaborationTestFactory.VORGANG_ID)).thenReturn(collaborations);
verify(service).getById(COLLABORATION_ID);
}
@Test
void shouldCallAssembler() {
void shouldCreateModel() {
performRequest();
verify(assembler).toCollectionModel(collaborations, OrganisationsEinheitCollaborationTestFactory.VORGANG_ID);
verify(assembler).toModel(collaboration);
}
@SneakyThrows
@Test
void shouldReturnStatusOk() {
when(assembler.toCollectionModel(collaborations, OrganisationsEinheitCollaborationTestFactory.VORGANG_ID))
.thenReturn(CollectionModel.of(Collections.singletonList(EntityModel.of(collaboration))));
var response = performRequest();
response.andExpect(status().isOk());
}
@Nested
class TestResponseBody {
@BeforeEach
void mockAssembler() {
when(assembler.toCollectionModel(collaborations, OrganisationsEinheitCollaborationTestFactory.VORGANG_ID))
.thenReturn(CollectionModel.of(Collections.singletonList(EntityModel.of(collaboration))));
}
@SneakyThrows
@Test
void shouldNotHaveVorgangId() {
void shouldHaveContentWithFields() {
var response = performRequest();
response.andExpect(jsonPath("$.vorgangId").doesNotExist());
collaborationAssertions.assertHasFields(response);
}
@SneakyThrows
@Test
void shouldNotHaveCollaborationVorgangId() {
void shouldHaveContentWithLink() {
var response = performRequest();
response.andExpect(jsonPath("$.collaborationVorgangId").doesNotExist());
collaborationAssertions.assertHasZustaendigeStelleLink(response, OrganisationsEinheitController.PATH,
OrganisationsEinheitCollaborationTestFactory.ZUSTAENDIGE_STELLE);
}
@SneakyThrows
@Test
void shouldHaveTitel() {
var response = performRequest();
response.andExpect(jsonPath("$.content[0].titel").value(OrganisationsEinheitCollaborationTestFactory.TITEL));
private ResultActions performRequest() {
return mockMvc.perform(get(CollaborationController.PATH + "/" + COLLABORATION_ID));
}
}
@SneakyThrows
@Test
void shouldHaveBeschreibung() {
var response = performRequest();
@Nested
class OnFachstelleCollaboration {
System.out.println(response.andReturn().getResponse().getContentAsString());
public static final String COLLABORATION_ID = FachstelleCollaborationTestFactory.ID;
private final Collaboration collaboration = FachstelleCollaborationTestFactory.create();
response.andExpect(jsonPath("$.content[0].beschreibung").value(OrganisationsEinheitCollaborationTestFactory.BESCHREIBUNG));
@BeforeEach
void init() {
when(service.getById(FachstelleCollaborationTestFactory.ID)).thenReturn(collaboration);
when(assembler.toModel(collaboration)).thenReturn(EntityModel.of(collaboration));
}
@SneakyThrows
@Test
void shouldHaveZustaendigeStelle() {
var expectedLink = UriComponentsBuilder
.fromUriString("http://localhost")
.path(OrganisationsEinheitController.PATH)
.pathSegment(OrganisationsEinheitCollaborationTestFactory.ZUSTAENDIGE_STELLE)
.build();
void shouldHaveContentWithLink() {
var response = performRequest();
response.andExpect(jsonPath("$.content[0].zustaendigeStelle")
.value(expectedLink.toString()));
}
}
collaborationAssertions.assertHasZustaendigeStelleLink(response, FachstelleController.PATH,
FachstelleCollaborationTestFactory.ZUSTAENDIGE_STELLE);
}
@SneakyThrows
private ResultActions performRequest() {
return mockMvc.perform(get(CollaborationController.PATH + "/" + OrganisationsEinheitCollaborationTestFactory.VORGANG_ID + "/collaborations"));
return mockMvc.perform(get(CollaborationController.PATH + "/" + COLLABORATION_ID));
}
}
}
}
......@@ -17,6 +17,7 @@ import org.springframework.hateoas.IanaLinkRelations;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.UriTemplate;
import de.ozgcloud.alfa.collaboration.CollaborationController.CollaborationByVorgangController;
import de.ozgcloud.alfa.common.ModelBuilder;
import de.ozgcloud.alfa.common.command.CommandController.CommandByRelationController;
import de.ozgcloud.alfa.vorgang.VorgangController;
......@@ -118,7 +119,7 @@ class CollaborationModelAssemblerTest {
var collectionModel = callAssembler();
assertThat(collectionModel.getLink(IanaLinkRelations.SELF_VALUE)).get().extracting(Link::getHref)
.isEqualTo(CollaborationController.PATH + "/" + VorgangHeaderTestFactory.ID + "/collaborations");
.isEqualTo(CollaborationByVorgangController.PATH + "/" + VorgangHeaderTestFactory.ID + "/collaborations");
}
@Test
......@@ -156,7 +157,7 @@ class CollaborationModelAssemblerTest {
var collectionModel = callAssembler();
assertThat(collectionModel.getLink(IanaLinkRelations.SELF_VALUE)).get().extracting(Link::getHref)
.isEqualTo(CollaborationController.PATH + "/" + VorgangHeaderTestFactory.ID + "/collaborations");
.isEqualTo(CollaborationByVorgangController.PATH + "/" + VorgangHeaderTestFactory.ID + "/collaborations");
}
@Test
......
......@@ -8,6 +8,7 @@ import de.ozgcloud.alfa.collaboration.FachstelleCollaboration.FachstelleCollabor
public class FachstelleCollaborationTestFactory {
public static final String ID = UUID.randomUUID().toString();
public static final String VORGANG_ID = UUID.randomUUID().toString();
public static final String COLLABORATION_VORGANG_ID = UUID.randomUUID().toString();
public static final long COLLABORATION_LEVEL = 4L;
......@@ -22,6 +23,7 @@ public class FachstelleCollaborationTestFactory {
private static FachstelleCollaborationBuilder createBuilder() {
return FachstelleCollaboration.builder()
.id(ID)
.vorgangId(VORGANG_ID)
.collaborationVorgangId(COLLABORATION_VORGANG_ID)
.collaborationLevel(COLLABORATION_LEVEL)
......
package de.ozgcloud.alfa.collaboration;
import java.util.UUID;
import de.ozgcloud.collaboration.request.GrpcCollaborationRequest;
class GrpcCollaborationRequestForFachstelleTestFactory {
public static final String ID = UUID.randomUUID().toString();
public static final String ID = FachstelleCollaborationTestFactory.ID;
public static final String COLLABORATION_VORGANG_ID = FachstelleCollaborationTestFactory.COLLABORATION_VORGANG_ID;
public static final String TITEL = FachstelleCollaborationTestFactory.TITEL;
public static final String BESCHREIBUNG = FachstelleCollaborationTestFactory.BESCHREIBUNG;
......
package de.ozgcloud.alfa.collaboration;
import java.util.UUID;
import de.ozgcloud.collaboration.request.GrpcCollaborationRequest;
class GrpcCollaborationRequestForOrganisationsEinheitTestFactory {
public static final String ID = UUID.randomUUID().toString();
public static final String ID = OrganisationsEinheitCollaborationTestFactory.ID;
public static final String COLLABORATION_VORGANG_ID = OrganisationsEinheitCollaborationTestFactory.COLLABORATION_VORGANG_ID;
public static final String TITEL = OrganisationsEinheitCollaborationTestFactory.TITEL;
public static final String BESCHREIBUNG = OrganisationsEinheitCollaborationTestFactory.BESCHREIBUNG;
......
......@@ -8,6 +8,7 @@ import de.ozgcloud.alfa.collaboration.OrganisationsEinheitCollaboration.Organisa
public class OrganisationsEinheitCollaborationTestFactory {
public static final String ID = UUID.randomUUID().toString();
public static final String VORGANG_ID = UUID.randomUUID().toString();
public static final String COLLABORATION_VORGANG_ID = UUID.randomUUID().toString();
public static final long COLLABORATION_LEVEL = 1L;
......@@ -22,6 +23,7 @@ public class OrganisationsEinheitCollaborationTestFactory {
private static OrganisationsEinheitCollaborationBuilder createBuilder() {
return OrganisationsEinheitCollaboration.builder()
.id(ID)
.vorgangId(VORGANG_ID)
.collaborationVorgangId(COLLABORATION_VORGANG_ID)
.collaborationLevel(COLLABORATION_LEVEL)
......
package de.ozgcloud.alfa.common;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Stream;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.springframework.hateoas.Link;
import de.ozgcloud.alfa.vorgang.VorgangHeaderTestFactory;
......@@ -88,6 +91,36 @@ class CollectionModelBuilderTest {
assertThat(model.getLinks()).isEmpty();
}
}
@Nested
class TestWithLinkSupplier {
@Mock
private Supplier<Link> linkSupplier;
@Test
void shouldAddLink() {
when(linkSupplier.get()).thenReturn(Link.of(HREF, REL));
var model = CollectionModelBuilder.fromEntities(List.of()).ifMatch(() -> true).addLink(linkSupplier).buildModel();
assertThat(model.getLinks()).hasSize(1).first().extracting(Link::getHref, link -> link.getRel().value()).containsExactly(HREF, REL);
}
@Test
void shouldNotCallLinkSupplier() {
CollectionModelBuilder.fromEntities(List.of()).ifMatch(() -> false).addLink(linkSupplier).buildModel();
verify(linkSupplier, never()).get();
}
@Test
void shouldNotAddLink() {
var model = CollectionModelBuilder.fromEntities(List.of()).ifMatch(() -> false).addLink(linkSupplier).buildModel();
assertThat(model.getLinks()).isEmpty();
}
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment