aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile21
-rw-r--r--README.md4
-rw-r--r--README_SONAR.md73
-rw-r--r--docs/sonarqube/create_new_project_sonarqube.pngbin0 -> 14163 bytes
-rw-r--r--docs/sonarqube/create_new_project_step1_sonarqube.pngbin0 -> 21258 bytes
-rw-r--r--docs/sonarqube/create_new_project_step2_sonarqube.pngbin0 -> 33382 bytes
-rw-r--r--docs/sonarqube/create_new_project_step3_sonarqube.pngbin0 -> 37968 bytes
-rw-r--r--docs/sonarqube/create_new_project_step4_sonarqube.pngbin0 -> 100125 bytes
-rw-r--r--docs/sonarqube/login_sonarqube.pngbin0 -> 11670 bytes
-rw-r--r--docs/sonarqube/sonarqube_report.pngbin0 -> 92426 bytes
-rw-r--r--pnfsimulator/Makefile13
-rw-r--r--pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/model/TemplateRequest.java12
-rw-r--r--pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/utils/ssl/SslAuthenticationHelper.java45
-rw-r--r--pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/utils/ssl/SslSupportLevel.java2
-rw-r--r--pnfsimulator/src/test/java/org/onap/pnfsimulator/rest/SimulatorControllerTest.java116
-rw-r--r--pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/SimulatorServiceTest.java51
-rw-r--r--pom.xml19
-rw-r--r--sanitycheck/Makefile40
-rw-r--r--sanitycheck/README.md52
-rw-r--r--sanitycheck/dmaap-simulator/Dockerfile7
-rw-r--r--sanitycheck/dmaap-simulator/Makefile23
-rw-r--r--sanitycheck/dmaap-simulator/README.md23
-rw-r--r--sanitycheck/dmaap-simulator/requirements.txt6
-rw-r--r--sanitycheck/dmaap-simulator/simulator.py47
-rw-r--r--sanitycheck/events/eventToVes.json37
-rw-r--r--sanitycheck/events/fewEventsToVes.json32
-rw-r--r--sanitycheck/events/vesAddressConfiguration.json3
-rw-r--r--sanitycheck/ves/Makefile23
-rw-r--r--sanitycheck/ves/README.md21
-rw-r--r--sanitycheck/ves/docker-compose.yml20
30 files changed, 633 insertions, 57 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..cb456c5
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,21 @@
+create-sonarqube:
+ @echo "##### Create SonarQube #####"
+ docker run -d --name sonarqube -p 9000:9000 -p 9092:9092 sonarqube
+ @echo "************************************************"
+ @echo "*** Follow instructions from README_SONAR.md ***"
+ @echo "************************************************"
+ @echo "##### DONE #####"
+
+start-sonarqube:
+ @echo "##### Start SonarQube #####"
+ docker start sonarqube
+ @echo "************************************************"
+ @echo "*** Follow instructions from README_SONAR.md ***"
+ @echo "************************************************"
+ @echo "##### DONE #####"
+
+stop-sonarqube:
+ @echo "##### Stop SonarQube #####"
+ docker stop sonarqube
+ @echo "##### DONE #####"
+
diff --git a/README.md b/README.md
index 6300184..ff9da7a 100644
--- a/README.md
+++ b/README.md
@@ -21,6 +21,10 @@ mvn clean package
mvn clean package -P docker -DskipTests=true
```
+##Sanity check
+
+See README.md in sanitycheck directory
+
## Sonar
https://sonarcloud.io/dashboard?id=onap_integration-pnf-simulator
diff --git a/README_SONAR.md b/README_SONAR.md
new file mode 100644
index 0000000..e65b7e6
--- /dev/null
+++ b/README_SONAR.md
@@ -0,0 +1,73 @@
+# Run SonarQube locally
+All instructions based at an article at https://www.vogella.com/tutorials/SonarQube/article.html
+
+## Configure and run SonarQube locally
+* Create and run SonarQube container
+ ```
+ make create-sonarqube
+ ```
+* Configure SonarQube
+
+ a). Log in at http://localhost:9000
+
+ ![alt text](docs/sonarqube/login_sonarqube.png "Log in")
+
+ Username: admin
+ Password: admin
+
+ b). Create a new Sonar project.
+
+ ![alt text](docs/sonarqube/create_new_project_sonarqube.png "Create a new project")
+
+ - Set project name
+
+ ![alt text](docs/sonarqube/create_new_project_step1_sonarqube.png "Set project name")
+
+ - Generate token
+
+ ![alt text](docs/sonarqube/create_new_project_step2_sonarqube.png "Generate token")
+
+ You should see
+
+ ![alt text](docs/sonarqube/create_new_project_step3_sonarqube.png "Generated token")
+
+ - Select code language and building technology
+
+ ![alt text](docs/sonarqube/create_new_project_step4_sonarqube.png "Select code language")
+
+ c). Run code analyse using command from a previous step.
+
+ Before code analyse ALWAYS execute:
+
+ ```
+ mvn clean test
+ ```
+
+ Next (from previous step):
+ ```
+ mvn sonar:sonar \
+ -Dsonar.projectKey=pnf-simulator \
+ -Dsonar.host.url=http://localhost:9000 \
+ -Dsonar.login=de5dac7da79a4de88876006a05457902aab1a3a3
+ ```
+ After command execution you should see at the console:
+ ```
+ [INFO] ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard?id=pnf-simulator
+ [INFO] Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
+ ```
+ Click at link http://localhost:9000/dashboard?id=pnf-simulator to see Sonar report
+ ![alt text](docs/sonarqube/sonarqube_report.png "Select code language")
+
+ IMPORTANT: Please note command used to run code analise. You will need it later.
+
+## Stopping SonarQube
+If you do not want to repeat step **Configure and run SonarQube locally** you must use stopping and starting make goals.
+```
+ make stop-sonarqube
+```
+
+## Starting SonarQube
+If you do not want to repeat step **Configure and run SonarQube locally** you must use stopping and starting make goals.
+```
+ make start-sonarqube
+```
diff --git a/docs/sonarqube/create_new_project_sonarqube.png b/docs/sonarqube/create_new_project_sonarqube.png
new file mode 100644
index 0000000..0d41700
--- /dev/null
+++ b/docs/sonarqube/create_new_project_sonarqube.png
Binary files differ
diff --git a/docs/sonarqube/create_new_project_step1_sonarqube.png b/docs/sonarqube/create_new_project_step1_sonarqube.png
new file mode 100644
index 0000000..5601672
--- /dev/null
+++ b/docs/sonarqube/create_new_project_step1_sonarqube.png
Binary files differ
diff --git a/docs/sonarqube/create_new_project_step2_sonarqube.png b/docs/sonarqube/create_new_project_step2_sonarqube.png
new file mode 100644
index 0000000..0e759dc
--- /dev/null
+++ b/docs/sonarqube/create_new_project_step2_sonarqube.png
Binary files differ
diff --git a/docs/sonarqube/create_new_project_step3_sonarqube.png b/docs/sonarqube/create_new_project_step3_sonarqube.png
new file mode 100644
index 0000000..be8b1a1
--- /dev/null
+++ b/docs/sonarqube/create_new_project_step3_sonarqube.png
Binary files differ
diff --git a/docs/sonarqube/create_new_project_step4_sonarqube.png b/docs/sonarqube/create_new_project_step4_sonarqube.png
new file mode 100644
index 0000000..810b35f
--- /dev/null
+++ b/docs/sonarqube/create_new_project_step4_sonarqube.png
Binary files differ
diff --git a/docs/sonarqube/login_sonarqube.png b/docs/sonarqube/login_sonarqube.png
new file mode 100644
index 0000000..4810cf0
--- /dev/null
+++ b/docs/sonarqube/login_sonarqube.png
Binary files differ
diff --git a/docs/sonarqube/sonarqube_report.png b/docs/sonarqube/sonarqube_report.png
new file mode 100644
index 0000000..925d256
--- /dev/null
+++ b/docs/sonarqube/sonarqube_report.png
Binary files differ
diff --git a/pnfsimulator/Makefile b/pnfsimulator/Makefile
new file mode 100644
index 0000000..58de699
--- /dev/null
+++ b/pnfsimulator/Makefile
@@ -0,0 +1,13 @@
+all: start
+
+.PHONY: start
+
+start:
+ @echo "##### Start PNF simulator #####"
+ docker-compose up -d
+ @echo "##### DONE #####"
+
+stop:
+ @echo "##### Stop PNF simulator #####"
+ docker-compose down
+ @echo "##### DONE #####"
diff --git a/pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/model/TemplateRequest.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/model/TemplateRequest.java
index d5a77f0..f1e0243 100644
--- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/model/TemplateRequest.java
+++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/model/TemplateRequest.java
@@ -20,23 +20,19 @@
package org.onap.pnfsimulator.rest.model;
+import lombok.AllArgsConstructor;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.bson.Document;
+@AllArgsConstructor
+@NoArgsConstructor
@Getter
@Setter
@ToString
public class TemplateRequest {
private String name;
private Document template;
-
- public TemplateRequest(String name, Document template) {
- this.name = name;
- this.template = template;
- }
-
- public TemplateRequest() {
- }
}
diff --git a/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/utils/ssl/SslAuthenticationHelper.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/utils/ssl/SslAuthenticationHelper.java
index ee5fdb7..1887d37 100644
--- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/utils/ssl/SslAuthenticationHelper.java
+++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/utils/ssl/SslAuthenticationHelper.java
@@ -20,6 +20,9 @@
package org.onap.pnfsimulator.simulator.client.utils.ssl;
import java.io.Serializable;
+
+import lombok.Getter;
+import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Primary;
@@ -29,6 +32,8 @@ import org.springframework.stereotype.Component;
@ConfigurationProperties(prefix = "ssl")
@RefreshScope
@Primary
+@Getter
+@Setter
public class SslAuthenticationHelper implements Serializable {
private boolean clientCertificateEnabled;
@@ -36,44 +41,4 @@ public class SslAuthenticationHelper implements Serializable {
private String clientCertificatePassword;
private String trustStoreDir;
private String trustStorePassword;
-
- public boolean isClientCertificateEnabled() {
- return clientCertificateEnabled;
- }
-
- public void setClientCertificateEnabled(boolean clientCertificateEnabled) {
- this.clientCertificateEnabled = clientCertificateEnabled;
- }
-
- public String getClientCertificateDir() {
- return clientCertificateDir;
- }
-
- public void setClientCertificateDir(String clientCertificateDir) {
- this.clientCertificateDir = clientCertificateDir;
- }
-
- public String getClientCertificatePassword() {
- return clientCertificatePassword;
- }
-
- public void setClientCertificatePassword(String clientCertificatePassword) {
- this.clientCertificatePassword = clientCertificatePassword;
- }
-
- public String getTrustStoreDir() {
- return trustStoreDir;
- }
-
- public void setTrustStoreDir(String trustStoreDir) {
- this.trustStoreDir = trustStoreDir;
- }
-
- public String getTrustStorePassword() {
- return trustStorePassword;
- }
-
- public void setTrustStorePassword(String trustStorePassword) {
- this.trustStorePassword = trustStorePassword;
- }
}
diff --git a/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/utils/ssl/SslSupportLevel.java b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/utils/ssl/SslSupportLevel.java
index 393a6c5..2325ebc 100644
--- a/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/utils/ssl/SslSupportLevel.java
+++ b/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/client/utils/ssl/SslSupportLevel.java
@@ -68,7 +68,7 @@ public enum SslSupportLevel {
.build();
} catch (GeneralSecurityException e) {
- LOGGER.error("Could not initialize client due to SSL exception: {}. Default client without SSL support will be used instead.\nCause: {}", e.getMessage(), e.getCause().toString());
+ LOGGER.error("Could not initialize client due to SSL exception: {}. Default client without SSL support will be used instead.\nCause: {}", e.getMessage(), e.getCause());
client = NONE.getClient(requestConfig, sslAuthenticationHelper);
}
return client;
diff --git a/pnfsimulator/src/test/java/org/onap/pnfsimulator/rest/SimulatorControllerTest.java b/pnfsimulator/src/test/java/org/onap/pnfsimulator/rest/SimulatorControllerTest.java
index de824a4..0b87f69 100644
--- a/pnfsimulator/src/test/java/org/onap/pnfsimulator/rest/SimulatorControllerTest.java
+++ b/pnfsimulator/src/test/java/org/onap/pnfsimulator/rest/SimulatorControllerTest.java
@@ -30,22 +30,26 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
+import org.onap.pnfsimulator.event.EventData;
+import org.onap.pnfsimulator.event.EventDataService;
import org.onap.pnfsimulator.rest.model.FullEvent;
import org.onap.pnfsimulator.rest.model.SimulatorParams;
import org.onap.pnfsimulator.rest.model.SimulatorRequest;
-import org.onap.pnfsimulator.rest.util.JsonObjectDeserializer;
import org.onap.pnfsimulator.simulator.SimulatorService;
import org.onap.pnfsimulator.simulatorconfig.SimulatorConfig;
import org.quartz.SchedulerException;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
-import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import java.io.IOException;
import java.net.URL;
import java.security.GeneralSecurityException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
@@ -63,18 +67,27 @@ class SimulatorControllerTest {
private static final String START_ENDPOINT = "/simulator/start";
private static final String CONFIG_ENDPOINT = "/simulator/config";
private static final String EVENT_ENDPOINT = "/simulator/event";
+ private static final String CANCEL_JOB_ENDPOINT = "/simulator/cancel/";
+ private static final String ALL_EVENTS_ENDPOINT = "/simulator/all-events";
+ private static final String TEST_ENDPOINT = "/simulator/test";
+
private static final String JSON_MSG_EXPRESSION = "$.message";
+ private static final String EVENT_WAS_CANCELLED = "Event(s) was cancelled";
+ private static final String EVENT_WAS_NOT_CANCELLED = "Simulator was not able to cancel event(s)";
private static final String NEW_URL = "http://0.0.0.0:8090/eventListener/v7";
private static final String UPDATE_SIM_CONFIG_VALID_JSON = "{\"vesServerUrl\": \""
+ NEW_URL + "\"}";
private static final String SAMPLE_ID = "sampleId";
private static final Gson GSON_OBJ = new Gson();
+ private static final String JOB_NAME = "testJobName";
private static String simulatorRequestBody;
private MockMvc mockMvc;
@InjectMocks
private SimulatorController controller;
@Mock
+ private EventDataService eventDataService;
+ @Mock
private SimulatorService simulatorService;
@BeforeAll
@@ -197,6 +210,105 @@ class SimulatorControllerTest {
verify(simulatorService, Mockito.times(1)).triggerOneTimeEvent(any(FullEvent.class));
}
+ @Test
+ void shouldUseTestEndpointThenReceiveProperMessage() throws Exception {
+ String contentAsString = mockMvc
+ .perform(post(TEST_ENDPOINT)
+ .contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
+ .content("{\"simulatorParams\": {\n" +
+ " \"vesServerUrl\": \"http://localhost:9999/eventListener\"\n" +
+ " },\n" +
+ " \"templateName\": \"testTemplateName\"\n" +
+ "}"))
+ .andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
+ assertThat(contentAsString).contains("message1234");
+ }
+
+ @Test
+ void shouldSuccessfullyCancelJobThenReturnProperMessage() throws Exception {
+ when(simulatorService.cancelEvent(JOB_NAME)).thenReturn(true);
+
+ String contentAsString = mockMvc
+ .perform(post(CANCEL_JOB_ENDPOINT + JOB_NAME)
+ .contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
+ .content(""))
+ .andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
+
+ assertThat(contentAsString).contains(EVENT_WAS_CANCELLED);
+ }
+
+ @Test
+ void shouldFailWhileCancelingJobThenReturnProperMessage() throws Exception {
+ when(simulatorService.cancelEvent(JOB_NAME)).thenReturn(false);
+
+ String contentAsString = mockMvc
+ .perform(post(CANCEL_JOB_ENDPOINT + JOB_NAME)
+ .contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
+ .content(""))
+ .andExpect(status().isNotFound()).andReturn().getResponse().getContentAsString();
+
+ assertThat(contentAsString).contains(EVENT_WAS_NOT_CANCELLED);
+ }
+
+ @Test
+ void shouldSuccessfullyCancelAllJobsThenReturnsProperMessage() throws Exception {
+ when(simulatorService.cancelAllEvents()).thenReturn(true);
+
+ String contentAsString = mockMvc
+ .perform(post(CANCEL_JOB_ENDPOINT)
+ .contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
+ .content(""))
+ .andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
+
+ assertThat(contentAsString).contains(EVENT_WAS_CANCELLED);
+ }
+
+ @Test
+ void shouldSuccessfullyCancelJobWhenSendingJobNameWithBreakingCharactersThenReturnProperMessage() throws SchedulerException {
+ final String lineBreakingJobName = "test\tJob\nName\r";
+ when(simulatorService.cancelEvent(lineBreakingJobName)).thenReturn(true);
+
+ Object actualResponseBody = Objects.requireNonNull(controller.cancelEvent(lineBreakingJobName).getBody());
+
+ assertThat(actualResponseBody.toString()).contains(EVENT_WAS_CANCELLED);
+ }
+
+ @Test
+ void shouldReturnAllEvents() throws Exception {
+ List<EventData> events = getEventDatas();
+ String expectedMessage = events.stream()
+ .map(EventData::toString)
+ .collect(Collectors.joining("\\n"));
+
+ when(eventDataService.getAllEvents()).thenReturn(events);
+
+ String contentAsString = mockMvc
+ .perform(get(ALL_EVENTS_ENDPOINT)
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(""))
+ .andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
+
+ assertThat(contentAsString).contains(expectedMessage);
+ }
+
+
+ private List<EventData> getEventDatas() {
+ return Arrays.asList(
+ getEventData("id1", "keywords1", "input1", "patched1", "template1", 0),
+ getEventData("id2", "keywords2", "input2", "patched2", "template2", 1)
+ );
+ }
+
+ private EventData getEventData(String id, String keywords, String input, String patched, String template, int incrementValue) {
+ return EventData.builder()
+ .id(id)
+ .keywords(keywords)
+ .input(input)
+ .patched(patched)
+ .template(template)
+ .incrementValue(incrementValue)
+ .build();
+ }
private void startSimulator() throws Exception {
mockMvc
diff --git a/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/SimulatorServiceTest.java b/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/SimulatorServiceTest.java
index 870c963..c83c5cf 100644
--- a/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/SimulatorServiceTest.java
+++ b/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/SimulatorServiceTest.java
@@ -40,12 +40,17 @@ import org.onap.pnfsimulator.simulatorconfig.SimulatorConfigService;
import org.quartz.SchedulerException;
import java.io.IOException;
+import java.net.MalformedURLException;
import java.net.URL;
import java.security.GeneralSecurityException;
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
@@ -57,6 +62,7 @@ import static org.mockito.internal.verification.VerificationModeFactory.times;
class SimulatorServiceTest {
private static final String VES_URL = "http://0.0.0.0:8080";
+ private static final String IN_DB_VES_URL = "http://0.0.0.0:8080/eventListener/v6";
private static final Gson GSON = new Gson();
private static final JsonObject VALID_PATCH = GSON.fromJson("{\"event\": {\n"
+ " \"commonEventHeader\": {\n"
@@ -80,6 +86,7 @@ class SimulatorServiceTest {
private static final String CLOSED_LOOP_VNF = "ClosedLoopVNF";
private static final String SAMPLE_ID = "sampleId";
private static final EventData SAMPLE_EVENT = EventData.builder().id("1").build();
+ private static URL inDbVesUrl;
private final ArgumentCaptor<JsonObject> bodyCaptor = ArgumentCaptor.forClass(JsonObject.class);
private final ArgumentCaptor<Integer> intervalCaptor = ArgumentCaptor.forClass(Integer.class);
private final ArgumentCaptor<Integer> repeatCountCaptor = ArgumentCaptor
@@ -92,18 +99,20 @@ class SimulatorServiceTest {
private EventDataService eventDataService;
private EventScheduler eventScheduler;
private SimulatorConfigService simulatorConfigService;
+ private SslAuthenticationHelper sslAuthenticationHelper = new SslAuthenticationHelper() ;
private static TemplatePatcher templatePatcher = new TemplatePatcher();
private static TemplateReader templateReader = new FilesystemTemplateReader(
"src/test/resources/org/onap/pnfsimulator/simulator/", GSON);
@BeforeEach
- void setUp() {
+ void setUp() throws MalformedURLException {
+ inDbVesUrl = new URL(IN_DB_VES_URL);
eventDataService = mock(EventDataService.class);
eventScheduler = mock(EventScheduler.class);
simulatorConfigService = mock(SimulatorConfigService.class);
simulatorService = new SimulatorService(templatePatcher, templateReader,
- eventScheduler, eventDataService, simulatorConfigService, new SslAuthenticationHelper());
+ eventScheduler, eventDataService, simulatorConfigService, sslAuthenticationHelper);
}
@Test
@@ -127,7 +136,6 @@ class SimulatorServiceTest {
new SimulatorParams("", 1, 1),
templateName, VALID_PATCH);
- URL inDbVesUrl = new URL("http://0.0.0.0:8080/eventListener/v6");
doReturn(SAMPLE_EVENT).when(eventDataService).persistEventData(any(JsonObject.class), any(JsonObject.class), any(JsonObject.class), any(JsonObject.class));
when(simulatorConfigService.getConfiguration()).thenReturn(new SimulatorConfig(SAMPLE_ID, inDbVesUrl));
@@ -166,7 +174,6 @@ class SimulatorServiceTest {
new SimulatorParams("", 1, 1),
templateName, null);
- URL inDbVesUrl = new URL("http://0.0.0.0:8080/eventListener/v6");
doReturn(SAMPLE_EVENT).when(eventDataService).persistEventData(any(JsonObject.class), any(JsonObject.class), any(JsonObject.class), any(JsonObject.class));
doReturn(new SimulatorConfig(SAMPLE_ID, inDbVesUrl)).when(simulatorConfigService).getConfiguration();
@@ -207,6 +214,38 @@ class SimulatorServiceTest {
assertThat(sentContent.getAsJsonObject("event").getAsJsonObject("commonEventHeader").get("eventName").getAsString()).hasSize(20);
}
+ @Test
+ void shouldGetSimulatorConfiguration() {
+ SimulatorConfig simulatorConfig = getSimulatorConfig();
+
+ when(simulatorConfigService.getConfiguration()).thenReturn(simulatorConfig);
+
+ assertEquals(simulatorService.getConfiguration(), simulatorConfig);
+ }
+
+ @Test
+ void shouldUpdateSimulatorConfiguration() {
+ SimulatorConfig simulatorConfig = getSimulatorConfig();
+
+ when(simulatorConfigService.updateConfiguration(simulatorConfig)).thenReturn(simulatorConfig);
+
+ assertEquals(simulatorService.updateConfiguration(simulatorConfig), simulatorConfig);
+ }
+
+ @Test
+ void shouldCancelAllEvents() throws SchedulerException {
+ when(eventScheduler.cancelAllEvents()).thenReturn(true);
+
+ assertTrue(simulatorService.cancelAllEvents());
+ }
+
+ @Test
+ void shouldCancelSingleEvent() throws SchedulerException {
+ final String jobName = "testJobName";
+ when(eventScheduler.cancelEvent(jobName)).thenReturn(true);
+
+ assertTrue(simulatorService.cancelEvent(jobName));
+ }
private void assertEventHasExpectedStructure(String expectedVesUrl, String templateName, String sourceNameString) throws SchedulerException, IOException, GeneralSecurityException {
verify(eventScheduler, times(1)).scheduleEvent(vesUrlCaptor.capture(), intervalCaptor.capture(),
@@ -224,4 +263,8 @@ class SimulatorServiceTest {
.persistEventData(any(JsonObject.class), any(JsonObject.class), any(JsonObject.class),
any(JsonObject.class));
}
+
+ private SimulatorConfig getSimulatorConfig() {
+ return new SimulatorConfig(SAMPLE_ID, inDbVesUrl);
+ }
}
diff --git a/pom.xml b/pom.xml
index 42e5405..50bf928 100644
--- a/pom.xml
+++ b/pom.xml
@@ -86,6 +86,7 @@
<quartz-jobs.version>2.2.1</quartz-jobs.version>
<guava.version>21.0</guava.version>
<logback-classic.version>1.2.3</logback-classic.version>
+ <sonar-maven-plugin.version>3.7.0.1746</sonar-maven-plugin.version>
<!-- TEST DEPENDENCIES VERSION -->
@@ -104,9 +105,12 @@
<dependencyManagement>
<dependencies>
-
<!-- Compile DEPENDENCIES -->
-
+ <dependency>
+ <groupId>org.sonarsource.scanner.maven</groupId>
+ <artifactId>sonar-maven-plugin</artifactId>
+ <version>${sonar-maven-plugin.version}</version>
+ </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
@@ -326,6 +330,17 @@
</profiles>
<build>
+ <pluginManagement>
+ <plugins>
+ <!-- To run SonarQube locally -->
+ <plugin>
+ <groupId>org.sonarsource.scanner.maven</groupId>
+ <artifactId>sonar-maven-plugin</artifactId>
+ <version>${sonar-maven-plugin.version}</version>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+
<plugins>
<plugin>
<artifactId>maven-checkstyle-plugin</artifactId>
diff --git a/sanitycheck/Makefile b/sanitycheck/Makefile
new file mode 100644
index 0000000..37f2669
--- /dev/null
+++ b/sanitycheck/Makefile
@@ -0,0 +1,40 @@
+all: start
+
+.PHONY: start
+
+build:
+ @echo "##### build (dmaap sim) #####"
+ make -C dmaap-simulator build
+ @echo "##### DONE #####"
+
+start: build
+ @echo "##### start (dmaap sim,ves,pnf sim) #####"
+ make -C ves start
+ make -C ../pnfsimulator start
+ @echo "##### DONE #####"
+
+stop:
+ @echo "##### Stop (dmaap sim,ves,pnf sim) #####"
+ make -C ves stop
+ make -C ../pnfsimulator stop
+ @echo "##### DONE #####"
+
+generate-event:
+ @echo "##### Trigger PNF Simulator to generate event #####"
+ curl -X POST http://localhost:5000/simulator/event -d @events/eventToVes.json --header "Content-Type: application/json"
+ @echo "\n##### DONE #####"
+
+reconfigure-ves-url:
+ @echo "##### Change VES address configuration in PNF Simulator #####"
+ curl -X PUT http://localhost:5000/simulator/config -d @events/vesAddressConfiguration.json --header "Content-Type: application/json"
+ @echo "\n##### DONE #####"
+
+generate-multiple-events:
+ @echo "\n##### Trigger PNF Simulator to generate multiple events #####"
+ curl -X POST http://localhost:5000/simulator/start -d @events/fewEventsToVes.json --header "Content-Type: application/json"
+ @echo "\n##### DONE #####"
+
+check-dmaap:
+ @echo "##### Check dmaap simulator for collected events #####"
+ make -C dmaap-simulator get-data
+ @echo "\n##### DONE #####" \ No newline at end of file
diff --git a/sanitycheck/README.md b/sanitycheck/README.md
new file mode 100644
index 0000000..9fb4929
--- /dev/null
+++ b/sanitycheck/README.md
@@ -0,0 +1,52 @@
+### Run test case pnfsimulator -> ves collector -> dmaap simulator
+
+### Prerequisites
+* Check your docker network ip:
+```
+ip a | grep docker0 | grep inet
+```
+If the IP address is different than 172.17.0.1/16:
+inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
+
+You have to change the IP address in file events/vesAddressConfiguration.json
+```
+{
+ "vesServerUrl": "http://<IP_Address>:8080/eventListener/v7"
+}
+```
+and in file events/eventToVes.json
+
+```
+{
+"vesServerUrl": "http://<IP_Address>:8080/eventListener/v7",
+"event": { ...
+```
+### 1. Build Projects
+```
+make start
+```
+### 2. Send one event
+```
+make generate-event
+```
+### 2.1 Check dmaap sim
+```
+make check-dmaap
+```
+### 3. Send few events:
+### 3.1 Reconfigure ves url
+```
+make reconfigure-ves-url
+```
+### 3.2 Send events
+```
+make generate-multiple-events
+```
+### 3.3 Check dmaap sim
+```
+make check-dmaap
+```
+### 4. Clear environment
+```
+make stop
+```
diff --git a/sanitycheck/dmaap-simulator/Dockerfile b/sanitycheck/dmaap-simulator/Dockerfile
new file mode 100644
index 0000000..f84cac2
--- /dev/null
+++ b/sanitycheck/dmaap-simulator/Dockerfile
@@ -0,0 +1,7 @@
+FROM python:3
+WORKDIR /application
+COPY ./simulator.py ./
+COPY ./requirements.txt ./
+RUN pip install -r ./requirements.txt
+ENV FLASK_APP=./simulator.py
+CMD ["python", "./simulator.py"]
diff --git a/sanitycheck/dmaap-simulator/Makefile b/sanitycheck/dmaap-simulator/Makefile
new file mode 100644
index 0000000..af8f162
--- /dev/null
+++ b/sanitycheck/dmaap-simulator/Makefile
@@ -0,0 +1,23 @@
+all: build
+
+.PHONY: build
+
+build:
+ @echo "##### Build dmaap simulator image #####"
+ docker build . -t dmaap-simulator
+ @echo "##### DONE #####"
+
+start:
+ @echo "##### Start dmaap simulator #####"
+ docker run -d -p 3904:3904 --name dmaap-simulator dmaap-simulator
+ @echo "##### DONE #####"
+
+stop:
+ @echo "##### Stop dmaap simulator #####"
+ docker rm -f dmaap-simulator
+ @echo "##### DONE #####"
+
+get-data:
+ @echo "##### Get data fetched by dmaap-simulator #####\n"
+ curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET http://localhost:3904/events
+ @echo "\n\n##### DONE #####"
diff --git a/sanitycheck/dmaap-simulator/README.md b/sanitycheck/dmaap-simulator/README.md
new file mode 100644
index 0000000..c06afdf
--- /dev/null
+++ b/sanitycheck/dmaap-simulator/README.md
@@ -0,0 +1,23 @@
+DMaaP simulator
+---------------
+
+
+### Build an image
+```
+make build
+```
+
+### Start
+```
+make start
+```
+
+### Stop
+```
+make stop
+```
+
+### Get fetched events
+```
+make get-data
+```
diff --git a/sanitycheck/dmaap-simulator/requirements.txt b/sanitycheck/dmaap-simulator/requirements.txt
new file mode 100644
index 0000000..a6d2d3a
--- /dev/null
+++ b/sanitycheck/dmaap-simulator/requirements.txt
@@ -0,0 +1,6 @@
+Click==7.0
+Flask==1.1.1
+itsdangerous==1.1.0
+Jinja2==2.10.3
+MarkupSafe==1.1.1
+Werkzeug==0.16.0
diff --git a/sanitycheck/dmaap-simulator/simulator.py b/sanitycheck/dmaap-simulator/simulator.py
new file mode 100644
index 0000000..3437442
--- /dev/null
+++ b/sanitycheck/dmaap-simulator/simulator.py
@@ -0,0 +1,47 @@
+import json
+import logging as sys_logging
+
+from flask import Flask, request, logging
+app = Flask(__name__)
+
+sys_logging.basicConfig(level=sys_logging.DEBUG)
+logger = logging.create_logger(app)
+events = []
+
+@app.route("/events/unauthenticated.VES_NOTIFICATION_OUTPUT", methods=['POST'])
+def event_ves_notification_output():
+ return handle_new_event(request)
+
+@app.route("/events/unauthenticated.SEC_FAULT_OUTPUT", methods=['POST'])
+def event_sec_fault_output():
+ return handle_new_event(request)
+
+def handle_new_event(http_request):
+ receive_events = decode_request_data(http_request.data)
+ for event in receive_events:
+ events.append(json.loads(event))
+ return {}, 200
+
+@app.route("/events", methods=['GET'])
+def get_events():
+ return json.dumps(events), 200
+
+def decode_request_data(request_data):
+ data = request_data.decode("utf-8")
+ receive_events = data.split("\n")
+ receive_events = receive_events[:-1]
+ logger.info("received events: " + str(receive_events))
+ correct_events = []
+ for event in receive_events:
+ logger.info("received event: " + str(event))
+ correct_events.append(get_correct_json(event))
+ return correct_events
+
+def get_correct_json(incorrect_json):
+ json_start_position = incorrect_json.find("{")
+ correct_json = incorrect_json[json_start_position:]
+ correct_json = correct_json.replace("\r", "").replace("\t", "").replace(" ", "")
+ return correct_json
+
+if __name__ == "__main__":
+ app.run(host='0.0.0.0', port=3904)
diff --git a/sanitycheck/events/eventToVes.json b/sanitycheck/events/eventToVes.json
new file mode 100644
index 0000000..7299306
--- /dev/null
+++ b/sanitycheck/events/eventToVes.json
@@ -0,0 +1,37 @@
+{
+ "vesServerUrl": "http://172.17.0.1:8080/eventListener/v7",
+ "event": {
+ "event": {
+ "commonEventHeader": {
+ "version": "4.0.1",
+ "vesEventListenerVersion": "7.0.1",
+ "domain": "fault",
+ "eventName": "Fault_Vscf:Acs-Ericcson_PilotNumberPoolExhaustion",
+ "eventId": "fault0000245",
+ "sequence": 1,
+ "priority": "High",
+ "reportingEntityId": "cc305d54-75b4-431b-adb2-eb6b9e541234",
+ "reportingEntityName": "ibcx0001vm002oam001",
+ "sourceId": "de305d54-75b4-431b-adb2-eb6b9e546014",
+ "sourceName": "scfx0001vm002cap001",
+ "nfVendorName": "Ericsson",
+ "nfNamingCode": "scfx",
+ "nfcNamingCode": "ssc",
+ "startEpochMicrosec": 1413378172000000,
+ "lastEpochMicrosec": 1413378172000000,
+ "timeZoneOffset": "UTC-05:30"
+ },
+ "faultFields": {
+ "faultFieldsVersion": "4.0",
+ "alarmCondition": "PilotNumberPoolExhaustion",
+ "eventSourceType": "other",
+ "specificProblem": "Calls cannot complete - pilot numbers are unavailable",
+ "eventSeverity": "CRITICAL",
+ "vfStatus": "Active",
+ "alarmAdditionalInformation": {
+ "PilotNumberPoolSize": "1000"
+ }
+ }
+ }
+ }
+}
diff --git a/sanitycheck/events/fewEventsToVes.json b/sanitycheck/events/fewEventsToVes.json
new file mode 100644
index 0000000..9733469
--- /dev/null
+++ b/sanitycheck/events/fewEventsToVes.json
@@ -0,0 +1,32 @@
+{
+ "simulatorParams": {
+ "repeatCount": 4,
+ "repeatInterval": 1
+ },
+ "templateName": "notification.json",
+ "patch": {
+ "event": {
+ "commonEventHeader": {
+ "domain": "notification",
+ "eventName": "vFirewallBroadcastPackets",
+ "eventId": "#RandomString(10)",
+ "priority": "Normal",
+ "reportingEntityName": "myVNF",
+ "sequence": 1,
+ "sourceName": "ClosedLoopVNF",
+ "startEpochMicrosec": 1531616794,
+ "lastEpochMicrosec": 1531719042,
+ "vesEventListenerVersion": "7.0.1",
+ "version": "4.0.1"
+ }
+ }
+ },
+ "variables": {
+ "dN": "NRNB=5, NRCEL=1234",
+ "dn": "Test_dn",
+ "attributeList": {
+ "threshXHighQ": "50",
+ "threshXHighP": "52"
+ }
+ }
+}
diff --git a/sanitycheck/events/vesAddressConfiguration.json b/sanitycheck/events/vesAddressConfiguration.json
new file mode 100644
index 0000000..9c6aa22
--- /dev/null
+++ b/sanitycheck/events/vesAddressConfiguration.json
@@ -0,0 +1,3 @@
+{
+ "vesServerUrl": "http://172.17.0.1:8080/eventListener/v7"
+}
diff --git a/sanitycheck/ves/Makefile b/sanitycheck/ves/Makefile
new file mode 100644
index 0000000..4fe5e4b
--- /dev/null
+++ b/sanitycheck/ves/Makefile
@@ -0,0 +1,23 @@
+all: start
+
+.PHONY: start
+
+start:
+ @echo "##### Start VES with DMAAP simulator #####"
+ docker-compose up -d
+ @echo "##### DONE #####"
+
+stop:
+ @echo "##### Stop VES with DMAAP simulator #####"
+ docker-compose down
+ @echo "##### DONE #####"
+
+health-check:
+ @echo "##### Health check #####\n"
+
+ @echo "##### DMAAP simulator is ready #####\n"
+ curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET http://localhost:3904/events
+
+ @echo "\n\n##### VES is ready #####\n"
+ curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET GET http://localhost:8080/healthcheck
+ @echo "\n\n##### DONE #####"
diff --git a/sanitycheck/ves/README.md b/sanitycheck/ves/README.md
new file mode 100644
index 0000000..29309a4
--- /dev/null
+++ b/sanitycheck/ves/README.md
@@ -0,0 +1,21 @@
+VES with DMAAP simulator
+------------------------
+
+### Prerequisites
+* DMaaP Simulator image available.
+
+See README.md in dmaap-simulator directory
+
+### Start
+```
+make start
+```
+
+### Health check
+```
+make health-check
+```
+
+### Stop
+```
+make stop \ No newline at end of file
diff --git a/sanitycheck/ves/docker-compose.yml b/sanitycheck/ves/docker-compose.yml
new file mode 100644
index 0000000..d9666d8
--- /dev/null
+++ b/sanitycheck/ves/docker-compose.yml
@@ -0,0 +1,20 @@
+version: '3'
+services:
+ ves:
+ container_name: ves
+ image: nexus3.onap.org:10003/onap/org.onap.dcaegen2.collectors.ves.vescollector:latest
+ ports:
+ - "8080:8080"
+ - "8443:8443"
+ networks:
+ - vesnetwork
+ onap-dmaap:
+ container_name: dmaap
+ image: dmaap-simulator
+ ports:
+ - "3904:3904"
+ networks:
+ - vesnetwork
+networks:
+ vesnetwork:
+ driver: bridge