Unittestcoverage erhoeht
diff --git a/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/service/ImportService.java b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/service/ImportService.java
index 071c51f..98cfb1e 100644
--- a/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/service/ImportService.java
+++ b/gfsBackendService/src/main/java/org/eclipse/openk/gridfailureinformation/service/ImportService.java
@@ -112,7 +112,7 @@
if (foreignFailureDataDto.isAutopublish()) {
failureInformationService.insertPublicationChannelForFailureInfo(retVal.getUuid(), Constants.PUBLICATION_CHANNEL_OWNDMZ, true);
log.info("External failure information [MetaId: " + importDataDto.getMetaId() + "] from "
- + importDataDto.getSource() + "is prepared for autopublish to channel: " + Constants.PUBLICATION_CHANNEL_OWNDMZ);
+ + importDataDto.getSource() + " is prepared for autopublish to channel: " + Constants.PUBLICATION_CHANNEL_OWNDMZ);
}
return retVal;
} else {
diff --git a/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/service/ImportServiceTest.java b/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/service/ImportServiceTest.java
index aab6a28..251f941 100644
--- a/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/service/ImportServiceTest.java
+++ b/gfsBackendService/src/test/java/org/eclipse/openk/gridfailureinformation/service/ImportServiceTest.java
@@ -15,6 +15,7 @@
package org.eclipse.openk.gridfailureinformation.service;
import org.eclipse.openk.gridfailureinformation.bpmn.impl.GfiProcessState;
+import org.eclipse.openk.gridfailureinformation.bpmn.impl.tasks.ProcessHelper;
import org.eclipse.openk.gridfailureinformation.config.TestConfiguration;
import org.eclipse.openk.gridfailureinformation.exceptions.InternalServerErrorException;
import org.eclipse.openk.gridfailureinformation.support.MockDataHelper;
@@ -27,6 +28,7 @@
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.boot.test.mock.mockito.SpyBean;
import org.springframework.test.context.ContextConfiguration;
import java.math.BigDecimal;
@@ -61,6 +63,9 @@
@MockBean
private FailureInformationService failureInformationService;
+ @MockBean
+ private ProcessHelper processHelper;
+
@Test
public void shouldImportDifferentRadiiProperly() throws Exception {
List<RadiusDto> radiusDtos = getRadiusDtoList();
@@ -314,7 +319,6 @@
" \"radiusInMeters\": 678,\n" +
" \"stationDescription\": null,\n" +
" \"stationId\": null,\n" +
- " \"street\": \"Oxfordstreet\",\n" +
" \"voltageLevel\": \"HS\"\n" +
" }");
@@ -434,4 +438,90 @@
.updateFailureInfo(any( FailureInformationDto.class));
}
+ @Test
+ public void shouldImportMessagesCorrectlyWithNewAutopublish() {
+ ImportDataDto dto = MockDataHelper.mockImportDataDto();
+ dto.setMessageContent("{\n" +
+ " \"branch\": \"S\",\n" + // invalid branch
+ " \"city\": \"Belfast\",\n" +
+ " \"description\": \"Schlimmer Fehler im System\",\n" +
+ " \"district\": \"\",\n" +
+ " \"failureBegin\": \"2020-11-19T14:13:15.666Z\",\n" +
+ " \"housenumber\": \"10b\",\n" +
+ " \"latitude\": 12.345,\n" +
+ " \"longitude\": 0,\n" +
+ " \"planned\": false,\n" +
+ " \"postcode\": \"3456\",\n" +
+ " \"pressureLevel\": null,\n" +
+ " \"radiusInMeters\": 678,\n" +
+ " \"stationDescription\": null,\n" +
+ " \"stationId\": null,\n" +
+ " \"street\": \"Oxfordstreet\",\n" +
+ " \"voltageLevel\": \"HS\",\n" +
+ " \"autopublish\": \"true\"\n" +
+ " }");
+
+ BranchDto branchStromDto = MockDataHelper.mockBranchDto();
+ branchStromDto.setName("S");
+ when( branchService.findByName(eq("S"))).thenReturn(branchStromDto);
+
+ FailureInformationDto savedFailureInformationDto = MockDataHelper.mockFailureInformationDto();
+ when( radiusService.getRadii() ).thenReturn(getRadiusDtoList());
+ when( failureInformationService.insertFailureInfo(any(), any())).thenReturn(savedFailureInformationDto);
+ //when( failureInformationService.insertPublicationChannelForFailureInfo(any(), anyString(), anyBoolean())).thenReturn(new FailureInformationPublicationChannelDto());
+
+ importService.validateAndImport(dto);
+
+ verify(failureInformationService, times(1))
+ .insertFailureInfo(any( FailureInformationDto.class), eq(GfiProcessState.QUALIFIED));
+ }
+
+ @Test
+ public void shouldImportUpdateMessageAutopublish() {
+ ImportDataDto dto = MockDataHelper.mockImportDataDto();
+ dto.setMessageContent("{\n" +
+ " \"branch\": \"S\",\n" + // invalid branch
+ " \"city\": \"Belfast\",\n" +
+ " \"description\": \"Schlimmer Fehler im System\",\n" +
+ " \"district\": \"\",\n" +
+ " \"failureBegin\": \"2020-11-19T14:13:15.666Z\",\n" +
+ " \"housenumber\": \"10b\",\n" +
+ " \"latitude\": 12.345,\n" +
+ " \"longitude\": 0,\n" +
+ " \"planned\": false,\n" +
+ " \"postcode\": \"3456\",\n" +
+ " \"pressureLevel\": null,\n" +
+ " \"radiusInMeters\": 678,\n" +
+ " \"stationDescription\": null,\n" +
+ " \"stationId\": null,\n" +
+ " \"street\": \"Oxfordstreet\",\n" +
+ " \"voltageLevel\": \"HS\",\n" +
+ " \"autopublish\": \"true\"\n" +
+ " }");
+
+ BranchDto branchStromDto = MockDataHelper.mockBranchDto();
+ branchStromDto.setName("S");
+ when( branchService.findByName(eq("S"))).thenReturn(branchStromDto);
+ StatusDto qualifiedStatusDto = MockDataHelper.mockStatusDto("qualified", UUID.randomUUID());
+ StatusDto canceledStatusDto = MockDataHelper.mockStatusDto("canceled", UUID.randomUUID());
+ StatusDto completedStatusDto = MockDataHelper.mockStatusDto("completed", UUID.randomUUID());
+ StatusDto udpatedStatusDto = MockDataHelper.mockStatusDto("updated", UUID.randomUUID());
+
+ when( statusService.getStatusFromId( GfiProcessState.QUALIFIED.getStatusValue()) ).thenReturn(qualifiedStatusDto);
+ when( statusService.getStatusFromId( GfiProcessState.COMPLETED.getStatusValue()) ).thenReturn(completedStatusDto);
+ when( statusService.getStatusFromId( GfiProcessState.CANCELED.getStatusValue()) ).thenReturn(canceledStatusDto);
+ when( statusService.getStatusFromId( GfiProcessState.UPDATED.getStatusValue()) ).thenReturn(udpatedStatusDto);
+ when( radiusService.getRadii() ).thenReturn(getRadiusDtoList());
+
+ FailureInformationDto existingDto = MockDataHelper.mockFailureInformationDto();
+ existingDto.setStatusInternId(qualifiedStatusDto.getUuid());
+ when( failureInformationService.findByObjectReferenceExternalSystem(anyString())).thenReturn(existingDto);
+
+ importService.validateAndImport(dto);
+
+ verify(failureInformationService, times(0))
+ .updateFailureInfo(any( FailureInformationDto.class));
+ verify(processHelper, times(1)).resetPublishedStateForChannels(any());
+ }
+
}