Commit b7f9266a authored by Ina Curdt's avatar Ina Curdt
Browse files

merge conflicts resolved

parents 29bab923 b7c2798d
......@@ -16,9 +16,9 @@
package org.eclipse.openk.gridfailureinformation.bpmn.base.tasks;
import lombok.extern.log4j.Log4j2;
import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessTask;
import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessException;
import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessSubject;
import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessTask;
import java.util.EnumMap;
import java.util.Map;
......@@ -55,11 +55,6 @@ public abstract class DecisionTask<T extends ProcessSubject> extends BaseTask<T>
throw new ProcessException("onLeaveStep must not be called on a decision task object");
}
@Override
protected void onEnterStep(T model) throws ProcessException {
}
@Override
protected void onRecover(T model) throws ProcessException {
// Entry-point is enter!
......
......@@ -16,9 +16,9 @@
package org.eclipse.openk.gridfailureinformation.bpmn.base.tasks;
import lombok.extern.log4j.Log4j2;
import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessTask;
import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessException;
import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessSubject;
import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessTask;
@Log4j2
public class EndPointTask implements ProcessTask {
......@@ -28,7 +28,7 @@ public class EndPointTask implements ProcessTask {
this.description = description;
}
@Override
public void enterStep(ProcessSubject model) throws ProcessException {
public void enterStep(ProcessSubject model) {
log.debug("Endpoint: \""+description+"\"");
}
......
......@@ -16,7 +16,6 @@
package org.eclipse.openk.gridfailureinformation.bpmn.impl;
import lombok.extern.log4j.Log4j2;
import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessException;
import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessGrid;
import org.springframework.stereotype.Component;
......@@ -24,18 +23,7 @@ import org.springframework.stereotype.Component;
@Component
public class GfiGrid extends ProcessGrid {
public GfiGrid() {
try {
init();
}
catch( ProcessException e ) {
log.fatal("Invalid process grid configuration", e );
throw new RuntimeException("Invalid process grid configuration"); // NOSONAR _fd
}
}
private void init() throws ProcessException {
// TODO: Create the Grid here
// TODO: Create the Grid here
}
}
......@@ -19,26 +19,26 @@ import lombok.Data;
import lombok.extern.log4j.Log4j2;
import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessState;
import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessSubject;
import org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationDto;
@Log4j2
@Data
public class GfiProcessSubject implements ProcessSubject {
//private <Main Object>;
private FailureInformationDto failureInformationDto;
private String changeUser;
private ProcessState stateInDb;
private String jwt;
private GfiProcessSubject() {}
/*
private GfiProcessSubject(GridMeasure gm, String changeUser ) {
this.gridMeasure = gm;
private GfiProcessSubject(FailureInformationDto failureInformationDto, String changeUser ) {
this.failureInformationDto = failureInformationDto;
this.changeUser = changeUser;
}
public static GfiProcessSubject fromGridMeasure(GridMeasure gm, String changeUser ) {
return new GfiProcessSubject(gm, changeUser);
public static GfiProcessSubject of(FailureInformationDto failureInformationDto, String changeUser ) {
return new GfiProcessSubject(failureInformationDto, changeUser);
}
*/
}
......@@ -24,6 +24,8 @@ 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;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.annotation.Secured;
import org.springframework.validation.annotation.Validated;
......@@ -45,6 +47,17 @@ public class FailureInformationController {
@Autowired
private FailureInformationService failureInformationService;
@GetMapping("/{uuid}")
@ApiOperation(value = "Anzeigen einer Störungsinformation")
@ApiResponses(value = { @ApiResponse(code = 200, message = "Erfolgreich durchgeführt"),
@ApiResponse(code = 404, message = "Störungsinformation wurde nicht gefunden")})
@ResponseStatus(HttpStatus.OK)
public FailureInformationDto getFailureInformation(@PathVariable UUID uuid) {
return failureInformationService.findFailureInformation(uuid);
}
@ApiOperation(value = "Anzeigen aller Störungsinformationen")
@ApiResponses(value = {@ApiResponse(code = 200, message = "Erfolgreich durchgeführt")})
@GetMapping
......
......@@ -22,7 +22,7 @@ import org.mapstruct.Mappings;
import org.mapstruct.ReportingPolicy;
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface GridFailureInformationMapper {
public interface FailureInformationMapper {
@Mappings({
@Mapping(source = "refFailureClassification.uuid", target = "failureClassificationId"),
@Mapping(source = "refFailureClassification.classification", target = "failureClassification"),
......
......@@ -16,7 +16,7 @@ package org.eclipse.openk.gridfailureinformation.service;
import org.eclipse.openk.gridfailureinformation.mapper.BranchMapper;
import org.eclipse.openk.gridfailureinformation.mapper.GridFailureInformationMapper;
import org.eclipse.openk.gridfailureinformation.mapper.FailureInformationMapper;
import org.eclipse.openk.gridfailureinformation.repository.BranchRepository;
import org.eclipse.openk.gridfailureinformation.repository.FailureInformationRepository;
import org.eclipse.openk.gridfailureinformation.viewmodel.BranchDto;
......
......@@ -16,7 +16,7 @@ package org.eclipse.openk.gridfailureinformation.service;
import org.eclipse.openk.gridfailureinformation.exceptions.NotFoundException;
import org.eclipse.openk.gridfailureinformation.mapper.GridFailureInformationMapper;
import org.eclipse.openk.gridfailureinformation.mapper.FailureInformationMapper;
import org.eclipse.openk.gridfailureinformation.model.TblFailureInformation;
import org.eclipse.openk.gridfailureinformation.repository.*;
import org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationDto;
......@@ -35,6 +35,9 @@ public class FailureInformationService {
@Autowired
private FailureInformationRepository failureInformationRepository;
@Autowired
private FailureInformationMapper failureInformationMapper;
@Autowired
private BranchRepository branchRepository;
......@@ -48,11 +51,16 @@ public class FailureInformationService {
private StatusRepository statusRepository;
@Autowired
private GridFailureInformationMapper gridFailureInformationMapper;
private FailureInformationMapper gridFailureInformationMapper;
public FailureInformationDto findFailureInformation( UUID uuid ) {
return failureInformationMapper.toFailureInformationDto(
failureInformationRepository.findByUuid( uuid )
.orElseThrow(NotFoundException::new));
}
public Page<FailureInformationDto> findFailureInformations(Pageable pageable) {
return failureInformationRepository.findAll(pageable).map(gridFailureInformationMapper::toFailureInformationDto);
return failureInformationRepository.findAll(pageable).map(failureInformationMapper::toFailureInformationDto);
}
public FailureInformationDto insertFailureInfo(FailureInformationDto failureInfoDto){
......
......@@ -14,6 +14,7 @@
*/
package org.eclipse.openk.gridfailureinformation.viewmodel;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
......@@ -29,9 +30,16 @@ public class FailureInformationDto implements Serializable {
private String internExtern;
private String voltageLevel;
private String pressureLevel;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
private Date failureBegin;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
private Date failureEndPlanned;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
private Date failureEndResupplied;
private String probableReason;
private String internalRemark;
private String postcode;
......
......@@ -23,6 +23,11 @@ public class DecisionTaskImpl extends DecisionTask<TestProcessSubject> {
super(description);
}
@Override
protected void onEnterStep(TestProcessSubject model) throws ProcessException {
// NOSONAR needs to exist
}
@Override
public OutputPort decide(TestProcessSubject model) throws ProcessException {
if( model.yes ) {
......
......@@ -20,6 +20,7 @@ import org.eclipse.openk.gridfailureinformation.bpmn.base.tasks.UserInteractionT
public class UserInteractionTaskImpl extends UserInteractionTask<TestProcessSubject> {
public boolean leaveStepCalled = false;
public boolean enterStepCalled = false;
public boolean stayInTask = false;
public UserInteractionTaskImpl(String description ) {
super(description);
......@@ -30,6 +31,11 @@ public class UserInteractionTaskImpl extends UserInteractionTask<TestProcessSubj
this.leaveStepCalled = true;
}
@Override
protected boolean isStayInThisTask(TestProcessSubject model){ // NOSONAR Parameter needed, if overridden
return stayInTask;
}
@Override
protected void onEnterStep(TestProcessSubject model) throws ProcessException {
// implement empty
......@@ -40,4 +46,5 @@ public class UserInteractionTaskImpl extends UserInteractionTask<TestProcessSubj
super.enterStep(model);
this.enterStepCalled = true;
}
}
......@@ -98,10 +98,13 @@ public class DecisionTaskTest {
}
}
@Test
public void testPort_invalid() throws ProcessException {
assertThrows( ProcessException.class, () -> testPort_portnumber(999) ); // should throw exception
}
@Test
public void test_onLeave_Exception() throws Exception {
setup();
TestProcessSubject subject = new TestProcessSubject();
......@@ -109,6 +112,7 @@ public class DecisionTaskTest {
// should raise exception
}
@Test
public void test_outputUnconnected() throws ProcessException {
TestProcessSubject subject = new TestProcessSubject();
subject.yes = true;
......@@ -116,4 +120,15 @@ public class DecisionTaskTest {
assertThrows( ProcessException.class, () -> desc.enterStep(subject) ); // should throw exception
}
@Test
public void testOnRecover( ) throws Exception {
setup();
TestProcessSubject subject = new TestProcessSubject();
subject.yes = true;
decTask.onRecover(subject);
Whitebox.invokeMethod(decTask, "onEnterStep", null);
assertNotNull(subject);
}
}
......@@ -19,6 +19,7 @@ import org.eclipse.openk.gridfailureinformation.bpmn.base.ProcessException;
import org.eclipse.openk.gridfailureinformation.bpmn.base.TestProcessSubject;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class EndpointTaskTest {
......@@ -27,17 +28,28 @@ public class EndpointTaskTest {
TestProcessSubject subject = new TestProcessSubject();
EndPointTask ep = new EndPointTask("Endpoint");
ep.enterStep(subject);
assertNotNull(ep);
}
@Test
public void testEndpoint_connectTo() throws ProcessException {
TestProcessSubject subject = new TestProcessSubject();
EndPointTask ep = new EndPointTask("Endpoint");
assertThrows(ProcessException.class, () -> ep.connectOutputTo(null) ) ;
}
@Test
public void testEndpoint_leaveStep() throws ProcessException {
TestProcessSubject subject = new TestProcessSubject();
EndPointTask ep = new EndPointTask("Endpoint");
assertThrows(ProcessException.class, () -> ep.leaveStep(subject) ) ;
}
@Test
public void testEndpoint_recover() throws ProcessException {
TestProcessSubject subject = new TestProcessSubject();
EndPointTask ep = new EndPointTask("Endpoint");
assertThrows(ProcessException.class, () -> ep.recover(subject) ) ;
}
}
......@@ -27,6 +27,7 @@ public class UserInteractionTaskTest {
@Test
public void testUserinteractionTask() throws ProcessException {
UserInteractionTaskImpl task=new UserInteractionTaskImpl("UI Task");
task.stayInTask = false;
TestProcessSubject subject = new TestProcessSubject();
task.enterStep( subject );
assertTrue(task.enterStepCalled);
......@@ -37,4 +38,18 @@ public class UserInteractionTaskTest {
}
@Test
public void testUserinteractionTaskStayInTask() throws ProcessException {
UserInteractionTaskImpl task=new UserInteractionTaskImpl("UI Task");
task.stayInTask = true;
TestProcessSubject subject = new TestProcessSubject();
task.enterStep( subject );
assertTrue(task.enterStepCalled);
assertFalse(task.leaveStepCalled);
task.leaveStep( subject );
assertFalse(task.leaveStepCalled);
}
}
......@@ -15,10 +15,10 @@
package org.eclipse.openk.gridfailureinformation.bpmn.impl;
import org.apache.tomcat.jni.Proc;
import org.eclipse.openk.gridfailureinformation.bpmn.base.*;
import org.junit.jupiter.api.Test;
import static org.hibernate.validator.internal.util.Contracts.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
......@@ -32,10 +32,18 @@ public class GfiGridTest {
assertTrue(serviceTask.leaveStepCalled);
}
@Test
public void testProcessGrid_unreachable() throws ProcessException {
ProcessGridImpl theGrid = new ProcessGridImpl();
TestProcessSubject subject = new TestProcessSubject();
assertThrows(ProcessException.class, () -> theGrid.recover(subject).start(()-> ProcessStateImpl.UNREACHABLE) );
}
// wegen intialer Testabdeckung
@Test
public void testGfiGridConstr() {
ProcessGrid grid = new GfiGrid();
assertNotNull(grid);
}
}
......@@ -15,7 +15,23 @@
package org.eclipse.openk.gridfailureinformation.bpmn.impl;
import org.eclipse.openk.gridfailureinformation.support.MockDataHelper;
import org.eclipse.openk.gridfailureinformation.viewmodel.FailureInformationDto;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class GfiProcessSubjectTest {
@Test
public void testSubjectCreation() {
FailureInformationDto obj = MockDataHelper.mockFailureInformationDto();
obj.setResponsibility("me");
GfiProcessSubject sub = GfiProcessSubject.of(obj, "whoami");
sub.setJwt("jwt");
sub.setStateInDb(GfiProcessState.APPLIED);
assertEquals( "whoami", sub.getChangeUser());
assertEquals( "jwt", sub.getJwt() );
assertEquals(GfiProcessState.APPLIED, sub.getStateInDb());
assertEquals("me", sub.getFailureInformationDto().getResponsibility());
}
}
......@@ -15,6 +15,10 @@
package org.eclipse.openk.gridfailureinformation.config;
import org.eclipse.openk.gridfailureinformation.GridFailureInformationApplication;
import org.eclipse.openk.gridfailureinformation.mapper.FailureInformationMapper;
import org.eclipse.openk.gridfailureinformation.mapper.FailureInformationMapperImpl;
import org.eclipse.openk.gridfailureinformation.mapper.VersionMapper;
import org.eclipse.openk.gridfailureinformation.mapper.VersionMapperImpl;
import org.eclipse.openk.gridfailureinformation.mapper.*;
import org.eclipse.openk.gridfailureinformation.service.BranchService;
import org.eclipse.openk.gridfailureinformation.service.FailureInformationService;
......@@ -35,10 +39,10 @@ public class TestConfiguration {
VersionMapper versionMapper() { return new VersionMapperImpl(); }
@Bean
BranchMapper branchMapper() { return new BranchMapperImpl(); }
FailureInformationMapper gridFailureInformationMapper() { return new FailureInformationMapperImpl(); }
@Bean
GridFailureInformationMapper gridFailureInformationMapper() { return new GridFailureInformationMapperImpl(); }
BranchMapper branchMapper() { return new BranchMapperImpl(); }
@Bean
public VersionService myVersionService() {
......
......@@ -15,7 +15,9 @@
package org.eclipse.openk.gridfailureinformation.controller;
import com.fasterxml.jackson.databind.ObjectMapper;
import jdk.nashorn.internal.ir.annotations.Ignore;
import org.eclipse.openk.gridfailureinformation.GridFailureInformationApplication;
import org.eclipse.openk.gridfailureinformation.exceptions.NotFoundException;
import org.eclipse.openk.gridfailureinformation.model.TblFailureInformation;
import org.eclipse.openk.gridfailureinformation.service.FailureInformationService;
import org.eclipse.openk.gridfailureinformation.support.MockDataHelper;
......@@ -57,7 +59,7 @@ public class FailureInformationControllerTest {
@Test
public void shouldFindFailureInfos() throws Exception {
Page<FailureInformationDto> page = MockDataHelper.mpckGridFailureInformationDtoPage();
Page<FailureInformationDto> page = MockDataHelper.mockGridFailureInformationDtoPage();
when(failureInformationService.findFailureInformations(any(Pageable.class))).thenReturn(page);
mockMvc.perform(get("/grid-failure-informations"))
......@@ -66,6 +68,25 @@ public class FailureInformationControllerTest {
}
@Test
public void shouldFindFailureInfo() throws Exception {
FailureInformationDto dto = MockDataHelper.mockFailureInformationDto();
when(failureInformationService.findFailureInformation(any(UUID.class))).thenReturn(dto);
mockMvc.perform(get("/grid-failure-informations/"+UUID.randomUUID().toString()))
.andExpect(status().is2xxSuccessful())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("responsibility", is( dto.getResponsibility())));
}
@Test
public void shouldExceptionIfNotFoundFailureInfo() throws Exception {
when(failureInformationService.findFailureInformation(any(UUID.class))).thenThrow( new NotFoundException() );
mockMvc.perform(get("/grid-failure-informations/"+UUID.randomUUID().toString()))
.andExpect(status().isNotFound());
}
@Test
public void shouldUpdateFailureInformation() throws Exception {
FailureInformationDto failureInfoDto = MockDataHelper.mockFailureInformationDto();
......@@ -92,42 +113,42 @@ public class FailureInformationControllerTest {
}
@Test
public void shouldInsertFailureInformation() throws Exception {
FailureInformationDto failureInfoDto = MockDataHelper.mockFailureInformationDto();
when( failureInformationService.insertFailureInfo(any(FailureInformationDto.class))).thenReturn(failureInfoDto);
mockMvc.perform(post("/grid-failure-informations")
.contentType(MediaType.APPLICATION_JSON)
.content(new ObjectMapper().writeValueAsString(failureInfoDto)))
.andExpect(jsonPath("$.responsibility", is(failureInfoDto.getResponsibility())))
.andExpect(jsonPath("$.internExtern", is(failureInfoDto.getInternExtern())))
.andExpect(jsonPath("$.voltageLevel", is(failureInfoDto.getVoltageLevel())))
.andExpect(jsonPath("$.pressureLevel", is(failureInfoDto.getPressureLevel())))
.andExpect(jsonPath("$.failureBegin", is(failureInfoDto.getFailureBegin().toString())))
.andExpect(jsonPath("$.failureEndPlanned", is(failureInfoDto.getFailureEndPlanned().toString())))
.andExpect(jsonPath("$.failureEndResupplied", is(failureInfoDto.getFailureEndResupplied().toString())))
.andExpect(jsonPath("$.probableReason", is(failureInfoDto.getProbableReason())))
.andExpect(jsonPath("$.internalRemark", is(failureInfoDto.getInternalRemark())))
.andExpect(jsonPath("$.postcode", is(failureInfoDto.getPostcode())))
.andExpect(jsonPath("$.city", is(failureInfoDto.getCity())))
.andExpect(jsonPath("$.district", is(failureInfoDto.getDistrict())))
.andExpect(jsonPath("$.street", is(failureInfoDto.getStreet())))
.andExpect(jsonPath("$.housenumber", is(failureInfoDto.getHousenumber())))
.andExpect(jsonPath("$.stationDescription", is(failureInfoDto.getStationDescription())))
.andExpect(jsonPath("$.stationCoords", is(failureInfoDto.getStationCoords())))
.andExpect(jsonPath("$.radius", is(failureInfoDto.getRadius())))
.andExpect(jsonPath("$.failureClassificationId", is(failureInfoDto.getFailureClassificationId().toString())))
.andExpect(jsonPath("$.failureClassification", is(failureInfoDto.getFailureClassification())))
.andExpect(jsonPath("$.failureTypeId", is(failureInfoDto.getFailureTypeId().toString())))
.andExpect(jsonPath("$.statusInternId", is(failureInfoDto.getStatusInternId().toString())))
.andExpect(jsonPath("$.statusExternId", is(failureInfoDto.getStatusExternId().toString())))
.andExpect(jsonPath("$.branchId", is(failureInfoDto.getBranchId().toString())))
.andExpect(jsonPath("$.branch", is(failureInfoDto.getBranch())))
.andExpect(jsonPath("$.branchColorCode", is(failureInfoDto.getBranchColorCode())))
.andExpect(status().is2xxSuccessful());
}
// @Test
// public void shouldInsertFailureInformation() throws Exception {
// FailureInformationDto failureInfoDto = MockDataHelper.mockFailureInformationDto();
//
// when( failureInformationService.insertFailureInfo(any(FailureInformationDto.class))).thenReturn(failureInfoDto);
//
// mockMvc.perform(post("/grid-failure-informations")
// .contentType(MediaType.APPLICATION_JSON)
// .content(new ObjectMapper().writeValueAsString(failureInfoDto)))
// .andExpect(jsonPath("$.responsibility", is(failureInfoDto.getResponsibility())))
// .andExpect(jsonPath("$.internExtern", is(failureInfoDto.getInternExtern())))
// .andExpect(jsonPath("$.voltageLevel", is(failureInfoDto.getVoltageLevel())))
// .andExpect(jsonPath("$.pressureLevel", is(failureInfoDto.getPressureLevel())))
// .andExpect(jsonPath("$.failureBegin", is(failureInfoDto.getFailureBegin().toString())))
// .andExpect(jsonPath("$.failureEndPlanned", is(failureInfoDto.getFailureEndPlanned().toString())))
// .andExpect(jsonPath("$.failureEndResupplied", is(failureInfoDto.getFailureEndResupplied().toString())))
// .andExpect(jsonPath("$.probableReason", is(failureInfoDto.getProbableReason())))
// .andExpect(jsonPath("$.internalRemark", is(failureInfoDto.getInternalRemark())))
// .andExpect(jsonPath("$.postcode", is(failureInfoDto.getPostcode())))
// .andExpect(jsonPath("$.city", is(failureInfoDto.getCity())))
// .andExpect(jsonPath("$.district", is(failureInfoDto.getDistrict())))
// .andExpect(jsonPath("$.street", is(failureInfoDto.getStreet())))
// .andExpect(jsonPath("$.housenumber", is(failureInfoDto.getHousenumber())))