Commit 6446a15c authored by dietricf's avatar dietricf
Browse files

SI-61 UnitTests

parent d689bacd
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -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";
}
......@@ -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;
......@@ -32,19 +32,19 @@ import java.util.List;
@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();
}
......
......@@ -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,5 +36,5 @@ public interface GridFailureInformationMapper {
@Mapping(source = "refBranch.name", target = "branch"),
@Mapping(source = "refBranch.colorCode", target = "branchColorCode")
})
GridFailureInformationDto toGridFailureInformationDto(TblFailureInformation tblFailureInformation);
FailureInformationDto toGridFailureInformationDto(TblFailureInformation tblFailureInformation);
}
......@@ -17,7 +17,7 @@ package org.eclipse.openk.gridfailureinformation.service;
import org.eclipse.openk.gridfailureinformation.mapper.GridFailureInformationMapper;
import org.eclipse.openk.gridfailureinformation.repository.FailureInformationRepository;
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;
......@@ -25,7 +25,7 @@ import org.springframework.stereotype.Service;
@Service
public class GridFailureInformationService {
public class FailureInformationService {
@Autowired
private FailureInformationRepository failureInformationRepository;
......@@ -34,7 +34,7 @@ public class GridFailureInformationService {
private GridFailureInformationMapper gridFailureInformationMapper;
public Page<GridFailureInformationDto> findFailureInformations(Pageable pageable) {
public Page<FailureInformationDto> findFailureInformations(Pageable pageable) {
return failureInformationRepository.findAll(pageable).map(gridFailureInformationMapper::toGridFailureInformationDto);
}
}
......@@ -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;
......
......@@ -19,7 +19,7 @@ import org.eclipse.openk.gridfailureinformation.mapper.GridFailureInformationMap
import org.eclipse.openk.gridfailureinformation.mapper.GridFailureInformationMapperImpl;
import org.eclipse.openk.gridfailureinformation.mapper.VersionMapper;
import org.eclipse.openk.gridfailureinformation.mapper.VersionMapperImpl;
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;
......@@ -45,8 +45,8 @@ public class TestConfiguration {
}
@Bean
public GridFailureInformationService myGridFailureInformationService() {
return new GridFailureInformationService();
public FailureInformationService myGridFailureInformationService() {
return new FailureInformationService();
}
}
/*
*******************************************************************************
* 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,10 +14,24 @@
*/
package org.eclipse.openk.gridfailureinformation.support;
import org.eclipse.openk.gridfailureinformation.constants.Constants;
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.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;
public class MockDataHelper {
private MockDataHelper() {}
public static Version mockVersion() {
......@@ -33,4 +47,73 @@ public class MockDataHelper {
versionDto.setDbVersion("550");
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() );
}
}
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