Commit 020aa9c5 authored by Ina Curdt's avatar Ina Curdt
Browse files

resolved merge conflicts

parents 641dd156 31ba4eff
......@@ -15,9 +15,20 @@
package org.eclipse.openk.gridfailureinformation.constants;
public final class Constants {
public static final String VOLTAGE_LEVEL_NS = "NS";
public static final String VOLTAGE_LEVEL_MS = "MS";
public static final String VOLTAGE_LEVEL_HS = "HS";
public static final String PRESSURE_LEVEL_ND = "ND";
public static final String PRESSURE_LEVEL_MD = "MD";
public static final String PRESSURE_LEVEL_HD = "HD";
public static final String DB_VERSION_NOT_PRESENT = "DB-Version-not_present";
public static final String INTERNAL_SHORT = "I";
public static final String EXTERNAL_SHORT = "E";
private Constants() {
// empty Constructor for the sake of SONAR
}
public static final String DB_VERSION_NOT_PRESENT = "DB-Version-not_present";
}
......@@ -19,9 +19,9 @@ import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.log4j.Log4j2;
import org.eclipse.openk.gridfailureinformation.service.BranchService;
import org.eclipse.openk.gridfailureinformation.service.GridFailureInformationService;
import org.eclipse.openk.gridfailureinformation.service.FailureInformationService;
import org.eclipse.openk.gridfailureinformation.viewmodel.BranchDto;
import org.eclipse.openk.gridfailureinformation.viewmodel.GridFailureInformationDto;
import org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.PageRequest;
......
......@@ -18,8 +18,8 @@ import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.log4j.Log4j2;
import org.eclipse.openk.gridfailureinformation.service.GridFailureInformationService;
import org.eclipse.openk.gridfailureinformation.viewmodel.GridFailureInformationDto;
import org.eclipse.openk.gridfailureinformation.service.FailureInformationService;
import org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.PageRequest;
......@@ -36,19 +36,19 @@ import java.util.UUID;
@Log4j2
@RestController
@RequestMapping("/grid-failure-informations")
public class GridFailureInformationController {
public class FailureInformationController {
@Value("${gridFailureInformation.maxListSize}")
int maxListSize;
@Autowired
private GridFailureInformationService gridFailureInformationService;
private FailureInformationService failureInformationService;
@ApiOperation(value = "Anzeigen aller Störungsinformationen")
@ApiResponses(value = {@ApiResponse(code = 200, message = "Erfolgreich durchgeführt")})
@GetMapping
public List<GridFailureInformationDto> findFailureInfos() {
return gridFailureInformationService.findFailureInformations(PageRequest.of(0, maxListSize)).getContent();
public List<FailureInformationDto> findFailureInfos() {
return failureInformationService.findFailureInformations(PageRequest.of(0, maxListSize)).getContent();
}
@PostMapping
......@@ -57,9 +57,9 @@ public class GridFailureInformationController {
@ApiResponse(code = 201, message = "Störungsinformation erfolgreich angelegt"),
@ApiResponse(code = 500, message = "Konnte nicht durchgeführt werden")
})
public ResponseEntity<GridFailureInformationDto> insertFailureInfo(
@Validated @RequestBody GridFailureInformationDto gfDto) {
GridFailureInformationDto savedgfDto = gridFailureInformationService.insertGridFailure(gfDto);
public ResponseEntity<FailureInformationDto> insertFailureInfo(
@Validated @RequestBody FailureInformationDto gfDto) {
FailureInformationDto savedgfDto = failureInformationService.insertGridFailure(gfDto);
URI location = ServletUriComponentsBuilder
.fromCurrentRequestUri()
.path("/{uuid}")
......
......@@ -17,7 +17,7 @@ package org.eclipse.openk.gridfailureinformation.mapper;
import org.eclipse.openk.gridfailureinformation.model.RefBranch;
import org.eclipse.openk.gridfailureinformation.model.TblFailureInformation;
import org.eclipse.openk.gridfailureinformation.viewmodel.BranchDto;
import org.eclipse.openk.gridfailureinformation.viewmodel.GridFailureInformationDto;
import org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationDto;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
......
......@@ -15,7 +15,7 @@
package org.eclipse.openk.gridfailureinformation.mapper;
import org.eclipse.openk.gridfailureinformation.model.TblFailureInformation;
import org.eclipse.openk.gridfailureinformation.viewmodel.GridFailureInformationDto;
import org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationDto;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
......@@ -36,7 +36,7 @@ public interface GridFailureInformationMapper {
@Mapping(source = "refBranch.name", target = "branch"),
@Mapping(source = "refBranch.colorCode", target = "branchColorCode")
})
GridFailureInformationDto toGridFailureInformationDto(TblFailureInformation tblFailureInformation);
FailureInformationDto toFailureInformationDto(TblFailureInformation tblFailureInformation);
@Mappings({
@Mapping(target = "refFailureClassification.uuid", source = "failureClassificationId"),
......@@ -51,7 +51,7 @@ public interface GridFailureInformationMapper {
@Mapping(target = "refBranch.name", source = "branch"),
@Mapping(target = "refBranch.colorCode", source = "branchColorCode")
})
TblFailureInformation toRefFailureInformation(GridFailureInformationDto gridFailureInformationDto);
TblFailureInformation toRefFailureInformation(FailureInformationDto FailureInformationDto);
}
......@@ -20,7 +20,7 @@ import org.eclipse.openk.gridfailureinformation.mapper.GridFailureInformationMap
import org.eclipse.openk.gridfailureinformation.repository.BranchRepository;
import org.eclipse.openk.gridfailureinformation.repository.FailureInformationRepository;
import org.eclipse.openk.gridfailureinformation.viewmodel.BranchDto;
import org.eclipse.openk.gridfailureinformation.viewmodel.GridFailureInformationDto;
import org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
......
......@@ -19,7 +19,7 @@ import org.eclipse.openk.gridfailureinformation.exceptions.NotFoundException;
import org.eclipse.openk.gridfailureinformation.mapper.GridFailureInformationMapper;
import org.eclipse.openk.gridfailureinformation.model.TblFailureInformation;
import org.eclipse.openk.gridfailureinformation.repository.*;
import org.eclipse.openk.gridfailureinformation.viewmodel.GridFailureInformationDto;
import org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
......@@ -30,7 +30,7 @@ import java.util.UUID;
@Service
public class GridFailureInformationService {
public class FailureInformationService {
@Autowired
private FailureInformationRepository failureInformationRepository;
......@@ -51,18 +51,18 @@ public class GridFailureInformationService {
private GridFailureInformationMapper gridFailureInformationMapper;
public Page<GridFailureInformationDto> findFailureInformations(Pageable pageable) {
return failureInformationRepository.findAll(pageable).map(gridFailureInformationMapper::toGridFailureInformationDto);
public Page<FailureInformationDto> findFailureInformations(Pageable pageable) {
return failureInformationRepository.findAll(pageable).map(gridFailureInformationMapper::toFailureInformationDto);
}
public GridFailureInformationDto insertGridFailure(GridFailureInformationDto gfiDto){
public FailureInformationDto insertGridFailure(FailureInformationDto gfiDto){
TblFailureInformation tblGfiToSave = gridFailureInformationMapper.toRefFailureInformation(gfiDto);
tblGfiToSave.setUuid(UUID.randomUUID());
setFromGridFailureInformationDto(tblGfiToSave, gfiDto);
return gridFailureInformationMapper.toGridFailureInformationDto(failureInformationRepository.save(tblGfiToSave));
return gridFailureInformationMapper.toFailureInformationDto(failureInformationRepository.save(tblGfiToSave));
}
private void setFromGridFailureInformationDto( TblFailureInformation destTblFailureInformation, GridFailureInformationDto sourceDto ) {
private void setFromGridFailureInformationDto( TblFailureInformation destTblFailureInformation, FailureInformationDto sourceDto ) {
if( sourceDto.getBranchId() != null ) {
destTblFailureInformation.setRefBranch( branchRepository
......
......@@ -22,7 +22,7 @@ import java.util.Date;
import java.util.UUID;
@Data
public class GridFailureInformationDto implements Serializable {
public class FailureInformationDto implements Serializable {
@JsonProperty("id")
private UUID uuid;
private String responsibility;
......
......@@ -17,7 +17,7 @@ package org.eclipse.openk.gridfailureinformation.config;
import org.eclipse.openk.gridfailureinformation.GridFailureInformationApplication;
import org.eclipse.openk.gridfailureinformation.mapper.*;
import org.eclipse.openk.gridfailureinformation.service.BranchService;
import org.eclipse.openk.gridfailureinformation.service.GridFailureInformationService;
import org.eclipse.openk.gridfailureinformation.service.FailureInformationService;
import org.eclipse.openk.gridfailureinformation.service.VersionService;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.test.context.ConfigFileApplicationContextInitializer;
......@@ -46,13 +46,13 @@ public class TestConfiguration {
}
@Bean
public BranchService myBranchService() {
return new BranchService();
public FailureInformationService myGridFailureInformationService() {
return new FailureInformationService();
}
@Bean
public GridFailureInformationService myGridFailureInformationService() {
return new GridFailureInformationService();
public BranchService myBranchService() {
return new BranchService();
}
}
/*
*******************************************************************************
* Copyright (c) 2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************
*/
package org.eclipse.openk.gridfailureinformation.controller;
import org.eclipse.openk.gridfailureinformation.GridFailureInformationApplication;
import org.eclipse.openk.gridfailureinformation.service.FailureInformationService;
import org.eclipse.openk.gridfailureinformation.support.MockDataHelper;
import org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationDto;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@SpringBootTest(classes = GridFailureInformationApplication.class)
@AutoConfigureMockMvc
public class FailureInformationControllerTest {
@MockBean
private FailureInformationService failureInformationService;
@Autowired
private MockMvc mockMvc;
@Test
public void shouldFindFailureInfos() throws Exception {
Page<FailureInformationDto> page = MockDataHelper.mpckGridFailureInformationDtoPage();
when(failureInformationService.findFailureInformations(any(Pageable.class))).thenReturn(page);
mockMvc.perform(get("/grid-failure-informations"))
.andExpect(status().is2xxSuccessful())
.andExpect(content().contentType(MediaType.APPLICATION_JSON));
}
}
\ No newline at end of file
/*
*******************************************************************************
* Copyright (c) 2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************
*/
package org.eclipse.openk.gridfailureinformation.service;
import org.eclipse.openk.gridfailureinformation.config.TestConfiguration;
import org.eclipse.openk.gridfailureinformation.model.TblFailureInformation;
import org.eclipse.openk.gridfailureinformation.repository.FailureInformationRepository;
import org.eclipse.openk.gridfailureinformation.support.MockDataHelper;
import org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationDto;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.test.context.ContextConfiguration;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
@DataJpaTest
@ContextConfiguration(classes = {TestConfiguration.class})
public class FailureInformationServiceTest {
@Qualifier("myGridFailureInformationService")
@Autowired
private FailureInformationService failureInformationService;
@MockBean
private FailureInformationRepository failureInformationRepository;
@Test
public void shouldFindFailureInformations() {
Page<TblFailureInformation> mockfailurePage = MockDataHelper.mockTblFailureInformationPage();
when(failureInformationRepository.findAll(any(Pageable.class))).thenReturn(mockfailurePage);
Page<FailureInformationDto> retPage = failureInformationService.findFailureInformations(Pageable.unpaged());
assertEquals( mockfailurePage.getTotalElements(), retPage.getTotalElements() );
assertEquals( mockfailurePage.getContent().get(0).getResponsibility(), retPage.getContent().get(0).getResponsibility());
}
}
......@@ -14,16 +14,30 @@
*/
package org.eclipse.openk.gridfailureinformation.support;
import org.eclipse.openk.gridfailureinformation.constants.Constants;
import org.eclipse.openk.gridfailureinformation.model.RefBranch;
import org.eclipse.openk.gridfailureinformation.model.TblFailureInformation;
import org.eclipse.openk.gridfailureinformation.model.Version;
import org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationDto;
import org.eclipse.openk.gridfailureinformation.viewmodel.BranchDto;
import org.eclipse.openk.gridfailureinformation.viewmodel.VersionDto;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import java.sql.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import static org.eclipse.openk.gridfailureinformation.constants.Constants.INTERNAL_SHORT;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class MockDataHelper {
private MockDataHelper() {}
public static Version mockVersion() {
......@@ -40,6 +54,75 @@ public class MockDataHelper {
return versionDto;
}
public static FailureInformationDto mockGridFailureInformationDto() {
FailureInformationDto dto = new FailureInformationDto();
dto.setUuid(UUID.randomUUID());
dto.setResponsibility("Vatter Abraham");
dto.setInternExtern(INTERNAL_SHORT);
dto.setVoltageLevel(Constants.VOLTAGE_LEVEL_MS);
dto.setPressureLevel(Constants.PRESSURE_LEVEL_HD);
dto.setFailureBegin(Date.valueOf("2022-12-01"));
dto.setFailureEndPlanned(Date.valueOf("2022-12-02"));
dto.setFailureEndResupplied(Date.valueOf("2022-12-03"));
dto.setProbableReason("Über Kabel gestolpert");
dto.setFailureClassificationId(UUID.randomUUID());
dto.setFailureClassification("FailClazz");
dto.setFailureTypeId(UUID.randomUUID());
dto.setFailureType("FailTypo");
dto.setStatusInternId(UUID.randomUUID());
dto.setStatusIntern("NEW");
dto.setStatusExternId(UUID.randomUUID());
dto.setStatusExtern("CLOSED");
dto.setBranchId(UUID.randomUUID());
dto.setBranch("G");
dto.setBranchColorCode("#fdea64");
return dto;
}
public static TblFailureInformation mockTblFailureInformation() {
TblFailureInformation obj = new TblFailureInformation();
obj.setUuid(UUID.randomUUID());
obj.setResponsibility("Vatter Abraham");
obj.setInternExtern(INTERNAL_SHORT);
obj.setVoltageLevel(Constants.VOLTAGE_LEVEL_MS);
obj.setPressureLevel(Constants.PRESSURE_LEVEL_HD);
obj.setFailureBegin(Date.valueOf("2022-12-01"));
obj.setFailureEndPlanned(Date.valueOf("2022-12-02"));
obj.setFailureEndResupplied(Date.valueOf("2022-12-03"));
obj.setProbableReason("Über Kabel gestolpert");
return obj;
}
public static Page<TblFailureInformation> mockTblFailureInformationPage() {
List<TblFailureInformation> retList = new LinkedList<>();
retList.add( mockTblFailureInformation() );
retList.add( mockTblFailureInformation() );
retList.get(1).setResponsibility("Lionel Lümmelprinz");
return new PageImpl<>(retList, Pageable.unpaged(), retList.size());
}
public static List<FailureInformationDto> mockGridFailureInformationDtos() {
List<FailureInformationDto> retList = new LinkedList<>();
retList.add( mockGridFailureInformationDto() );
retList.add( mockGridFailureInformationDto() );
retList.get(1).setBranch("W");
retList.get(1).setStatusExtern("IN_WORK");
retList.get(1).setStatusIntern("IN_WORK");
retList.get(1).setResponsibility("Lionel Lümmelprinz");
return retList;
}
public static Page<FailureInformationDto> mpckGridFailureInformationDtoPage() {
List<FailureInformationDto> dtos = mockGridFailureInformationDtos();
return new PageImpl<>(dtos, Pageable.unpaged(), dtos.size() );
}
public static BranchDto mockBranchDto() {
BranchDto branchDto = new BranchDto();
branchDto.setUuid(UUID.fromString("14d4327c-594b-11ea-82b4-0242ac130003"));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment