Skip to content
Snippets Groups Projects
Commit 3d304068 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-6477 OZG-6439 Create correct type of Collaboration

parent cff7c9c7
Branches
Tags
No related merge requests found
Showing
with 258 additions and 61 deletions
package de.ozgcloud.alfa.collaboration;
import com.fasterxml.jackson.annotation.JsonIgnore;
public interface Collaboration {
import de.ozgcloud.alfa.common.LinkedResource;
import de.ozgcloud.alfa.common.command.CommandBody;
import lombok.Builder;
import lombok.Getter;
String getVorgangId();
@Getter
@Builder
public class Collaboration implements CommandBody {
String getCollaborationVorgangId();
@JsonIgnore
private String vorgangId;
@JsonIgnore
private String collaborationVorgangId;
String getTitel();
private String titel;
private String beschreibung;
private int collaborationLevel;
String getBeschreibung();
@LinkedResource(controllerClass = OrganisationsEinheitController.class)
private String zustaendigeStelle;
long getCollaborationLevel();
String getZustaendigeStelle();
}
......@@ -9,5 +9,7 @@ import de.ozgcloud.collaboration.request.GrpcCollaborationRequest;
@Mapper(unmappedTargetPolicy = ReportingPolicy.ERROR, nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS)
interface CollaborationMapper {
Collaboration fromGrpc(GrpcCollaborationRequest request, String vorgangId);
OrganisationsEinheitCollaboration fromOrganisationsEinheitRequest(GrpcCollaborationRequest request, String vorgangId);
FachstelleCollaboration fromFachstelleRequest(GrpcCollaborationRequest request, String vorgangId);
}
......@@ -32,6 +32,12 @@ public class CollaborationRemoteService {
}
private Function<GrpcCollaborationRequest, Collaboration> getCollaborationMapperForVorgang(String vorgangId) {
return request -> collaborationMapper.fromGrpc(request, vorgangId);
return request -> isFachstelle(request)
? collaborationMapper.fromFachstelleRequest(request, vorgangId)
: collaborationMapper.fromOrganisationsEinheitRequest(request, vorgangId);
}
private boolean isFachstelle(GrpcCollaborationRequest request) {
return Long.valueOf(4).equals(request.getCollaborationLevel());
}
}
package de.ozgcloud.alfa.collaboration;
import com.fasterxml.jackson.annotation.JsonIgnore;
import de.ozgcloud.alfa.common.LinkedResource;
import de.ozgcloud.alfa.common.command.CommandBody;
import lombok.Builder;
import lombok.Getter;
@Getter
@Builder
public class FachstelleCollaboration implements CommandBody, Collaboration {
@JsonIgnore
private String vorgangId;
@JsonIgnore
private String collaborationVorgangId;
private String titel;
private String beschreibung;
private long collaborationLevel;
@LinkedResource(controllerClass = FachstelleController.class)
private String zustaendigeStelle;
}
package de.ozgcloud.alfa.collaboration;
import com.fasterxml.jackson.annotation.JsonIgnore;
import de.ozgcloud.alfa.common.LinkedResource;
import de.ozgcloud.alfa.common.command.CommandBody;
import lombok.Builder;
import lombok.Getter;
@Getter
@Builder
public class OrganisationsEinheitCollaboration implements CommandBody, Collaboration {
@JsonIgnore
private String vorgangId;
@JsonIgnore
private String collaborationVorgangId;
private String titel;
private String beschreibung;
private long collaborationLevel;
@LinkedResource(controllerClass = OrganisationsEinheitController.class)
private String zustaendigeStelle;
}
......@@ -42,14 +42,14 @@ class CollaborationControllerTest {
@Nested
class TestGetAllByVorgangId {
private final Collaboration collaboration = CollaborationTestFactory.create();
private final Collaboration collaboration = OrganisationsEinheitCollaborationTestFactory.create();
@SneakyThrows
@Test
void shouldCallCollaborationService() {
performRequest();
verify(service).getCollaborations(CollaborationTestFactory.VORGANG_ID);
verify(service).getCollaborations(OrganisationsEinheitCollaborationTestFactory.VORGANG_ID);
}
@Nested
......@@ -59,20 +59,20 @@ class CollaborationControllerTest {
@BeforeEach
void mock() {
when(service.getCollaborations(CollaborationTestFactory.VORGANG_ID)).thenReturn(collaborations);
when(service.getCollaborations(OrganisationsEinheitCollaborationTestFactory.VORGANG_ID)).thenReturn(collaborations);
}
@Test
void shouldCallAssembler() {
performRequest();
verify(assembler).toCollectionModel(collaborations, CollaborationTestFactory.VORGANG_ID);
verify(assembler).toCollectionModel(collaborations, OrganisationsEinheitCollaborationTestFactory.VORGANG_ID);
}
@SneakyThrows
@Test
void shouldReturnStatusOk() {
when(assembler.toCollectionModel(collaborations, CollaborationTestFactory.VORGANG_ID))
when(assembler.toCollectionModel(collaborations, OrganisationsEinheitCollaborationTestFactory.VORGANG_ID))
.thenReturn(CollectionModel.of(Collections.singletonList(EntityModel.of(collaboration))));
var response = performRequest();
......@@ -85,7 +85,7 @@ class CollaborationControllerTest {
@BeforeEach
void mockAssembler() {
when(assembler.toCollectionModel(collaborations, CollaborationTestFactory.VORGANG_ID))
when(assembler.toCollectionModel(collaborations, OrganisationsEinheitCollaborationTestFactory.VORGANG_ID))
.thenReturn(CollectionModel.of(Collections.singletonList(EntityModel.of(collaboration))));
}
......@@ -110,7 +110,7 @@ class CollaborationControllerTest {
void shouldHaveTitel() {
var response = performRequest();
response.andExpect(jsonPath("$.content[0].titel").value(CollaborationTestFactory.TITEL));
response.andExpect(jsonPath("$.content[0].titel").value(OrganisationsEinheitCollaborationTestFactory.TITEL));
}
@SneakyThrows
......@@ -120,7 +120,7 @@ class CollaborationControllerTest {
System.out.println(response.andReturn().getResponse().getContentAsString());
response.andExpect(jsonPath("$.content[0].beschreibung").value(CollaborationTestFactory.BESCHREIBUNG));
response.andExpect(jsonPath("$.content[0].beschreibung").value(OrganisationsEinheitCollaborationTestFactory.BESCHREIBUNG));
}
@SneakyThrows
......@@ -129,7 +129,7 @@ class CollaborationControllerTest {
var expectedLink = UriComponentsBuilder
.fromUriString("http://localhost")
.path(OrganisationsEinheitController.PATH)
.pathSegment(CollaborationTestFactory.ZUSTAENDIGE_STELLE)
.pathSegment(OrganisationsEinheitCollaborationTestFactory.ZUSTAENDIGE_STELLE)
.build();
var response = performRequest();
......@@ -142,7 +142,7 @@ class CollaborationControllerTest {
@SneakyThrows
private ResultActions performRequest() {
return mockMvc.perform(get(CollaborationController.PATH + "/" + CollaborationTestFactory.VORGANG_ID + "/collaborations"));
return mockMvc.perform(get(CollaborationController.PATH + "/" + OrganisationsEinheitCollaborationTestFactory.VORGANG_ID + "/collaborations"));
}
}
}
......@@ -13,13 +13,26 @@ class CollaborationMapperTest {
private CollaborationMapper mapper = Mappers.getMapper(CollaborationMapper.class);
@Nested
class TestFromRequest {
class TestFromOrganisationsEinheitRequest {
@Test
void shouldMap() {
var collaboration = mapper.fromGrpc(GrpcCollaborationRequestTestFactory.create(), CollaborationTestFactory.VORGANG_ID);
var collaboration = mapper.fromOrganisationsEinheitRequest(GrpcCollaborationRequestForOrganisationsEinheitTestFactory.create(),
OrganisationsEinheitCollaborationTestFactory.VORGANG_ID);
assertThat(collaboration).usingRecursiveComparison().isEqualTo(CollaborationTestFactory.create());
assertThat(collaboration).usingRecursiveComparison().isEqualTo(OrganisationsEinheitCollaborationTestFactory.create());
}
}
@Nested
class TestFromFachstelleRequest {
@Test
void shouldMap() {
var collaboration = mapper.fromFachstelleRequest(GrpcCollaborationRequestForFachstelleTestFactory.create(),
FachstelleCollaborationTestFactory.VORGANG_ID);
assertThat(collaboration).usingRecursiveComparison().isEqualTo(FachstelleCollaborationTestFactory.create());
}
}
}
......@@ -37,7 +37,11 @@ class CollaborationModelAssemblerTest {
class TestToModel {
private static final String REL_ZUSTAENDIGE_STELLE = "zustaendigeStelle";
private final Collaboration collaboration = CollaborationTestFactory.create();
@Nested
class OnOrganisationsEinheitCollaboration {
private final OrganisationsEinheitCollaboration collaboration = OrganisationsEinheitCollaborationTestFactory.create();
@Test
void shouldHaveContent() {
......@@ -59,9 +63,35 @@ class CollaborationModelAssemblerTest {
}
}
@Nested
class OnFachstelleCollaboration {
private final FachstelleCollaboration collaboration = FachstelleCollaborationTestFactory.create();
@Test
void shouldHaveContent() {
var entityModel = callAssembler();
assertThat(entityModel.getContent()).isEqualTo(collaboration);
}
@Test
void shouldHaveLinkToFachstelle() {
var entityModel = callAssembler();
assertThat(entityModel.getLink(REL_ZUSTAENDIGE_STELLE)).get().extracting(Link::getHref)
.isEqualTo(FachstelleController.PATH + "/" + FachstelleTestFactory.ID);
}
private EntityModel<Collaboration> callAssembler() {
return assembler.toModel(collaboration);
}
}
}
@Nested
class TestToCollectionModel {
private final Collaboration collaboration = CollaborationTestFactory.create();
private final Collaboration collaboration = FachstelleCollaborationTestFactory.create();
@Nested
class OnNonEmptyCollaborationList {
......
......@@ -11,6 +11,7 @@ import org.mockito.Mock;
import org.mockito.Spy;
import de.ozgcloud.collaboration.request.CollaborationRequestServiceGrpc.CollaborationRequestServiceBlockingStub;
import de.ozgcloud.collaboration.request.GrpcCollaborationRequest;
import de.ozgcloud.collaboration.request.GrpcFindRequestsRequest;
class CollaborationRemoteServiceTest {
......@@ -26,16 +27,20 @@ class CollaborationRemoteServiceTest {
@Nested
class TestGetCollaborations {
public static final String VORGANG_ID = CollaborationTestFactory.VORGANG_ID;
public static final String VORGANG_ID = FachstelleCollaborationTestFactory.VORGANG_ID;
private final GrpcFindRequestsRequest searchRequest = GrpcFindRequestsRequestTestFactory.create();
private final Collaboration collaboration = CollaborationTestFactory.create();
private final GrpcCollaborationRequest organisationsEinheitRequest = GrpcCollaborationRequestForOrganisationsEinheitTestFactory.create();
private final GrpcCollaborationRequest fachstelleRequest = GrpcCollaborationRequestForFachstelleTestFactory.create();
private final OrganisationsEinheitCollaboration organisationsEinheitCollaboration = OrganisationsEinheitCollaborationTestFactory.create();
private final FachstelleCollaboration fachstelleCollaboration = FachstelleCollaborationTestFactory.create();
@BeforeEach
void init() {
doReturn(searchRequest).when(service).buildSearchRequest(VORGANG_ID);
when(stub.findRequests(searchRequest)).thenReturn(GrpcFindRequestsResponseTestFactory.create());
when(mapper.fromGrpc(GrpcFindRequestsResponseTestFactory.REQUEST, VORGANG_ID)).thenReturn(collaboration);
when(mapper.fromOrganisationsEinheitRequest(organisationsEinheitRequest, VORGANG_ID)).thenReturn(organisationsEinheitCollaboration);
when(mapper.fromFachstelleRequest(fachstelleRequest, VORGANG_ID)).thenReturn(fachstelleCollaboration);
}
@Test
......@@ -53,17 +58,24 @@ class CollaborationRemoteServiceTest {
}
@Test
void shouldMapToCollaboration() {
void shouldMapOrganisationsEinheitRequest() {
service.getCollaborations(VORGANG_ID).toList();
verify(mapper).fromGrpc(GrpcFindRequestsResponseTestFactory.REQUEST, VORGANG_ID);
verify(mapper).fromOrganisationsEinheitRequest(GrpcFindRequestsResponseTestFactory.ORGANISATIONS_EINHEIT_REQUEST, VORGANG_ID);
}
@Test
void shouldMapFachstelleRequest() {
service.getCollaborations(VORGANG_ID).toList();
verify(mapper).fromFachstelleRequest(GrpcFindRequestsResponseTestFactory.FACHSTELLE_REQUEST, VORGANG_ID);
}
@Test
void shouldReturnCollaborations() {
var collaborations = service.getCollaborations(VORGANG_ID).toList();
assertThat(collaborations).containsExactly(collaboration);
assertThat(collaborations).containsExactlyInAnyOrder(organisationsEinheitCollaboration, fachstelleCollaboration);
}
}
......
......@@ -33,7 +33,7 @@ class CollaborationServiceTest {
@Test
void shouldReturnCollaboration() {
var collaboration = CollaborationTestFactory.create();
var collaboration = FachstelleCollaborationTestFactory.create();
when(remoteService.getCollaborations(id)).thenReturn(Stream.of(collaboration));
var returnedCollaboration = callService();
......@@ -60,7 +60,7 @@ class CollaborationServiceTest {
@Test
void shouldReturnTrue() {
var collaboration = CollaborationTestFactory.create();
var collaboration = FachstelleCollaborationTestFactory.create();
when(remoteService.getCollaborations(id)).thenReturn(Stream.of(collaboration));
var hasCollaboration = callService();
......
package de.ozgcloud.alfa.collaboration;
import java.util.UUID;
import com.thedeanda.lorem.LoremIpsum;
import de.ozgcloud.alfa.collaboration.FachstelleCollaboration.FachstelleCollaborationBuilder;
public class FachstelleCollaborationTestFactory {
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;
public static final String TITEL = LoremIpsum.getInstance().getWords(7);
public static final String BESCHREIBUNG = LoremIpsum.getInstance().getParagraphs(2, 5);
public static final String ZUSTAENDIGE_STELLE = FachstelleTestFactory.ID;
public static FachstelleCollaboration create() {
return createBuilder()
.build();
}
private static FachstelleCollaborationBuilder createBuilder() {
return FachstelleCollaboration.builder()
.vorgangId(VORGANG_ID)
.collaborationVorgangId(COLLABORATION_VORGANG_ID)
.collaborationLevel(COLLABORATION_LEVEL)
.titel(TITEL)
.beschreibung(BESCHREIBUNG)
.zustaendigeStelle(ZUSTAENDIGE_STELLE);
}
}
......@@ -4,20 +4,21 @@ import java.util.UUID;
import de.ozgcloud.collaboration.request.GrpcCollaborationRequest;
class GrpcCollaborationRequestTestFactory {
class GrpcCollaborationRequestForFachstelleTestFactory {
public static final String ID = UUID.randomUUID().toString();
public static final String COLLABORATION_VORGANG_ID = CollaborationTestFactory.COLLABORATION_VORGANG_ID;
public static final String TITEL = CollaborationTestFactory.TITEL;
public static final String BESCHREIBUNG = CollaborationTestFactory.BESCHREIBUNG;
public static final String ZUSTAENDIGE_STELLE = CollaborationTestFactory.ZUSTAENDIGE_STELLE;
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;
public static final String ZUSTAENDIGE_STELLE = FachstelleCollaborationTestFactory.ZUSTAENDIGE_STELLE;
public static GrpcCollaborationRequest create() {
return createBuilder()
.setCollaborationLevel(FachstelleCollaborationTestFactory.COLLABORATION_LEVEL)
.build();
}
private static GrpcCollaborationRequest.Builder createBuilder() {
public static GrpcCollaborationRequest.Builder createBuilder() {
return GrpcCollaborationRequest.newBuilder()
.setId(ID)
.setCollaborationVorgangId(COLLABORATION_VORGANG_ID)
......
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 COLLABORATION_VORGANG_ID = OrganisationsEinheitCollaborationTestFactory.COLLABORATION_VORGANG_ID;
public static final String TITEL = OrganisationsEinheitCollaborationTestFactory.TITEL;
public static final String BESCHREIBUNG = OrganisationsEinheitCollaborationTestFactory.BESCHREIBUNG;
public static final String ZUSTAENDIGE_STELLE = OrganisationsEinheitCollaborationTestFactory.ZUSTAENDIGE_STELLE;
public static GrpcCollaborationRequest create() {
return createBuilder()
.setCollaborationLevel(OrganisationsEinheitCollaborationTestFactory.COLLABORATION_LEVEL)
.build();
}
public static GrpcCollaborationRequest.Builder createBuilder() {
return GrpcCollaborationRequest.newBuilder()
.setId(ID)
.setCollaborationVorgangId(COLLABORATION_VORGANG_ID)
.setTitel(TITEL)
.setBeschreibung(BESCHREIBUNG)
.setZustaendigeStelle(ZUSTAENDIGE_STELLE);
}
}
......@@ -5,13 +5,14 @@ import de.ozgcloud.collaboration.request.GrpcFindRequestsResponse;
class GrpcFindRequestsResponseTestFactory {
public static final GrpcCollaborationRequest REQUEST = GrpcCollaborationRequestTestFactory.create();
public static final GrpcCollaborationRequest ORGANISATIONS_EINHEIT_REQUEST = GrpcCollaborationRequestForOrganisationsEinheitTestFactory.create();
public static final GrpcCollaborationRequest FACHSTELLE_REQUEST = GrpcCollaborationRequestForFachstelleTestFactory.create();
public static GrpcFindRequestsResponse create() {
return createBuilder().build();
}
public static GrpcFindRequestsResponse.Builder createBuilder() {
return GrpcFindRequestsResponse.newBuilder().addRequests(REQUEST);
return GrpcFindRequestsResponse.newBuilder().addRequests(ORGANISATIONS_EINHEIT_REQUEST).addRequests(FACHSTELLE_REQUEST);
}
}
......@@ -4,25 +4,27 @@ import java.util.UUID;
import com.thedeanda.lorem.LoremIpsum;
import de.ozgcloud.alfa.collaboration.Collaboration.CollaborationBuilder;
import de.ozgcloud.alfa.collaboration.OrganisationsEinheitCollaboration.OrganisationsEinheitCollaborationBuilder;
public class CollaborationTestFactory {
public class OrganisationsEinheitCollaborationTestFactory {
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;
public static final String TITEL = LoremIpsum.getInstance().getWords(7);
public static final String BESCHREIBUNG = LoremIpsum.getInstance().getParagraphs(2, 5);
public static final String ZUSTAENDIGE_STELLE = OrganisationsEinheitTestFactory.ID;
public static Collaboration create() {
public static OrganisationsEinheitCollaboration create() {
return createBuilder()
.build();
}
private static CollaborationBuilder createBuilder() {
return Collaboration.builder()
private static OrganisationsEinheitCollaborationBuilder createBuilder() {
return OrganisationsEinheitCollaboration.builder()
.vorgangId(VORGANG_ID)
.collaborationVorgangId(COLLABORATION_VORGANG_ID)
.collaborationLevel(COLLABORATION_LEVEL)
.titel(TITEL)
.beschreibung(BESCHREIBUNG)
.zustaendigeStelle(ZUSTAENDIGE_STELLE);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment