From bae12bf7d5a92a4d6be22e9ce8c3dc9878c59f36 Mon Sep 17 00:00:00 2001 From: Bogumil Zebek Date: Wed, 10 Mar 2021 12:55:08 +0100 Subject: Package rename Step 2: package rename, fix pom.xml, fix integration tests Issue-ID: INT-1869 Signed-off-by: Zebek Bogumil Change-Id: Ia4c6823e4facc3791583fb39caba3bcc125b3af7 --- Dockerfile | 2 +- integration/pom.xml | 24 +- .../nfsimulator/vesclient/integration/Main.java | 35 +++ .../integration/VesSimulatorController.java | 71 +++++ .../vesclient/integration/VesSimulatorService.java | 36 +++ .../org/onap/pnfsimulator/integration/Main.java | 35 --- .../integration/VesSimulatorController.java | 71 ----- .../integration/VesSimulatorService.java | 36 --- .../integration/BasicAvailabilityTest.java | 229 ++++++++++++++ .../integration/OptionalTemplatesTest.java | 156 ++++++++++ .../integration/SearchInTemplatesTest.java | 269 +++++++++++++++++ .../vesclient/integration/SingleEventTest.java | 147 +++++++++ .../integration/TemplatesManagementTest.java | 175 +++++++++++ .../vesclient/integration/TestConfiguration.java | 36 +++ .../vesclient/integration/TestUtils.java | 57 ++++ .../integration/VariablesReplacement.java | 75 +++++ .../integration/suites/DockerBasedTestsSuite.java | 90 ++++++ .../integration/BasicAvailabilityTest.java | 234 --------------- .../integration/OptionalTemplatesTest.java | 161 ---------- .../integration/SearchInTemplatesTest.java | 269 ----------------- .../pnfsimulator/integration/SingleEventTest.java | 151 ---------- .../integration/TemplatesManagementTest.java | 175 ----------- .../integration/TestConfiguration.java | 36 --- .../onap/pnfsimulator/integration/TestUtils.java | 57 ---- .../integration/VariablesReplacement.java | 80 ----- .../integration/suites/DockerBasedTestsSuite.java | 90 ------ pom.xml | 73 +---- .../simulators/nfsimulator/vesclient/Main.java | 59 ++++ .../nfsimulator/vesclient/SwaggerConfig.java | 46 +++ .../simulators/nfsimulator/vesclient/db/Row.java | 39 +++ .../nfsimulator/vesclient/db/Storage.java | 41 +++ .../nfsimulator/vesclient/event/EventData.java | 67 +++++ .../vesclient/event/EventDataRepository.java | 26 ++ .../vesclient/event/EventDataService.java | 65 ++++ .../vesclient/filesystem/WatcherConfig.java | 39 +++ .../filesystem/WatcherEventProcessor.java | 111 +++++++ .../vesclient/filesystem/WatcherService.java | 44 +++ .../vesclient/filesystem/WatcherThread.java | 81 +++++ .../vesclient/logging/MdcVariables.java | 35 +++ .../vesclient/rest/SimulatorController.java | 235 +++++++++++++++ .../vesclient/rest/TemplateController.java | 112 +++++++ .../vesclient/rest/model/FullEvent.java | 48 +++ .../vesclient/rest/model/SearchExp.java | 42 +++ .../vesclient/rest/model/SimulatorParams.java | 46 +++ .../vesclient/rest/model/SimulatorRequest.java | 55 ++++ .../vesclient/rest/model/TemplateRequest.java | 38 +++ .../nfsimulator/vesclient/rest/util/DateUtil.java | 35 +++ .../rest/util/JsonObjectDeserializer.java | 42 +++ .../vesclient/rest/util/ResponseBuilder.java | 62 ++++ .../vesclient/simulator/DbTemplateReader.java | 51 ++++ .../simulator/EventNotFoundException.java | 29 ++ .../simulator/FilesystemTemplateReader.java | 54 ++++ .../vesclient/simulator/IncrementProvider.java | 26 ++ .../vesclient/simulator/IncrementProviderImpl.java | 47 +++ .../vesclient/simulator/JsonTokenProcessor.java | 134 +++++++++ .../vesclient/simulator/KeywordsExtractor.java | 122 ++++++++ .../vesclient/simulator/KeywordsHandler.java | 74 +++++ .../simulator/KeywordsHandlerException.java | 28 ++ .../vesclient/simulator/KeywordsValueProvider.java | 80 +++++ .../vesclient/simulator/SimulatorService.java | 132 +++++++++ .../vesclient/simulator/TemplatePatcher.java | 53 ++++ .../vesclient/simulator/TemplateReader.java | 29 ++ .../simulator/TemplateVariablesReplacer.java | 50 ++++ .../client/HttpApacheResponseAdapterFactory.java | 45 +++ .../simulator/client/HttpClientAdapter.java | 27 ++ .../simulator/client/HttpClientAdapterImpl.java | 119 ++++++++ .../simulator/client/HttpResponseAdapter.java | 41 +++ .../utils/ssl/CertAuthSslContextFactory.java | 53 ++++ .../client/utils/ssl/CertificateReader.java | 46 +++ .../client/utils/ssl/HttpClientFactory.java | 104 +++++++ .../client/utils/ssl/HttpClientFactoryFacade.java | 40 +++ .../client/utils/ssl/PasswordConverter.java | 32 ++ .../client/utils/ssl/SSLContextFactory.java | 48 +++ .../client/utils/ssl/SslAuthenticationHelper.java | 45 +++ .../vesclient/simulator/keywords/Keyword.java | 76 +++++ .../simulator/keywords/NonParameterKeyword.java | 65 ++++ .../simulator/keywords/SingleParameterKeyword.java | 73 +++++ .../simulator/keywords/TwoParameterKeyword.java | 80 +++++ .../vesclient/simulator/scheduler/EventJob.java | 99 +++++++ .../simulator/scheduler/EventScheduler.java | 120 ++++++++ .../simulator/scheduler/QuartzConfiguration.java | 38 +++ .../vesclient/simulatorconfig/SimulatorConfig.java | 49 +++ .../simulatorconfig/SimulatorConfigRepository.java | 26 ++ .../simulatorconfig/SimulatorConfigService.java | 52 ++++ .../template/FsToDbTemplateSynchronizer.java | 74 +++++ .../nfsimulator/vesclient/template/Template.java | 92 ++++++ .../vesclient/template/TemplateRepository.java | 26 ++ .../vesclient/template/TemplateService.java | 81 +++++ .../template/search/IllegalJsonValueException.java | 28 ++ .../vesclient/template/search/JsonUtils.java | 104 +++++++ .../template/search/TemplateSearchHelper.java | 95 ++++++ .../handler/PrimitiveValueCriteriaBuilder.java | 103 +++++++ .../search/viewmodel/FlatTemplateContent.java | 45 +++ .../template/search/viewmodel/KeyValuePair.java | 40 +++ src/main/java/org/onap/pnfsimulator/Main.java | 59 ---- .../java/org/onap/pnfsimulator/SwaggerConfig.java | 46 --- src/main/java/org/onap/pnfsimulator/db/Row.java | 39 --- .../java/org/onap/pnfsimulator/db/Storage.java | 41 --- .../org/onap/pnfsimulator/event/EventData.java | 67 ----- .../pnfsimulator/event/EventDataRepository.java | 26 -- .../onap/pnfsimulator/event/EventDataService.java | 65 ---- .../pnfsimulator/filesystem/WatcherConfig.java | 39 --- .../filesystem/WatcherEventProcessor.java | 111 ------- .../pnfsimulator/filesystem/WatcherService.java | 44 --- .../pnfsimulator/filesystem/WatcherThread.java | 81 ----- .../onap/pnfsimulator/logging/MdcVariables.java | 35 --- .../pnfsimulator/rest/SimulatorController.java | 241 --------------- .../onap/pnfsimulator/rest/TemplateController.java | 112 ------- .../onap/pnfsimulator/rest/model/FullEvent.java | 48 --- .../onap/pnfsimulator/rest/model/SearchExp.java | 42 --- .../pnfsimulator/rest/model/SimulatorParams.java | 46 --- .../pnfsimulator/rest/model/SimulatorRequest.java | 55 ---- .../pnfsimulator/rest/model/TemplateRequest.java | 38 --- .../org/onap/pnfsimulator/rest/util/DateUtil.java | 35 --- .../rest/util/JsonObjectDeserializer.java | 42 --- .../pnfsimulator/rest/util/ResponseBuilder.java | 62 ---- .../pnfsimulator/simulator/DbTemplateReader.java | 51 ---- .../simulator/EventNotFoundException.java | 29 -- .../simulator/FilesystemTemplateReader.java | 54 ---- .../pnfsimulator/simulator/IncrementProvider.java | 26 -- .../simulator/IncrementProviderImpl.java | 47 --- .../pnfsimulator/simulator/JsonTokenProcessor.java | 134 --------- .../pnfsimulator/simulator/KeywordsExtractor.java | 129 -------- .../pnfsimulator/simulator/KeywordsHandler.java | 74 ----- .../simulator/KeywordsHandlerException.java | 28 -- .../simulator/KeywordsValueProvider.java | 80 ----- .../pnfsimulator/simulator/SimulatorService.java | 132 --------- .../pnfsimulator/simulator/TemplatePatcher.java | 53 ---- .../pnfsimulator/simulator/TemplateReader.java | 29 -- .../simulator/TemplateVariablesReplacer.java | 50 ---- .../client/HttpApacheResponseAdapterFactory.java | 45 --- .../simulator/client/HttpClientAdapter.java | 27 -- .../simulator/client/HttpClientAdapterImpl.java | 119 -------- .../simulator/client/HttpResponseAdapter.java | 41 --- .../utils/ssl/CertAuthSslContextFactory.java | 53 ---- .../client/utils/ssl/CertificateReader.java | 46 --- .../client/utils/ssl/HttpClientFactory.java | 104 ------- .../client/utils/ssl/HttpClientFactoryFacade.java | 40 --- .../client/utils/ssl/PasswordConverter.java | 32 -- .../client/utils/ssl/SSLContextFactory.java | 48 --- .../client/utils/ssl/SslAuthenticationHelper.java | 45 --- .../pnfsimulator/simulator/keywords/Keyword.java | 76 ----- .../simulator/keywords/NonParameterKeyword.java | 65 ---- .../simulator/keywords/SingleParameterKeyword.java | 73 ----- .../simulator/keywords/TwoParameterKeyword.java | 80 ----- .../pnfsimulator/simulator/scheduler/EventJob.java | 99 ------- .../simulator/scheduler/EventScheduler.java | 120 -------- .../simulator/scheduler/QuartzConfiguration.java | 38 --- .../simulatorconfig/SimulatorConfig.java | 49 --- .../simulatorconfig/SimulatorConfigRepository.java | 26 -- .../simulatorconfig/SimulatorConfigService.java | 52 ---- .../template/FsToDbTemplateSynchronizer.java | 74 ----- .../org/onap/pnfsimulator/template/Template.java | 92 ------ .../pnfsimulator/template/TemplateRepository.java | 26 -- .../pnfsimulator/template/TemplateService.java | 81 ----- .../template/search/IllegalJsonValueException.java | 28 -- .../pnfsimulator/template/search/JsonUtils.java | 104 ------- .../template/search/TemplateSearchHelper.java | 95 ------ .../handler/PrimitiveValueCriteriaBuilder.java | 103 ------- .../search/viewmodel/FlatTemplateContent.java | 45 --- .../template/search/viewmodel/KeyValuePair.java | 40 --- .../vesclient/event/EventDataServiceTest.java | 133 +++++++++ .../filesystem/InMemoryTemplateStorage.java | 71 +++++ .../filesystem/WatcherEventProcessorTest.java | 125 ++++++++ .../vesclient/rest/SimulatorControllerTest.java | 329 +++++++++++++++++++++ .../vesclient/rest/TemplateControllerTest.java | 256 ++++++++++++++++ .../vesclient/rest/util/DateUtilTest.java | 38 +++ .../vesclient/rest/util/ResponseBuilderTest.java | 66 +++++ .../vesclient/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 | 68 +++++ ...ywordsExtractorValidTimestampPrimitiveTest.java | 66 +++++ .../KeywordsExtractorValidTimestampTest.java | 68 +++++ .../vesclient/simulator/KeywordsHandlerTest.java | 305 +++++++++++++++++++ .../simulator/KeywordsValueProviderTest.java | 82 +++++ .../vesclient/simulator/SimulatorServiceTest.java | 309 +++++++++++++++++++ .../vesclient/simulator/TemplatePatcherTest.java | 164 ++++++++++ .../vesclient/simulator/TemplateReaderTest.java | 51 ++++ .../simulator/TemplateVariablesReplacerTest.java | 174 +++++++++++ .../HttpApacheResponseAdapterFactoryTest.java | 98 ++++++ .../client/HttpClientAdapterImplTest.java | 157 ++++++++++ .../vesclient/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 | 84 ++++++ .../simulator/scheduler/EventSchedulerTest.java | 148 +++++++++ .../SimulatorConfigServiceTest.java | 104 +++++++ .../template/FsToDbTemplateSynchronizerTest.java | 53 ++++ .../vesclient/template/TemplateServiceTest.java | 153 ++++++++++ .../vesclient/template/search/JsonUtilsTest.java | 166 +++++++++++ .../template/search/TemplateSearchHelperTest.java | 159 ++++++++++ .../handler/PrimitiveValueCriteriaBuilderTest.java | 75 +++++ .../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 ----- .../vesclient/simulator/filesystem/test1.json | 12 + .../simulator/invalidJsonStructureEvent.json | 1 + .../simulator/validExampleMeasurementEvent.json | 86 ++++++ .../pnfsimulator/simulator/filesystem/test1.json | 12 - .../simulator/invalidJsonStructureEvent.json | 1 - .../simulator/validExampleMeasurementEvent.json | 86 ------ 247 files changed, 10256 insertions(+), 10358 deletions(-) create mode 100644 integration/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/Main.java create mode 100644 integration/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/VesSimulatorController.java create mode 100644 integration/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/VesSimulatorService.java delete mode 100644 integration/src/main/java/org/onap/pnfsimulator/integration/Main.java delete mode 100644 integration/src/main/java/org/onap/pnfsimulator/integration/VesSimulatorController.java delete mode 100644 integration/src/main/java/org/onap/pnfsimulator/integration/VesSimulatorService.java create mode 100644 integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/BasicAvailabilityTest.java create mode 100644 integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/OptionalTemplatesTest.java create mode 100644 integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/SearchInTemplatesTest.java create mode 100644 integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/SingleEventTest.java create mode 100644 integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/TemplatesManagementTest.java create mode 100644 integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/TestConfiguration.java create mode 100644 integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/TestUtils.java create mode 100644 integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/VariablesReplacement.java create mode 100644 integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/suites/DockerBasedTestsSuite.java delete mode 100644 integration/src/test/java/org/onap/pnfsimulator/integration/BasicAvailabilityTest.java delete mode 100644 integration/src/test/java/org/onap/pnfsimulator/integration/OptionalTemplatesTest.java delete mode 100644 integration/src/test/java/org/onap/pnfsimulator/integration/SearchInTemplatesTest.java delete mode 100644 integration/src/test/java/org/onap/pnfsimulator/integration/SingleEventTest.java delete mode 100644 integration/src/test/java/org/onap/pnfsimulator/integration/TemplatesManagementTest.java delete mode 100644 integration/src/test/java/org/onap/pnfsimulator/integration/TestConfiguration.java delete mode 100644 integration/src/test/java/org/onap/pnfsimulator/integration/TestUtils.java delete mode 100644 integration/src/test/java/org/onap/pnfsimulator/integration/VariablesReplacement.java delete mode 100644 integration/src/test/java/org/onap/pnfsimulator/integration/suites/DockerBasedTestsSuite.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/Main.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/SwaggerConfig.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/db/Row.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/db/Storage.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/event/EventData.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/event/EventDataRepository.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/event/EventDataService.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/filesystem/WatcherConfig.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/filesystem/WatcherEventProcessor.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/filesystem/WatcherService.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/filesystem/WatcherThread.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/logging/MdcVariables.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/rest/SimulatorController.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/rest/TemplateController.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/rest/model/FullEvent.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/rest/model/SearchExp.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/rest/model/SimulatorParams.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/rest/model/SimulatorRequest.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/rest/model/TemplateRequest.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/rest/util/DateUtil.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/rest/util/JsonObjectDeserializer.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/rest/util/ResponseBuilder.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/DbTemplateReader.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/EventNotFoundException.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/FilesystemTemplateReader.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/IncrementProvider.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/IncrementProviderImpl.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/JsonTokenProcessor.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/KeywordsExtractor.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/KeywordsHandler.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/KeywordsHandlerException.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/KeywordsValueProvider.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/SimulatorService.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/TemplatePatcher.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/TemplateReader.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/TemplateVariablesReplacer.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/client/HttpApacheResponseAdapterFactory.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/client/HttpClientAdapter.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/client/HttpClientAdapterImpl.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/client/HttpResponseAdapter.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/client/utils/ssl/CertAuthSslContextFactory.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/client/utils/ssl/CertificateReader.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/client/utils/ssl/HttpClientFactory.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/client/utils/ssl/HttpClientFactoryFacade.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/client/utils/ssl/PasswordConverter.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/client/utils/ssl/SSLContextFactory.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/client/utils/ssl/SslAuthenticationHelper.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/keywords/Keyword.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/keywords/NonParameterKeyword.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/keywords/SingleParameterKeyword.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/keywords/TwoParameterKeyword.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/scheduler/EventJob.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/scheduler/EventScheduler.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/scheduler/QuartzConfiguration.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulatorconfig/SimulatorConfig.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulatorconfig/SimulatorConfigRepository.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/simulatorconfig/SimulatorConfigService.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/template/FsToDbTemplateSynchronizer.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/template/Template.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/template/TemplateRepository.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/template/TemplateService.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/template/search/IllegalJsonValueException.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/template/search/JsonUtils.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/template/search/TemplateSearchHelper.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/template/search/handler/PrimitiveValueCriteriaBuilder.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/template/search/viewmodel/FlatTemplateContent.java create mode 100644 src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/template/search/viewmodel/KeyValuePair.java delete mode 100644 src/main/java/org/onap/pnfsimulator/Main.java delete mode 100644 src/main/java/org/onap/pnfsimulator/SwaggerConfig.java delete mode 100644 src/main/java/org/onap/pnfsimulator/db/Row.java delete mode 100644 src/main/java/org/onap/pnfsimulator/db/Storage.java delete mode 100644 src/main/java/org/onap/pnfsimulator/event/EventData.java delete mode 100644 src/main/java/org/onap/pnfsimulator/event/EventDataRepository.java delete mode 100644 src/main/java/org/onap/pnfsimulator/event/EventDataService.java delete mode 100644 src/main/java/org/onap/pnfsimulator/filesystem/WatcherConfig.java delete mode 100644 src/main/java/org/onap/pnfsimulator/filesystem/WatcherEventProcessor.java delete mode 100644 src/main/java/org/onap/pnfsimulator/filesystem/WatcherService.java delete mode 100644 src/main/java/org/onap/pnfsimulator/filesystem/WatcherThread.java delete mode 100644 src/main/java/org/onap/pnfsimulator/logging/MdcVariables.java delete mode 100644 src/main/java/org/onap/pnfsimulator/rest/SimulatorController.java delete mode 100644 src/main/java/org/onap/pnfsimulator/rest/TemplateController.java delete mode 100644 src/main/java/org/onap/pnfsimulator/rest/model/FullEvent.java delete mode 100644 src/main/java/org/onap/pnfsimulator/rest/model/SearchExp.java delete mode 100644 src/main/java/org/onap/pnfsimulator/rest/model/SimulatorParams.java delete mode 100644 src/main/java/org/onap/pnfsimulator/rest/model/SimulatorRequest.java delete mode 100644 src/main/java/org/onap/pnfsimulator/rest/model/TemplateRequest.java delete mode 100644 src/main/java/org/onap/pnfsimulator/rest/util/DateUtil.java delete mode 100644 src/main/java/org/onap/pnfsimulator/rest/util/JsonObjectDeserializer.java delete mode 100644 src/main/java/org/onap/pnfsimulator/rest/util/ResponseBuilder.java delete mode 100644 src/main/java/org/onap/pnfsimulator/simulator/DbTemplateReader.java delete mode 100644 src/main/java/org/onap/pnfsimulator/simulator/EventNotFoundException.java delete mode 100644 src/main/java/org/onap/pnfsimulator/simulator/FilesystemTemplateReader.java delete mode 100644 src/main/java/org/onap/pnfsimulator/simulator/IncrementProvider.java delete mode 100644 src/main/java/org/onap/pnfsimulator/simulator/IncrementProviderImpl.java delete mode 100644 src/main/java/org/onap/pnfsimulator/simulator/JsonTokenProcessor.java delete mode 100644 src/main/java/org/onap/pnfsimulator/simulator/KeywordsExtractor.java delete mode 100644 src/main/java/org/onap/pnfsimulator/simulator/KeywordsHandler.java delete mode 100644 src/main/java/org/onap/pnfsimulator/simulator/KeywordsHandlerException.java delete mode 100644 src/main/java/org/onap/pnfsimulator/simulator/KeywordsValueProvider.java delete mode 100644 src/main/java/org/onap/pnfsimulator/simulator/SimulatorService.java delete mode 100644 src/main/java/org/onap/pnfsimulator/simulator/TemplatePatcher.java delete mode 100644 src/main/java/org/onap/pnfsimulator/simulator/TemplateReader.java delete mode 100644 src/main/java/org/onap/pnfsimulator/simulator/TemplateVariablesReplacer.java delete mode 100644 src/main/java/org/onap/pnfsimulator/simulator/client/HttpApacheResponseAdapterFactory.java delete mode 100644 src/main/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapter.java delete mode 100644 src/main/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapterImpl.java delete mode 100644 src/main/java/org/onap/pnfsimulator/simulator/client/HttpResponseAdapter.java delete mode 100644 src/main/java/org/onap/pnfsimulator/simulator/client/utils/ssl/CertAuthSslContextFactory.java delete mode 100644 src/main/java/org/onap/pnfsimulator/simulator/client/utils/ssl/CertificateReader.java delete mode 100644 src/main/java/org/onap/pnfsimulator/simulator/client/utils/ssl/HttpClientFactory.java delete mode 100644 src/main/java/org/onap/pnfsimulator/simulator/client/utils/ssl/HttpClientFactoryFacade.java delete mode 100644 src/main/java/org/onap/pnfsimulator/simulator/client/utils/ssl/PasswordConverter.java delete mode 100644 src/main/java/org/onap/pnfsimulator/simulator/client/utils/ssl/SSLContextFactory.java delete mode 100644 src/main/java/org/onap/pnfsimulator/simulator/client/utils/ssl/SslAuthenticationHelper.java delete mode 100644 src/main/java/org/onap/pnfsimulator/simulator/keywords/Keyword.java delete mode 100644 src/main/java/org/onap/pnfsimulator/simulator/keywords/NonParameterKeyword.java delete mode 100644 src/main/java/org/onap/pnfsimulator/simulator/keywords/SingleParameterKeyword.java delete mode 100644 src/main/java/org/onap/pnfsimulator/simulator/keywords/TwoParameterKeyword.java delete mode 100644 src/main/java/org/onap/pnfsimulator/simulator/scheduler/EventJob.java delete mode 100644 src/main/java/org/onap/pnfsimulator/simulator/scheduler/EventScheduler.java delete mode 100644 src/main/java/org/onap/pnfsimulator/simulator/scheduler/QuartzConfiguration.java delete mode 100644 src/main/java/org/onap/pnfsimulator/simulatorconfig/SimulatorConfig.java delete mode 100644 src/main/java/org/onap/pnfsimulator/simulatorconfig/SimulatorConfigRepository.java delete mode 100644 src/main/java/org/onap/pnfsimulator/simulatorconfig/SimulatorConfigService.java delete mode 100644 src/main/java/org/onap/pnfsimulator/template/FsToDbTemplateSynchronizer.java delete mode 100644 src/main/java/org/onap/pnfsimulator/template/Template.java delete mode 100644 src/main/java/org/onap/pnfsimulator/template/TemplateRepository.java delete mode 100644 src/main/java/org/onap/pnfsimulator/template/TemplateService.java delete mode 100644 src/main/java/org/onap/pnfsimulator/template/search/IllegalJsonValueException.java delete mode 100644 src/main/java/org/onap/pnfsimulator/template/search/JsonUtils.java delete mode 100644 src/main/java/org/onap/pnfsimulator/template/search/TemplateSearchHelper.java delete mode 100644 src/main/java/org/onap/pnfsimulator/template/search/handler/PrimitiveValueCriteriaBuilder.java delete mode 100644 src/main/java/org/onap/pnfsimulator/template/search/viewmodel/FlatTemplateContent.java delete mode 100644 src/main/java/org/onap/pnfsimulator/template/search/viewmodel/KeyValuePair.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/event/EventDataServiceTest.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/filesystem/InMemoryTemplateStorage.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/filesystem/WatcherEventProcessorTest.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/rest/SimulatorControllerTest.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/rest/TemplateControllerTest.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/rest/util/DateUtilTest.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/rest/util/ResponseBuilderTest.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/DbTemplateReaderTest.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/IncrementProviderImplTest.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/KeywordsExtractorInvalidRandomIntegerTest.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/KeywordsExtractorInvalidRandomStringTest.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/KeywordsExtractorInvalidTimestampTest.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/KeywordsExtractorValidRandomIntegerTest.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/KeywordsExtractorValidRandomPrimitiveIntegerTest.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/KeywordsExtractorValidRandomStringTest.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/KeywordsExtractorValidTimestampPrimitiveTest.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/KeywordsExtractorValidTimestampTest.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/KeywordsHandlerTest.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/KeywordsValueProviderTest.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/SimulatorServiceTest.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/TemplatePatcherTest.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/TemplateReaderTest.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/TemplateVariablesReplacerTest.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/client/HttpApacheResponseAdapterFactoryTest.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/client/HttpClientAdapterImplTest.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/client/HttpTestUtils.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/client/utils/ssl/CertAuthSslContextFactoryTest.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/client/utils/ssl/HttpClientFactoryFacadeTest.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/client/utils/ssl/HttpClientFactoryTest.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/client/utils/ssl/PasswordConverterTest.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/client/utils/ssl/SSLContextFactoryTest.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/keywords/TwoParameterKeywordTest.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/scheduler/EventJobTest.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/simulator/scheduler/EventSchedulerTest.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/simulatorconfig/SimulatorConfigServiceTest.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/template/FsToDbTemplateSynchronizerTest.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/template/TemplateServiceTest.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/template/search/JsonUtilsTest.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/template/search/TemplateSearchHelperTest.java create mode 100644 src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/template/search/handler/PrimitiveValueCriteriaBuilderTest.java delete mode 100644 src/test/java/org/onap/pnfsimulator/event/EventDataServiceTest.java delete mode 100644 src/test/java/org/onap/pnfsimulator/filesystem/InMemoryTemplateStorage.java delete mode 100644 src/test/java/org/onap/pnfsimulator/filesystem/WatcherEventProcessorTest.java delete mode 100644 src/test/java/org/onap/pnfsimulator/rest/SimulatorControllerTest.java delete mode 100644 src/test/java/org/onap/pnfsimulator/rest/TemplateControllerTest.java delete mode 100644 src/test/java/org/onap/pnfsimulator/rest/util/DateUtilTest.java delete mode 100644 src/test/java/org/onap/pnfsimulator/rest/util/ResponseBuilderTest.java delete mode 100644 src/test/java/org/onap/pnfsimulator/simulator/DbTemplateReaderTest.java delete mode 100644 src/test/java/org/onap/pnfsimulator/simulator/IncrementProviderImplTest.java delete mode 100644 src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorInvalidRandomIntegerTest.java delete mode 100644 src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorInvalidRandomStringTest.java delete mode 100644 src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorInvalidTimestampTest.java delete mode 100644 src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorValidRandomIntegerTest.java delete mode 100644 src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorValidRandomPrimitiveIntegerTest.java delete mode 100644 src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorValidRandomStringTest.java delete mode 100644 src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorValidTimestampPrimitiveTest.java delete mode 100644 src/test/java/org/onap/pnfsimulator/simulator/KeywordsExtractorValidTimestampTest.java delete mode 100644 src/test/java/org/onap/pnfsimulator/simulator/KeywordsHandlerTest.java delete mode 100644 src/test/java/org/onap/pnfsimulator/simulator/KeywordsValueProviderTest.java delete mode 100644 src/test/java/org/onap/pnfsimulator/simulator/SimulatorServiceTest.java delete mode 100644 src/test/java/org/onap/pnfsimulator/simulator/TemplatePatcherTest.java delete mode 100644 src/test/java/org/onap/pnfsimulator/simulator/TemplateReaderTest.java delete mode 100644 src/test/java/org/onap/pnfsimulator/simulator/TemplateVariablesReplacerTest.java delete mode 100644 src/test/java/org/onap/pnfsimulator/simulator/client/HttpApacheResponseAdapterFactoryTest.java delete mode 100644 src/test/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapterImplTest.java delete mode 100644 src/test/java/org/onap/pnfsimulator/simulator/client/HttpTestUtils.java delete mode 100644 src/test/java/org/onap/pnfsimulator/simulator/client/utils/ssl/CertAuthSslContextFactoryTest.java delete mode 100644 src/test/java/org/onap/pnfsimulator/simulator/client/utils/ssl/HttpClientFactoryFacadeTest.java delete mode 100644 src/test/java/org/onap/pnfsimulator/simulator/client/utils/ssl/HttpClientFactoryTest.java delete mode 100644 src/test/java/org/onap/pnfsimulator/simulator/client/utils/ssl/PasswordConverterTest.java delete mode 100644 src/test/java/org/onap/pnfsimulator/simulator/client/utils/ssl/SSLContextFactoryTest.java delete mode 100644 src/test/java/org/onap/pnfsimulator/simulator/keywords/TwoParameterKeywordTest.java delete mode 100644 src/test/java/org/onap/pnfsimulator/simulator/scheduler/EventJobTest.java delete mode 100644 src/test/java/org/onap/pnfsimulator/simulator/scheduler/EventSchedulerTest.java delete mode 100644 src/test/java/org/onap/pnfsimulator/simulatorconfig/SimulatorConfigServiceTest.java delete mode 100644 src/test/java/org/onap/pnfsimulator/template/FsToDbTemplateSynchronizerTest.java delete mode 100644 src/test/java/org/onap/pnfsimulator/template/TemplateServiceTest.java delete mode 100644 src/test/java/org/onap/pnfsimulator/template/search/JsonUtilsTest.java delete mode 100644 src/test/java/org/onap/pnfsimulator/template/search/TemplateSearchHelperTest.java delete mode 100644 src/test/java/org/onap/pnfsimulator/template/search/handler/PrimitiveValueCriteriaBuilderTest.java create mode 100644 src/test/resources/org/onap/integration/simulators/nfsimulator/vesclient/simulator/filesystem/test1.json create mode 100644 src/test/resources/org/onap/integration/simulators/nfsimulator/vesclient/simulator/invalidJsonStructureEvent.json create mode 100644 src/test/resources/org/onap/integration/simulators/nfsimulator/vesclient/simulator/validExampleMeasurementEvent.json delete mode 100644 src/test/resources/org/onap/pnfsimulator/simulator/filesystem/test1.json delete mode 100644 src/test/resources/org/onap/pnfsimulator/simulator/invalidJsonStructureEvent.json delete mode 100644 src/test/resources/org/onap/pnfsimulator/simulator/validExampleMeasurementEvent.json diff --git a/Dockerfile b/Dockerfile index ae26b36..5e571ee 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,4 +15,4 @@ ADD certificates /usr/local/share/ca-certificates/ RUN update-ca-certificates CMD python /opt/db/config/mongo_db_schema_creation.py \ && if [ -f /app/store/trust.pass ]; then cp /app/store/trust.pass /app/store/truststore.pass; fi \ - && java -Dspring.config.location=file:/app/application.properties -cp /app/libs/*:/app/vesclient.jar org.onap.pnfsimulator.Main \ + && java -Dspring.config.location=file:/app/application.properties -cp /app/libs/*:/app/vesclient.jar org.onap.integration.simulators.nfsimulator.vesclient.Main \ diff --git a/integration/pom.xml b/integration/pom.xml index e56d838..834c6ae 100644 --- a/integration/pom.xml +++ b/integration/pom.xml @@ -24,14 +24,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - - org.onap.integration.nfsimulator - vesclient - 1.0.0-SNAPSHOT - ../../pom.xml - - - pnf-simulator-integration + org.onap.integration.simulators.nf-simulator.ves-client + vesclient-integration 1.0.0-SNAPSHOT vesclient-integration @@ -47,6 +41,13 @@ 11 3.2.0 3.9.1 + 2.1.6.RELEASE + 2.1.6.RELEASE + 5.0.4.RELEASE + 2.1.6.RELEASE + 2.8.2 + 0.34.0 + 3.19.0 @@ -54,16 +55,19 @@ org.assertj assertj-core + ${assertj-core.version} test org.springframework.boot spring-boot-starter + ${spring-boot-starter.version} org.springframework.boot spring-boot-starter-web + ${spring-boot-starter-web.version} @@ -80,20 +84,24 @@ org.springframework spring-test + ${spring-test.version} test org.springframework.boot spring-boot-starter-test + ${spring-boot-starter-test.version} test com.google.code.gson gson + ${gson.version} com.palantir.docker.compose docker-compose-rule-junit4 + ${docker-compose-rule-junit4.version} diff --git a/integration/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/Main.java b/integration/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/Main.java new file mode 100644 index 0000000..af3cdcc --- /dev/null +++ b/integration/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/Main.java @@ -0,0 +1,35 @@ +/* + * ============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.integration.simulators.nfsimulator.vesclient.integration; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.scheduling.annotation.EnableAsync; + +@SpringBootApplication +@EnableAsync +public class Main { + + public static void main(String[] args) { + SpringApplication.run(Main.class, args); + } +} + + diff --git a/integration/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/VesSimulatorController.java b/integration/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/VesSimulatorController.java new file mode 100644 index 0000000..ee5c380 --- /dev/null +++ b/integration/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/VesSimulatorController.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.integration.simulators.nfsimulator.vesclient.integration; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + + +@RequestMapping("ves-simulator") +@RestController +public class VesSimulatorController { + + private static final Logger LOGGER = LoggerFactory.getLogger(VesSimulatorController.class); + private final VesSimulatorService vesSimulatorService; + private final Gson gson; + private final ResponseEntity response = ResponseEntity + .status(HttpStatus.ACCEPTED) + .body("Accepted"); + + @Autowired + public VesSimulatorController(VesSimulatorService vesSimulatorService, Gson gson) { + this.vesSimulatorService = vesSimulatorService; + this.gson = gson; + } + + @PostMapping("eventListener/v5") + public ResponseEntity sendEventToDmaapV5(@RequestBody String body) { + JsonObject jsonObject = getJsonObjectFromBody(body); + vesSimulatorService.sendEventToDmaapV5(jsonObject); + return response; + } + + @PostMapping("eventListener/v7") + public ResponseEntity sendEventToDmaapV7(@RequestBody String body) { + JsonObject jsonObject = getJsonObjectFromBody(body); + vesSimulatorService.sendEventToDmaapV7(jsonObject); + return response; + } + + private JsonObject getJsonObjectFromBody(@RequestBody String body) { + LOGGER.info(String.format("Received event: %s", body)); + return gson.fromJson(body, JsonObject.class); + } +} diff --git a/integration/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/VesSimulatorService.java b/integration/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/VesSimulatorService.java new file mode 100644 index 0000000..f53864c --- /dev/null +++ b/integration/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/VesSimulatorService.java @@ -0,0 +1,36 @@ +/*- + * ============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.integration.simulators.nfsimulator.vesclient.integration; + +import com.google.gson.JsonObject; +import org.springframework.stereotype.Service; + +@Service +public class VesSimulatorService { + + void sendEventToDmaapV5(JsonObject jsonObject) { + //JUST FOR TESTING PURPOSE + } + + void sendEventToDmaapV7(JsonObject jsonObject) { + //JUST FOR TESTING PURPOSE + } +} diff --git a/integration/src/main/java/org/onap/pnfsimulator/integration/Main.java b/integration/src/main/java/org/onap/pnfsimulator/integration/Main.java deleted file mode 100644 index 7288c2a..0000000 --- a/integration/src/main/java/org/onap/pnfsimulator/integration/Main.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * ============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.integration; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.scheduling.annotation.EnableAsync; - -@SpringBootApplication -@EnableAsync -public class Main { - - public static void main(String[] args) { - SpringApplication.run(Main.class, args); - } -} - - diff --git a/integration/src/main/java/org/onap/pnfsimulator/integration/VesSimulatorController.java b/integration/src/main/java/org/onap/pnfsimulator/integration/VesSimulatorController.java deleted file mode 100644 index 304df60..0000000 --- a/integration/src/main/java/org/onap/pnfsimulator/integration/VesSimulatorController.java +++ /dev/null @@ -1,71 +0,0 @@ -/*- - * ============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.integration; - -import com.google.gson.Gson; -import com.google.gson.JsonObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - - -@RequestMapping("ves-simulator") -@RestController -public class VesSimulatorController { - - private static final Logger LOGGER = LoggerFactory.getLogger(VesSimulatorController.class); - private final VesSimulatorService vesSimulatorService; - private final Gson gson; - private final ResponseEntity response = ResponseEntity - .status(HttpStatus.ACCEPTED) - .body("Accepted"); - - @Autowired - public VesSimulatorController(VesSimulatorService vesSimulatorService, Gson gson) { - this.vesSimulatorService = vesSimulatorService; - this.gson = gson; - } - - @PostMapping("eventListener/v5") - public ResponseEntity sendEventToDmaapV5(@RequestBody String body) { - JsonObject jsonObject = getJsonObjectFromBody(body); - vesSimulatorService.sendEventToDmaapV5(jsonObject); - return response; - } - - @PostMapping("eventListener/v7") - public ResponseEntity sendEventToDmaapV7(@RequestBody String body) { - JsonObject jsonObject = getJsonObjectFromBody(body); - vesSimulatorService.sendEventToDmaapV7(jsonObject); - return response; - } - - private JsonObject getJsonObjectFromBody(@RequestBody String body) { - LOGGER.info(String.format("Received event: %s", body)); - return gson.fromJson(body, JsonObject.class); - } -} diff --git a/integration/src/main/java/org/onap/pnfsimulator/integration/VesSimulatorService.java b/integration/src/main/java/org/onap/pnfsimulator/integration/VesSimulatorService.java deleted file mode 100644 index 65e5d3e..0000000 --- a/integration/src/main/java/org/onap/pnfsimulator/integration/VesSimulatorService.java +++ /dev/null @@ -1,36 +0,0 @@ -/*- - * ============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.integration; - -import com.google.gson.JsonObject; -import org.springframework.stereotype.Service; - -@Service -public class VesSimulatorService { - - void sendEventToDmaapV5(JsonObject jsonObject) { - //JUST FOR TESTING PURPOSE - } - - void sendEventToDmaapV7(JsonObject jsonObject) { - //JUST FOR TESTING PURPOSE - } -} diff --git a/integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/BasicAvailabilityTest.java b/integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/BasicAvailabilityTest.java new file mode 100644 index 0000000..268d738 --- /dev/null +++ b/integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/BasicAvailabilityTest.java @@ -0,0 +1,229 @@ +/*- + * ============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.integration.simulators.nfsimulator.vesclient.integration; + +import static io.restassured.RestAssured.given; +import static io.restassured.RestAssured.when; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.hamcrest.Matchers.equalTo; + +import com.google.gson.JsonObject; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.UUID; + +import io.restassured.response.Response; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Mockito; +import org.mockito.internal.util.Timer; +import org.mockito.internal.verification.VerificationOverTimeImpl; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.http.HttpStatus; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = {Main.class, TestConfiguration.class}, webEnvironment = WebEnvironment.DEFINED_PORT) +public class BasicAvailabilityTest { + + private static final int VERIFICATION_TIMEOUT_MILLIS = 10000; + + @Autowired + VesSimulatorController vesSimulatorController; + + @Autowired + VesSimulatorService vesSimulatorService; + + private final String ACTION_START = "start"; + + private String currenVesSimulatorIp; + + @Before + public void setUp() throws Exception { + currenVesSimulatorIp = TestUtils.getCurrentIpAddress(); + } + + @After + public void tearDown() { + Mockito.reset(vesSimulatorService); + } + + @Test + public void simulatorShouldFailWhenTriggeredNonexistentTemplate() { + //given + String startUrl = prepareRequestUrl(ACTION_START); + String body = "{\n" + + "\"templateName\": \"any_nonexistent_template.json\",\n" + + "\"patch\":{},\n" + + "\"simulatorParams\": {\n" + + "\"vesServerUrl\": \"https://" + currenVesSimulatorIp + ":9443/ves-simulator/eventListener/v5\",\n" + + "\"repeatInterval\": 1,\n" + + "\"repeatCount\": 1\n" + + "}\n" + + "}"; + + //when + given() + .contentType("application/json") + .body(body) + .when() + .post(startUrl) + .then() + .statusCode(HttpStatus.BAD_REQUEST.value()) + .body("message", equalTo("Cannot start simulator - template any_nonexistent_template.json not found.")); + } + + @Test + public void whenTriggeredSimulatorShouldSendSingleEventToVes() { + //given + String startUrl = prepareRequestUrl(ACTION_START); + String body = "{\n" + + "\"templateName\": \"notification.json\",\n" + + "\"patch\":{},\n" + + "\"simulatorParams\": {\n" + + "\"vesServerUrl\": \"https://" + currenVesSimulatorIp + ":9443/ves-simulator/eventListener/v5\",\n" + + "\"repeatInterval\": 1,\n" + + "\"repeatCount\": 1\n" + + "}\n" + + "}"; + ArgumentCaptor parameterCaptor = ArgumentCaptor.forClass(JsonObject.class); + + //when + given() + .contentType("application/json") + .body(body) + .when() + .post(startUrl) + .then() + .statusCode(HttpStatus.OK.value()) + .body("message", equalTo("Request started")); + + Mockito.verify(vesSimulatorService, + Mockito.timeout(VERIFICATION_TIMEOUT_MILLIS)) + .sendEventToDmaapV5(parameterCaptor.capture()); + + assertThat(parameterCaptor.getValue() + .getAsJsonObject("event") + .getAsJsonObject("commonEventHeader") + .get("domain").getAsString()).isEqualTo("notification"); + } + + @Test + public void simulatorShouldCorrectlyRespondOnCancellAllEvent() { + //given + String ACTION_CANCEL_ALL = "cancel"; + String cancelAllUrl = prepareRequestUrl(ACTION_CANCEL_ALL); + + //when + when() + .post(cancelAllUrl) + .then() + .statusCode(HttpStatus.OK.value()) + .body("message", equalTo("Event(s) was cancelled")); + + } + + @Test + public void simulatorBeAbleToUseNewlyAddedTemplate() throws IOException { + //given + String templateBody = "{\"fake\":\"template\"}\n"; + String fileName = UUID.randomUUID() + ".json"; + String requestBody = "{\n" + + "\"templateName\": \"" + fileName + "\",\n" + + "\"patch\":{},\n" + + "\"simulatorParams\": {\n" + + "\"vesServerUrl\": \"https://" + currenVesSimulatorIp + ":9443/ves-simulator/eventListener/v5\",\n" + + "\"repeatInterval\": 1,\n" + + "\"repeatCount\": 1\n" + + "}\n" + + "}"; + ArgumentCaptor parameterCaptor = ArgumentCaptor.forClass(JsonObject.class); + + //when + Path newFile = Files.createFile(Paths.get("..", "templates", fileName)); + Files.write(newFile, templateBody.getBytes()); + + Response postResponse = given() + .contentType("application/json") + .body(requestBody) + .when() + .post(prepareRequestUrl(ACTION_START)); + + Files.delete(newFile); + + //then + assertThat(postResponse.statusCode()).isEqualTo(HttpStatus.OK.value()); + Mockito.verify(vesSimulatorService, Mockito.timeout(VERIFICATION_TIMEOUT_MILLIS)) + .sendEventToDmaapV5(parameterCaptor.capture()); + assertThat(parameterCaptor.getValue() + .get("fake").getAsString()).isEqualTo("template"); + + } + + @Test + public void whenTriggeredSimulatorShouldSendGivenAmountOfEventsToVes() { + //given + String startUrl = prepareRequestUrl(ACTION_START); + String body = "{\n" + + "\"templateName\": \"notification.json\",\n" + + "\"patch\":{},\n" + + "\"simulatorParams\": {\n" + + "\"vesServerUrl\": \"https://" + currenVesSimulatorIp + ":9443/ves-simulator/eventListener/v5\",\n" + + "\"repeatInterval\": 1,\n" + + "\"repeatCount\": 4\n" + + "}\n" + + "}"; + ArgumentCaptor parameterCaptor = ArgumentCaptor.forClass(JsonObject.class); + + //when + given() + .contentType("application/json") + .body(body) + .when() + .post(startUrl) + .then() + .statusCode(HttpStatus.OK.value()) + .body("message", equalTo("Request started")); + + VerificationOverTimeImpl verificator = new VerificationOverTimeImpl(100, Mockito.times(4), false, new Timer(6000)); + Mockito.verify(vesSimulatorService, verificator).sendEventToDmaapV5(parameterCaptor.capture()); + + for (JsonObject value : parameterCaptor.getAllValues()) { + assertThat(value + .getAsJsonObject("event") + .getAsJsonObject("commonEventHeader") + .get("domain").getAsString()).isEqualTo("notification"); + } + } + + private String prepareRequestUrl(String action) { + return "http://0.0.0.0:5000/simulator/" + action; + } + +} diff --git a/integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/OptionalTemplatesTest.java b/integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/OptionalTemplatesTest.java new file mode 100644 index 0000000..33dcf97 --- /dev/null +++ b/integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/OptionalTemplatesTest.java @@ -0,0 +1,156 @@ +/*- + * ============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.integration.simulators.nfsimulator.vesclient.integration; + +import static io.restassured.RestAssured.given; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.hamcrest.Matchers.equalTo; + +import com.google.gson.JsonObject; +import java.time.Instant; +import java.net.UnknownHostException; + +import org.assertj.core.api.Assertions; +import org.bson.Document; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Mockito; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.http.HttpStatus; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = {Main.class, TestConfiguration.class}, webEnvironment = WebEnvironment.DEFINED_PORT) +public class OptionalTemplatesTest { + + @Autowired + private VesSimulatorService vesSimulatorService; + + private String currentVesSimulatorIp; + + @Before + public void setUp() throws Exception { + currentVesSimulatorIp = TestUtils.getCurrentIpAddress(); + } + + @After + public void tearDown() { + Mockito.reset(vesSimulatorService); + } + + @Test + public void whenTriggeredSimulatorWithoutTemplateShouldSendSingleEventToVes() { + //given + long currentTimestamp = Instant.now().getEpochSecond(); + + String body = "{\n" + + "\"vesServerUrl\": \"https://" + currentVesSimulatorIp + ":9443/ves-simulator/eventListener/v5\",\n" + + "\"event\": { \n" + + "\"commonEventHeader\": {\n" + + "\"eventId1\": \"#RandomString(20)\",\n" + + "\"eventId2\": \"#RandomInteger(10,10)\",\n" + + "\"eventId3\": \"#Increment\",\n" + + "\"eventId4\": \"#RandomPrimitiveInteger(10,10)\",\n" + + "\"eventId5\": \"#TimestampPrimitive\",\n" + + "\"sourceName\": \"Single_sourceName\",\n" + + "\"version\": 3" + + "}\n" + + "}\n" + + "}"; + ArgumentCaptor parameterCaptor = ArgumentCaptor.forClass(JsonObject.class); + + //when + given() + .contentType("application/json") + .body(body) + .when() + .post(TestUtils.SINGLE_EVENT_URL) + .then() + .statusCode(HttpStatus.ACCEPTED.value()) + .body("message", equalTo("Accepted")); + + //then + long afterExecution = Instant.now().getEpochSecond(); + Mockito.verify(vesSimulatorService, + Mockito.timeout(3000)) + .sendEventToDmaapV5(parameterCaptor.capture()); + + JsonObject value = parameterCaptor.getValue(); + assertThat(value + .getAsJsonObject(TestUtils.COMMON_EVENT_HEADER) + .get("sourceName").getAsString()).isEqualTo("Single_sourceName"); + assertThat(value + .getAsJsonObject(TestUtils.COMMON_EVENT_HEADER) + .get("eventId1").getAsString()).hasSize(20); + assertThat(value + .getAsJsonObject(TestUtils.COMMON_EVENT_HEADER) + .get("eventId2").getAsString()).isEqualTo("10"); + assertThat(value + .getAsJsonObject(TestUtils.COMMON_EVENT_HEADER) + .get("eventId3").getAsString()).isEqualTo("1"); + assertThat(value + .getAsJsonObject(TestUtils.COMMON_EVENT_HEADER) + .get("eventId4").getAsInt()).isEqualTo(10); + assertThat(value + .getAsJsonObject(TestUtils.COMMON_EVENT_HEADER) + .get("eventId5").getAsLong()).isBetween(currentTimestamp, afterExecution); + } + + @Test + public void whenTriggeredSimulatorWithoutTemplateEventShouldBeVisibleInDB() throws UnknownHostException { + //given + String body = "{\n" + + "\"vesServerUrl\": \"https://" + currentVesSimulatorIp + ":9443/ves-simulator/eventListener/v5\",\n" + + "\"event\": { \n" + + "\"commonEventHeader\": {\n" + + "\"sourceName\": \"HistoricalEvent\",\n" + + "\"version\": 3" + + "}\n" + + "}\n" + + "}"; + ArgumentCaptor parameterCaptor = ArgumentCaptor.forClass(JsonObject.class); + + //when + given() + .contentType("application/json") + .body(body) + .when() + .post(TestUtils.SINGLE_EVENT_URL) + .then() + .statusCode(HttpStatus.ACCEPTED.value()) + .body("message", equalTo("Accepted")); + + //then + Mockito.verify(vesSimulatorService, + Mockito.timeout(3000)) + .sendEventToDmaapV5(parameterCaptor.capture()); + + Document sourceNameInMongoDB = TestUtils.findSourceNameInMongoDB(); + Assertions.assertThat(sourceNameInMongoDB.get(TestUtils.PATCHED)) + .isEqualTo("{\"commonEventHeader\":{\"sourceName\":\"HistoricalEvent\",\"version\":3}}"); + } + +} diff --git a/integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/SearchInTemplatesTest.java b/integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/SearchInTemplatesTest.java new file mode 100644 index 0000000..a0d8742 --- /dev/null +++ b/integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/SearchInTemplatesTest.java @@ -0,0 +1,269 @@ +/*- + * ============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.integration.simulators.nfsimulator.vesclient.integration; + +import static io.restassured.RestAssured.given; +import static java.nio.file.Files.readAllBytes; + +import io.restassured.http.Header; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import org.hamcrest.Matchers; +import org.junit.BeforeClass; +import org.junit.Test; +import org.springframework.util.ResourceUtils; + +public class SearchInTemplatesTest { + + private static final String UPLOAD = "upload"; + private static final String SEARCH = "search"; + private static final String APPLICATION_JSON = "application/json"; + private static final String CONTENT_TYPE = "Content-Type"; + + @BeforeClass + public static void setUp() throws IOException { + for (File file : readFileFromTemplatesFolder()) { + byte[] body = readAllBytes(file.toPath()); + + given() + .body(body) + .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) + .when() + .post(prepareRequestUrl(UPLOAD) + "?override=true") + .then() + .statusCode(201); + } + } + + @Test + public void shouldFindNothingWhenNonexistentValueIsProvided(){ + given() + .body("{\"searchExpr\": { \"child3\": \"nonexistentValue\" }}") + .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) + .when() + .post(prepareRequestUrl(SEARCH)) + .then() + .statusCode(200) + .body("", Matchers.empty()); + } + + @Test + public void shouldFindNothingWhenNonexistentKeyIsProvided(){ + given() + .body("{\"searchExpr\": { \"nonexistentKey\": \"Any value 1\" }}") + .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) + .when() + .post(prepareRequestUrl(SEARCH)) + .then() + .statusCode(200) + .body("", Matchers.empty()); + } + + @Test + public void shouldFindNothingWhenPartOfKeyIsProvided(){ + given() + .body("{\"searchExpr\": { \"child\": \"Any value 1\" }}") + .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) + .when() + .post(prepareRequestUrl(SEARCH)) + .then() + .statusCode(200) + .body("", Matchers.empty()); + } + + @Test + public void shouldFindNothingWhenPartOfValueIsProvided(){ + given() + .body("{\"searchExpr\": { \"child5\": \"Any\" }}") + .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) + .when() + .post(prepareRequestUrl(SEARCH)) + .then() + .statusCode(200) + .body("", Matchers.empty()); + } + + @Test + public void shouldBeAbleToSearchForString(){ + given() + .body("{\"searchExpr\": { \"child1\": \"Any value 1\" }}") + .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) + .when() + .post(prepareRequestUrl(SEARCH)) + .then() + .statusCode(200) + .body("", Matchers.hasItems("template_with_array.json", "complicated_template.json", "simple_template.json")); + + given() + .body("{\"searchExpr\": { \"child2\": \"any value 4\" }}") + .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) + .when() + .post(prepareRequestUrl(SEARCH)) + .then() + .statusCode(200) + .body("", Matchers.hasItems("template_with_array.json")); + } + + @Test + public void shouldBeAbleToSearchForManyStrings(){ + given() + .body("{\"searchExpr\": { \"child1\": \"Any value 1\", \"child2\": \"any value 2\"}}") + .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) + .when() + .post(prepareRequestUrl(SEARCH)) + .then() + .statusCode(200) + .body("", Matchers.hasItems("simple_template.json", "complicated_template.json")); + } + + @Test + public void shouldBeAbleToSearchForStarSign(){ + given() + .body("{\"searchExpr\": { \"child2\": \"*\" }}") + .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) + .when() + .post(prepareRequestUrl(SEARCH)) + .then() + .statusCode(200) + .body("", Matchers.hasItems("complicated_template.json")); + } + + @Test + public void shouldBeAbleToSearchForQuestionMark(){ + given() + .body("{\"searchExpr\": { \"child1\": \"?\" }}") + .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) + .when() + .post(prepareRequestUrl(SEARCH)) + .then() + .statusCode(200) + .body("", Matchers.hasItems("complicated_template.json")); + } + + @Test + public void shouldBeAbleToSearchForBrackets(){ + given() + .body("{\"searchExpr\": { \"parent2\": \"[]\" }}") + .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) + .when() + .post(prepareRequestUrl(SEARCH)) + .then() + .statusCode(200) + .body("", Matchers.hasItems("template_with_array.json")); + } + + @Test + public void shouldInformThatSearchForNullsIsProhibited(){ + given() + .body("{\"searchExpr\": { \"child3\": null }}") + .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) + .when() + .post(prepareRequestUrl(SEARCH)) + .then() + .statusCode(400); + } + + @Test + public void shouldBeAbleToSearchForURI(){ + given() + .body("{\"searchExpr\": { \"child3\": \"https://url.com?param1=test¶m2=*\" }}") + .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) + .when() + .post(prepareRequestUrl(SEARCH)) + .then() + .statusCode(200) + .body("", Matchers.hasItems("complicated_template.json")); + } + + @Test + public void shouldBeAbleToSearchForFloats(){ + given() + .body("{\"searchExpr\": { \"child2\": 4.44 }}") + .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) + .when() + .post(prepareRequestUrl(SEARCH)) + .then() + .statusCode(200) + .body("", Matchers.hasItems("template_with_array.json")); + + given() + .body("{\"searchExpr\": { \"child5\": 4.4 }}") + .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) + .when() + .post(prepareRequestUrl(SEARCH)) + .then() + .statusCode(200) + .body("", Matchers.hasItems("complicated_template.json", "template_with_floats.json")); + } + + @Test + public void shouldBeAbleToSearchForIntegers(){ + given() + .body("{\"searchExpr\": { \"child2\": 1 }}") + .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) + .when() + .post(prepareRequestUrl(SEARCH)) + .then() + .statusCode(200) + .body("", Matchers.hasItems("template_with_array.json", "template_with_ints.json")); + + given() + .body("{\"searchExpr\": { \"child2\": 4 }}") + .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) + .when() + .post(prepareRequestUrl(SEARCH)) + .then() + .statusCode(200) + .body("", Matchers.hasItems("template_with_array.json")); + } + + @Test + public void shouldBeAbleToSearchForBooleans(){ + given() + .body("{\"searchExpr\": { \"child4\": true}}") + .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) + .when() + .post(prepareRequestUrl(SEARCH)) + .then() + .statusCode(200) + .body("", Matchers.hasItems("template_with_booleans.json")); + + given() + .body("{\"searchExpr\": { \"parent2\": false}}") + .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) + .when() + .post(prepareRequestUrl(SEARCH)) + .then() + .statusCode(200) + .body("", Matchers.hasItems("template_with_booleans.json")); + } + + + private static String prepareRequestUrl(String action) { + return "http://0.0.0.0:5000/template/" + action; + } + + private static File[] readFileFromTemplatesFolder() throws FileNotFoundException { + return ResourceUtils.getFile("classpath:templates/search").listFiles(); + } + +} diff --git a/integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/SingleEventTest.java b/integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/SingleEventTest.java new file mode 100644 index 0000000..7d15842 --- /dev/null +++ b/integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/SingleEventTest.java @@ -0,0 +1,147 @@ +/*- + * ============LICENSE_START======================================================= + * Simulator + * ================================================================================ + * Copyright (C) 2020 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.integration.simulators.nfsimulator.vesclient.integration; + +import com.google.gson.JsonObject; +import org.assertj.core.api.Assertions; +import org.bson.Document; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Mockito; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.HttpStatus; +import org.springframework.test.context.junit4.SpringRunner; + +import java.net.UnknownHostException; +import java.util.List; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.stringContainsInOrder; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = {Main.class, TestConfiguration.class}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +public class SingleEventTest { + + @Autowired + private VesSimulatorService vesSimulatorService; + + private String currentVesSimulatorIp; + + @Before + public void setUp() throws Exception { + currentVesSimulatorIp = TestUtils.getCurrentIpAddress(); + } + + @After + public void tearDown() { + Mockito.reset(vesSimulatorService); + } + + @Test + public void whenTriggeredSimulatorWithWrongVesAddressInformationShouldBeReturned() { + //given + String body = "{\n" + + "\"vesServerUrl\": \"https://" + currentVesSimulatorIp + ":8080/ves-simulator/eventListener/v5\",\n" + + "\"event\": { \n" + + "\"commonEventHeader\": {\n" + + "\"sourceName\": \"HistoricalEvent\",\n" + + "\"version\": 3" + + "}\n" + + "}\n" + + "}"; + + //when + given() + .contentType("application/json") + .body(body) + .when() + .post(TestUtils.SINGLE_EVENT_URL) + .then() + .statusCode(421) + .body("message", + equalTo( + "Fail to connect with ves: Connect to "+currentVesSimulatorIp+":8080 " + + "[/"+currentVesSimulatorIp+"] " + + "failed: Connection refused (Connection refused)")); + } + + @Test + public void whenTriggeredSimulatorWithWrongEventShouldReturnedError() { + //given + String body = "{\n" + + "\"vesServerUrl\": \"https://" + currentVesSimulatorIp + ":9443/ves-simulator/eventListener/v5\",\n" + + "\"event\": { \n" + + "this is not JSON {}" + + "}\n" + + "}"; + + //when + given() + .contentType("application/json") + .body(body) + .when() + .post(TestUtils.SINGLE_EVENT_URL) + .then() + .statusCode(HttpStatus.BAD_REQUEST.value()) + .body("message", + stringContainsInOrder(List.of("JSON parse error:","Unexpected character ('t' (code 116)):")) + ); + } + + @Test + public void whenTriggeredSimulatorWithUsernameAndPasswordInUrlVesShouldAcceptRequest() throws UnknownHostException { + //given + String body = "{\n" + + "\"vesServerUrl\": \"https://user1:pass1@" + currentVesSimulatorIp + ":9443/ves-simulator/eventListener/v5\",\n" + + "\"event\": { \n" + + "\"commonEventHeader\": {\n" + + "\"sourceName\": \"HistoricalEvent\",\n" + + "\"version\": 3" + + "}\n" + + "}\n" + + "}"; + ArgumentCaptor parameterCaptor = ArgumentCaptor.forClass(JsonObject.class); + + //when + given() + .contentType("application/json") + .body(body) + .when() + .post(TestUtils.SINGLE_EVENT_URL) + .then() + .statusCode(HttpStatus.ACCEPTED.value()) + .body("message", equalTo("Accepted")); + + //then + Mockito.verify(vesSimulatorService, + Mockito.timeout(3000)) + .sendEventToDmaapV5(parameterCaptor.capture()); + + Document sourceNameInMongoDB = TestUtils.findSourceNameInMongoDB(); + Assertions.assertThat(sourceNameInMongoDB.get(TestUtils.PATCHED)) + .isEqualTo("{\"commonEventHeader\":{\"sourceName\":\"HistoricalEvent\",\"version\":3}}"); + } +} diff --git a/integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/TemplatesManagementTest.java b/integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/TemplatesManagementTest.java new file mode 100644 index 0000000..ecaa0db --- /dev/null +++ b/integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/TemplatesManagementTest.java @@ -0,0 +1,175 @@ +/*- + * ============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.integration.simulators.nfsimulator.vesclient.integration; + +import static io.restassured.RestAssured.given; + +import io.restassured.http.Header; +import io.restassured.path.json.JsonPath; +import io.restassured.path.json.config.JsonPathConfig; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Map; +import org.hamcrest.Matchers; +import org.json.JSONException; +import org.json.JSONObject; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.util.ResourceUtils; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = {Main.class, TestConfiguration.class}, webEnvironment = WebEnvironment.DEFINED_PORT) +public class TemplatesManagementTest { + + private static final String LIST_URL = "list"; + private static final String GET_URL = "get/"; + private static final String UPLOAD = "upload"; + private static final String NOTIFICATION_JSON = "notification.json"; + private static final String REGISTRATION_JSON = "registration.json"; + private static final String UPLOAD_TEMPLATE_JSON = "upload_template.json"; + private static final String OVERWRITE_TEMPLATE_JSON = "overwrite_template.json"; + private static final String OVERWRITTEN_TEMPLATE_JSON = "overwritten_template.json"; + private static final String APPLICATION_JSON = "application/json"; + private static final String CONTENT_TYPE = "Content-Type"; + private static final String FORCE_FLAG = "?override=true"; + private static final String CONTENT = "content"; + private static final String TEMPLATE = "template"; + private static final String ID = "id"; + + @Test + public void whenCallingGetShouldReceiveNotificationTemplate() throws IOException { + given() + .when() + .get(prepareRequestUrl(GET_URL) + NOTIFICATION_JSON) + .then() + .statusCode(200) + .body(ID, Matchers.equalTo(NOTIFICATION_JSON)) + .body(CONTENT, Matchers.equalTo(readTemplateFromResources(NOTIFICATION_JSON).getMap(CONTENT))); + } + + @Test + public void whenCallingGetShouldReceiveRegistrationTemplate() throws IOException { + given() + .when() + .get(prepareRequestUrl(GET_URL) + REGISTRATION_JSON) + .then() + .statusCode(200) + .body(ID, Matchers.equalTo(REGISTRATION_JSON)) + .body(CONTENT, Matchers.equalTo(readTemplateFromResources(REGISTRATION_JSON).getMap(CONTENT))); + } + + @Test + public void whenCallingListShouldReceiveAllPredefinedTemplates() throws IOException { + Map registration = readTemplateFromResources(REGISTRATION_JSON).getMap(CONTENT); + Map notification = readTemplateFromResources(NOTIFICATION_JSON).getMap(CONTENT); + + given() + .when() + .get(prepareRequestUrl(LIST_URL)) + .then() + .statusCode(200) + .body(CONTENT, Matchers.hasItems( + registration, + notification + )); + } + + @Test + public void whenCallingUploadAndGetShouldReceiveNewTemplate() throws IOException { + byte[] body = Files.readAllBytes(readFileFromTemplatesFolder(UPLOAD_TEMPLATE_JSON)); + + given() + .body(body) + .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) + .when() + .post(prepareRequestUrl(UPLOAD)) + .then() + .statusCode(201); + + given() + .when() + .get(prepareRequestUrl(GET_URL) + UPLOAD_TEMPLATE_JSON) + .then() + .statusCode(200) + .body(ID, Matchers.equalTo(UPLOAD_TEMPLATE_JSON)) + .body(CONTENT, Matchers.equalTo(readTemplateFromResources(UPLOAD_TEMPLATE_JSON).getMap(TEMPLATE))); + } + + @Test + public void whenCallingOverrideAndGetShouldReceiveNewTemplate() throws IOException, JSONException { + byte[] body = Files.readAllBytes(readFileFromTemplatesFolder(OVERWRITE_TEMPLATE_JSON)); + + given() + .body(body) + .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) + .when() + .post(prepareRequestUrl(UPLOAD)) + .then() + .statusCode(201); + + JSONObject overwrittenBody = new JSONObject(new String(body)); + JSONObject overwrittenTemplate = new JSONObject("{\"field1\": \"overwritten_field1\"}"); + overwrittenBody.put(TEMPLATE, overwrittenTemplate); + + given() + .body(overwrittenBody.toString().getBytes()) + .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) + .when() + .post(prepareRequestUrl(UPLOAD)) + .then() + .statusCode(409); + + given() + .body(overwrittenBody.toString().getBytes()) + .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) + .when() + .post(prepareRequestUrl(UPLOAD + FORCE_FLAG)) + .then() + .statusCode(201); + + given() + .when() + .get(prepareRequestUrl(GET_URL) + OVERWRITE_TEMPLATE_JSON) + .then() + .statusCode(200) + .body(ID, Matchers.equalTo(OVERWRITE_TEMPLATE_JSON)) + .body(CONTENT, Matchers.equalTo(readTemplateFromResources(OVERWRITTEN_TEMPLATE_JSON).getMap(CONTENT))); + } + + private String prepareRequestUrl(String action) { + return "http://0.0.0.0:5000/template/" + action; + } + + private JsonPath readTemplateFromResources(String templateName) throws IOException { + byte[] content = Files.readAllBytes(readFileFromTemplatesFolder(templateName)); + return new JsonPath(new String(content)).using(new JsonPathConfig("UTF-8")); + } + + private Path readFileFromTemplatesFolder(String templateName) throws FileNotFoundException { + return ResourceUtils.getFile("classpath:templates/"+templateName).toPath(); + } + +} diff --git a/integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/TestConfiguration.java b/integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/TestConfiguration.java new file mode 100644 index 0000000..cbfca42 --- /dev/null +++ b/integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/TestConfiguration.java @@ -0,0 +1,36 @@ +/*- + * ============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.integration.simulators.nfsimulator.vesclient.integration; + +import org.mockito.Mockito; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; + +@Configuration +public class TestConfiguration { + + @Bean + @Primary + VesSimulatorService provideVesSimulatorService() { + return Mockito.mock(VesSimulatorService.class); + } +} diff --git a/integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/TestUtils.java b/integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/TestUtils.java new file mode 100644 index 0000000..8ad3ddd --- /dev/null +++ b/integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/TestUtils.java @@ -0,0 +1,57 @@ +package org.onap.integration.simulators.nfsimulator.vesclient.integration; + +import com.mongodb.MongoClient; +import com.mongodb.MongoClientOptions; +import com.mongodb.MongoCredential; +import com.mongodb.ServerAddress; +import com.mongodb.client.FindIterable; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoCursor; +import com.mongodb.client.MongoDatabase; +import org.bson.Document; + +import java.net.Inet4Address; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.net.UnknownHostException; +import java.util.Collections; + +public class TestUtils { + + private TestUtils() {} + + public static final String PNF_SIMULATOR_DB = "pnf_simulator"; + public static final String COMMON_EVENT_HEADER = "commonEventHeader"; + public static final String PNF_SIMULATOR_DB_PSWD = "zXcVbN123!"; + public static final String PNF_SIMULATOR_DB_USER = "pnf_simulator_user"; + public static final String PATCHED = "patched"; + public static final String SINGLE_EVENT_URL = "http://0.0.0.0:5000/simulator/event"; + + public static Document findSourceNameInMongoDB() throws UnknownHostException { + MongoCredential credential = MongoCredential + .createCredential(PNF_SIMULATOR_DB_USER, PNF_SIMULATOR_DB, PNF_SIMULATOR_DB_PSWD.toCharArray()); + MongoClient mongoClient = new MongoClient(new ServerAddress(Inet4Address.getLocalHost(), 27017), + credential, MongoClientOptions.builder().build()); + MongoDatabase pnfSimulatorDb = mongoClient.getDatabase(PNF_SIMULATOR_DB); + MongoCollection table = pnfSimulatorDb.getCollection("eventData"); + Document searchQuery = new Document(); + searchQuery.put(PATCHED, new Document("$regex", ".*" + "HistoricalEvent" + ".*")); + FindIterable findOfPatched = table.find(searchQuery); + Document dbObject = null; + MongoCursor cursor = findOfPatched.iterator(); + if (cursor.hasNext()) { + dbObject = cursor.next(); + } + return dbObject; + } + + public static String getCurrentIpAddress() throws SocketException { + return Collections.list(NetworkInterface.getNetworkInterfaces()).stream() + .flatMap(i -> Collections.list(i.getInetAddresses()).stream()) + .filter(ip -> ip instanceof Inet4Address) + .map(e -> (Inet4Address) e) + .findFirst() + .orElseThrow(RuntimeException::new) + .getHostAddress(); + } +} diff --git a/integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/VariablesReplacement.java b/integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/VariablesReplacement.java new file mode 100644 index 0000000..da93e60 --- /dev/null +++ b/integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/VariablesReplacement.java @@ -0,0 +1,75 @@ +package org.onap.integration.simulators.nfsimulator.vesclient.integration; + +import static io.restassured.RestAssured.given; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.hamcrest.Matchers.equalTo; + +import com.google.gson.JsonObject; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Mockito; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = {Main.class, TestConfiguration.class}, + webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +public class VariablesReplacement { + + @Autowired + private VesSimulatorService vesSimulatorService; + + private String currentVesSimulatorIp; + + @Before + public void setUp() throws Exception { + currentVesSimulatorIp = TestUtils.getCurrentIpAddress(); + } + + @Test + public void whenTriggeredSimulatorShouldReplaceStringKeyword() { + String startUrl = prepareRequestUrl(); + String body = "{\n" + "\"templateName\": \"cmNotification.json\",\n" + "\"patch\":{},\n" + "\"variables\":{\n" + + "\"dN\": \"NRNB=5, NRCEL=1234\",\n" + "\"attributeList\":{\n" + + "\"threshXHighQ\": \"50\",\n" + "\"threshXHighP\": \"52\"\n" + "}\n" + "},\n" + + "\"simulatorParams\": {\n" + "\"vesServerUrl\": \"https://" + currentVesSimulatorIp + + ":9443/ves-simulator/eventListener/v5\",\n" + "\"repeatInterval\": 1,\n" + + "\"repeatCount\": 1\n" + "}\n" + "}"; + ArgumentCaptor parameterCaptor = ArgumentCaptor.forClass(JsonObject.class); + + given().contentType("application/json").body(body).when().post(startUrl).then().statusCode(200) + .body("message", equalTo("Request started")); + + Mockito.verify(vesSimulatorService, Mockito.timeout(3000)).sendEventToDmaapV5(parameterCaptor.capture()); + + assertAttributeList(parameterCaptor); + assertDn(parameterCaptor); + } + + private void assertDn(ArgumentCaptor parameterCaptor) { + String dn = parameterCaptor.getValue().getAsJsonObject("event").getAsJsonObject("otherFields") + .getAsJsonArray("jsonObjects").get(0) + .getAsJsonObject().getAsJsonArray("objectInstances") + .get(0).getAsJsonObject().getAsJsonObject("objectInstance") + .getAsJsonObject("cm3gppNotifyFields").getAsJsonPrimitive("dN").getAsString(); + assertThat(dn).isEqualTo("NRNB=5, NRCEL=1234"); + } + + private void assertAttributeList(ArgumentCaptor parameterCaptor) { + JsonObject attributeList = parameterCaptor.getValue().getAsJsonObject("event").getAsJsonObject("otherFields") + .getAsJsonArray("jsonObjects").get(0).getAsJsonObject() + .getAsJsonArray("objectInstances").get(0).getAsJsonObject() + .getAsJsonObject("objectInstance").getAsJsonObject("cm3gppNotifyFields") + .getAsJsonObject("attributeList"); + assertThat(attributeList.get("threshXHighQ").getAsString()).isEqualTo("50"); + assertThat(attributeList.get("threshXHighP").getAsString()).isEqualTo("52"); + } + + private String prepareRequestUrl() { + return "http://0.0.0.0:5000/simulator/start"; + } + +} diff --git a/integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/suites/DockerBasedTestsSuite.java b/integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/suites/DockerBasedTestsSuite.java new file mode 100644 index 0000000..16638ac --- /dev/null +++ b/integration/src/test/java/org/onap/integration/simulators/nfsimulator/vesclient/integration/suites/DockerBasedTestsSuite.java @@ -0,0 +1,90 @@ +/*- + * ============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.integration.simulators.nfsimulator.vesclient.integration.suites; + +import com.palantir.docker.compose.DockerComposeRule; +import com.palantir.docker.compose.connection.waiting.HealthChecks; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; +import org.onap.integration.simulators.nfsimulator.vesclient.integration.OptionalTemplatesTest; +import org.onap.integration.simulators.nfsimulator.vesclient.integration.BasicAvailabilityTest; +import org.onap.integration.simulators.nfsimulator.vesclient.integration.SearchInTemplatesTest; +import org.onap.integration.simulators.nfsimulator.vesclient.integration.SingleEventTest; +import org.onap.integration.simulators.nfsimulator.vesclient.integration.TemplatesManagementTest; +import org.onap.integration.simulators.nfsimulator.vesclient.integration.VariablesReplacement; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpStatus; + +import static io.restassured.RestAssured.given; + +@RunWith(Suite.class) +@SuiteClasses({BasicAvailabilityTest.class, TemplatesManagementTest.class, OptionalTemplatesTest.class, + SearchInTemplatesTest.class, VariablesReplacement.class, SingleEventTest.class}) +public class DockerBasedTestsSuite { + + private static final Logger LOGGER = LoggerFactory.getLogger(DockerBasedTestsSuite.class); + + private static final String HEALTH_CHECK_ADDRESS = "http://0.0.0.0:5000/health"; + private static final int RETRY_COUNT = 10; + private static final int RETRY_INTERVAL = 1000; + + @ClassRule + public static DockerComposeRule docker = DockerComposeRule.builder() + .file("../docker-compose.yml") + .waitingForService("pnf-simulator", HealthChecks.toHaveAllPortsOpen()) + .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen()) + .build(); + + @BeforeClass + public static void waitForPnfSimulatorToBeHealthy() throws InterruptedException { + boolean isHealthy = false; + int retry = 0; + while (!isHealthy && retry < RETRY_COUNT) { + retry++; + LOGGER.info("Checking PNF health, try {} out of {}", retry, RETRY_COUNT); + isHealthy = performHealthCheck(); + if (isHealthy) { + LOGGER.info("PNF is healthy"); + } else { + LOGGER.info("PNF no healthy retrying in {}", RETRY_COUNT); + Thread.sleep(RETRY_INTERVAL); + } + } + } + + private static boolean performHealthCheck() { + boolean isUp = false; + try { + int statusCode = given().get(HEALTH_CHECK_ADDRESS).getStatusCode(); + if (statusCode == HttpStatus.OK.value()) { + isUp = true; + } + } catch (Exception e) { + e.printStackTrace(); + } + return isUp; + } + +} diff --git a/integration/src/test/java/org/onap/pnfsimulator/integration/BasicAvailabilityTest.java b/integration/src/test/java/org/onap/pnfsimulator/integration/BasicAvailabilityTest.java deleted file mode 100644 index 323243c..0000000 --- a/integration/src/test/java/org/onap/pnfsimulator/integration/BasicAvailabilityTest.java +++ /dev/null @@ -1,234 +0,0 @@ -/*- - * ============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.integration; - -import static io.restassured.RestAssured.given; -import static io.restassured.RestAssured.when; -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.onap.pnfsimulator.integration.TestUtils.getCurrentIpAddress; - -import com.google.gson.JsonObject; - -import java.io.IOException; -import java.net.Inet4Address; -import java.net.NetworkInterface; -import java.net.SocketException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Collections; -import java.util.UUID; - -import io.restassured.response.Response; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.ArgumentCaptor; -import org.mockito.Mockito; -import org.mockito.internal.util.Timer; -import org.mockito.internal.verification.VerificationOverTimeImpl; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.http.HttpStatus; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = {Main.class, TestConfiguration.class}, webEnvironment = WebEnvironment.DEFINED_PORT) -public class BasicAvailabilityTest { - - private static final int VERIFICATION_TIMEOUT_MILLIS = 10000; - - @Autowired - VesSimulatorController vesSimulatorController; - - @Autowired - VesSimulatorService vesSimulatorService; - - private final String ACTION_START = "start"; - - private String currenVesSimulatorIp; - - @Before - public void setUp() throws Exception { - currenVesSimulatorIp = getCurrentIpAddress(); - } - - @After - public void tearDown() { - Mockito.reset(vesSimulatorService); - } - - @Test - public void simulatorShouldFailWhenTriggeredNonexistentTemplate() { - //given - String startUrl = prepareRequestUrl(ACTION_START); - String body = "{\n" - + "\"templateName\": \"any_nonexistent_template.json\",\n" - + "\"patch\":{},\n" - + "\"simulatorParams\": {\n" - + "\"vesServerUrl\": \"https://" + currenVesSimulatorIp + ":9443/ves-simulator/eventListener/v5\",\n" - + "\"repeatInterval\": 1,\n" - + "\"repeatCount\": 1\n" - + "}\n" - + "}"; - - //when - given() - .contentType("application/json") - .body(body) - .when() - .post(startUrl) - .then() - .statusCode(HttpStatus.BAD_REQUEST.value()) - .body("message", equalTo("Cannot start simulator - template any_nonexistent_template.json not found.")); - } - - @Test - public void whenTriggeredSimulatorShouldSendSingleEventToVes() { - //given - String startUrl = prepareRequestUrl(ACTION_START); - String body = "{\n" - + "\"templateName\": \"notification.json\",\n" - + "\"patch\":{},\n" - + "\"simulatorParams\": {\n" - + "\"vesServerUrl\": \"https://" + currenVesSimulatorIp + ":9443/ves-simulator/eventListener/v5\",\n" - + "\"repeatInterval\": 1,\n" - + "\"repeatCount\": 1\n" - + "}\n" - + "}"; - ArgumentCaptor parameterCaptor = ArgumentCaptor.forClass(JsonObject.class); - - //when - given() - .contentType("application/json") - .body(body) - .when() - .post(startUrl) - .then() - .statusCode(HttpStatus.OK.value()) - .body("message", equalTo("Request started")); - - Mockito.verify(vesSimulatorService, - Mockito.timeout(VERIFICATION_TIMEOUT_MILLIS)) - .sendEventToDmaapV5(parameterCaptor.capture()); - - assertThat(parameterCaptor.getValue() - .getAsJsonObject("event") - .getAsJsonObject("commonEventHeader") - .get("domain").getAsString()).isEqualTo("notification"); - } - - @Test - public void simulatorShouldCorrectlyRespondOnCancellAllEvent() { - //given - String ACTION_CANCEL_ALL = "cancel"; - String cancelAllUrl = prepareRequestUrl(ACTION_CANCEL_ALL); - - //when - when() - .post(cancelAllUrl) - .then() - .statusCode(HttpStatus.OK.value()) - .body("message", equalTo("Event(s) was cancelled")); - - } - - @Test - public void simulatorBeAbleToUseNewlyAddedTemplate() throws IOException { - //given - String templateBody = "{\"fake\":\"template\"}\n"; - String fileName = UUID.randomUUID() + ".json"; - String requestBody = "{\n" - + "\"templateName\": \"" + fileName + "\",\n" - + "\"patch\":{},\n" - + "\"simulatorParams\": {\n" - + "\"vesServerUrl\": \"https://" + currenVesSimulatorIp + ":9443/ves-simulator/eventListener/v5\",\n" - + "\"repeatInterval\": 1,\n" - + "\"repeatCount\": 1\n" - + "}\n" - + "}"; - ArgumentCaptor parameterCaptor = ArgumentCaptor.forClass(JsonObject.class); - - //when - Path newFile = Files.createFile(Paths.get("..", "templates", fileName)); - Files.write(newFile, templateBody.getBytes()); - - Response postResponse = given() - .contentType("application/json") - .body(requestBody) - .when() - .post(prepareRequestUrl(ACTION_START)); - - Files.delete(newFile); - - //then - assertThat(postResponse.statusCode()).isEqualTo(HttpStatus.OK.value()); - Mockito.verify(vesSimulatorService, Mockito.timeout(VERIFICATION_TIMEOUT_MILLIS)) - .sendEventToDmaapV5(parameterCaptor.capture()); - assertThat(parameterCaptor.getValue() - .get("fake").getAsString()).isEqualTo("template"); - - } - - @Test - public void whenTriggeredSimulatorShouldSendGivenAmountOfEventsToVes() { - //given - String startUrl = prepareRequestUrl(ACTION_START); - String body = "{\n" - + "\"templateName\": \"notification.json\",\n" - + "\"patch\":{},\n" - + "\"simulatorParams\": {\n" - + "\"vesServerUrl\": \"https://" + currenVesSimulatorIp + ":9443/ves-simulator/eventListener/v5\",\n" - + "\"repeatInterval\": 1,\n" - + "\"repeatCount\": 4\n" - + "}\n" - + "}"; - ArgumentCaptor parameterCaptor = ArgumentCaptor.forClass(JsonObject.class); - - //when - given() - .contentType("application/json") - .body(body) - .when() - .post(startUrl) - .then() - .statusCode(HttpStatus.OK.value()) - .body("message", equalTo("Request started")); - - VerificationOverTimeImpl verificator = new VerificationOverTimeImpl(100, Mockito.times(4), false, new Timer(6000)); - Mockito.verify(vesSimulatorService, verificator).sendEventToDmaapV5(parameterCaptor.capture()); - - for (JsonObject value : parameterCaptor.getAllValues()) { - assertThat(value - .getAsJsonObject("event") - .getAsJsonObject("commonEventHeader") - .get("domain").getAsString()).isEqualTo("notification"); - } - } - - private String prepareRequestUrl(String action) { - return "http://0.0.0.0:5000/simulator/" + action; - } - -} diff --git a/integration/src/test/java/org/onap/pnfsimulator/integration/OptionalTemplatesTest.java b/integration/src/test/java/org/onap/pnfsimulator/integration/OptionalTemplatesTest.java deleted file mode 100644 index 50ad1cd..0000000 --- a/integration/src/test/java/org/onap/pnfsimulator/integration/OptionalTemplatesTest.java +++ /dev/null @@ -1,161 +0,0 @@ -/*- - * ============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.integration; - -import static io.restassured.RestAssured.given; -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.onap.pnfsimulator.integration.TestUtils.COMMON_EVENT_HEADER; -import static org.onap.pnfsimulator.integration.TestUtils.PATCHED; -import static org.onap.pnfsimulator.integration.TestUtils.SINGLE_EVENT_URL; -import static org.onap.pnfsimulator.integration.TestUtils.findSourceNameInMongoDB; -import static org.onap.pnfsimulator.integration.TestUtils.getCurrentIpAddress; - -import com.google.gson.JsonObject; -import java.time.Instant; -import java.net.UnknownHostException; - -import org.assertj.core.api.Assertions; -import org.bson.Document; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.ArgumentCaptor; -import org.mockito.Mockito; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.http.HttpStatus; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = {Main.class, TestConfiguration.class}, webEnvironment = WebEnvironment.DEFINED_PORT) -public class OptionalTemplatesTest { - - @Autowired - private VesSimulatorService vesSimulatorService; - - private String currentVesSimulatorIp; - - @Before - public void setUp() throws Exception { - currentVesSimulatorIp = getCurrentIpAddress(); - } - - @After - public void tearDown() { - Mockito.reset(vesSimulatorService); - } - - @Test - public void whenTriggeredSimulatorWithoutTemplateShouldSendSingleEventToVes() { - //given - long currentTimestamp = Instant.now().getEpochSecond(); - - String body = "{\n" - + "\"vesServerUrl\": \"https://" + currentVesSimulatorIp + ":9443/ves-simulator/eventListener/v5\",\n" - + "\"event\": { \n" - + "\"commonEventHeader\": {\n" - + "\"eventId1\": \"#RandomString(20)\",\n" - + "\"eventId2\": \"#RandomInteger(10,10)\",\n" - + "\"eventId3\": \"#Increment\",\n" - + "\"eventId4\": \"#RandomPrimitiveInteger(10,10)\",\n" - + "\"eventId5\": \"#TimestampPrimitive\",\n" - + "\"sourceName\": \"Single_sourceName\",\n" - + "\"version\": 3" - + "}\n" - + "}\n" - + "}"; - ArgumentCaptor parameterCaptor = ArgumentCaptor.forClass(JsonObject.class); - - //when - given() - .contentType("application/json") - .body(body) - .when() - .post(SINGLE_EVENT_URL) - .then() - .statusCode(HttpStatus.ACCEPTED.value()) - .body("message", equalTo("Accepted")); - - //then - long afterExecution = Instant.now().getEpochSecond(); - Mockito.verify(vesSimulatorService, - Mockito.timeout(3000)) - .sendEventToDmaapV5(parameterCaptor.capture()); - - JsonObject value = parameterCaptor.getValue(); - assertThat(value - .getAsJsonObject(COMMON_EVENT_HEADER) - .get("sourceName").getAsString()).isEqualTo("Single_sourceName"); - assertThat(value - .getAsJsonObject(COMMON_EVENT_HEADER) - .get("eventId1").getAsString()).hasSize(20); - assertThat(value - .getAsJsonObject(COMMON_EVENT_HEADER) - .get("eventId2").getAsString()).isEqualTo("10"); - assertThat(value - .getAsJsonObject(COMMON_EVENT_HEADER) - .get("eventId3").getAsString()).isEqualTo("1"); - assertThat(value - .getAsJsonObject(COMMON_EVENT_HEADER) - .get("eventId4").getAsInt()).isEqualTo(10); - assertThat(value - .getAsJsonObject(COMMON_EVENT_HEADER) - .get("eventId5").getAsLong()).isBetween(currentTimestamp, afterExecution); - } - - @Test - public void whenTriggeredSimulatorWithoutTemplateEventShouldBeVisibleInDB() throws UnknownHostException { - //given - String body = "{\n" - + "\"vesServerUrl\": \"https://" + currentVesSimulatorIp + ":9443/ves-simulator/eventListener/v5\",\n" - + "\"event\": { \n" - + "\"commonEventHeader\": {\n" - + "\"sourceName\": \"HistoricalEvent\",\n" - + "\"version\": 3" - + "}\n" - + "}\n" - + "}"; - ArgumentCaptor parameterCaptor = ArgumentCaptor.forClass(JsonObject.class); - - //when - given() - .contentType("application/json") - .body(body) - .when() - .post(SINGLE_EVENT_URL) - .then() - .statusCode(HttpStatus.ACCEPTED.value()) - .body("message", equalTo("Accepted")); - - //then - Mockito.verify(vesSimulatorService, - Mockito.timeout(3000)) - .sendEventToDmaapV5(parameterCaptor.capture()); - - Document sourceNameInMongoDB = findSourceNameInMongoDB(); - Assertions.assertThat(sourceNameInMongoDB.get(PATCHED)) - .isEqualTo("{\"commonEventHeader\":{\"sourceName\":\"HistoricalEvent\",\"version\":3}}"); - } - -} diff --git a/integration/src/test/java/org/onap/pnfsimulator/integration/SearchInTemplatesTest.java b/integration/src/test/java/org/onap/pnfsimulator/integration/SearchInTemplatesTest.java deleted file mode 100644 index 9d4ff3b..0000000 --- a/integration/src/test/java/org/onap/pnfsimulator/integration/SearchInTemplatesTest.java +++ /dev/null @@ -1,269 +0,0 @@ -/*- - * ============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.integration; - -import static io.restassured.RestAssured.given; -import static java.nio.file.Files.readAllBytes; - -import io.restassured.http.Header; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import org.hamcrest.Matchers; -import org.junit.BeforeClass; -import org.junit.Test; -import org.springframework.util.ResourceUtils; - -public class SearchInTemplatesTest { - - private static final String UPLOAD = "upload"; - private static final String SEARCH = "search"; - private static final String APPLICATION_JSON = "application/json"; - private static final String CONTENT_TYPE = "Content-Type"; - - @BeforeClass - public static void setUp() throws IOException { - for (File file : readFileFromTemplatesFolder()) { - byte[] body = readAllBytes(file.toPath()); - - given() - .body(body) - .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) - .when() - .post(prepareRequestUrl(UPLOAD) + "?override=true") - .then() - .statusCode(201); - } - } - - @Test - public void shouldFindNothingWhenNonexistentValueIsProvided(){ - given() - .body("{\"searchExpr\": { \"child3\": \"nonexistentValue\" }}") - .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) - .when() - .post(prepareRequestUrl(SEARCH)) - .then() - .statusCode(200) - .body("", Matchers.empty()); - } - - @Test - public void shouldFindNothingWhenNonexistentKeyIsProvided(){ - given() - .body("{\"searchExpr\": { \"nonexistentKey\": \"Any value 1\" }}") - .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) - .when() - .post(prepareRequestUrl(SEARCH)) - .then() - .statusCode(200) - .body("", Matchers.empty()); - } - - @Test - public void shouldFindNothingWhenPartOfKeyIsProvided(){ - given() - .body("{\"searchExpr\": { \"child\": \"Any value 1\" }}") - .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) - .when() - .post(prepareRequestUrl(SEARCH)) - .then() - .statusCode(200) - .body("", Matchers.empty()); - } - - @Test - public void shouldFindNothingWhenPartOfValueIsProvided(){ - given() - .body("{\"searchExpr\": { \"child5\": \"Any\" }}") - .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) - .when() - .post(prepareRequestUrl(SEARCH)) - .then() - .statusCode(200) - .body("", Matchers.empty()); - } - - @Test - public void shouldBeAbleToSearchForString(){ - given() - .body("{\"searchExpr\": { \"child1\": \"Any value 1\" }}") - .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) - .when() - .post(prepareRequestUrl(SEARCH)) - .then() - .statusCode(200) - .body("", Matchers.hasItems("template_with_array.json", "complicated_template.json", "simple_template.json")); - - given() - .body("{\"searchExpr\": { \"child2\": \"any value 4\" }}") - .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) - .when() - .post(prepareRequestUrl(SEARCH)) - .then() - .statusCode(200) - .body("", Matchers.hasItems("template_with_array.json")); - } - - @Test - public void shouldBeAbleToSearchForManyStrings(){ - given() - .body("{\"searchExpr\": { \"child1\": \"Any value 1\", \"child2\": \"any value 2\"}}") - .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) - .when() - .post(prepareRequestUrl(SEARCH)) - .then() - .statusCode(200) - .body("", Matchers.hasItems("simple_template.json", "complicated_template.json")); - } - - @Test - public void shouldBeAbleToSearchForStarSign(){ - given() - .body("{\"searchExpr\": { \"child2\": \"*\" }}") - .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) - .when() - .post(prepareRequestUrl(SEARCH)) - .then() - .statusCode(200) - .body("", Matchers.hasItems("complicated_template.json")); - } - - @Test - public void shouldBeAbleToSearchForQuestionMark(){ - given() - .body("{\"searchExpr\": { \"child1\": \"?\" }}") - .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) - .when() - .post(prepareRequestUrl(SEARCH)) - .then() - .statusCode(200) - .body("", Matchers.hasItems("complicated_template.json")); - } - - @Test - public void shouldBeAbleToSearchForBrackets(){ - given() - .body("{\"searchExpr\": { \"parent2\": \"[]\" }}") - .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) - .when() - .post(prepareRequestUrl(SEARCH)) - .then() - .statusCode(200) - .body("", Matchers.hasItems("template_with_array.json")); - } - - @Test - public void shouldInformThatSearchForNullsIsProhibited(){ - given() - .body("{\"searchExpr\": { \"child3\": null }}") - .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) - .when() - .post(prepareRequestUrl(SEARCH)) - .then() - .statusCode(400); - } - - @Test - public void shouldBeAbleToSearchForURI(){ - given() - .body("{\"searchExpr\": { \"child3\": \"https://url.com?param1=test¶m2=*\" }}") - .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) - .when() - .post(prepareRequestUrl(SEARCH)) - .then() - .statusCode(200) - .body("", Matchers.hasItems("complicated_template.json")); - } - - @Test - public void shouldBeAbleToSearchForFloats(){ - given() - .body("{\"searchExpr\": { \"child2\": 4.44 }}") - .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) - .when() - .post(prepareRequestUrl(SEARCH)) - .then() - .statusCode(200) - .body("", Matchers.hasItems("template_with_array.json")); - - given() - .body("{\"searchExpr\": { \"child5\": 4.4 }}") - .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) - .when() - .post(prepareRequestUrl(SEARCH)) - .then() - .statusCode(200) - .body("", Matchers.hasItems("complicated_template.json", "template_with_floats.json")); - } - - @Test - public void shouldBeAbleToSearchForIntegers(){ - given() - .body("{\"searchExpr\": { \"child2\": 1 }}") - .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) - .when() - .post(prepareRequestUrl(SEARCH)) - .then() - .statusCode(200) - .body("", Matchers.hasItems("template_with_array.json", "template_with_ints.json")); - - given() - .body("{\"searchExpr\": { \"child2\": 4 }}") - .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) - .when() - .post(prepareRequestUrl(SEARCH)) - .then() - .statusCode(200) - .body("", Matchers.hasItems("template_with_array.json")); - } - - @Test - public void shouldBeAbleToSearchForBooleans(){ - given() - .body("{\"searchExpr\": { \"child4\": true}}") - .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) - .when() - .post(prepareRequestUrl(SEARCH)) - .then() - .statusCode(200) - .body("", Matchers.hasItems("template_with_booleans.json")); - - given() - .body("{\"searchExpr\": { \"parent2\": false}}") - .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) - .when() - .post(prepareRequestUrl(SEARCH)) - .then() - .statusCode(200) - .body("", Matchers.hasItems("template_with_booleans.json")); - } - - - private static String prepareRequestUrl(String action) { - return "http://0.0.0.0:5000/template/" + action; - } - - private static File[] readFileFromTemplatesFolder() throws FileNotFoundException { - return ResourceUtils.getFile("classpath:templates/search").listFiles(); - } - -} diff --git a/integration/src/test/java/org/onap/pnfsimulator/integration/SingleEventTest.java b/integration/src/test/java/org/onap/pnfsimulator/integration/SingleEventTest.java deleted file mode 100644 index 3ad1385..0000000 --- a/integration/src/test/java/org/onap/pnfsimulator/integration/SingleEventTest.java +++ /dev/null @@ -1,151 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Simulator - * ================================================================================ - * Copyright (C) 2020 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.integration; - -import com.google.gson.JsonObject; -import org.assertj.core.api.Assertions; -import org.bson.Document; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.ArgumentCaptor; -import org.mockito.Mockito; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.HttpStatus; -import org.springframework.test.context.junit4.SpringRunner; - -import java.net.UnknownHostException; -import java.util.List; - -import static io.restassured.RestAssured.given; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.stringContainsInOrder; -import static org.onap.pnfsimulator.integration.TestUtils.PATCHED; -import static org.onap.pnfsimulator.integration.TestUtils.SINGLE_EVENT_URL; -import static org.onap.pnfsimulator.integration.TestUtils.findSourceNameInMongoDB; -import static org.onap.pnfsimulator.integration.TestUtils.getCurrentIpAddress; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = {Main.class, TestConfiguration.class}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) -public class SingleEventTest { - - @Autowired - private VesSimulatorService vesSimulatorService; - - private String currentVesSimulatorIp; - - @Before - public void setUp() throws Exception { - currentVesSimulatorIp = getCurrentIpAddress(); - } - - @After - public void tearDown() { - Mockito.reset(vesSimulatorService); - } - - @Test - public void whenTriggeredSimulatorWithWrongVesAddressInformationShouldBeReturned() { - //given - String body = "{\n" - + "\"vesServerUrl\": \"https://" + currentVesSimulatorIp + ":8080/ves-simulator/eventListener/v5\",\n" - + "\"event\": { \n" - + "\"commonEventHeader\": {\n" - + "\"sourceName\": \"HistoricalEvent\",\n" - + "\"version\": 3" - + "}\n" - + "}\n" - + "}"; - - //when - given() - .contentType("application/json") - .body(body) - .when() - .post(SINGLE_EVENT_URL) - .then() - .statusCode(421) - .body("message", - equalTo( - "Fail to connect with ves: Connect to "+currentVesSimulatorIp+":8080 " + - "[/"+currentVesSimulatorIp+"] " + - "failed: Connection refused (Connection refused)")); - } - - @Test - public void whenTriggeredSimulatorWithWrongEventShouldReturnedError() { - //given - String body = "{\n" - + "\"vesServerUrl\": \"https://" + currentVesSimulatorIp + ":9443/ves-simulator/eventListener/v5\",\n" - + "\"event\": { \n" - + "this is not JSON {}" - + "}\n" - + "}"; - - //when - given() - .contentType("application/json") - .body(body) - .when() - .post(SINGLE_EVENT_URL) - .then() - .statusCode(HttpStatus.BAD_REQUEST.value()) - .body("message", - stringContainsInOrder(List.of("JSON parse error:","Unexpected character ('t' (code 116)):")) - ); - } - - @Test - public void whenTriggeredSimulatorWithUsernameAndPasswordInUrlVesShouldAcceptRequest() throws UnknownHostException { - //given - String body = "{\n" - + "\"vesServerUrl\": \"https://user1:pass1@" + currentVesSimulatorIp + ":9443/ves-simulator/eventListener/v5\",\n" - + "\"event\": { \n" - + "\"commonEventHeader\": {\n" - + "\"sourceName\": \"HistoricalEvent\",\n" - + "\"version\": 3" - + "}\n" - + "}\n" - + "}"; - ArgumentCaptor parameterCaptor = ArgumentCaptor.forClass(JsonObject.class); - - //when - given() - .contentType("application/json") - .body(body) - .when() - .post(SINGLE_EVENT_URL) - .then() - .statusCode(HttpStatus.ACCEPTED.value()) - .body("message", equalTo("Accepted")); - - //then - Mockito.verify(vesSimulatorService, - Mockito.timeout(3000)) - .sendEventToDmaapV5(parameterCaptor.capture()); - - Document sourceNameInMongoDB = findSourceNameInMongoDB(); - Assertions.assertThat(sourceNameInMongoDB.get(PATCHED)) - .isEqualTo("{\"commonEventHeader\":{\"sourceName\":\"HistoricalEvent\",\"version\":3}}"); - } -} diff --git a/integration/src/test/java/org/onap/pnfsimulator/integration/TemplatesManagementTest.java b/integration/src/test/java/org/onap/pnfsimulator/integration/TemplatesManagementTest.java deleted file mode 100644 index 7e74dd4..0000000 --- a/integration/src/test/java/org/onap/pnfsimulator/integration/TemplatesManagementTest.java +++ /dev/null @@ -1,175 +0,0 @@ -/*- - * ============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.integration; - -import static io.restassured.RestAssured.given; - -import io.restassured.http.Header; -import io.restassured.path.json.JsonPath; -import io.restassured.path.json.config.JsonPathConfig; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Map; -import org.hamcrest.Matchers; -import org.json.JSONException; -import org.json.JSONObject; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.util.ResourceUtils; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = {Main.class, TestConfiguration.class}, webEnvironment = WebEnvironment.DEFINED_PORT) -public class TemplatesManagementTest { - - private static final String LIST_URL = "list"; - private static final String GET_URL = "get/"; - private static final String UPLOAD = "upload"; - private static final String NOTIFICATION_JSON = "notification.json"; - private static final String REGISTRATION_JSON = "registration.json"; - private static final String UPLOAD_TEMPLATE_JSON = "upload_template.json"; - private static final String OVERWRITE_TEMPLATE_JSON = "overwrite_template.json"; - private static final String OVERWRITTEN_TEMPLATE_JSON = "overwritten_template.json"; - private static final String APPLICATION_JSON = "application/json"; - private static final String CONTENT_TYPE = "Content-Type"; - private static final String FORCE_FLAG = "?override=true"; - private static final String CONTENT = "content"; - private static final String TEMPLATE = "template"; - private static final String ID = "id"; - - @Test - public void whenCallingGetShouldReceiveNotificationTemplate() throws IOException { - given() - .when() - .get(prepareRequestUrl(GET_URL) + NOTIFICATION_JSON) - .then() - .statusCode(200) - .body(ID, Matchers.equalTo(NOTIFICATION_JSON)) - .body(CONTENT, Matchers.equalTo(readTemplateFromResources(NOTIFICATION_JSON).getMap(CONTENT))); - } - - @Test - public void whenCallingGetShouldReceiveRegistrationTemplate() throws IOException { - given() - .when() - .get(prepareRequestUrl(GET_URL) + REGISTRATION_JSON) - .then() - .statusCode(200) - .body(ID, Matchers.equalTo(REGISTRATION_JSON)) - .body(CONTENT, Matchers.equalTo(readTemplateFromResources(REGISTRATION_JSON).getMap(CONTENT))); - } - - @Test - public void whenCallingListShouldReceiveAllPredefinedTemplates() throws IOException { - Map registration = readTemplateFromResources(REGISTRATION_JSON).getMap(CONTENT); - Map notification = readTemplateFromResources(NOTIFICATION_JSON).getMap(CONTENT); - - given() - .when() - .get(prepareRequestUrl(LIST_URL)) - .then() - .statusCode(200) - .body(CONTENT, Matchers.hasItems( - registration, - notification - )); - } - - @Test - public void whenCallingUploadAndGetShouldReceiveNewTemplate() throws IOException { - byte[] body = Files.readAllBytes(readFileFromTemplatesFolder(UPLOAD_TEMPLATE_JSON)); - - given() - .body(body) - .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) - .when() - .post(prepareRequestUrl(UPLOAD)) - .then() - .statusCode(201); - - given() - .when() - .get(prepareRequestUrl(GET_URL) + UPLOAD_TEMPLATE_JSON) - .then() - .statusCode(200) - .body(ID, Matchers.equalTo(UPLOAD_TEMPLATE_JSON)) - .body(CONTENT, Matchers.equalTo(readTemplateFromResources(UPLOAD_TEMPLATE_JSON).getMap(TEMPLATE))); - } - - @Test - public void whenCallingOverrideAndGetShouldReceiveNewTemplate() throws IOException, JSONException { - byte[] body = Files.readAllBytes(readFileFromTemplatesFolder(OVERWRITE_TEMPLATE_JSON)); - - given() - .body(body) - .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) - .when() - .post(prepareRequestUrl(UPLOAD)) - .then() - .statusCode(201); - - JSONObject overwrittenBody = new JSONObject(new String(body)); - JSONObject overwrittenTemplate = new JSONObject("{\"field1\": \"overwritten_field1\"}"); - overwrittenBody.put(TEMPLATE, overwrittenTemplate); - - given() - .body(overwrittenBody.toString().getBytes()) - .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) - .when() - .post(prepareRequestUrl(UPLOAD)) - .then() - .statusCode(409); - - given() - .body(overwrittenBody.toString().getBytes()) - .header(new Header(CONTENT_TYPE, APPLICATION_JSON)) - .when() - .post(prepareRequestUrl(UPLOAD + FORCE_FLAG)) - .then() - .statusCode(201); - - given() - .when() - .get(prepareRequestUrl(GET_URL) + OVERWRITE_TEMPLATE_JSON) - .then() - .statusCode(200) - .body(ID, Matchers.equalTo(OVERWRITE_TEMPLATE_JSON)) - .body(CONTENT, Matchers.equalTo(readTemplateFromResources(OVERWRITTEN_TEMPLATE_JSON).getMap(CONTENT))); - } - - private String prepareRequestUrl(String action) { - return "http://0.0.0.0:5000/template/" + action; - } - - private JsonPath readTemplateFromResources(String templateName) throws IOException { - byte[] content = Files.readAllBytes(readFileFromTemplatesFolder(templateName)); - return new JsonPath(new String(content)).using(new JsonPathConfig("UTF-8")); - } - - private Path readFileFromTemplatesFolder(String templateName) throws FileNotFoundException { - return ResourceUtils.getFile("classpath:templates/"+templateName).toPath(); - } - -} diff --git a/integration/src/test/java/org/onap/pnfsimulator/integration/TestConfiguration.java b/integration/src/test/java/org/onap/pnfsimulator/integration/TestConfiguration.java deleted file mode 100644 index 19ae050..0000000 --- a/integration/src/test/java/org/onap/pnfsimulator/integration/TestConfiguration.java +++ /dev/null @@ -1,36 +0,0 @@ -/*- - * ============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.integration; - -import org.mockito.Mockito; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; - -@Configuration -public class TestConfiguration { - - @Bean - @Primary - VesSimulatorService provideVesSimulatorService() { - return Mockito.mock(VesSimulatorService.class); - } -} diff --git a/integration/src/test/java/org/onap/pnfsimulator/integration/TestUtils.java b/integration/src/test/java/org/onap/pnfsimulator/integration/TestUtils.java deleted file mode 100644 index f7df5e9..0000000 --- a/integration/src/test/java/org/onap/pnfsimulator/integration/TestUtils.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.onap.pnfsimulator.integration; - -import com.mongodb.MongoClient; -import com.mongodb.MongoClientOptions; -import com.mongodb.MongoCredential; -import com.mongodb.ServerAddress; -import com.mongodb.client.FindIterable; -import com.mongodb.client.MongoCollection; -import com.mongodb.client.MongoCursor; -import com.mongodb.client.MongoDatabase; -import org.bson.Document; - -import java.net.Inet4Address; -import java.net.NetworkInterface; -import java.net.SocketException; -import java.net.UnknownHostException; -import java.util.Collections; - -public class TestUtils { - - private TestUtils() {} - - public static final String PNF_SIMULATOR_DB = "pnf_simulator"; - public static final String COMMON_EVENT_HEADER = "commonEventHeader"; - public static final String PNF_SIMULATOR_DB_PSWD = "zXcVbN123!"; - public static final String PNF_SIMULATOR_DB_USER = "pnf_simulator_user"; - public static final String PATCHED = "patched"; - public static final String SINGLE_EVENT_URL = "http://0.0.0.0:5000/simulator/event"; - - public static Document findSourceNameInMongoDB() throws UnknownHostException { - MongoCredential credential = MongoCredential - .createCredential(PNF_SIMULATOR_DB_USER, PNF_SIMULATOR_DB, PNF_SIMULATOR_DB_PSWD.toCharArray()); - MongoClient mongoClient = new MongoClient(new ServerAddress(Inet4Address.getLocalHost(), 27017), - credential, MongoClientOptions.builder().build()); - MongoDatabase pnfSimulatorDb = mongoClient.getDatabase(PNF_SIMULATOR_DB); - MongoCollection table = pnfSimulatorDb.getCollection("eventData"); - Document searchQuery = new Document(); - searchQuery.put(PATCHED, new Document("$regex", ".*" + "HistoricalEvent" + ".*")); - FindIterable findOfPatched = table.find(searchQuery); - Document dbObject = null; - MongoCursor cursor = findOfPatched.iterator(); - if (cursor.hasNext()) { - dbObject = cursor.next(); - } - return dbObject; - } - - public static String getCurrentIpAddress() throws SocketException { - return Collections.list(NetworkInterface.getNetworkInterfaces()).stream() - .flatMap(i -> Collections.list(i.getInetAddresses()).stream()) - .filter(ip -> ip instanceof Inet4Address) - .map(e -> (Inet4Address) e) - .findFirst() - .orElseThrow(RuntimeException::new) - .getHostAddress(); - } -} diff --git a/integration/src/test/java/org/onap/pnfsimulator/integration/VariablesReplacement.java b/integration/src/test/java/org/onap/pnfsimulator/integration/VariablesReplacement.java deleted file mode 100644 index ae7970c..0000000 --- a/integration/src/test/java/org/onap/pnfsimulator/integration/VariablesReplacement.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.onap.pnfsimulator.integration; - -import static io.restassured.RestAssured.given; -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.onap.pnfsimulator.integration.TestUtils.getCurrentIpAddress; - -import com.google.gson.JsonObject; -import java.net.Inet4Address; -import java.net.NetworkInterface; -import java.net.SocketException; -import java.util.Collections; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.ArgumentCaptor; -import org.mockito.Mockito; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = {Main.class, TestConfiguration.class}, - webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) -public class VariablesReplacement { - - @Autowired - private VesSimulatorService vesSimulatorService; - - private String currentVesSimulatorIp; - - @Before - public void setUp() throws Exception { - currentVesSimulatorIp = getCurrentIpAddress(); - } - - @Test - public void whenTriggeredSimulatorShouldReplaceStringKeyword() { - String startUrl = prepareRequestUrl(); - String body = "{\n" + "\"templateName\": \"cmNotification.json\",\n" + "\"patch\":{},\n" + "\"variables\":{\n" - + "\"dN\": \"NRNB=5, NRCEL=1234\",\n" + "\"attributeList\":{\n" - + "\"threshXHighQ\": \"50\",\n" + "\"threshXHighP\": \"52\"\n" + "}\n" + "},\n" - + "\"simulatorParams\": {\n" + "\"vesServerUrl\": \"https://" + currentVesSimulatorIp - + ":9443/ves-simulator/eventListener/v5\",\n" + "\"repeatInterval\": 1,\n" - + "\"repeatCount\": 1\n" + "}\n" + "}"; - ArgumentCaptor parameterCaptor = ArgumentCaptor.forClass(JsonObject.class); - - given().contentType("application/json").body(body).when().post(startUrl).then().statusCode(200) - .body("message", equalTo("Request started")); - - Mockito.verify(vesSimulatorService, Mockito.timeout(3000)).sendEventToDmaapV5(parameterCaptor.capture()); - - assertAttributeList(parameterCaptor); - assertDn(parameterCaptor); - } - - private void assertDn(ArgumentCaptor parameterCaptor) { - String dn = parameterCaptor.getValue().getAsJsonObject("event").getAsJsonObject("otherFields") - .getAsJsonArray("jsonObjects").get(0) - .getAsJsonObject().getAsJsonArray("objectInstances") - .get(0).getAsJsonObject().getAsJsonObject("objectInstance") - .getAsJsonObject("cm3gppNotifyFields").getAsJsonPrimitive("dN").getAsString(); - assertThat(dn).isEqualTo("NRNB=5, NRCEL=1234"); - } - - private void assertAttributeList(ArgumentCaptor parameterCaptor) { - JsonObject attributeList = parameterCaptor.getValue().getAsJsonObject("event").getAsJsonObject("otherFields") - .getAsJsonArray("jsonObjects").get(0).getAsJsonObject() - .getAsJsonArray("objectInstances").get(0).getAsJsonObject() - .getAsJsonObject("objectInstance").getAsJsonObject("cm3gppNotifyFields") - .getAsJsonObject("attributeList"); - assertThat(attributeList.get("threshXHighQ").getAsString()).isEqualTo("50"); - assertThat(attributeList.get("threshXHighP").getAsString()).isEqualTo("52"); - } - - private String prepareRequestUrl() { - return "http://0.0.0.0:5000/simulator/start"; - } - -} diff --git a/integration/src/test/java/org/onap/pnfsimulator/integration/suites/DockerBasedTestsSuite.java b/integration/src/test/java/org/onap/pnfsimulator/integration/suites/DockerBasedTestsSuite.java deleted file mode 100644 index f6a4c24..0000000 --- a/integration/src/test/java/org/onap/pnfsimulator/integration/suites/DockerBasedTestsSuite.java +++ /dev/null @@ -1,90 +0,0 @@ -/*- - * ============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.integration.suites; - -import com.palantir.docker.compose.DockerComposeRule; -import com.palantir.docker.compose.connection.waiting.HealthChecks; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; -import org.onap.pnfsimulator.integration.BasicAvailabilityTest; -import org.onap.pnfsimulator.integration.OptionalTemplatesTest; -import org.onap.pnfsimulator.integration.SearchInTemplatesTest; -import org.onap.pnfsimulator.integration.SingleEventTest; -import org.onap.pnfsimulator.integration.TemplatesManagementTest; -import org.onap.pnfsimulator.integration.VariablesReplacement; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.http.HttpStatus; - -import static io.restassured.RestAssured.given; - -@RunWith(Suite.class) -@SuiteClasses({BasicAvailabilityTest.class, TemplatesManagementTest.class, OptionalTemplatesTest.class, - SearchInTemplatesTest.class, VariablesReplacement.class, SingleEventTest.class}) -public class DockerBasedTestsSuite { - - private static final Logger LOGGER = LoggerFactory.getLogger(DockerBasedTestsSuite.class); - - private static final String HEALTH_CHECK_ADDRESS = "http://0.0.0.0:5000/health"; - private static final int RETRY_COUNT = 10; - private static final int RETRY_INTERVAL = 1000; - - @ClassRule - public static DockerComposeRule docker = DockerComposeRule.builder() - .file("../docker-compose.yml") - .waitingForService("pnf-simulator", HealthChecks.toHaveAllPortsOpen()) - .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen()) - .build(); - - @BeforeClass - public static void waitForPnfSimulatorToBeHealthy() throws InterruptedException { - boolean isHealthy = false; - int retry = 0; - while (!isHealthy && retry < RETRY_COUNT) { - retry++; - LOGGER.info("Checking PNF health, try {} out of {}", retry, RETRY_COUNT); - isHealthy = performHealthCheck(); - if (isHealthy) { - LOGGER.info("PNF is healthy"); - } else { - LOGGER.info("PNF no healthy retrying in {}", RETRY_COUNT); - Thread.sleep(RETRY_INTERVAL); - } - } - } - - private static boolean performHealthCheck() { - boolean isUp = false; - try { - int statusCode = given().get(HEALTH_CHECK_ADDRESS).getStatusCode(); - if (statusCode == HttpStatus.OK.value()) { - isUp = true; - } - } catch (Exception e) { - e.printStackTrace(); - } - return isUp; - } - -} diff --git a/pom.xml b/pom.xml index 546d44a..2d45894 100644 --- a/pom.xml +++ b/pom.xml @@ -41,7 +41,7 @@ 11 11 yyyyMMdd'T'HHmmss - org.onap.pnfsimulator.Main + org.onap.integration.simulators.nfsimulator.vesclient.Main latest libs ${project.build.directory}/${dependency.directory.name} @@ -149,11 +149,6 @@ spring-boot-starter-data-mongodb ${spring-boot-starter-data-mongodb.version} - - - - - org.springframework.cloud spring-cloud-config-client @@ -170,21 +165,6 @@ logback-classic ${logback-classic.version} - - - - - - - - - - - - - - - org.json json @@ -200,32 +180,11 @@ httpclient ${apache.httpclient.version} - - - - - - - - - - org.apache.commons commons-lang3 ${commons-lang3.version} - - - - - - - - - - - io.vavr vavr-match @@ -265,36 +224,6 @@ test ${junit-jupiter-engine.version} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - org.springframework.boot spring-boot-starter-test diff --git a/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/Main.java b/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/Main.java new file mode 100644 index 0000000..17ff65b --- /dev/null +++ b/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/Main.java @@ -0,0 +1,59 @@ +/* + * ============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.integration.simulators.nfsimulator.vesclient; + +import javax.annotation.PostConstruct; + +import org.onap.integration.simulators.nfsimulator.vesclient.template.FsToDbTemplateSynchronizer; +import org.onap.integration.simulators.nfsimulator.vesclient.filesystem.WatcherService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.scheduling.annotation.EnableAsync; + +@SpringBootApplication +@EnableAsync +public class Main { + + private final WatcherService watcherService; + private final FsToDbTemplateSynchronizer fsToDbTemplateSynchronizer; + + @Autowired + public Main(WatcherService watcherService, + FsToDbTemplateSynchronizer fsToDbTemplateSynchronizer) { + this.watcherService = watcherService; + this.fsToDbTemplateSynchronizer = fsToDbTemplateSynchronizer; + } + + // We are excluding this line in Sonar due to fact that + // Spring is handling arguments + public static void main(String[] args) { // NOSONAR + SpringApplication.run(Main.class, args); + } + + @PostConstruct + public void createWatchers() { + fsToDbTemplateSynchronizer.synchronize(); + watcherService.createWatcher(); + } +} + + diff --git a/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/SwaggerConfig.java b/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/SwaggerConfig.java new file mode 100644 index 0000000..c709729 --- /dev/null +++ b/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/SwaggerConfig.java @@ -0,0 +1,46 @@ +/* + * ============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.integration.simulators.nfsimulator.vesclient; + +import org.onap.integration.simulators.nfsimulator.vesclient.simulator.client.utils.ssl.SslAuthenticationHelper; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +@Configuration +@EnableConfigurationProperties(SslAuthenticationHelper.class) +@EnableSwagger2 +public class SwaggerConfig { + + @Bean + public Docket api() { + return new Docket(DocumentationType.SWAGGER_2) + .select() + .apis(RequestHandlerSelectors.basePackage("org.onap.pnfsimulator")) + .paths(PathSelectors.any()) + .build(); + } +} diff --git a/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/db/Row.java b/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/db/Row.java new file mode 100644 index 0000000..cd9edff --- /dev/null +++ b/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/db/Row.java @@ -0,0 +1,39 @@ +/*- + * ============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.integration.simulators.nfsimulator.vesclient.db; + +import lombok.Getter; +import lombok.Setter; +import org.springframework.data.annotation.Id; +import org.springframework.data.mongodb.core.mapping.Field; + +public abstract class Row { + @Id + @Field("_id") + @Getter + @Setter + private String id; + + + public String getId() { + return id; + } +} diff --git a/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/db/Storage.java b/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/db/Storage.java new file mode 100644 index 0000000..7e9a378 --- /dev/null +++ b/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/db/Storage.java @@ -0,0 +1,41 @@ +/*- + * ============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.integration.simulators.nfsimulator.vesclient.db; + +import com.google.gson.JsonObject; + +import java.util.List; +import java.util.Optional; + +public interface Storage { + + List getAll(); + + Optional get(String rowId); + + void persist(T row); + + boolean tryPersistOrOverwrite(T row, boolean overwrite); + + void delete(String rowId); + + List getIdsByContentCriteria(JsonObject queryJson); +} diff --git a/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/event/EventData.java b/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/event/EventData.java new file mode 100644 index 0000000..7ebdfba --- /dev/null +++ b/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/event/EventData.java @@ -0,0 +1,67 @@ +/* + * ============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.integration.simulators.nfsimulator.vesclient.event; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import org.springframework.data.annotation.Id; +import org.springframework.data.mongodb.core.mapping.Field; + +@Builder +@Getter +@Setter +@ToString(exclude = "incrementValue") +public class EventData { + @Id + private String id; + + @Field("template") + @JsonInclude + private String template; + + @Field("patched") + @JsonInclude + private String patched; + + @Field("input") + @JsonInclude + private String input; + + @Field("keywords") + @JsonInclude + private String keywords; + + @Field("incrementValue") + @JsonInclude + private int incrementValue; + + protected EventData(String id, String template, String patched, String input, String keywords, int incrementValue) { + this.id = id; + this.template = template; + this.patched = patched; + this.input = input; + this.keywords = keywords; + this.incrementValue = incrementValue; + } +} diff --git a/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/event/EventDataRepository.java b/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/event/EventDataRepository.java new file mode 100644 index 0000000..67f4e2f --- /dev/null +++ b/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/event/EventDataRepository.java @@ -0,0 +1,26 @@ +/* + * ============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.integration.simulators.nfsimulator.vesclient.event; + +import org.springframework.data.mongodb.repository.MongoRepository; + +public interface EventDataRepository extends MongoRepository { +} diff --git a/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/event/EventDataService.java b/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/event/EventDataService.java new file mode 100644 index 0000000..638afee --- /dev/null +++ b/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/event/EventDataService.java @@ -0,0 +1,65 @@ +/* + * ============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.integration.simulators.nfsimulator.vesclient.event; + +import com.google.gson.JsonObject; + +import java.util.List; +import java.util.Optional; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class EventDataService { + private final EventDataRepository repository; + + @Autowired + public EventDataService(EventDataRepository repository) { + this.repository = repository; + } + + private EventData persistEventData(String templateString, String patchedString, String inputString, String keywordsString) { + EventData eventData = EventData.builder() + .template(templateString) + .patched(patchedString) + .input(inputString) + .keywords(keywordsString) + .build(); + return repository.save(eventData); + } + + public EventData persistEventData(JsonObject templateJson, JsonObject patchedJson, JsonObject inputJson, + JsonObject keywordsJson) { + return persistEventData(templateJson.toString(), + patchedJson.toString(), + inputJson.toString(), + keywordsJson.toString()); + } + + public List getAllEvents() { + return repository.findAll(); + } + + public Optional getById(String id) { + return repository.findById(id); + } +} diff --git a/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/filesystem/WatcherConfig.java b/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/filesystem/WatcherConfig.java new file mode 100644 index 0000000..3d99a03 --- /dev/null +++ b/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/filesystem/WatcherConfig.java @@ -0,0 +1,39 @@ +/*- + * ============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.integration.simulators.nfsimulator.vesclient.filesystem; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.task.TaskExecutor; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; + +@Configuration +public class WatcherConfig { + + @Bean + public TaskExecutor watcherTaskExecutor() { + ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); + executor.setThreadNamePrefix("pnfsimulator_fs_watcher"); + executor.initialize(); + return executor; + } + +} diff --git a/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/filesystem/WatcherEventProcessor.java b/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/filesystem/WatcherEventProcessor.java new file mode 100644 index 0000000..15c5d7b --- /dev/null +++ b/src/main/java/org/onap/integration/simulators/nfsimulator/vesclient/filesystem/WatcherEventProcessor.java @@ -0,0 +1,111 @@ +/*- + * ============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.integration.simulators.nfsimulator.vesclient.filesystem; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardWatchEventKinds; +import java.nio.file.WatchEvent; +import java.nio.file.WatchEvent.Kind; +import java.time.Instant; +import java.util.Arrays; +import java.util.Optional; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import lombok.extern.slf4j.Slf4j; +import org.bson.BSONException; +import org.bson.json.JsonParseException; +import org.onap.integration.simulators.nfsimulator.vesclient.db.Storage; +import org.onap.integration.simulators.nfsimulator.vesclient.template.Template; +import org.bson.Document; + +@Slf4j +public enum WatcherEventProcessor { + CREATED(StandardWatchEventKinds.ENTRY_CREATE) { + @Override + public void processEvent(Path path, Storage