diff --git a/backend/src/main/java/ch/puzzle/okr/controller/AlignmentController.java b/backend/src/main/java/ch/puzzle/okr/controller/AlignmentController.java deleted file mode 100644 index 85b6a77ec1..0000000000 --- a/backend/src/main/java/ch/puzzle/okr/controller/AlignmentController.java +++ /dev/null @@ -1,45 +0,0 @@ -package ch.puzzle.okr.controller; - -import ch.puzzle.okr.dto.alignment.AlignmentObjectiveDto; -import ch.puzzle.okr.mapper.AlignmentSelectionMapper; -import ch.puzzle.okr.service.business.AlignmentSelectionBusinessService; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; -import io.swagger.v3.oas.annotations.responses.ApiResponses; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -import java.util.List; - -@RestController -@RequestMapping("api/v2/alignments") -public class AlignmentController { - private final AlignmentSelectionMapper alignmentSelectionMapper; - private final AlignmentSelectionBusinessService alignmentSelectionBusinessService; - - public AlignmentController(AlignmentSelectionMapper alignmentSelectionMapper, - AlignmentSelectionBusinessService alignmentSelectionBusinessService) { - this.alignmentSelectionMapper = alignmentSelectionMapper; - this.alignmentSelectionBusinessService = alignmentSelectionBusinessService; - } - - @Operation(summary = "Get all objectives and their key results to select the alignment", description = "Get a list of objectives with their key results to select the alignment") - @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "Returned a list of objectives with their key results to select the alignment", content = { - @Content(mediaType = "application/json", schema = @Schema(implementation = AlignmentObjectiveDto.class)) }), - @ApiResponse(responseCode = "400", description = "Can't return list of objectives with their key results to select the alignment", content = @Content) }) - @GetMapping("/selections") - public ResponseEntity> getAlignmentSelections( - @RequestParam(required = false, defaultValue = "", name = "quarter") Long quarterFilter, - @RequestParam(required = false, defaultValue = "", name = "team") Long teamFilter) { - return ResponseEntity.status(HttpStatus.OK) - .body(alignmentSelectionMapper.toDto(alignmentSelectionBusinessService - .getAlignmentSelectionByQuarterIdAndTeamIdNot(quarterFilter, teamFilter))); - } -} diff --git a/backend/src/main/java/ch/puzzle/okr/mapper/AlignmentSelectionMapper.java b/backend/src/main/java/ch/puzzle/okr/mapper/AlignmentSelectionMapper.java deleted file mode 100644 index 547181b95e..0000000000 --- a/backend/src/main/java/ch/puzzle/okr/mapper/AlignmentSelectionMapper.java +++ /dev/null @@ -1,58 +0,0 @@ -package ch.puzzle.okr.mapper; - -import ch.puzzle.okr.dto.alignment.AlignmentKeyResultDto; -import ch.puzzle.okr.dto.alignment.AlignmentObjectiveDto; -import ch.puzzle.okr.models.alignment.AlignmentSelection; -import org.springframework.stereotype.Component; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.Optional; - -@Component -public class AlignmentSelectionMapper { - - public List toDto(List alignments) { - List alignmentDtos = new ArrayList<>(); - alignments.forEach(alignment -> processObjectives(alignmentDtos, alignment)); - return alignmentDtos; - } - - private Optional getMatchingObjectiveDto(Long objectiveId, - List objectives) { - return objectives.stream().filter(objectiveDto -> Objects.equals(objectiveId, objectiveDto.id())).findFirst(); - } - - private void processObjectives(List objectiveDtos, AlignmentSelection alignment) { - Optional objectiveDto = getMatchingObjectiveDto( - alignment.getAlignmentSelectionId().getObjectiveId(), objectiveDtos); - if (objectiveDto.isPresent()) { - processKeyResults(objectiveDto.get(), alignment); - } else { - AlignmentObjectiveDto alignmentObjectiveDto = createObjectiveDto(alignment); - objectiveDtos.add(alignmentObjectiveDto); - processKeyResults(alignmentObjectiveDto, alignment); - } - } - - private void processKeyResults(AlignmentObjectiveDto objectiveDto, AlignmentSelection alignment) { - if (isValidId(alignment.getAlignmentSelectionId().getKeyResultId())) { - objectiveDto.keyResults().add(createKeyResultDto(alignment)); - } - } - - private AlignmentObjectiveDto createObjectiveDto(AlignmentSelection alignment) { - return new AlignmentObjectiveDto(alignment.getAlignmentSelectionId().getObjectiveId(), - alignment.getObjectiveTitle(), new ArrayList<>()); - } - - private AlignmentKeyResultDto createKeyResultDto(AlignmentSelection alignment) { - return new AlignmentKeyResultDto(alignment.getAlignmentSelectionId().getKeyResultId(), - alignment.getKeyResultTitle()); - } - - private boolean isValidId(Long id) { - return id != null && id > -1; - } -} diff --git a/backend/src/main/java/ch/puzzle/okr/models/alignment/AlignmentSelection.java b/backend/src/main/java/ch/puzzle/okr/models/alignment/AlignmentSelection.java deleted file mode 100644 index 0246817184..0000000000 --- a/backend/src/main/java/ch/puzzle/okr/models/alignment/AlignmentSelection.java +++ /dev/null @@ -1,140 +0,0 @@ -package ch.puzzle.okr.models.alignment; - -import jakarta.persistence.EmbeddedId; -import jakarta.persistence.Entity; -import org.hibernate.annotations.Immutable; - -import java.util.Objects; - -@Entity -@Immutable -public class AlignmentSelection { - - @EmbeddedId - private AlignmentSelectionId alignmentSelectionId; - - private Long teamId; - private String teamName; - private String objectiveTitle; - private Long quarterId; - private String quarterLabel; - private String keyResultTitle; - - public AlignmentSelection() { - } - - private AlignmentSelection(Builder builder) { - alignmentSelectionId = builder.alignmentSelectionId; - teamId = builder.teamId; - teamName = builder.teamName; - objectiveTitle = builder.objectiveTitle; - quarterId = builder.quarterId; - quarterLabel = builder.quarterLabel; - keyResultTitle = builder.keyResultTitle; - } - - public AlignmentSelectionId getAlignmentSelectionId() { - return alignmentSelectionId; - } - - public Long getTeamId() { - return teamId; - } - - public String getObjectiveTitle() { - return objectiveTitle; - } - - public Long getQuarterId() { - return quarterId; - } - - public String getKeyResultTitle() { - return keyResultTitle; - } - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - AlignmentSelection alignmentSelection = (AlignmentSelection) o; - return Objects.equals(alignmentSelectionId, alignmentSelection.alignmentSelectionId) - && Objects.equals(teamId, alignmentSelection.teamId) - && Objects.equals(objectiveTitle, alignmentSelection.objectiveTitle) - && Objects.equals(quarterId, alignmentSelection.quarterId) - && Objects.equals(keyResultTitle, alignmentSelection.keyResultTitle); - } - - @Override - public int hashCode() { - return Objects.hash(alignmentSelectionId, teamId, objectiveTitle, quarterId, keyResultTitle); - } - - @Override - public String toString() { - return "AlignmentSelection{" + "alignmentSelectionId=" + alignmentSelectionId + ", teamId='" + teamId - + ", teamName='" + teamName + '\'' + ", objectiveTitle='" + objectiveTitle + '\'' + ", quarterId=" - + quarterId + ", quarterLabel='" + quarterLabel + '\'' + ", keyResultTitle='" + keyResultTitle + '\'' - + '}'; - } - - public static final class Builder { - private AlignmentSelectionId alignmentSelectionId; - - private Long teamId; - private String teamName; - private String objectiveTitle; - private Long quarterId; - private String quarterLabel; - private String keyResultTitle; - - public Builder() { - // This builder can be empty, so that it can get called - } - - public static Builder builder() { - return new Builder(); - } - - public Builder withAlignmentSelectionId(AlignmentSelectionId alignmentSelectionId) { - this.alignmentSelectionId = alignmentSelectionId; - return this; - } - - public Builder withTeamId(Long teamId) { - this.teamId = teamId; - return this; - } - - public Builder withTeamName(String teamName) { - this.teamName = teamName; - return this; - } - - public Builder withObjectiveTitle(String objectiveTitle) { - this.objectiveTitle = objectiveTitle; - return this; - } - - public Builder withQuarterId(Long quarterId) { - this.quarterId = quarterId; - return this; - } - - public Builder withQuarterLabel(String quarterLabel) { - this.quarterLabel = quarterLabel; - return this; - } - - public Builder withKeyResultTitle(String keyResultTitle) { - this.keyResultTitle = keyResultTitle; - return this; - } - - public AlignmentSelection build() { - return new AlignmentSelection(this); - } - } -} diff --git a/backend/src/main/java/ch/puzzle/okr/models/alignment/AlignmentSelectionId.java b/backend/src/main/java/ch/puzzle/okr/models/alignment/AlignmentSelectionId.java deleted file mode 100644 index 75c52cf2b8..0000000000 --- a/backend/src/main/java/ch/puzzle/okr/models/alignment/AlignmentSelectionId.java +++ /dev/null @@ -1,83 +0,0 @@ -package ch.puzzle.okr.models.alignment; - -import jakarta.persistence.Embeddable; - -import java.io.Serializable; -import java.util.Objects; - -@Embeddable -public class AlignmentSelectionId implements Serializable { - - private Long objectiveId; - private Long keyResultId; - - public AlignmentSelectionId() { - } - - private AlignmentSelectionId(Long objectiveId, Long keyResultId) { - this.objectiveId = objectiveId; - this.keyResultId = keyResultId; - } - - private AlignmentSelectionId(Builder builder) { - this(builder.objectiveId, builder.keyResultId); - } - - public static AlignmentSelectionId of(Long objectiveId, Long keyResultId) { - return new AlignmentSelectionId(objectiveId, keyResultId); - } - - public Long getObjectiveId() { - return objectiveId; - } - - public Long getKeyResultId() { - return keyResultId; - } - - @Override - public String toString() { - return "AlignmentSelectionId{" + "objectiveId=" + objectiveId + ", keyResultId=" + keyResultId + '}'; - } - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - AlignmentSelectionId that = (AlignmentSelectionId) o; - return Objects.equals(objectiveId, that.objectiveId) && Objects.equals(keyResultId, that.keyResultId); - } - - @Override - public int hashCode() { - return Objects.hash(objectiveId, keyResultId); - } - - public static final class Builder { - private Long objectiveId; - private Long keyResultId; - - private Builder() { - } - - public static Builder builder() { - return new Builder(); - } - - public Builder withObjectiveId(Long objectiveId) { - this.objectiveId = objectiveId; - return this; - } - - public Builder withKeyResultId(Long keyResultId) { - this.keyResultId = keyResultId; - return this; - } - - public AlignmentSelectionId build() { - return new AlignmentSelectionId(this); - } - } -} diff --git a/backend/src/main/java/ch/puzzle/okr/repository/AlignmentSelectionRepository.java b/backend/src/main/java/ch/puzzle/okr/repository/AlignmentSelectionRepository.java deleted file mode 100644 index 50896b44f3..0000000000 --- a/backend/src/main/java/ch/puzzle/okr/repository/AlignmentSelectionRepository.java +++ /dev/null @@ -1,15 +0,0 @@ -package ch.puzzle.okr.repository; - -import ch.puzzle.okr.models.alignment.AlignmentSelection; -import ch.puzzle.okr.models.alignment.AlignmentSelectionId; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; - -import java.util.List; - -public interface AlignmentSelectionRepository extends ReadOnlyRepository { - - @Query(value = "from AlignmentSelection where quarterId = :quarter_id and teamId != :ignoredTeamId") - List getAlignmentSelectionByQuarterIdAndTeamIdNot(@Param("quarter_id") Long quarterId, - @Param("ignoredTeamId") Long ignoredTeamId); -} diff --git a/backend/src/main/java/ch/puzzle/okr/service/business/AlignmentSelectionBusinessService.java b/backend/src/main/java/ch/puzzle/okr/service/business/AlignmentSelectionBusinessService.java deleted file mode 100644 index 8e6feefed1..0000000000 --- a/backend/src/main/java/ch/puzzle/okr/service/business/AlignmentSelectionBusinessService.java +++ /dev/null @@ -1,23 +0,0 @@ -package ch.puzzle.okr.service.business; - -import ch.puzzle.okr.models.alignment.AlignmentSelection; -import ch.puzzle.okr.service.persistence.AlignmentSelectionPersistenceService; -import org.springframework.stereotype.Service; - -import java.util.List; - -@Service -public class AlignmentSelectionBusinessService { - - private final AlignmentSelectionPersistenceService alignmentSelectionPersistenceService; - - public AlignmentSelectionBusinessService( - AlignmentSelectionPersistenceService alignmentSelectionPersistenceService) { - this.alignmentSelectionPersistenceService = alignmentSelectionPersistenceService; - } - - public List getAlignmentSelectionByQuarterIdAndTeamIdNot(Long quarterId, Long ignoredTeamId) { - return alignmentSelectionPersistenceService.getAlignmentSelectionByQuarterIdAndTeamIdNot(quarterId, - ignoredTeamId); - } -} diff --git a/backend/src/main/java/ch/puzzle/okr/service/persistence/AlignmentSelectionPersistenceService.java b/backend/src/main/java/ch/puzzle/okr/service/persistence/AlignmentSelectionPersistenceService.java deleted file mode 100644 index 3a439073b8..0000000000 --- a/backend/src/main/java/ch/puzzle/okr/service/persistence/AlignmentSelectionPersistenceService.java +++ /dev/null @@ -1,21 +0,0 @@ -package ch.puzzle.okr.service.persistence; - -import ch.puzzle.okr.models.alignment.AlignmentSelection; -import ch.puzzle.okr.repository.AlignmentSelectionRepository; -import org.springframework.stereotype.Service; - -import java.util.List; - -@Service -public class AlignmentSelectionPersistenceService { - - private final AlignmentSelectionRepository alignmentSelectionRepository; - - public AlignmentSelectionPersistenceService(AlignmentSelectionRepository alignmentSelectionRepository) { - this.alignmentSelectionRepository = alignmentSelectionRepository; - } - - public List getAlignmentSelectionByQuarterIdAndTeamIdNot(Long quarterId, Long ignoredTeamId) { - return alignmentSelectionRepository.getAlignmentSelectionByQuarterIdAndTeamIdNot(quarterId, ignoredTeamId); - } -} diff --git a/backend/src/main/resources/db/h2-db/database-h2-schema/V1_0_0__current-db-schema-for-testing.sql b/backend/src/main/resources/db/h2-db/database-h2-schema/V1_0_0__current-db-schema-for-testing.sql index 51fbbfc187..19f8f23ee7 100644 --- a/backend/src/main/resources/db/h2-db/database-h2-schema/V1_0_0__current-db-schema-for-testing.sql +++ b/backend/src/main/resources/db/h2-db/database-h2-schema/V1_0_0__current-db-schema-for-testing.sql @@ -208,21 +208,6 @@ create table if not exists alignment foreign key (target_objective_id) references objective ); -DROP VIEW IF EXISTS ALIGNMENT_SELECTION; -CREATE VIEW ALIGNMENT_SELECTION AS -SELECT O.ID AS "OBJECTIVE_ID", - O.TITLE AS "OBJECTIVE_TITLE", - T.ID AS "TEAM_ID", - T.NAME AS "TEAM_NAME", - Q.ID AS "QUARTER_ID", - Q.LABEL AS "QUARTER_LABEL", - COALESCE(KR.ID, -1) AS "KEY_RESULT_ID", - KR.TITLE AS "KEY_RESULT_TITLE" -FROM OBJECTIVE O - LEFT JOIN TEAM T ON O.TEAM_ID = T.ID - LEFT JOIN QUARTER Q ON O.QUARTER_ID = Q.ID - LEFT JOIN KEY_RESULT KR ON O.ID = KR.OBJECTIVE_ID; - create table if not exists organisation ( id bigint not null, diff --git a/backend/src/main/resources/db/migration/V2_1_3__removeAlignmentSelection.sql b/backend/src/main/resources/db/migration/V2_1_3__removeAlignmentSelection.sql new file mode 100644 index 0000000000..751c03e89b --- /dev/null +++ b/backend/src/main/resources/db/migration/V2_1_3__removeAlignmentSelection.sql @@ -0,0 +1 @@ +drop view if exists alignment_selection; \ No newline at end of file diff --git a/backend/src/test/java/ch/puzzle/okr/controller/AlignmentControllerIT.java b/backend/src/test/java/ch/puzzle/okr/controller/AlignmentControllerIT.java deleted file mode 100644 index c0372930db..0000000000 --- a/backend/src/test/java/ch/puzzle/okr/controller/AlignmentControllerIT.java +++ /dev/null @@ -1,97 +0,0 @@ -package ch.puzzle.okr.controller; - -import ch.puzzle.okr.mapper.AlignmentSelectionMapper; -import ch.puzzle.okr.models.alignment.AlignmentSelection; -import ch.puzzle.okr.models.alignment.AlignmentSelectionId; -import ch.puzzle.okr.service.business.AlignmentSelectionBusinessService; -import org.hamcrest.Matchers; -import org.hamcrest.core.Is; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.BDDMockito; -import org.mockito.junit.jupiter.MockitoExtension; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.boot.test.mock.mockito.SpyBean; -import org.springframework.http.MediaType; -import org.springframework.security.test.context.support.WithMockUser; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.result.MockMvcResultMatchers; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import static org.mockito.ArgumentMatchers.any; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; - -@WithMockUser(value = "spring") -@ExtendWith(MockitoExtension.class) -@WebMvcTest(AlignmentController.class) -class AlignmentControllerIT { - @Autowired - private MockMvc mvc; - @MockBean - private AlignmentSelectionBusinessService alignmentSelectionBusinessService; - @SpyBean - private AlignmentSelectionMapper alignmentSelectionMapper; - - static String alignmentObjectiveName = "Objective 5"; - static List alignmentSelectionPuzzle = List.of( - AlignmentSelection.Builder.builder().withAlignmentSelectionId(AlignmentSelectionId.of(1L, 20L)) - .withObjectiveTitle("Objective 1").withKeyResultTitle("KeyResult 20").build(), - AlignmentSelection.Builder.builder().withAlignmentSelectionId(AlignmentSelectionId.of(1L, 40L)) - .withObjectiveTitle("Objective 1").withKeyResultTitle("KeyResult 40").build()); - static List alignmentSelectionOKR = List.of( - AlignmentSelection.Builder.builder().withAlignmentSelectionId(AlignmentSelectionId.of(5L, 21L)) - .withObjectiveTitle(alignmentObjectiveName).withKeyResultTitle("KeyResult 21").build(), - AlignmentSelection.Builder.builder().withAlignmentSelectionId(AlignmentSelectionId.of(5L, 41L)) - .withObjectiveTitle(alignmentObjectiveName).withKeyResultTitle("KeyResult 41").build(), - AlignmentSelection.Builder.builder().withAlignmentSelectionId(AlignmentSelectionId.of(5L, 61L)) - .withObjectiveTitle(alignmentObjectiveName).withKeyResultTitle("KeyResult 61").build(), - AlignmentSelection.Builder.builder().withAlignmentSelectionId(AlignmentSelectionId.of(5L, 81L)) - .withObjectiveTitle(alignmentObjectiveName).withKeyResultTitle("KeyResult 81").build()); - static AlignmentSelection alignmentSelectionEmptyKeyResults = AlignmentSelection.Builder.builder() - .withAlignmentSelectionId(AlignmentSelectionId.of(8L, null)).withObjectiveTitle("Objective 8").build(); - - @Test - void shouldGetAllObjectivesWithKeyResults() throws Exception { - List alignmentSelections = new ArrayList<>(); - alignmentSelections.addAll(alignmentSelectionPuzzle); - alignmentSelections.addAll(alignmentSelectionOKR); - alignmentSelections.add(alignmentSelectionEmptyKeyResults); - BDDMockito.given(alignmentSelectionBusinessService.getAlignmentSelectionByQuarterIdAndTeamIdNot(2L, 4L)) - .willReturn(alignmentSelections); - - mvc.perform(get("/api/v2/alignments/selections?quarter=2&team=4").contentType(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.status().isOk()).andExpect(jsonPath("$", Matchers.hasSize(3))) - .andExpect(jsonPath("$[0].id", Is.is(1))).andExpect(jsonPath("$[0].keyResults[0].id", Is.is(20))) - .andExpect(jsonPath("$[0].keyResults[1].id", Is.is(40))).andExpect(jsonPath("$[1].id", Is.is(5))) - .andExpect(jsonPath("$[1].keyResults[0].id", Is.is(21))) - .andExpect(jsonPath("$[1].keyResults[1].id", Is.is(41))) - .andExpect(jsonPath("$[1].keyResults[2].id", Is.is(61))) - .andExpect(jsonPath("$[1].keyResults[3].id", Is.is(81))).andExpect(jsonPath("$[2].id", Is.is(8))) - .andExpect(jsonPath("$[2].keyResults.size()", Is.is(0))); - } - - @Test - void shouldGetAllObjectivesWithKeyResultsIfAllObjectivesFiltered() throws Exception { - BDDMockito.given(alignmentSelectionBusinessService.getAlignmentSelectionByQuarterIdAndTeamIdNot(any(), any())) - .willReturn(Collections.emptyList()); - - mvc.perform(get("/api/v2/alignments/selections").contentType(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.status().isOk()).andExpect(jsonPath("$", Matchers.hasSize(0))); - } - - @Test - void shouldReturnObjectiveWithEmptyKeyResultListWhenNoKeyResultsInFilteredQuarter() throws Exception { - BDDMockito.given(alignmentSelectionBusinessService.getAlignmentSelectionByQuarterIdAndTeamIdNot(2L, 4L)) - .willReturn(List.of(alignmentSelectionEmptyKeyResults)); - - mvc.perform(get("/api/v2/alignments/selections?quarter=2&team=4").contentType(MediaType.APPLICATION_JSON)) - .andExpect(MockMvcResultMatchers.status().isOk()).andExpect(jsonPath("$", Matchers.hasSize(1))) - .andExpect(jsonPath("$[0].id", Is.is(8))).andExpect(jsonPath("$[0].keyResults.size()", Is.is(0))); - } -} diff --git a/backend/src/test/java/ch/puzzle/okr/mapper/AlignmentSelectionMapperTest.java b/backend/src/test/java/ch/puzzle/okr/mapper/AlignmentSelectionMapperTest.java deleted file mode 100644 index 8a7f6fb366..0000000000 --- a/backend/src/test/java/ch/puzzle/okr/mapper/AlignmentSelectionMapperTest.java +++ /dev/null @@ -1,92 +0,0 @@ -package ch.puzzle.okr.mapper; - -import ch.puzzle.okr.dto.alignment.AlignmentObjectiveDto; -import ch.puzzle.okr.models.alignment.AlignmentSelection; -import ch.puzzle.okr.models.alignment.AlignmentSelectionId; -import org.junit.jupiter.api.Test; - -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static ch.puzzle.okr.TestConstants.*; - -class AlignmentSelectionMapperTest { - private final AlignmentSelectionMapper alignmentSelectionMapper = new AlignmentSelectionMapper(); - - @Test - void toDtoShouldReturnEmptyListWhenNoObjectiveFound() { - List alignmentSelections = List.of(); - List alignmentObjectiveDtos = alignmentSelectionMapper.toDto(alignmentSelections); - - assertTrue(alignmentObjectiveDtos.isEmpty()); - } - - @Test - void toDtoShouldReturnOneElementWhenObjectiveFound() { - List alignmentSelections = List.of(AlignmentSelection.Builder.builder() - .withAlignmentSelectionId(AlignmentSelectionId.Builder.builder().withObjectiveId(1L).build()) - .withTeamId(2L).withTeamName(TEAM_PUZZLE).withObjectiveTitle("Objective 1").build()); - List alignmentObjectiveDtos = alignmentSelectionMapper.toDto(alignmentSelections); - - assertEquals(1, alignmentObjectiveDtos.size()); - assertEquals(0, alignmentObjectiveDtos.get(0).keyResults().size()); - } - - @Test - void toDtoShouldReturnOneElementWhenObjectiveWithKeyResultFound() { - List alignmentSelections = List.of(AlignmentSelection.Builder.builder() - .withAlignmentSelectionId( - AlignmentSelectionId.Builder.builder().withObjectiveId(1L).withKeyResultId(3L).build()) - .withTeamId(2L).withTeamName(TEAM_PUZZLE).withObjectiveTitle("Objective 1") - .withKeyResultTitle("Key Result 3").build()); - List alignmentObjectiveDtos = alignmentSelectionMapper.toDto(alignmentSelections); - - assertEquals(1, alignmentObjectiveDtos.size()); - assertEquals(1, alignmentObjectiveDtos.get(0).keyResults().size()); - } - - @Test - void toDtoShouldReturnOneElementWhenObjectiveWithTwoKeyResultsFound() { - List alignmentSelections = List.of( - AlignmentSelection.Builder.builder() - .withAlignmentSelectionId( - AlignmentSelectionId.Builder.builder().withObjectiveId(1L).withKeyResultId(3L).build()) - .withTeamId(2L).withTeamName(TEAM_PUZZLE).withObjectiveTitle("Objective 1") - .withKeyResultTitle("Key Result 3").build(), - AlignmentSelection.Builder.builder() - .withAlignmentSelectionId( - AlignmentSelectionId.Builder.builder().withObjectiveId(1L).withKeyResultId(5L).build()) - .withTeamId(2L).withTeamName(TEAM_PUZZLE).withObjectiveTitle("Objective 1") - .withKeyResultTitle("Key Result 5").build()); - List alignmentObjectiveDtos = alignmentSelectionMapper.toDto(alignmentSelections); - - assertEquals(1, alignmentObjectiveDtos.size()); - assertEquals(2, alignmentObjectiveDtos.get(0).keyResults().size()); - } - - @Test - void toDtoShouldReturnOneElementWhenTwoObjectivesWithKeyResultsFound() { - List alignmentSelections = List.of( - AlignmentSelection.Builder.builder() - .withAlignmentSelectionId( - AlignmentSelectionId.Builder.builder().withObjectiveId(1L).withKeyResultId(3L).build()) - .withTeamId(2L).withTeamName(TEAM_PUZZLE).withObjectiveTitle("Objective 1") - .withKeyResultTitle("Key Result 3").build(), - AlignmentSelection.Builder.builder() - .withAlignmentSelectionId( - AlignmentSelectionId.Builder.builder().withObjectiveId(5L).withKeyResultId(6L).build()) - .withTeamId(2L).withTeamName(TEAM_PUZZLE).withObjectiveTitle("Objective 5") - .withKeyResultTitle("Key Result 6").build(), - AlignmentSelection.Builder.builder() - .withAlignmentSelectionId( - AlignmentSelectionId.Builder.builder().withObjectiveId(1L).withKeyResultId(9L).build()) - .withTeamId(2L).withTeamName(TEAM_PUZZLE).withObjectiveTitle("Objective 1") - .withKeyResultTitle("Key Result 9").build()); - List alignmentObjectiveDtos = alignmentSelectionMapper.toDto(alignmentSelections); - - assertEquals(2, alignmentObjectiveDtos.size()); - assertEquals(2, alignmentObjectiveDtos.get(0).keyResults().size()); - assertEquals(1, alignmentObjectiveDtos.get(1).keyResults().size()); - } -} diff --git a/backend/src/test/java/ch/puzzle/okr/service/business/AlignmentSelectionBusinessServiceTest.java b/backend/src/test/java/ch/puzzle/okr/service/business/AlignmentSelectionBusinessServiceTest.java deleted file mode 100644 index f0071bfe61..0000000000 --- a/backend/src/test/java/ch/puzzle/okr/service/business/AlignmentSelectionBusinessServiceTest.java +++ /dev/null @@ -1,43 +0,0 @@ -package ch.puzzle.okr.service.business; - -import ch.puzzle.okr.models.alignment.AlignmentSelection; -import ch.puzzle.okr.models.alignment.AlignmentSelectionId; -import ch.puzzle.okr.service.persistence.AlignmentSelectionPersistenceService; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.Mockito.*; -import static ch.puzzle.okr.TestConstants.*; - -@ExtendWith(MockitoExtension.class) -class AlignmentSelectionBusinessServiceTest { - - @InjectMocks - AlignmentSelectionBusinessService alignmentSelectionBusinessService; - @Mock - AlignmentSelectionPersistenceService alignmentSelectionPersistenceService; - - private static AlignmentSelection createAlignmentSelection() { - return AlignmentSelection.Builder.builder().withAlignmentSelectionId(AlignmentSelectionId.of(9L, 15L)) - .withTeamId(5L).withTeamName(TEAM_PUZZLE).withObjectiveTitle("Objective 9").withQuarterId(2L) - .withQuarterLabel("GJ 23/24-Q1").withKeyResultTitle("Key Result 15").build(); - } - - @Test - void getAlignmentSelectionByQuarterIdAndTeamIdNotShouldReturnListOfAlignmentSelections() { - when(alignmentSelectionPersistenceService.getAlignmentSelectionByQuarterIdAndTeamIdNot(2L, 4L)) - .thenReturn(List.of(createAlignmentSelection())); - - List alignmentSelections = alignmentSelectionBusinessService - .getAlignmentSelectionByQuarterIdAndTeamIdNot(2L, 4L); - - assertEquals(1, alignmentSelections.size()); - verify(alignmentSelectionPersistenceService, times(1)).getAlignmentSelectionByQuarterIdAndTeamIdNot(2L, 4L); - } -} diff --git a/backend/src/test/java/ch/puzzle/okr/service/persistence/AlignmentSelectionPersistenceServiceIT.java b/backend/src/test/java/ch/puzzle/okr/service/persistence/AlignmentSelectionPersistenceServiceIT.java deleted file mode 100644 index d01a662f88..0000000000 --- a/backend/src/test/java/ch/puzzle/okr/service/persistence/AlignmentSelectionPersistenceServiceIT.java +++ /dev/null @@ -1,48 +0,0 @@ -package ch.puzzle.okr.service.persistence; - -import ch.puzzle.okr.models.alignment.AlignmentSelection; -import ch.puzzle.okr.models.alignment.AlignmentSelectionId; -import ch.puzzle.okr.test.SpringIntegrationTest; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; - -import java.util.List; -import java.util.stream.Stream; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -@SpringIntegrationTest -class AlignmentSelectionPersistenceServiceIT { - @Autowired - private AlignmentSelectionPersistenceService alignmentSelectionPersistenceService; - - @Test - void getAlignmentSelectionByQuarterIdAndTeamIdNotShouldReturnAlignmentSelections() { - List alignmentSelections = alignmentSelectionPersistenceService - .getAlignmentSelectionByQuarterIdAndTeamIdNot(2L, 4L); - - assertEquals(12, alignmentSelections.size()); - alignmentSelections.forEach(alignmentSelection -> assertTrue( - matchAlignmentSelectionId(alignmentSelection.getAlignmentSelectionId()))); - } - - private boolean matchAlignmentSelectionId(AlignmentSelectionId alignmentSelectionId) { - return getExpectedAlignmentSelectionIds().anyMatch(id -> id.equals(alignmentSelectionId)); - } - - private static Stream getExpectedAlignmentSelectionIds() { - return Stream.of(AlignmentSelectionId.of(9L, 15L), // - AlignmentSelectionId.of(9L, 16L), // - AlignmentSelectionId.of(9L, 17L), // - AlignmentSelectionId.of(4L, 6L), // - AlignmentSelectionId.of(4L, 7L), // - AlignmentSelectionId.of(4L, 8L), // - AlignmentSelectionId.of(3L, 3L), // - AlignmentSelectionId.of(3L, 4L), // - AlignmentSelectionId.of(3L, 5L), // - AlignmentSelectionId.of(8L, 18L), // - AlignmentSelectionId.of(8L, 19L), // - AlignmentSelectionId.of(10L, -1L)); - } -} diff --git a/backend/src/test/resources/repositoriesAndPersistenceServices.csv b/backend/src/test/resources/repositoriesAndPersistenceServices.csv index 36f53411b3..671175a7f6 100644 --- a/backend/src/test/resources/repositoriesAndPersistenceServices.csv +++ b/backend/src/test/resources/repositoriesAndPersistenceServices.csv @@ -1,7 +1,6 @@ repository,persistenceService,validationService ActionRepository,ActionPersistenceService,ActionValidationService AlignmentRepository,AlignmentPersistenceService,"" -AlignmentSelectionRepository,AlignmentSelectionPersistenceService,"" CheckInRepository,CheckInPersistenceService,CheckInValidationService CompletedRepository,CompletedPersistenceService,CompletedValidationService KeyResultRepository,KeyResultPersistenceService,KeyResultValidationService