diff options
Diffstat (limited to 'pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/SimulatorServiceTest.java')
-rw-r--r-- | pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/SimulatorServiceTest.java | 86 |
1 files changed, 43 insertions, 43 deletions
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 0196eb0..870c963 100644 --- a/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/SimulatorServiceTest.java +++ b/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/SimulatorServiceTest.java @@ -33,14 +33,13 @@ 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.simulator.client.HttpClientAdapter; -import org.onap.pnfsimulator.simulator.client.utils.ssl.SSLAuthenticationHelper; +import org.onap.pnfsimulator.simulator.client.utils.ssl.SslAuthenticationHelper; import org.onap.pnfsimulator.simulator.scheduler.EventScheduler; import org.onap.pnfsimulator.simulatorconfig.SimulatorConfig; 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; @@ -59,32 +58,32 @@ class SimulatorServiceTest { private static final String VES_URL = "http://0.0.0.0:8080"; private static final Gson GSON = new Gson(); - private static final JsonObject VALID_PATCH = GSON.fromJson("{\"event\": {\n" + - " \"commonEventHeader\": {\n" + - " \"sourceName\": \"SomeCustomSource\"}}}\n", JsonObject.class); - private static JsonObject VALID_FULL_EVENT = GSON.fromJson("{\"event\": {\n" + - " \"commonEventHeader\": {\n" + - " \"domain\": \"notification\",\n" + - " \"eventName\": \"vFirewallBroadcastPackets\"\n" + - " },\n" + - " \"notificationFields\": {\n" + - " \"arrayOfNamedHashMap\": [{\n" + - " \"name\": \"A20161221.1031-1041.bin.gz\",\n" + - " \"hashMap\": {\n" + - " \"fileformatType\": \"org.3GPP.32.435#measCollec\"}}]}}}", JsonObject.class); - private static JsonObject FULL_EVENT_WITH_KEYWORDS = GSON.fromJson("{\"event\":{ \n" + - " \"commonEventHeader\":{ \n" + - " \"domain\":\"notification\",\n" + - " \"eventName\":\"#RandomString(20)\",\n" + - " \"eventOrderNo\":\"#Increment\"}}}", JsonObject.class); + private static final JsonObject VALID_PATCH = GSON.fromJson("{\"event\": {\n" + + " \"commonEventHeader\": {\n" + + " \"sourceName\": \"SomeCustomSource\"}}}\n", JsonObject.class); + private static JsonObject VALID_FULL_EVENT = GSON.fromJson("{\"event\": {\n" + + " \"commonEventHeader\": {\n" + + " \"domain\": \"notification\",\n" + + " \"eventName\": \"vFirewallBroadcastPackets\"\n" + + " },\n" + + " \"notificationFields\": {\n" + + " \"arrayOfNamedHashMap\": [{\n" + + " \"name\": \"A20161221.1031-1041.bin.gz\",\n" + + " \"hashMap\": {\n" + + " \"fileformatType\": \"org.3GPP.32.435#measCollec\"}}]}}}", JsonObject.class); + private static JsonObject FULL_EVENT_WITH_KEYWORDS = GSON.fromJson("{\"event\":{ \n" + + " \"commonEventHeader\":{ \n" + + " \"domain\":\"notification\",\n" + + " \"eventName\":\"#RandomString(20)\",\n" + + " \"eventOrderNo\":\"#Increment\"}}}", JsonObject.class); private static final String SOME_CUSTOM_SOURCE = "SomeCustomSource"; - private static final String CLOSED_LOOP_VNF ="ClosedLoopVNF"; + 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 final ArgumentCaptor<JsonObject> bodyCaptor = ArgumentCaptor.forClass(JsonObject.class); private final ArgumentCaptor<Integer> intervalCaptor = ArgumentCaptor.forClass(Integer.class); private final ArgumentCaptor<Integer> repeatCountCaptor = ArgumentCaptor - .forClass(Integer.class); + .forClass(Integer.class); private final ArgumentCaptor<String> templateNameCaptor = ArgumentCaptor.forClass(String.class); private final ArgumentCaptor<String> eventIdCaptor = ArgumentCaptor.forClass(String.class); private final ArgumentCaptor<String> vesUrlCaptor = ArgumentCaptor.forClass(String.class); @@ -104,7 +103,7 @@ class SimulatorServiceTest { simulatorConfigService = mock(SimulatorConfigService.class); simulatorService = new SimulatorService(templatePatcher, templateReader, - eventScheduler, eventDataService, simulatorConfigService, new SSLAuthenticationHelper()); + eventScheduler, eventDataService, simulatorConfigService, new SslAuthenticationHelper()); } @Test @@ -112,7 +111,7 @@ class SimulatorServiceTest { String templateName = "validExampleMeasurementEvent.json"; SimulatorParams simulatorParams = new SimulatorParams(VES_URL, 1, 1); SimulatorRequest simulatorRequest = new SimulatorRequest(simulatorParams, - templateName, VALID_PATCH); + templateName, VALID_PATCH); doReturn(SAMPLE_EVENT).when(eventDataService).persistEventData(any(JsonObject.class), any(JsonObject.class), any(JsonObject.class), any(JsonObject.class)); @@ -125,8 +124,8 @@ class SimulatorServiceTest { void shouldTriggerEventWithDefaultVesUrlWhenNotProvidedInRequest() throws IOException, SchedulerException, GeneralSecurityException { String templateName = "validExampleMeasurementEvent.json"; SimulatorRequest simulatorRequest = new SimulatorRequest( - new SimulatorParams("", 1, 1), - templateName, VALID_PATCH); + 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)); @@ -140,23 +139,24 @@ class SimulatorServiceTest { @Test void shouldThrowJsonSyntaxWhenInvalidJson() { //given - JsonObject patch = GSON.fromJson("{\n" + - " \"event\": {\n" + - " \"commonEventHeader\": {\n" + - " \"sourceName\": \"" + SOME_CUSTOM_SOURCE + "\"\n" + - " }\n" + - " }\n" + - "}\n", JsonObject.class); + JsonObject patch = GSON.fromJson("{\n" + + " \"event\": {\n" + + " \"commonEventHeader\": {\n" + + " \"sourceName\": \"" + + SOME_CUSTOM_SOURCE + "\"\n" + + " }\n" + + " }\n" + + "}\n", JsonObject.class); EventData eventData = EventData.builder().id("1").build(); SimulatorParams simulatorParams = new SimulatorParams(VES_URL, 1, 1); SimulatorRequest simulatorRequest = new SimulatorRequest(simulatorParams, - "invalidJsonStructureEvent.json", patch); + "invalidJsonStructureEvent.json", patch); doReturn(eventData).when(eventDataService).persistEventData(any(JsonObject.class), any(JsonObject.class), any(JsonObject.class), any(JsonObject.class)); //when assertThrows(JsonSyntaxException.class, - () -> simulatorService.triggerEvent(simulatorRequest)); + () -> simulatorService.triggerEvent(simulatorRequest)); } @Test @@ -177,7 +177,7 @@ class SimulatorServiceTest { @Test void shouldSuccessfullySendOneTimeEventWithVesUrlWhenPassed() throws IOException, GeneralSecurityException { - SimulatorService spiedTestedService = spy(new SimulatorService(templatePatcher,templateReader, eventScheduler, eventDataService, simulatorConfigService, new SSLAuthenticationHelper())); + SimulatorService spiedTestedService = spy(new SimulatorService(templatePatcher, templateReader, eventScheduler, eventDataService, simulatorConfigService, new SslAuthenticationHelper())); HttpClientAdapter adapterMock = mock(HttpClientAdapter.class); doNothing().when(adapterMock).send(eventContentCaptor.capture()); @@ -193,7 +193,7 @@ class SimulatorServiceTest { @Test void shouldSubstituteKeywordsAndSuccessfullySendOneTimeEvent() throws IOException, GeneralSecurityException { - SimulatorService spiedTestedService = spy(new SimulatorService(templatePatcher,templateReader, eventScheduler, eventDataService, simulatorConfigService, new SSLAuthenticationHelper())); + SimulatorService spiedTestedService = spy(new SimulatorService(templatePatcher, templateReader, eventScheduler, eventDataService, simulatorConfigService, new SslAuthenticationHelper())); HttpClientAdapter adapterMock = mock(HttpClientAdapter.class); doNothing().when(adapterMock).send(eventContentCaptor.capture()); @@ -210,18 +210,18 @@ class SimulatorServiceTest { private void assertEventHasExpectedStructure(String expectedVesUrl, String templateName, String sourceNameString) throws SchedulerException, IOException, GeneralSecurityException { verify(eventScheduler, times(1)).scheduleEvent(vesUrlCaptor.capture(), intervalCaptor.capture(), - repeatCountCaptor.capture(), templateNameCaptor.capture(), eventIdCaptor.capture(), bodyCaptor.capture()); + repeatCountCaptor.capture(), templateNameCaptor.capture(), eventIdCaptor.capture(), bodyCaptor.capture()); assertThat(vesUrlCaptor.getValue()).isEqualTo(expectedVesUrl); assertThat(intervalCaptor.getValue()).isEqualTo(1); assertThat(repeatCountCaptor.getValue()).isEqualTo(1); assertThat(templateNameCaptor.getValue()).isEqualTo(templateName); String actualSourceName = GSON.fromJson(bodyCaptor.getValue(), JsonObject.class) - .get("event").getAsJsonObject() - .get("commonEventHeader").getAsJsonObject() - .get("sourceName").getAsString(); + .get("event").getAsJsonObject() + .get("commonEventHeader").getAsJsonObject() + .get("sourceName").getAsString(); assertThat(actualSourceName).isEqualTo(sourceNameString); verify(eventDataService) - .persistEventData(any(JsonObject.class), any(JsonObject.class), any(JsonObject.class), - any(JsonObject.class)); + .persistEventData(any(JsonObject.class), any(JsonObject.class), any(JsonObject.class), + any(JsonObject.class)); } } |