Merge branch 'DEVELOP' of ssh://git.eclipse.org:29418/openk-usermodules/org.eclipse.openk-usermodules.gridFailureInformation.backend into DEVELOP
diff --git a/stoerungsauskunftInterface/Dockerfile_DevServer b/stoerungsauskunftInterface/Dockerfile_DevServer
index 66c3eaa..9667714 100644
--- a/stoerungsauskunftInterface/Dockerfile_DevServer
+++ b/stoerungsauskunftInterface/Dockerfile_DevServer
@@ -10,4 +10,4 @@
COPY /target/grid-failure-information.backend.stoerungsauskunft-interface.jar /usr/src/cbd/
WORKDIR usr/src/cbd
-CMD ["java", "-jar", "-Dspring.profiles.active=devserver", "grid-failure-information.backend.stoerungsauskunft-interface.jar"]
\ No newline at end of file
+CMD ["java", "-jar", "-Dspring.profiles.active=devserver,swagger", "grid-failure-information.backend.stoerungsauskunft-interface.jar"]
\ No newline at end of file
diff --git a/stoerungsauskunftInterface/Dockerfile_DevServerUnsecure b/stoerungsauskunftInterface/Dockerfile_DevServerUnsecure
index dc10133..4ad36c6 100644
--- a/stoerungsauskunftInterface/Dockerfile_DevServerUnsecure
+++ b/stoerungsauskunftInterface/Dockerfile_DevServerUnsecure
@@ -10,4 +10,4 @@
COPY /target/grid-failure-information.backend.stoerungsauskunft-interface.jar /usr/src/cbd/
WORKDIR usr/src/cbd
-CMD ["java", "-jar", "-Dspring.profiles.active=devserver-unsecure", "grid-failure-information.backend.stoerungsauskunft-interface.jar"]
\ No newline at end of file
+CMD ["java", "-jar", "-Dspring.profiles.active=devserver-unsecure,swagger", "grid-failure-information.backend.stoerungsauskunft-interface.jar"]
\ No newline at end of file
diff --git a/stoerungsauskunftInterface/pom.xml b/stoerungsauskunftInterface/pom.xml
index 2cb49a1..a29835f 100644
--- a/stoerungsauskunftInterface/pom.xml
+++ b/stoerungsauskunftInterface/pom.xml
@@ -43,6 +43,14 @@
</properties>
<dependencies>
+ <!-- https://mvnrepository.com/artifact/org.springframework.amqp/spring-rabbit-test -->
+ <dependency>
+ <groupId>org.springframework.amqp</groupId>
+ <artifactId>spring-rabbit-test</artifactId>
+ <version>2.2.7.RELEASE</version>
+ <scope>test</scope>
+ </dependency>
+
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
diff --git a/stoerungsauskunftInterface/src/main/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/StoerungsaulkunftInterfaceApplication.java b/stoerungsauskunftInterface/src/main/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/StoerungsauskunftInterfaceApplication.java
similarity index 75%
rename from stoerungsauskunftInterface/src/main/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/StoerungsaulkunftInterfaceApplication.java
rename to stoerungsauskunftInterface/src/main/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/StoerungsauskunftInterfaceApplication.java
index 02f6814..0a95ee3 100644
--- a/stoerungsauskunftInterface/src/main/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/StoerungsaulkunftInterfaceApplication.java
+++ b/stoerungsauskunftInterface/src/main/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/StoerungsauskunftInterfaceApplication.java
@@ -6,10 +6,10 @@
@SpringBootApplication
@EnableFeignClients
-public class StoerungsaulkunftInterfaceApplication {
+public class StoerungsauskunftInterfaceApplication {
public static void main(String[] args) {
- SpringApplication.run(StoerungsaulkunftInterfaceApplication.class);
+ SpringApplication.run(StoerungsauskunftInterfaceApplication.class);
}
}
diff --git a/stoerungsauskunftInterface/src/main/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/config/SwaggerConfig.java b/stoerungsauskunftInterface/src/main/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/config/SwaggerConfig.java
index 085d1a2..49f1250 100644
--- a/stoerungsauskunftInterface/src/main/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/config/SwaggerConfig.java
+++ b/stoerungsauskunftInterface/src/main/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/config/SwaggerConfig.java
@@ -15,12 +15,12 @@
@Log4j2
@Configuration
@EnableSwagger2
-@Profile("!prod")
+@Profile("swagger")
public class SwaggerConfig {
- @Value("${swagger.baseUrl}")
+ @Value("${swagger.baseUrl:}")
public String baseUrl;
- @Value("${swagger.proxyUrl}")
+ @Value("${swagger.proxyUrl:}")
public String proxyUrl;
@Bean
diff --git a/stoerungsauskunftInterface/src/main/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/constants/Constants.java b/stoerungsauskunftInterface/src/main/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/constants/Constants.java
index 8cd09fb..ae634f5 100644
--- a/stoerungsauskunftInterface/src/main/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/constants/Constants.java
+++ b/stoerungsauskunftInterface/src/main/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/constants/Constants.java
@@ -19,6 +19,7 @@
public static final String SRC_STOERUNGSAUSKUNFT_DE = "stoerungsauskunft.de";
public static final String BRANCH_ELECTRICITY = "S";
+ public static final String VOLTAGE_LVL_LOW = "NS";
public static final String PLANNED_OUTAGE = "planned";
public static final String UNPLANNED_OUTAGE = "unplanned";
diff --git a/stoerungsauskunftInterface/src/main/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/dtos/StoerungsauskunftUserNotification.java b/stoerungsauskunftInterface/src/main/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/dtos/StoerungsauskunftUserNotification.java
index 4db2c54..c9cf7fb 100644
--- a/stoerungsauskunftInterface/src/main/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/dtos/StoerungsauskunftUserNotification.java
+++ b/stoerungsauskunftInterface/src/main/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/dtos/StoerungsauskunftUserNotification.java
@@ -17,7 +17,6 @@
private String houseNo;
private String district;
private String ags;
- private Integer radius;
private String lat;
private String lng;
private String comment;
diff --git a/stoerungsauskunftInterface/src/main/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/mapper/StoerungsauskunftMapper.java b/stoerungsauskunftInterface/src/main/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/mapper/StoerungsauskunftMapper.java
index 3463cbb..197b789 100644
--- a/stoerungsauskunftInterface/src/main/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/mapper/StoerungsauskunftMapper.java
+++ b/stoerungsauskunftInterface/src/main/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/mapper/StoerungsauskunftMapper.java
@@ -14,6 +14,7 @@
*/
package org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.mapper;
+import org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.constants.Constants;
import org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.dtos.*;
import org.mapstruct.*;
@@ -33,7 +34,6 @@
@Mapping(target = "failureBegin", source = "date", dateFormat = "dd.MM.yyyy HH:mm:ss"),
@Mapping(target = "longitude", source = "lng"),
@Mapping(target = "latitude", source = "lat"),
- @Mapping(target = "radiusInMeters", source = "radius", defaultValue = "0"),
@Mapping(target = "street", source = "street", qualifiedByName = "streetMapperToForeignFailureDataDto"),
@Mapping(target = "housenumber", source = "houseNo"),
})
@@ -41,10 +41,12 @@
@AfterMapping
- default void setStreetAndHouseNumber(StoerungsauskunftUserNotification srcEntity, @MappingTarget ForeignFailureDataDto targetEntity){
+ default void afterMappingProcess(StoerungsauskunftUserNotification srcEntity, @MappingTarget ForeignFailureDataDto targetEntity){
if (targetEntity.getHousenumber() == null || targetEntity.getHousenumber().isEmpty()){
targetEntity.setHousenumber(housenumberMapperToForeignFailureDataDto(srcEntity.getStreet()));
}
+ targetEntity.setRadiusInMeters(0L);
+ targetEntity.setVoltageLevel(Constants.VOLTAGE_LVL_LOW);
}
@Named("streetMapperToForeignFailureDataDto")
diff --git a/stoerungsauskunftInterface/src/main/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/controller/MessageConsumer.java b/stoerungsauskunftInterface/src/main/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/service/MessageConsumerService.java
similarity index 92%
rename from stoerungsauskunftInterface/src/main/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/controller/MessageConsumer.java
rename to stoerungsauskunftInterface/src/main/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/service/MessageConsumerService.java
index d982fa0..668e1d8 100644
--- a/stoerungsauskunftInterface/src/main/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/controller/MessageConsumer.java
+++ b/stoerungsauskunftInterface/src/main/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/service/MessageConsumerService.java
@@ -1,4 +1,4 @@
-package org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.controller;
+package org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.service;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -10,10 +10,11 @@
import org.springframework.amqp.support.converter.SimpleMessageConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+import org.springframework.stereotype.Service;
@Log4j2
-@Component
-public class MessageConsumer {
+@Service
+public class MessageConsumerService {
@Autowired
ObjectMapper objectMapper;
@@ -36,6 +37,5 @@
String messagePayload = (String) converter.fromMessage(message);
RabbitMqMessageDto rabbitMqMessageDto = objectMapper.readValue(messagePayload, RabbitMqMessageDto.class);
importExportService.exportStoerungsauskunftOutage(rabbitMqMessageDto);
-
}
}
diff --git a/stoerungsauskunftInterface/src/main/resources/application.yml b/stoerungsauskunftInterface/src/main/resources/application.yml
index 03f0bcd..249988a 100644
--- a/stoerungsauskunftInterface/src/main/resources/application.yml
+++ b/stoerungsauskunftInterface/src/main/resources/application.yml
@@ -68,10 +68,6 @@
enabled: false
cron: 0 */15 * ? * *
-swagger:
- baseUrl:
- proxyUrl:
-
---
spring:
@@ -175,5 +171,4 @@
corsEnabled: true
swagger:
- baseUrl: /test-stoerungsauskunft-interface
- proxyUrl:
\ No newline at end of file
+ baseUrl: /test-stoerungsauskunft-interface
\ No newline at end of file
diff --git a/stoerungsauskunftInterface/src/main/resources/application_localdev.yml b/stoerungsauskunftInterface/src/main/resources/application_localdev.yml
index e9c0025..1c04bd5 100644
--- a/stoerungsauskunftInterface/src/main/resources/application_localdev.yml
+++ b/stoerungsauskunftInterface/src/main/resources/application_localdev.yml
@@ -81,9 +81,6 @@
enabled: false
cron: 0 */15 * ? * *
-swagger:
- baseUrl:
- proxyUrl:
---
spring:
diff --git a/stoerungsauskunftInterface/src/test/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/config/ImportSchedulerConfigTest.java b/stoerungsauskunftInterface/src/test/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/config/ImportSchedulerConfigTest.java
index 116646e..259d866 100644
--- a/stoerungsauskunftInterface/src/test/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/config/ImportSchedulerConfigTest.java
+++ b/stoerungsauskunftInterface/src/test/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/config/ImportSchedulerConfigTest.java
@@ -1,23 +1,24 @@
package org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.config;
-import org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.StoerungsaulkunftInterfaceApplication;
+import org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.StoerungsauskunftInterfaceApplication;
import org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.api.StoerungsauskunftApi;
import org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.service.ImportExportService;
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.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
-@SpringBootTest(classes = StoerungsaulkunftInterfaceApplication.class)
+@SpringBootTest(classes = StoerungsauskunftInterfaceApplication.class)
@ContextConfiguration(classes = {TestConfiguration.class})
@ActiveProfiles("test")
public class ImportSchedulerConfigTest {
- @Qualifier("myImportService")
- @Autowired
+ @SpyBean
private ImportExportService importExportService;
@MockBean
@@ -29,7 +30,6 @@
@Test
public void shoulImportUserNotification() {
importSchedulerConfig.scheduleTaskImportUserNotifications();
- //Todo kann ImportExportService nicht "mocken" (@Spybean vs @MockBean)
- //verify(myImportService, times(1)).importUserNotifications();
+ verify(importExportService, times(1)).importUserNotifications();
}
}
diff --git a/stoerungsauskunftInterface/src/test/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/config/TestConfiguration.java b/stoerungsauskunftInterface/src/test/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/config/TestConfiguration.java
index 88e6aab..4cd962c 100644
--- a/stoerungsauskunftInterface/src/test/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/config/TestConfiguration.java
+++ b/stoerungsauskunftInterface/src/test/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/config/TestConfiguration.java
@@ -16,11 +16,14 @@
import com.fasterxml.jackson.databind.ObjectMapper;
-import org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.StoerungsaulkunftInterfaceApplication;
+import com.rabbitmq.client.Channel;
+import org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.StoerungsauskunftInterfaceApplication;
import org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.config.rabbitMq.RabbitMqConfig;
import org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.mapper.StoerungsauskunftMapperImpl;
-import org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.service.ImportExportService;
-import org.mockito.Mockito;
+import org.springframework.amqp.rabbit.annotation.EnableRabbit;
+import org.springframework.amqp.rabbit.connection.Connection;
+import org.springframework.amqp.rabbit.connection.ConnectionFactory;
+import org.springframework.amqp.rabbit.test.TestRabbitTemplate;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.test.context.ConfigFileApplicationContextInitializer;
@@ -29,31 +32,51 @@
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
-import static org.mockito.Mockito.doNothing;
+import java.io.IOException;
-@EntityScan(basePackageClasses = StoerungsaulkunftInterfaceApplication.class)
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.BDDMockito.willReturn;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.mock;
+
+@EntityScan(basePackageClasses = StoerungsauskunftInterfaceApplication.class)
@ContextConfiguration( initializers = {ConfigFileApplicationContextInitializer.class})
@TestPropertySource("spring.config.location=classpath:application.yml")
+@EnableRabbit
public class TestConfiguration {
@Bean
ObjectMapper objectMapper() { return new ObjectMapper(); }
@Bean
- public ImportExportService myImportService() {return new ImportExportService();}
-
- @Bean
public StoerungsauskunftMapperImpl stoerungsauskunftMapper() {return new StoerungsauskunftMapperImpl();}
@Bean
- public MessageChannel failureImportChannel() {return Mockito.mock(MessageChannel.class);}
+ public MessageChannel failureImportChannel() {return mock(MessageChannel.class);}
@Bean
@Qualifier("rabbitMqConfig")
public RabbitMqConfig rabbitMqConfig() {
- RabbitMqConfig rabbitMqConfigMock = Mockito.mock(RabbitMqConfig.class);
+ RabbitMqConfig rabbitMqConfigMock = mock(RabbitMqConfig.class);
doNothing().when(rabbitMqConfigMock).buildAllQueues();
return rabbitMqConfigMock;
}
+ @Bean
+ public TestRabbitTemplate template() throws IOException {
+ return new TestRabbitTemplate(connectionFactory());
+ }
+
+ @Bean
+ public ConnectionFactory connectionFactory() throws IOException {
+ ConnectionFactory factory = mock(ConnectionFactory.class);
+ Connection connection = mock(Connection.class);
+ Channel channel = mock(Channel.class);
+ willReturn(connection).given(factory).createConnection();
+ willReturn(channel).given(connection).createChannel(anyBoolean());
+ given(channel.isOpen()).willReturn(true);
+ return factory;
+ }
+
}
diff --git a/stoerungsauskunftInterface/src/test/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/controller/ImportExportControllerTest.java b/stoerungsauskunftInterface/src/test/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/controller/ImportExportControllerTest.java
index 33e90c4..02b4b52 100644
--- a/stoerungsauskunftInterface/src/test/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/controller/ImportExportControllerTest.java
+++ b/stoerungsauskunftInterface/src/test/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/controller/ImportExportControllerTest.java
@@ -15,9 +15,8 @@
package org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.controller;
import com.fasterxml.jackson.databind.ObjectMapper;
-import org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.StoerungsaulkunftInterfaceApplication;
+import org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.StoerungsauskunftInterfaceApplication;
import org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.api.StoerungsauskunftApi;
-import org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.dtos.ForeignFailureMessageDto;
import org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.dtos.RabbitMqMessageDto;
import org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.service.ImportExportService;
import org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.support.MockDataHelper;
@@ -36,7 +35,7 @@
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
-@SpringBootTest(classes = StoerungsaulkunftInterfaceApplication.class)
+@SpringBootTest(classes = StoerungsauskunftInterfaceApplication.class)
@AutoConfigureMockMvc
@ActiveProfiles("test")
public class ImportExportControllerTest {
diff --git a/stoerungsauskunftInterface/src/test/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/service/ImportExportServiceTest.java b/stoerungsauskunftInterface/src/test/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/service/ImportExportServiceTest.java
index 6f53c75..8d938dd 100644
--- a/stoerungsauskunftInterface/src/test/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/service/ImportExportServiceTest.java
+++ b/stoerungsauskunftInterface/src/test/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/service/ImportExportServiceTest.java
@@ -18,10 +18,9 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import feign.Request;
import feign.Response;
-import org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.StoerungsaulkunftInterfaceApplication;
+import org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.StoerungsauskunftInterfaceApplication;
import org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.api.StoerungsauskunftApi;
import org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.config.TestConfiguration;
-import org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.dtos.FailureInformationDto;
import org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.dtos.ForeignFailureMessageDto;
import org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.dtos.RabbitMqMessageDto;
import org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.dtos.StoerungsauskunftUserNotification;
@@ -29,7 +28,6 @@
import org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.support.MockDataHelper;
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.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.core.io.ClassPathResource;
@@ -40,18 +38,18 @@
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.text.ParseException;
+import java.util.ArrayList;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
-@SpringBootTest(classes = StoerungsaulkunftInterfaceApplication.class)
+@SpringBootTest(classes = StoerungsauskunftInterfaceApplication.class)
@ContextConfiguration(classes = {TestConfiguration.class})
@ActiveProfiles("test")
public class ImportExportServiceTest {
- @Qualifier("myImportService")
@Autowired
private ImportExportService importExportService;
@@ -105,6 +103,21 @@
}
@Test
+ public void shouldExportForeignFailureMessageDto_planned_polygons_empty() throws ParseException {
+ RabbitMqMessageDto rabbitMqMessageDto = MockDataHelper.mockRabbitMqMessageDto();
+
+ rabbitMqMessageDto.getFailureInformationDto().setPlanned(true);
+ rabbitMqMessageDto.getFailureInformationDto().setAddressPolygonPoints(new ArrayList<>());
+
+ Request request = mock(Request.class);
+ Response mockResponse = Response.builder().status(200).request(request).body("Test", StandardCharsets.UTF_8).build();
+
+ when(stoerungsauskunftApi.postOutage(any())).thenReturn(mockResponse);
+ importExportService.exportStoerungsauskunftOutage(rabbitMqMessageDto);
+ verify(stoerungsauskunftApi, times(1)).postOutage(anyList());
+ }
+
+ @Test
public void shouldThrowErrorWhenCallToExternalInterfacefailed() throws ParseException {
RabbitMqMessageDto rabbitMqMessageDto = MockDataHelper.mockRabbitMqMessageDto();
@@ -116,5 +129,21 @@
}
+ @Test
+ public void shoulImportUserNotificationMapperTest1() throws IOException {
+
+ ImportExportService importExportServicSpy = spy(importExportService);
+
+ InputStream is = new ClassPathResource("UsernotificationJsonResponse.json").getInputStream();
+ List<StoerungsauskunftUserNotification> userNotificationList =
+ objectMapper.readValue(is, new TypeReference<List<StoerungsauskunftUserNotification>>() {
+ });
+ when(stoerungsauskunftApi.getUserNotification(any(Integer.class))).thenReturn(userNotificationList);
+
+ importExportServicSpy.importUserNotifications();
+
+ verify(importExportServicSpy, times(userNotificationList.size())).pushForeignFailure(any(ForeignFailureMessageDto.class));
+ }
+
}
diff --git a/stoerungsauskunftInterface/src/test/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/service/MessageConsumerServiceTest.java b/stoerungsauskunftInterface/src/test/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/service/MessageConsumerServiceTest.java
new file mode 100644
index 0000000..17d894b
--- /dev/null
+++ b/stoerungsauskunftInterface/src/test/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/service/MessageConsumerServiceTest.java
@@ -0,0 +1,85 @@
+/*
+ *******************************************************************************
+ * 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.stoerauskunftinterface.service;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.StoerungsauskunftInterfaceApplication;
+import org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.api.StoerungsauskunftApi;
+import org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.config.TestConfiguration;
+import org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.dtos.RabbitMqMessageDto;
+import org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.support.MockDataHelper;
+import org.junit.jupiter.api.Test;
+import org.springframework.amqp.rabbit.test.RabbitListenerTest;
+import org.springframework.amqp.rabbit.test.RabbitListenerTestHarness;
+import org.springframework.amqp.rabbit.test.TestRabbitTemplate;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.boot.test.mock.mockito.SpyBean;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.ContextConfiguration;
+
+import java.text.ParseException;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+@SpringBootTest(classes = StoerungsauskunftInterfaceApplication.class)
+@ContextConfiguration(classes = {TestConfiguration.class})
+@ActiveProfiles("test")
+@RabbitListenerTest
+public class MessageConsumerServiceTest {
+
+ @Autowired
+ private RabbitListenerTestHarness harness;
+
+ @SpyBean
+ private ImportExportService importExportService;
+
+ @Autowired
+ ObjectMapper objectMapper;
+
+ @MockBean
+ StoerungsauskunftApi stoerungsauskunftApi;
+
+ @Autowired
+ private TestRabbitTemplate testRabbitTemplate;
+
+ @Value("${spring.rabbitmq.exportQueue}")
+ private String exportQueue;
+
+ @Test
+ public void shouldExportForeignFailureMessageDto() throws JsonProcessingException {
+
+ RabbitMqMessageDto rabbitMqMessageDto = MockDataHelper.mockRabbitMqMessageDto();
+ String rabbitMqMessageDtoString = objectMapper.writeValueAsString(rabbitMqMessageDto);
+
+ testRabbitTemplate.convertAndSend(exportQueue, rabbitMqMessageDtoString);
+
+ verify(importExportService, times(1)).exportStoerungsauskunftOutage(any());
+ }
+
+ @Test
+ public void shouldIgnoreButLogInputError() throws ParseException {
+ testRabbitTemplate.convertAndSend(exportQueue, "false input");
+ verify(importExportService, times(0)).exportStoerungsauskunftOutage(any());
+ }
+
+
+}
diff --git a/stoerungsauskunftInterface/src/test/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/support/MockDataHelper.java b/stoerungsauskunftInterface/src/test/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/support/MockDataHelper.java
index 3a2a7c9..2de3b74 100644
--- a/stoerungsauskunftInterface/src/test/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/support/MockDataHelper.java
+++ b/stoerungsauskunftInterface/src/test/java/org/eclipse/openk/gridfailureinformation/stoerauskunftinterface/support/MockDataHelper.java
@@ -14,11 +14,13 @@
*/
package org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.support;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.constants.Constants;
import org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.dtos.FailureInformationDto;
import org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.dtos.ForeignFailureDataDto;
import org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.dtos.ForeignFailureMessageDto;
import org.eclipse.openk.gridfailureinformation.stoerauskunftinterface.dtos.RabbitMqMessageDto;
+import org.springframework.beans.factory.annotation.Autowired;
import java.math.BigDecimal;
import java.sql.Date;
diff --git a/stoerungsauskunftInterface/src/test/resources/UsernotificationJsonResponse.json b/stoerungsauskunftInterface/src/test/resources/UsernotificationJsonResponse.json
index 12b4250..fb469bf 100644
--- a/stoerungsauskunftInterface/src/test/resources/UsernotificationJsonResponse.json
+++ b/stoerungsauskunftInterface/src/test/resources/UsernotificationJsonResponse.json
@@ -19,12 +19,51 @@
"city": "Flonheim",
"ags": null,
"district": null,
- "street": "Am Obertor 13",
+ "street": "Am Obertor",
"lat": "49.8031615",
"lng": "8.1932478",
"comment": "Zappenduster",
"operatorOutageInArea": 0,
- "houseNo": "12"
-
+ "houseNo": "13"
+ },
+ {
+ "id": 23,
+ "date": "28.5.2020 14:49:11",
+ "postcode": "55237",
+ "city": "Flonheim",
+ "ags": null,
+ "district": null,
+ "lat": "49.8031615",
+ "lng": "8.1932478",
+ "comment": "Zappenduster",
+ "operatorOutageInArea": 0
+ },
+ {
+ "id": 23,
+ "date": "28.5.2020 14:49:11",
+ "postcode": "55237",
+ "city": "Flonheim",
+ "ags": null,
+ "street": "",
+ "district": null,
+ "lat": "49.8031615",
+ "lng": "8.1932478",
+ "comment": "Zappenduster",
+ "operatorOutageInArea": 0,
+ "houseNo": ""
+ },
+ {
+ "id": 23,
+ "date": "28.5.2020 14:49:11",
+ "postcode": "55237",
+ "city": "Flonheim",
+ "ags": null,
+ "district": null,
+ "street": "Am Obertor",
+ "lat": "49.8031615",
+ "lng": "8.1932478",
+ "comment": "Zappenduster",
+ "phone": "01520123456",
+ "operatorOutageInArea": 0
}
]
\ No newline at end of file
diff --git a/stoerungsauskunftInterface/src/test/resources/application.yml b/stoerungsauskunftInterface/src/test/resources/application.yml
index 602e91b..843be83 100644
--- a/stoerungsauskunftInterface/src/test/resources/application.yml
+++ b/stoerungsauskunftInterface/src/test/resources/application.yml
@@ -57,10 +57,6 @@
enabled: false
cron: 0 */15 * ? * *
-swagger:
- baseUrl:
- proxyUrl:
-
---
spring: