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

OZG-7009 fix zustaendigeStelleId; validate collaborationLevel

parent ab3f7a15
No related branches found
No related tags found
No related merge requests found
package de.ozgcloud.alfa.collaboration;
import jakarta.validation.constraints.NotNull;
import com.fasterxml.jackson.annotation.JsonIgnore;
import de.ozgcloud.alfa.common.LinkedResource;
import de.ozgcloud.alfa.common.command.CommandBody;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
//TODO Rename to CollaborationRequest
@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class Collaboration implements CommandBody {
@JsonIgnore
......@@ -18,7 +26,8 @@ public class Collaboration implements CommandBody {
private String titel;
private String beschreibung;
private int collaborationLevel;
@NotNull
private Integer collaborationLevel;
@LinkedResource(controllerClass = OrganisationsEinheitController.class)
private String zustaendigeStelle;
......
......@@ -13,10 +13,10 @@ import org.springframework.web.bind.annotation.RestController;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
@RestController
@RequestMapping(OrganisationsEinheitController.PATH)
@RequiredArgsConstructor
class OrganisationsEinheitController {
public class OrganisationsEinheitController {
static final String PATH = "/api/organisationseinheits"; // NOSONAR
static final String SEARCH_BY_PARAM = "searchBy";
......
package de.ozgcloud.alfa.collaboration;
import java.util.Objects;
import java.util.UUID;
import com.thedeanda.lorem.LoremIpsum;
import de.ozgcloud.alfa.collaboration.Collaboration.CollaborationBuilder;
import de.ozgcloud.alfa.common.command.CommandOrder;
import de.ozgcloud.common.test.TestUtils;
public class CollaborationTestFactory {
public static final String VORGANG_ID = UUID.randomUUID().toString();
public static final String COLLABORATION_VORGANG_ID = UUID.randomUUID().toString();
public static final String TITEL = LoremIpsum.getInstance().getWords(7);
public static final String BESCHREIBUNG = LoremIpsum.getInstance().getParagraphs(2, 5);
public static final String BESCHREIBUNG = LoremIpsum.getInstance().getWords(10);
public static final String ZUSTAENDIGE_STELLE = OrganisationsEinheitTestFactory.ID;
public static final Integer COLLABORATION_LEVEL = 1;
public static Collaboration create() {
return createBuilder()
.build();
return createBuilder().build();
}
private static CollaborationBuilder createBuilder() {
public static CollaborationBuilder createBuilder() {
return Collaboration.builder()
.vorgangId(VORGANG_ID)
.collaborationVorgangId(COLLABORATION_VORGANG_ID)
.titel(TITEL)
.beschreibung(BESCHREIBUNG)
.zustaendigeStelle(ZUSTAENDIGE_STELLE);
.zustaendigeStelle(ZUSTAENDIGE_STELLE)
.collaborationLevel(COLLABORATION_LEVEL);
}
}
public static String buildCreateCollaborationRequestContent(Collaboration collaboration) {
return TestUtils.loadTextFile("jsonTemplates/command/createCollaborationRequestBody.json.tmpl",
CommandOrder.CREATE_COLLABORATION_REQUEST.name(),
collaboration.getTitel(),
collaboration.getBeschreibung(),
buildZustaendigeStelleUri(collaboration.getZustaendigeStelle()),
Objects.isNull(collaboration.getCollaborationLevel()) ? null : TestUtils.addQuote(collaboration.getCollaborationLevel().toString()));
}
private static String buildZustaendigeStelleUri(String zustaendigeStelleId) {
return Objects.nonNull(zustaendigeStelleId)
? "\"/api/organisationseinheits/" + zustaendigeStelleId + "\""
: zustaendigeStelleId;
}
}
\ No newline at end of file
......@@ -28,6 +28,7 @@ import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import org.apache.commons.lang3.ArrayUtils;
......@@ -47,6 +48,8 @@ import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;
import de.ozgcloud.alfa.collaboration.CollaborationTestFactory;
import de.ozgcloud.alfa.collaboration.OrganisationsEinheitHeaderTestFactory;
import de.ozgcloud.alfa.common.ValidationMessageCodes;
import de.ozgcloud.alfa.common.user.UserProfileTestFactory;
import de.ozgcloud.alfa.postfach.PostfachMailTestFactory;
......@@ -56,6 +59,7 @@ import de.ozgcloud.alfa.vorgang.VorgangHeaderTestFactory;
import de.ozgcloud.alfa.vorgang.VorgangWithEingangTestFactory;
import de.ozgcloud.alfa.vorgang.forwarding.RedirectRequest;
import de.ozgcloud.common.test.TestUtils;
import lombok.SneakyThrows;
@AutoConfigureMockMvc
@SpringBootTest
......@@ -68,6 +72,40 @@ public class CommandITCase {
@MockBean
private VorgangController vorgangController;
@DisplayName("Collaboration request")
@WithMockUser
@Nested
class TestCollaborationRequest {
@Captor
private ArgumentCaptor<CreateCommand> commandCaptor;
@SneakyThrows
@Test
void shouldValidateCollaborationLevel() {
var requestContent = CollaborationTestFactory.buildCreateCollaborationRequestContent(CollaborationTestFactory.createBuilder()
.collaborationLevel(null)
.build());
doRequest(requestContent).andDo(print()).andExpect(status().isUnprocessableEntity())
.andExpect(jsonPath("$.invalidParams.length()").value(1))
.andExpect(jsonPath("$.invalidParams[0].name").value("createCommand.command.body.collaborationLevel"))
.andExpect(jsonPath("$.invalidParams[0].reason").value("must not be null"));
}
@SneakyThrows
@Test
void shouldExtractZustaendigeStelleId() {
when(commandRemoteService.createCommand(any())).thenReturn(CommandTestFactory.create());
var requestContent = CollaborationTestFactory.buildCreateCollaborationRequestContent(CollaborationTestFactory.create());
doRequest(requestContent);
verify(commandRemoteService).createCommand(commandCaptor.capture());
assertThat(commandCaptor.getValue().getBody()).hasFieldOrPropertyWithValue("zustaendigeStelle", OrganisationsEinheitHeaderTestFactory.ID);
}
}
@Nested
@WithMockUser
class TestAssignUser {
......@@ -295,13 +333,13 @@ public class CommandITCase {
}
}
}
}
ResultActions doRequest(String content) throws Exception {
return mockMvc.perform(post("/api/vorgangs/" + CommandTestFactory.VORGANG_ID + "/relations/" + CommandTestFactory.RELATION_ID + "/"
+ CommandTestFactory.RELATION_VERSION + "/commands")
.with(csrf())
.contentType(MediaType.APPLICATION_JSON)
.content(content));
}
ResultActions doRequest(String content) throws Exception {
return mockMvc.perform(post("/api/vorgangs/" + CommandTestFactory.VORGANG_ID + "/relations/" + CommandTestFactory.RELATION_ID + "/"
+ CommandTestFactory.RELATION_VERSION + "/commands")
.with(csrf())
.contentType(MediaType.APPLICATION_JSON)
.content(content));
}
}
\ No newline at end of file
{
"order": "%s",
"body": {
"titel": "%s",
"beschreibung": "%s",
"zustaendigeStelle": %s,
"collaborationLevel": %s
}
}
\ 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