From 4af5241ab25b0103d8ea680789aaf9a8696dfc75 Mon Sep 17 00:00:00 2001 From: Bogumil Zebek Date: Tue, 9 Mar 2021 12:54:38 +0100 Subject: Move pnf simulator to the new repo In the first phase we renamed project from pnf simulator to vesclient. Next steps: package rename, update Readme.md, upgrade project dependencies. Issue-ID: INT-1869 Signed-off-by: Bogumil Zebek Change-Id: I7714792f9739eb746c9c533e8ef41b9618a3a1d9 --- .../pnfsimulator/event/EventDataServiceTest.java | 133 +++++++++ .../filesystem/InMemoryTemplateStorage.java | 71 +++++ .../filesystem/WatcherEventProcessorTest.java | 125 ++++++++ .../pnfsimulator/rest/SimulatorControllerTest.java | 329 +++++++++++++++++++++ .../pnfsimulator/rest/TemplateControllerTest.java | 256 ++++++++++++++++ .../onap/pnfsimulator/rest/util/DateUtilTest.java | 38 +++ .../rest/util/ResponseBuilderTest.java | 66 +++++ .../simulator/DbTemplateReaderTest.java | 81 +++++ .../simulator/IncrementProviderImplTest.java | 79 +++++ .../KeywordsExtractorInvalidRandomIntegerTest.java | 67 +++++ .../KeywordsExtractorInvalidRandomStringTest.java | 67 +++++ .../KeywordsExtractorInvalidTimestampTest.java | 65 ++++ .../KeywordsExtractorValidRandomIntegerTest.java | 66 +++++ ...dsExtractorValidRandomPrimitiveIntegerTest.java | 66 +++++ .../KeywordsExtractorValidRandomStringTest.java | 69 +++++ ...ywordsExtractorValidTimestampPrimitiveTest.java | 66 +++++ .../KeywordsExtractorValidTimestampTest.java | 68 +++++ .../simulator/KeywordsHandlerTest.java | 306 +++++++++++++++++++ .../simulator/KeywordsValueProviderTest.java | 82 +++++ .../simulator/SimulatorServiceTest.java | 308 +++++++++++++++++++ .../simulator/TemplatePatcherTest.java | 164 ++++++++++ .../pnfsimulator/simulator/TemplateReaderTest.java | 51 ++++ .../simulator/TemplateVariablesReplacerTest.java | 174 +++++++++++ .../HttpApacheResponseAdapterFactoryTest.java | 98 ++++++ .../client/HttpClientAdapterImplTest.java | 157 ++++++++++ .../simulator/client/HttpTestUtils.java | 55 ++++ .../utils/ssl/CertAuthSslContextFactoryTest.java | 141 +++++++++ .../utils/ssl/HttpClientFactoryFacadeTest.java | 35 +++ .../client/utils/ssl/HttpClientFactoryTest.java | 143 +++++++++ .../client/utils/ssl/PasswordConverterTest.java | 44 +++ .../client/utils/ssl/SSLContextFactoryTest.java | 61 ++++ .../keywords/TwoParameterKeywordTest.java | 48 +++ .../simulator/scheduler/EventJobTest.java | 90 ++++++ .../simulator/scheduler/EventSchedulerTest.java | 148 +++++++++ .../SimulatorConfigServiceTest.java | 104 +++++++ .../template/FsToDbTemplateSynchronizerTest.java | 53 ++++ .../pnfsimulator/template/TemplateServiceTest.java | 152 ++++++++++ .../template/search/JsonUtilsTest.java | 166 +++++++++++ .../template/search/TemplateSearchHelperTest.java | 160 ++++++++++ .../handler/PrimitiveValueCriteriaBuilderTest.java | 75 +++++ 40 files changed, 4527 insertions(+) create mode 100644 src/test/java/org/onap/pnfsimulator/event/EventDataServiceTest.java create mode 100644 src/test/java/org/onap/pnfsimulator/filesystem/InMemoryTemplateStorage.java create mode 100644 src/test/java/org/onap/pnfsimulator/filesystem/WatcherEventProcessorTest.java create mode 100644 src/test/java/org/onap/pnfsimulator/rest/SimulatorControllerTest.java create mode 100644 src/test/java/org/onap/pnfsimulator/rest/TemplateControllerTest.java create mode 100644 src/test/java/org/onap/pnfsimulator/rest/util/DateUtilTest.java create mode 100644 src/test/java/org/onap/pnfsimulator/rest/util/ResponseBuilderTest.java create mode 100644 src/test/java/org/onap/pnfsimulator/simulator/DbTemplateReaderTest.java create mode 100644 src/test/java/org/onap/pnfsimulator/simulator/IncrementProviderImplTest.java create mode 100644 src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorInvalidRandomIntegerTest.java create mode 100644 src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorInvalidRandomStringTest.java create mode 100644 src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorInvalidTimestampTest.java create mode 100644 src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorValidRandomIntegerTest.java create mode 100644 src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorValidRandomPrimitiveIntegerTest.java create mode 100644 src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorValidRandomStringTest.java create mode 100644 src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorValidTimestampPrimitiveTest.java create mode 100644 src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorValidTimestampTest.java create mode 100644 src/test/java/org/onap/pnfsimulator/simulator/KeywordsHandlerTest.java create mode 100644 src/test/java/org/onap/pnfsimulator/simulator/KeywordsValueProviderTest.java create mode 100644 src/test/java/org/onap/pnfsimulator/simulator/SimulatorServiceTest.java create mode 100644 src/test/java/org/onap/pnfsimulator/simulator/TemplatePatcherTest.java create mode 100644 src/test/java/org/onap/pnfsimulator/simulator/TemplateReaderTest.java create mode 100644 src/test/java/org/onap/pnfsimulator/simulator/TemplateVariablesReplacerTest.java create mode 100644 src/test/java/org/onap/pnfsimulator/simulator/client/HttpApacheResponseAdapterFactoryTest.java create mode 100644 src/test/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapterImplTest.java create mode 100644 src/test/java/org/onap/pnfsimulator/simulator/client/HttpTestUtils.java create mode 100644 src/test/java/org/onap/pnfsimulator/simulator/client/utils/ssl/CertAuthSslContextFactoryTest.java create mode 100644 src/test/java/org/onap/pnfsimulator/simulator/client/utils/ssl/HttpClientFactoryFacadeTest.java create mode 100644 src/test/java/org/onap/pnfsimulator/simulator/client/utils/ssl/HttpClientFactoryTest.java create mode 100644 src/test/java/org/onap/pnfsimulator/simulator/client/utils/ssl/PasswordConverterTest.java create mode 100644 src/test/java/org/onap/pnfsimulator/simulator/client/utils/ssl/SSLContextFactoryTest.java create mode 100644 src/test/java/org/onap/pnfsimulator/simulator/keywords/TwoParameterKeywordTest.java create mode 100644 src/test/java/org/onap/pnfsimulator/simulator/scheduler/EventJobTest.java create mode 100644 src/test/java/org/onap/pnfsimulator/simulator/scheduler/EventSchedulerTest.java create mode 100644 src/test/java/org/onap/pnfsimulator/simulatorconfig/SimulatorConfigServiceTest.java create mode 100644 src/test/java/org/onap/pnfsimulator/template/FsToDbTemplateSynchronizerTest.java create mode 100644 src/test/java/org/onap/pnfsimulator/template/TemplateServiceTest.java create mode 100644 src/test/java/org/onap/pnfsimulator/template/search/JsonUtilsTest.java create mode 100644 src/test/java/org/onap/pnfsimulator/template/search/TemplateSearchHelperTest.java create mode 100644 src/test/java/org/onap/pnfsimulator/template/search/handler/PrimitiveValueCriteriaBuilderTest.java (limited to 'src/test/java') diff --git a/src/test/java/org/onap/pnfsimulator/event/EventDataServiceTest.java b/src/test/java/org/onap/pnfsimulator/event/EventDataServiceTest.java new file mode 100644 index 0000000..5ed51cc --- /dev/null +++ b/src/test/java/org/onap/pnfsimulator/event/EventDataServiceTest.java @@ -0,0 +1,133 @@ +/* + * ============LICENSE_START======================================================= + * PNF-REGISTRATION-HANDLER + * ================================================================================ + * Copyright (C) 2018 Nokia. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.pnfsimulator.event; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import org.hamcrest.collection.IsIterableContainingInOrder; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.BeforeEach; +import org.mockito.ArgumentCaptor; +import org.mockito.InjectMocks; +import org.mockito.Mock; + +public class EventDataServiceTest { + + @Mock + private EventDataRepository repositoryMock; + + @InjectMocks + private EventDataService service; + + private static EventData sampleEventData(String id, String template, + String patched, String input, String keywords) { + return EventData.builder() + .id(id) + .template(template) + .patched(patched) + .input(input) + .keywords(keywords) + .build(); + } + + @BeforeEach + void resetMocks() { + initMocks(this); + } + + @Test + void persistEventDataJsonObjectTest() { + JsonParser parser = new JsonParser(); + JsonObject template = parser.parse("{ \"bla1\": \"bla2\"}").getAsJsonObject(); + JsonObject patched = parser.parse("{ \"bla3\": \"bla4\"}").getAsJsonObject(); + JsonObject input = parser.parse("{ \"bla5\": \"bla6\"}").getAsJsonObject(); + JsonObject keywords = parser.parse("{ \"bla7\": \"bla8\"}").getAsJsonObject(); + ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(EventData.class); + + service.persistEventData(template, patched, input, keywords); + + verify(repositoryMock).save(argumentCaptor.capture()); + EventData captured = argumentCaptor.getValue(); + + assertEquals(captured.getTemplate(), template.toString()); + assertEquals(captured.getPatched(), patched.toString()); + assertEquals(captured.getInput(), input.toString()); + assertEquals(captured.getKeywords(), keywords.toString()); + } + + @Test + void getAllEventsTest() { + + List eventDataList = new ArrayList<>(); + EventData ed1 = sampleEventData("id1", "t1", "p1", "i1", "k1"); + EventData ed2 = sampleEventData("id2", "t2", "p2", "i2", "k2"); + eventDataList.add(ed1); + eventDataList.add(ed2); + + when(repositoryMock.findAll()).thenReturn(eventDataList); + List actualList = service.getAllEvents(); + + assertEquals(eventDataList.size(), actualList.size()); + assertThat(actualList, IsIterableContainingInOrder.contains(ed1, ed2)); + } + + @Test + void findByIdPresentTest() { + String id = "some_object"; + EventData eventData = sampleEventData(id, "template", "patched", "input", "keywords"); + Optional optional = Optional.of(eventData); + + when(repositoryMock.findById(id)).thenReturn(optional); + + Optional actualOptional = service.getById(id); + assertTrue(actualOptional.isPresent()); + EventData actualObject = actualOptional.get(); + assertEquals(eventData.getId(), actualObject.getId()); + assertEquals(eventData.getTemplate(), actualObject.getTemplate()); + assertEquals(eventData.getPatched(), actualObject.getPatched()); + assertEquals(eventData.getInput(), actualObject.getInput()); + assertEquals(eventData.getKeywords(), actualObject.getKeywords()); + + } + + @Test + void findByIdNotPresentTest() { + String id = "some_object"; + Optional optional = Optional.empty(); + + when(repositoryMock.findById(id)).thenReturn(optional); + + Optional actualOptional = service.getById(id); + assertTrue(!actualOptional.isPresent()); + } +} diff --git a/src/test/java/org/onap/pnfsimulator/filesystem/InMemoryTemplateStorage.java b/src/test/java/org/onap/pnfsimulator/filesystem/InMemoryTemplateStorage.java new file mode 100644 index 0000000..b86a0f9 --- /dev/null +++ b/src/test/java/org/onap/pnfsimulator/filesystem/InMemoryTemplateStorage.java @@ -0,0 +1,71 @@ +/*- + * ============LICENSE_START======================================================= + * Simulator + * ================================================================================ + * Copyright (C) 2019 Nokia. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.pnfsimulator.filesystem; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import com.google.gson.JsonObject; +import org.onap.pnfsimulator.db.Storage; +import org.onap.pnfsimulator.template.Template; + +public class InMemoryTemplateStorage implements Storage