OSAM infra seed code - merge with osam-core side-by-side - fixed warnings in onap-enabler POMs
Change-Id: I0cd9ea39d4b7c1dc088ab0ecd6fb787c7f490e5e
Signed-off-by: Aharoni, Pavel (pa0916) <pavel.aharoni@intl.att.com>
diff --git a/osam-core-ext-services-simulator/README.txt b/osam-core-ext-services-simulator/README.txt
new file mode 100644
index 0000000..0332103
--- /dev/null
+++ b/osam-core-ext-services-simulator/README.txt
@@ -0,0 +1,436 @@
+VID Simulator
+************************************************************************************
+
+
+************************************************************************************
+Motivation:
+************************************************************************************
+Allow intuitive and extensible framework for mocking REST calls towards VID external peers,
+both for dev and testing purposes.
+
+
+
+************************************************************************************
+Technologies:
+************************************************************************************
+Spring MVC
+MockServer (Apache License 2.0)
+http://www.mock-server.com
+
+
+
+************************************************************************************
+High-level description:
+************************************************************************************
+
+The Simulator uses MockServer instance running "under the hood" listening to its own HTTP port.
+the Simulator allows to register the expected request and response to the MockServer instance
+with an exposed REST call (see details below), and all other requests are automatically redirected to MockServer.
+If a request was properly registered, the MockServer will reply with an expected response, which will be in turn
+returned by the Simulator to the caller.
+
+The Simulator supports both dynamic and preset (static) registration, looking for JSON files in correct registration format and
+registrating them on startup - see details below under "Preset registration"
+
+Note that the behaviour is generic, and no additional code is expected to be added when there are new
+MSO/AAI/any other component APIs to be mocked. They will just need to be properly registered using the existing API.
+
+
+Simulator can be used in both test and dev modes. You can change the server root of any of VID external REST peers
+to the one of the simulator (see details in "Usage"), and either register the expected request/response dynamically or preset it
+to be loaded during startup. That's it - you're ready to use the simulator either in dev mode, or in test mode by running integration tests vs VID.
+
+
+***********************************************************************************
+Simulator configuration:
+************************************************************************************
+
+Under src/main/resources/:
+
+1) simulator.properties - currently allows to configure the connection details of MockServer, preset registration mode, and other simulator-related props.
+
+2) mockserver.properties - TBD (MockServer logging, SSL etc.)
+
+
+************************************************************************************
+Preset registration:
+************************************************************************************
+
+If enabled in the properties, the Simulator will also run preset registration, looking for JSON files in correct registration format and
+registrating them on startup.
+
+The files must be placed under src/main/resources/preset_registration.
+
+If preset registration is enabled, the simulator will run the scheduler "schedulerDetails" API registration, and any other JSON file which it will find under the folder.
+
+
+get_scheduler_details_short.json:
+
+{
+ "simulatorRequest": {
+ "method": "GET",
+ "path": "/scheduler/v1/ChangeManagement/schedules/scheduleDetails"
+ } ,
+ "simulatorResponse": {
+ "responseCode": 200,
+ "body": "[{\"vnfName\":\"ZRDM1MMSC04c53a\",\"status\":\"Pending Schedule\",\"groupId\":\"\",\"policyId\":\"SNIRO.Config_MS_Demo_TimeLimitAndVerticalTopology_zone\",\"scheduleRequest\":{\"id\":1,\"createDateTime\":\"2017-09-06T13:29:43Z\",\"optimizerDateTime\":\"2017-09-06T13:29:55Z\",\"optimizerMessage\":\"\\n{\\n \\\"requestError\\\": {\\n \\\"serviceException\\\": {\\n \\\"messageId\\\": \\\"SVC0001\\\",\\n \\\"requestId\\\": \\\"CM-c098bd33-a51e-461b-8fd2-6c4d2666c706\\\",\\n \\\"text\\\": \\\"sniro.operation.exceptions.PolicyNotFoundException: Cannot fetch policy SNIRO.Config_MS_Demo_TimeLimitAndVerticalTopology_zone: : HTTPSConnectionPool(host='policypdp-conexus-ist.ecomp.cci.att.com', port=8081): Max retries exceeded with url: \/pdp\/getConfig (Caused by ConnectTimeoutError(<urllib3.connection.VerifiedHTTPSConnection object at 0x7f0ecc00d6d8>, 'Connection to policypdp-conexus-ist.ecomp.cci.att.com timed out. (connect timeout=6.5)'))\\\",\\n \\\"variables\\\": [\\\"severity\\\", 400]\\n }\\n }\\n}\",\"optimizerStatus\":\"HTTP Status: 400\",\"optimizerAttemptsToSchedule\":1,\"optimizerTransactionId\":\"08fb4c32-ecb4-4d72-b618-a6156d3fc53a\",\"scheduleId\":\"08fb4c32-ecb4-4d72-b618-a6156d3fc53a\",\"scheduleName\":\"08fb4c32-ecb4-4d72-b618-a6156d3fc53a\",\"status\":\"Schedule Failed\",\"userId\":\"su7376\",\"domain\":\"ChangeManagement\",\"domainData\":[{\"id\":1,\"name\":\"CallbackData\",\"value\":\"{\\\"requestDetails\\\": [{\\\"vnfInstanceId\\\": \\\"Test\\\", \\\"relatedInstanceList\\\": [{\\\"relatedInstance\\\": {\\\"instanceId\\\": \\\"{serviceInstanceId}\\\", \\\"modelInfo\\\": {\\\"modelName\\\": \\\"{parent service model name}\\\", \\\"modelVersion\\\": \\\"2.0\\\", \\\"modelType\\\": \\\"service\\\", \\\"modelInvariantId\\\": \\\"ff3514e3-5a33-55df-13ab-12abad84e7ff\\\", \\\"modelCustomizationName\\\": \\\"vSAMP12 1\\\", \\\"modelVersionId\\\": \\\"9ebb1521-2e74-47a4-aac7-e71a79f73a79\\\", \\\"modelCustomizationId\\\": \\\"c539433a-84a6-4082-a12e-5c9b00c3b960\\\"}}}], \\\"requestParameters\\\": {\\\"usePreload\\\": \\\"True\\\"}, \\\"requestInfo\\\": {\\\"source\\\": \\\"VID\\\", \\\"requestorId\\\": \\\"az2016\\\", \\\"suppressRollback\\\": \\\"False\\\"}, \\\"vnfName\\\": \\\"Name\\\", \\\"modelInfo\\\": {\\\"modelName\\\": \\\"vSAMP12\\\", \\\"modelVersion\\\": \\\"2.0\\\", \\\"modelType\\\": \\\"vnf\\\", \\\"modelInvariantId\\\": \\\"ff5256d1-5a33-55df-13ab-12abad84e7ff\\\", \\\"modelCustomizationName\\\": \\\"vSAMP12 1\\\", \\\"modelVersionId\\\": \\\"254583ad-b38c-498b-bdbd-b8de5e07541b\\\", \\\"modelCustomizationId\\\": \\\"c539433a-84a6-4082-a12e-5c9b00c3b960\\\"}, \\\"cloudConfiguration\\\": {\\\"lcpCloudRegionId\\\": \\\"mdt1\\\", \\\"tenantId\\\": \\\"88a6ca3ee0394ade9403f075db23167e\\\"}}]}\"},{\"id\":2,\"name\":\"WorkflowName\",\"value\":\"Build Software Upgrade for vNFs\"},{\"id\":3,\"name\":\"CallbackUrl\",\"value\":\"http:\/\/127.0.0.1:8989\/scheduler\/v1\/loopbacktest\/vid\"}],\"scheduleApprovals\":[]},\"schedulesId\":0}]"
+ }
+}
+
+
+************************************************************************************
+Dynamic registration:
+*************************************************************************************
+If you need dynamic registration, register API for dynamic registration:
+
+POST {protocol}://{Tomcat host}:{Tomcat port}/vidSimulator/registerToVidSimulator
+
+To unregister and clear *all* expectations, use DELETE action:
+
+DELETE {protocol}://{Tomcat host}:{Tomcat port}/vidSimulator/registerToVidSimulator
+
+
+***********************************************************************************
+Registration body JSON specification (see and copy/paste examples below):
+***************************************************************************************
+
+
+ "simulatorRequest" - request wrapper.
+
+ Note that from the below fields, it's mandatory to populate at least one.
+ No field is mandatory by itself.
+
+ "id" - String, will be expected as a value in an X-header with a key "x-simulator-id"
+ "method" - String, HTTP method of the request.
+ "path" - String, relative path of the request, MUST be WITH leading slash and WITHOUT trailing slash.
+ "queryParams" - Map<String, List<String>>, query params of key-->list of values.
+ "body" - String, body of the request in case of POST/PUT.
+ Note that JSON String should be properly escaped.
+
+ "simulatorResponse" - response wrapper.
+
+ Note that from the below fields, it's mandatory to populate at least "responseCode".
+
+ "responseCode" - integer, HTTP response code.
+ "responseHeaders" - Dictionary Object with HTTP headers and values.
+ "body" - String, body of the response.
+ Note that JSON String should be properly escaped.
+ "file" - String, a filename of the file sitting in "vid-ext-services-simulator\src\main\resources\download_files"
+ Used for simulating file download requests.
+
+ "misc" - optional configurations.
+ "numberOfTimes" - Integer. Limit this expectation to fire only a
+ given amount of times. Values like -1 or less are
+ treated as "unlimited". Default is unlimited.
+ "replace" - Boolean. If there is already a registered expectation with
+ same simulatorRequest, remove the old registered expectation.
+ If set to 'False' -- the result will be appended to fire
+ after the old registered expectation(s) will fulfill their
+ numberOfTimes. Default is 'True'.
+
+************************************************************************************
+Usage:
+************************************************************************************
+
+1) In system.properties, change the API you want to mock - set server root to be
+{protocol}://{Tomcat host}:{Tomcat port}/vidSimulator (for example http://localhost:7080/vidSimulator)
+
+Example of mocking the scheduler:
+
+#scheduler.server.url=http://mtanjv9sdlg10.aic.cip.att.com:8989/scheduler
+scheduler.server.url=http://localhost:7080/vidSimulator/scheduler
+
+
+2) Check the simulator.properties file under /resources to verify the desired properties of the inner MockServer instance.
+ * Default MockServer URI is http://localhost:1080
+
+3) Build VID and VID Simulator WARs
+
+4) Deploy the Simulator WAR under Tomcat, either same as VID or another instance.
+ * Application context path of the Simulator is /vidSimulator
+
+
+
+********************************************************************************
+Some more examples of usage with demo requests/responses:
+********************************************************************************
+
+
+********************************************************************************
+1) Getting a response by "id" (method and path are insignificant in this case)
+
+********************************************************************************
+Registration:
+-----------------
+
+ Request:
+
+ POST /vidSimulator/registerToVidSimulator HTTP/1.1
+ Host: localhost:7080
+ Content-Type: application/json
+ Cache-Control: no-cache
+ {
+ "simulatorRequest": {
+ "id": "pavelId"
+ } ,
+ "simulatorResponse": {
+ "responseCode": 200,
+ "responseHeaders": {
+ "Content-Type": "application/json"
+ },
+ "body": "{\"value1\": \"kuku\",\"value2\": \"shmuku\"}"
+ }
+ }
+
+
+ Response:
+
+ 200 OK
+ Registration successful!
+
+
+Running:
+--------
+
+
+ Request:
+
+ GET /vidSimulator/scheduler/testApi HTTP/1.1
+ Host: localhost:7080
+ Content-Type: application/json
+ X-Simulator-Id: pavelId
+ Cache-Control: no-cache
+
+ Response:
+
+ 200 OK
+ {
+ "value1": "kuku",
+ "value2": "shmuku"
+ }
+
+
+********************************************************************************
+2) Getting a response by "id", "method" and "path" - sunny and rainy flows
+********************************************************************************
+Registration:
+-------------
+
+ Request:
+
+ POST /vidSimulator/registerToVidSimulator HTTP/1.1
+ Host: localhost:7080
+ Content-Type: application/json
+ Cache-Control: no-cache
+
+ {
+ "simulatorRequest": {
+ "id": "pavelIdGet",
+ "method": "GET",
+ "path": "/scheduler/testApiGet"
+ } ,
+ "simulatorResponse": {
+ "responseCode": 200,
+ "responseHeaders": {
+ "Content-Type": "application/json"
+ },
+ "body": "{\"value1\": \"kukuResponse\",\"value2\": \"shmukuResponse\"}"
+ }
+ }
+
+
+ Response:
+
+ 200 OK
+ Registration successful!
+
+
+Running - sunny flow:
+---------------------
+
+
+ Request:
+
+ GET /vidSimulator/scheduler/testApiGet HTTP/1.1
+ Host: localhost:7080
+ Content-Type: application/json
+ X-Simulator-Id: pavelIdGet
+ Cache-Control: no-cache
+
+ Response:
+
+ 200 OK
+ {
+ "value1": "kukuResponse",
+ "value2": "shmukuResponse"
+ }
+
+
+Running POST - will return 404 since GET method was explicitly registered:
+--------------------------------------------------------------------------
+
+ Request:
+
+ POST /vidSimulator/scheduler/testApiGet HTTP/1.1
+ Host: localhost:7080
+ Content-Type: application/json
+ X-Simulator-Id: pavelIdGet
+ Cache-Control: no-cache
+ {
+ "id": "pavelId",
+ "responseCode": 200,
+ "body": {
+ "value1": "kuku",
+ "value2": "shmuku"
+ }
+ }
+
+ Response:
+
+ 404 Not Found
+
+
+********************************************************************************
+3) Getting an error HTTP response (based on "id" in this example)
+********************************************************************************
+
+Registration:
+-------------
+
+ Request:
+
+ POST /vidSimulator/registerToVidSimulator HTTP/1.1
+ Host: localhost:7080
+ Content-Type: application/json
+ Cache-Control: no-cache
+
+ {
+ "simulatorRequest": {
+ "id": "pavelIdError"
+ } ,
+ "simulatorResponse": {
+ "responseCode": 417
+ }
+ }
+
+ Response:
+
+ 200 OK
+ Registration successful!
+
+Running:
+-----------
+
+ Request:
+
+ GET /vidSimulator/scheduler/anyApi HTTP/1.1
+ Host: localhost:7080
+ Content-Type: application/json
+ X-Simulator-Id: pavelIdError
+ Cache-Control: no-cache
+
+
+ Response:
+
+ 417 Expectation Failed.
+
+
+********************************************************************************
+4) Query params
+********************************************************************************
+
+Registration:
+-------------
+
+ Request:
+
+ POST /vidSimulator/registerToVidSimulator HTTP/1.1
+ Host: localhost:7080
+ Content-Type: application/json
+ Cache-Control: no-cache
+ Postman-Token: 0bbfeb0f-b8b6-368e-6fbd-38a90fc544b4
+
+ {
+ "simulatorRequest": {
+ "method": "GET",
+ "path": "/cloudResourcesRequests/v1",
+ "queryParams": {
+ "requestId" : ["3212b08c-0dcd-4d20-8c84-51e4f325c14a", "3212b08c-0dcd-4d20-8c84-51e4f325c14b"]
+ }
+ } ,
+ "simulatorResponse": {
+ "responseCode": 200,
+ "body": "{\"requestId1\": \"3212b08c-0dcd-4d20-8c84-51e4f325c14a\",\"requestId2\": \"3212b08c-0dcd-4d20-8c84-51e4f325c14b\"}"
+ }
+ }
+
+ Response:
+
+ 200 OK
+ Registration successful!
+
+Running:
+-----------
+
+ Request:
+
+ GET /vidSimulator/cloudResourcesRequests/v1?requestId=3212b08c-0dcd-4d20-8c84-51e4f325c14b&requestId=3212b08c-0dcd-4d20-8c84-51e4f325c14a HTTP/1.1
+ Host: 127.0.0.1:7080
+ Accept: application/json
+ Cache-Control: no-cache
+ Postman-Token: 9ef5d9d2-77f4-7631-7e9f-4404df10acb6
+
+
+ Response:
+
+ 200 OK
+ {"requestId1": "3212b08c-0dcd-4d20-8c84-51e4f325c14a","requestId2": "3212b08c-0dcd-4d20-8c84-51e4f325c14b"}
+
+
+
+********************************************************************************
+5) File Download
+********************************************************************************
+
+Registration:
+-------------
+
+ Request:
+
+ POST /vidSimulator/registerToVidSimulator HTTP/1.1
+ Host: localhost:7080
+ Content-Type: application/json
+ Cache-Control: no-cache
+ Postman-Token: 0bbfeb0f-b8b6-368e-6fbd-38a90fc544b4
+
+ {
+ "simulatorRequest": {
+ "method": "GET",
+ "path": "/vidSimulator/getSomeFile"
+ } ,
+ "simulatorResponse": {
+ "responseCode": 200,
+ "file": "csar3933948645405128424.zip"
+ }
+ }
+
+ Response:
+
+ 200 OK
+ Registration successful!
+
+Running:
+-----------
+
+ Request:
+
+ GET /vidSimulator/getSomeFile HTTP/1.1
+ Host: 127.0.0.1:7080
+ Cache-Control: no-cache
+ Postman-Token: 9ef5d9d2-77f4-7631-7e9f-4404df10acb6
+
+
+ Response:
+
+ 200 OK
+ File for download.
diff --git a/osam-core-ext-services-simulator/pom.xml b/osam-core-ext-services-simulator/pom.xml
new file mode 100644
index 0000000..2c80fa9
--- /dev/null
+++ b/osam-core-ext-services-simulator/pom.xml
@@ -0,0 +1,204 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--/*-
+ * ============LICENSE_START=======================================================
+ * OSAM Core
+ * ================================================================================
+ * Copyright (C) 2018 AT&T
+ * ================================================================================
+ * 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=========================================================
+ */-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.onap.osam</groupId>
+ <artifactId>osam-core-ext-services-simulator</artifactId>
+ <version>1.0.0</version>
+ <name>OSAM Core Simulator</name>
+ <packaging>war</packaging>
+ <description>OSAM Core Simulator for mocking external peers</description>
+
+ <properties>
+ <encoding>UTF-8</encoding>
+ <epsdk.version>1.3.0</epsdk.version>
+ <springframework.version>4.2.0.RELEASE</springframework.version>
+ <hibernate.version>4.3.11.Final</hibernate.version>
+ <!-- Skip assembling the zip by default -->
+ <skipassembly>true</skipassembly>
+ <!-- Tests usually require some setup that maven cannot do, so skip. -->
+ <skiptests>true</skiptests>
+ <!-- this should be commented for local debugging -->
+ <!-- <deployenv>local</deployenv> -->
+ <nexusproxy>https://nexus.onap.org</nexusproxy>
+ <stagingNexusPath>content/repositories/staging/</stagingNexusPath>
+ <snapshotNexusPath>content/repositories/snapshots/</snapshotNexusPath>
+ <releaseNexusPath>content/repositories/releases/</releaseNexusPath>
+
+ <!-- "none" will skip cobertura by default; enable the profile "cobertura" to enable it -->
+ <coberturaBuildPhase>none</coberturaBuildPhase>
+ </properties>
+
+
+ <!--distributionManagement>
+ <repository>
+ <id>vid-releases</id>
+ <name>VID Release Repository</name>
+ <url>https://162.242.254.138:8443/repository/maven-releases</url>
+ </repository>
+
+ <snapshotRepository>
+ <id>vid-snapshots</id>
+ <name>VID Snapshot Repository</name>
+ <url>https://162.242.254.138:8443/repository/maven-snapshots</url>
+ </snapshotRepository>
+ </distributionManagement-->
+
+
+ <profiles>
+
+ <profile>
+ <id>onap</id>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+ <epsdk.version>1.1.0-SNAPSHOT</epsdk.version>
+ <nexusproxy>https://nexus.onap.org</nexusproxy>
+ <snapshotNexusPath>/content/repositories/snapshots/</snapshotNexusPath>
+ <releaseNexusPath>/content/repositories/releases/</releaseNexusPath>
+ <stagingNexusPath>/content/repositories/staging/</stagingNexusPath>
+ <sitePath>/content/sites/site/org/openecomp/vid/${project.version}</sitePath>
+ </properties>
+
+ <repositories>
+ <repository>
+ <id>oss-snapshots</id>
+ <name>oss Central - Snapshots</name>
+ <url>https://oss.sonatype.org/service/local/repositories/releases/content/</url>
+ </repository>
+ </repositories>
+ </profile>
+
+ <profile>
+ <id>default</id>
+
+
+ </profile>
+
+ <!-- disable doclint, a new feature in Java 8, when generating javadoc -->
+ <profile>
+ <id>doclint-java8-disable</id>
+ <activation>
+ <jdk>[1.8,)</jdk>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>2.10.4</version>
+ <configuration>
+ <additionalparam>-Xdoclint:none</additionalparam>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+
+ <profile>
+ <id>cobertura</id>
+ <properties>
+ <coberturaBuildPhase>package</coberturaBuildPhase>
+ </properties>
+ </profile>
+ </profiles>
+
+ <dependencies>
+ <!-- mockserver -->
+ <dependency>
+ <groupId>org.mock-server</groupId>
+ <artifactId>mockserver-netty</artifactId>
+ <version>3.11</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ <version>4.3.4.RELEASE</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-webmvc</artifactId>
+ <version>4.3.4.RELEASE</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-annotations</artifactId>
+ <version>2.8.7</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.xml.bind</groupId>
+ <artifactId>jaxb-api</artifactId>
+ <version>2.2.11</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <finalName>simulator</finalName>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>license-maven-plugin</artifactId>
+ <version>1.16</version>
+ <configuration>
+ <addJavaLicenseAfterPackage>false</addJavaLicenseAfterPackage>
+ <processStartTag>============LICENSE_START=======================================================</processStartTag>
+ <processEndTag>============LICENSE_END=========================================================</processEndTag>
+ <sectionDelimiter>================================================================================</sectionDelimiter>
+ <licenseName>apache_v2</licenseName>
+ <inceptionYear>2018</inceptionYear>
+ <organizationName>AT&T</organizationName>
+ <projectName>OSAM</projectName>
+ <canUpdateCopyright>true</canUpdateCopyright>
+ <canUpdateDescription>true</canUpdateDescription>
+ <canUpdateLicense>true</canUpdateLicense>
+ <emptyLineAfterHeader>true</emptyLineAfterHeader>
+ <verbose>false</verbose>
+ <includes>
+ <include>**/*.java</include>
+ </includes>
+ </configuration>
+ <executions>
+ <execution>
+ <id>first</id>
+ <goals>
+ <goal>update-file-header</goal>
+ </goals>
+ <phase>process-sources</phase>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.1</version>
+ <configuration>
+ <source>1.8</source>
+ <target>1.8</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
\ No newline at end of file
diff --git a/osam-core-ext-services-simulator/src/main/java/org/onap/simulator/controller/SimulatorController.java b/osam-core-ext-services-simulator/src/main/java/org/onap/simulator/controller/SimulatorController.java
new file mode 100644
index 0000000..34e7a13
--- /dev/null
+++ b/osam-core-ext-services-simulator/src/main/java/org/onap/simulator/controller/SimulatorController.java
@@ -0,0 +1,356 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OSAM
+ * ================================================================================
+ * Copyright (C) 2018 AT&T
+ * ================================================================================
+ * 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.simulator.controller;
+
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.mockserver.integration.ClientAndServer;
+import org.mockserver.matchers.Times;
+import org.mockserver.model.HttpRequest;
+import org.mockserver.model.HttpResponse;
+import static org.mockserver.model.HttpRequest.request;
+import static org.mockserver.model.HttpResponse.response;
+
+import org.mockserver.model.JsonBody;
+import org.onap.simulator.errorHandling.VidSimulatorException;
+import org.onap.simulator.model.SimulatorRequestResponseExpectation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
+import org.springframework.core.io.support.PropertiesLoaderUtils;
+import org.springframework.core.io.support.ResourcePatternResolver;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Component;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.servlet.HandlerMapping;
+import org.springframework.web.servlet.View;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.*;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.stream.Collectors;
+
+import static org.mockserver.integration.ClientAndServer.startClientAndServer;
+import static org.mockserver.matchers.Times.exactly;
+
+@RestController
+@Component
+public class SimulatorController {
+
+ private static final Times DEFAULT_NUMBER_OF_TIMES = Times.unlimited();
+ private ClientAndServer mockServer;
+ private String mockServerProtocol;
+ private String mockServerHost;
+ private Integer mockServerPort;
+ private Boolean enablePresetRegistration;
+ private volatile boolean isInitialized = false;
+
+
+ Logger logger = LoggerFactory.getLogger(SimulatorController.class);
+
+ @PostConstruct
+ public void init(){
+ logger.info("Starting VID Simulator....");
+ setProperties();
+ mockServer = startClientAndServer(mockServerPort);
+ presetRegister();
+ isInitialized = true;
+ logger.info("VID Simulator started successfully");
+ }
+
+ @PreDestroy
+ public void tearDown(){
+ logger.info("Stopping VID Simulator....");
+ isInitialized = false;
+ mockServer.stop();
+ }
+
+
+ private void presetRegister() {
+ //Checking if set
+ if (enablePresetRegistration == null || !enablePresetRegistration){
+ logger.info("Preset registration property is false or not set - skipping preset registration...");
+ return;
+ }
+ ClassLoader cl = this.getClass().getClassLoader();
+ ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(cl);
+ List<Path> resources = new ArrayList<>();
+ try {
+ File presetDir = resolver.getResource("/preset_registration/").getFile();
+ if (presetDir.exists() && presetDir.isDirectory()) {
+ resources = Files.walk(Paths.get(presetDir.getPath()))
+ .filter(p -> p.toString().endsWith(".json"))
+ .collect(Collectors.toList());
+ } else {
+ logger.error("preset_registration directory is not exists");
+ }
+ } catch (IOException e) {
+ logger.error("Error performing preset registration, error: ", e);
+ return;
+ }
+ logger.info("Starting preset registrations, number of requests: {}", resources.size());
+ for (Path resource: resources){
+ String content;
+ try {
+ content = new Scanner(resource).useDelimiter("\\Z").next();
+ } catch (IOException e){
+ logger.error("Error reading preset registration file {}, skipping to next one. Error: ", resource.getFileName(), e);
+ continue;
+ }
+ //register the preset request
+ try {
+ register(content);
+ } catch (VidSimulatorException e) {
+ logger.error("Error proceeding preset registration file {},skipping to next one. Check if the JSON is in correct format. Error: ", resource.getFileName(), e);
+ }
+ }
+ }
+
+
+
+ private void setProperties() {
+ Resource resource = new ClassPathResource("simulator.properties");
+ Properties props = new Properties();
+ try {
+ props = PropertiesLoaderUtils.loadProperties(resource);
+ } catch (IOException e) {
+ logger.error("Error loading simulator properties, error: ", e);
+ return;
+ }
+ logger.info("Simulator properties are {}", props);
+ mockServerProtocol = (String)props.get("simulator.mockserver.protocol");
+ mockServerHost = (String)props.get("simulator.mockserver.host");
+ mockServerPort = Integer.parseInt((String)props.get("simulator.mockserver.port"));
+ enablePresetRegistration = Boolean.parseBoolean((String)props.get("simulator.enablePresetRegistration"));
+ }
+
+ @RequestMapping(value = {"/registerToVidSimulator"}, method = RequestMethod.POST)
+ public @ResponseBody
+ ResponseEntity registerRequest(HttpServletRequest request, @RequestBody String expectation) {
+ try {
+ register(expectation);
+ } catch (VidSimulatorException e) {
+ return new ResponseEntity<>("Registration failure! Error: "+e.getMessage(),HttpStatus.BAD_REQUEST);
+ }
+ return new ResponseEntity<>("Registration successful!",HttpStatus.OK);
+ }
+
+ @RequestMapping(value = {"/echo"}, method = RequestMethod.GET)
+ ResponseEntity echo(HttpServletRequest request) {
+ return isInitialized ? new ResponseEntity<>("",HttpStatus.OK) : new ResponseEntity<>("",HttpStatus.SERVICE_UNAVAILABLE);
+ }
+
+// @RequestMapping(value = {"/registerToVidSimulator"}, method = RequestMethod.GET)
+// public ResponseEntity<String> getAllRegisteredRequests() throws JsonProcessingException {
+// final Expectation[] expectations = mockServer.retrieveExistingExpectations(null);
+// return new ResponseEntity<>(new ObjectMapper()
+// .configure(SerializationFeature.INDENT_OUTPUT, true)
+// .writeValueAsString(expectations), HttpStatus.OK);
+// }
+
+ @RequestMapping(value = {"/registerToVidSimulator"}, method = RequestMethod.DELETE)
+ @ResponseStatus(value = HttpStatus.OK)
+ public void wipeOutAllExpectations() {
+ mockServer.reset();
+ }
+
+ private void register(String expectation) throws VidSimulatorException{
+ ObjectMapper mapper = new ObjectMapper()
+ .configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
+
+ SimulatorRequestResponseExpectation[] expectationModels;
+ try {
+ expectationModels = mapper.readValue(expectation, SimulatorRequestResponseExpectation[].class);
+ } catch (IOException e) {
+ logger.error("Couldn't deserialize register expectation {}, error:", expectation, e);
+ throw new VidSimulatorException(e.getMessage());
+ }
+
+ for (SimulatorRequestResponseExpectation expectationModel : expectationModels) {
+ logger.info("Proceeding registration request: {}", expectationModel);
+ register(expectationModel);
+ }
+ }
+
+
+ @RequestMapping(value = {"/**"})
+ public String redirectToMockServer(HttpServletRequest request, HttpServletResponse response) {
+ //Currently, the easiest logic is redirecting
+
+ //This is needed to allow POST redirect - see http://www.baeldung.com/spring-redirect-and-forward
+ request.setAttribute(View.RESPONSE_STATUS_ATTRIBUTE, HttpStatus.TEMPORARY_REDIRECT);
+
+ //Building the redirect URL
+ String restOfTheUrl = (String) request.getAttribute(
+ HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
+
+ //TODO encode only characters like spaces, not slashes
+ /* try {
+ restOfTheUrl = URLEncoder.encode(restOfTheUrl, "UTF-8");
+ restOfTheUrl = restOfTheUrl.replaceAll("%2F", "/");
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }*/
+
+ StringBuilder sb = new StringBuilder();
+ sb.append(mockServerProtocol+"://"+mockServerHost+":"+mockServerPort+"/"+restOfTheUrl);
+ String queryString = request.getQueryString();
+ if (queryString != null){
+ sb.append("?").append(queryString);
+ }
+ String redirectUrl = sb.toString();
+ logger.info("Redirecting the request to : {}", redirectUrl);
+ return ("redirect:"+redirectUrl);
+
+ //This was a try to setup a proxy instead of redirect
+ //Abandoned this direction when trying to return the original HTTP error code which was registered to mock server, instead of wrapped up HTTP 500.
+
+ /* String restOfTheUrl = "/"+(String) request.getAttribute(
+ HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
+ URI uri = null;
+ try {
+ uri = new URI("http", null, "localhost", 1080, restOfTheUrl, request.getQueryString(), null);
+ } catch (URISyntaxException e) {
+ logger.error("Error during proxying request {}, error: ", request.getRequestURI(), e.getMessage());
+ return new ResponseEntity(e.getMessage(),HttpStatus.INTERNAL_SERVER_ERROR);
+ }
+ RestTemplate restTemplate = new RestTemplate();
+ //Preparing the headers
+ HttpHeaders headers = new HttpHeaders();
+ Enumeration<String> headerNames = request.getHeaderNames();
+ while (headerNames.hasMoreElements()){
+ String headerToSet = headerNames.nextElement();
+ headers.set(headerToSet, request.getHeader(headerToSet));
+ }
+
+ ResponseEntity<String> responseEntity =
+ restTemplate.exchange(uri, HttpMethod.resolve(request.getMethod()), new HttpEntity<String>(body, headers), String.class);
+
+ return responseEntity;*/
+ }
+
+ private void register(SimulatorRequestResponseExpectation expectationModel) throws VidSimulatorException{
+ //Setting request according to what is passed
+ HttpRequest request = HttpRequest.request();
+ String id = expectationModel.getSimulatorRequest().getId();
+ if (id != null) {
+ request.withHeader("x-simulator-id", id);
+ }
+ String method = expectationModel.getSimulatorRequest().getMethod();
+ if (method != null) {
+ request.withMethod(method);
+ }
+ String path = expectationModel.getSimulatorRequest().getPath();
+ if (path != null) {
+ request.withPath(path);
+ }
+ String body = expectationModel.getSimulatorRequest().getBody();
+ if (body != null) {
+ request.withBody(new JsonBody(body));
+ }
+
+ //Queryparams
+ final Map<String, List<String>> queryParams = expectationModel.getSimulatorRequest().getQueryParams();
+ if (queryParams != null){
+ String[] arr = new String[0];
+ queryParams.entrySet().stream().forEach(x -> {
+ request.withQueryStringParameter(x.getKey(), x.getValue().toArray(arr));
+ });
+ }
+
+ //Setting response according to what is passed
+ HttpResponse response = HttpResponse.response();
+ Integer responseCode = expectationModel.getSimulatorResponse().getResponseCode();
+ if (responseCode != null) {
+ response.withStatusCode(responseCode);
+ } else {
+ logger.error("Invalid registration - response code cannot be empty");
+ throw new VidSimulatorException("Invalid registration - response code cannot be empty");
+ }
+
+ String respBody = expectationModel.getSimulatorResponse().getBody();
+ if (respBody != null) {
+ response.withBody(respBody);
+ }
+
+ String file = expectationModel.getSimulatorResponse().getFile();
+ if (file != null) {
+ response.withBody(loadFileString(file));
+ }
+
+ Map<String, String> responseHeaders = expectationModel.getSimulatorResponse().getResponseHeaders();
+ if (responseHeaders != null) {
+ responseHeaders.forEach(response::withHeader);
+ }
+
+ Times numberOfTimes = getExpectationNumberOfTimes(expectationModel);
+
+ if (expectationModel.getMisc().getReplace()) {
+ logger.info("Unregistering request expectation, if previously set, request: {}", expectationModel.getSimulatorRequest());
+ mockServer.clear(request);
+ }
+
+ mockServer
+ .when(request, numberOfTimes).respond(response);
+ }
+
+
+ private byte[] loadFileString(String filePath) {
+ byte[] bytes = null;
+ try {
+ File file = new ClassPathResource("download_files/" + filePath).getFile();
+ bytes = new byte[(int)file.length()];
+ DataInputStream dataInputStream = null;
+
+ dataInputStream = new DataInputStream(new BufferedInputStream(new FileInputStream(file.getPath())));
+ dataInputStream.readFully(bytes);
+ dataInputStream.close();
+ } catch (FileNotFoundException e) {
+ logger.error("File not found for file:" + filePath);
+ e.printStackTrace();
+ } catch (IOException e) {
+ logger.error("Error reading file:" + filePath);
+ e.printStackTrace();
+ }
+
+ return bytes;
+ }
+ private Times getExpectationNumberOfTimes(SimulatorRequestResponseExpectation expectationModel) {
+ Integer expectationModelNumberOfTimes = expectationModel.getMisc().getNumberOfTimes();
+ Times effectiveNumberOfTimes;
+ if (expectationModelNumberOfTimes == null || expectationModelNumberOfTimes < 0) {
+ effectiveNumberOfTimes = DEFAULT_NUMBER_OF_TIMES;
+ } else {
+ effectiveNumberOfTimes = exactly(expectationModelNumberOfTimes);
+ }
+ return effectiveNumberOfTimes;
+ }
+}
diff --git a/osam-core-ext-services-simulator/src/main/java/org/onap/simulator/errorHandling/VidSimulatorException.java b/osam-core-ext-services-simulator/src/main/java/org/onap/simulator/errorHandling/VidSimulatorException.java
new file mode 100644
index 0000000..28b8425
--- /dev/null
+++ b/osam-core-ext-services-simulator/src/main/java/org/onap/simulator/errorHandling/VidSimulatorException.java
@@ -0,0 +1,27 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OSAM
+ * ================================================================================
+ * Copyright (C) 2018 AT&T
+ * ================================================================================
+ * 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.simulator.errorHandling;
+
+public class VidSimulatorException extends Exception {
+
+ public VidSimulatorException(String message) {
+ super(message);
+ }
+}
diff --git a/osam-core-ext-services-simulator/src/main/java/org/onap/simulator/model/Misc.java b/osam-core-ext-services-simulator/src/main/java/org/onap/simulator/model/Misc.java
new file mode 100644
index 0000000..48ca529
--- /dev/null
+++ b/osam-core-ext-services-simulator/src/main/java/org/onap/simulator/model/Misc.java
@@ -0,0 +1,49 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OSAM
+ * ================================================================================
+ * Copyright (C) 2018 AT&T
+ * ================================================================================
+ * 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.simulator.model;
+
+public class Misc {
+ private Integer numberOfTimes;
+ private boolean replace = true;
+
+ public Integer getNumberOfTimes() {
+ return numberOfTimes;
+ }
+
+ public void setNumberOfTimes(Integer numberOfTimes) {
+ this.numberOfTimes = numberOfTimes;
+ }
+
+ public boolean getReplace() {
+ return replace;
+ }
+
+ public void setReplace(Boolean replace) {
+ this.replace = replace;
+ }
+
+ @Override
+ public String toString() {
+ return "Misc{" +
+ "numberOfTimes='" + numberOfTimes + '\'' +
+ ", replace='" + replace + '\'' +
+ '}';
+ }
+}
diff --git a/osam-core-ext-services-simulator/src/main/java/org/onap/simulator/model/SimulatorRequest.java b/osam-core-ext-services-simulator/src/main/java/org/onap/simulator/model/SimulatorRequest.java
new file mode 100644
index 0000000..5e1197e
--- /dev/null
+++ b/osam-core-ext-services-simulator/src/main/java/org/onap/simulator/model/SimulatorRequest.java
@@ -0,0 +1,86 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OSAM
+ * ================================================================================
+ * Copyright (C) 2018 AT&T
+ * ================================================================================
+ * 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.simulator.model;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.databind.JsonNode;
+
+import java.util.List;
+import java.util.Map;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class SimulatorRequest {
+ private String id;
+ private String method;
+ private String path;
+ private String body;
+ private Map<String, List<String>> queryParams;
+
+ public Map<String, List<String>> getQueryParams() {
+ return queryParams;
+ }
+
+ public void setQueryParams(Map<String, List<String>> queryParams) {
+ this.queryParams = queryParams;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getMethod() {
+ return method;
+ }
+
+ public void setMethod(String method) {
+ this.method = method;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ public String getBody() {
+ return body;
+ }
+
+ public void setBody(JsonNode body) {
+ this.body = body.isTextual() ? body.textValue() : body.toString();
+ }
+
+ @Override
+ public String toString() {
+ return "SimulatorRequest{" +
+ "id='" + id + '\'' +
+ ", method='" + method + '\'' +
+ ", path='" + path + '\'' +
+ ", body='" + body + '\'' +
+ ", queryParams=" + queryParams +
+ '}';
+ }
+}
diff --git a/osam-core-ext-services-simulator/src/main/java/org/onap/simulator/model/SimulatorRequestResponseExpectation.java b/osam-core-ext-services-simulator/src/main/java/org/onap/simulator/model/SimulatorRequestResponseExpectation.java
new file mode 100644
index 0000000..70ee234
--- /dev/null
+++ b/osam-core-ext-services-simulator/src/main/java/org/onap/simulator/model/SimulatorRequestResponseExpectation.java
@@ -0,0 +1,67 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OSAM
+ * ================================================================================
+ * Copyright (C) 2018 AT&T
+ * ================================================================================
+ * 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.simulator.model;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class SimulatorRequestResponseExpectation {
+
+ Logger logger = LoggerFactory.getLogger(SimulatorRequestResponseExpectation.class);
+
+ private SimulatorRequest simulatorRequest;
+ private SimulatorResponse simulatorResponse;
+ private Misc misc;
+
+ public SimulatorRequest getSimulatorRequest() {
+ return simulatorRequest;
+ }
+
+ public void setSimulatorRequest(SimulatorRequest simulatorRequest) {
+ this.simulatorRequest = simulatorRequest;
+ }
+
+ public SimulatorResponse getSimulatorResponse() {
+ return simulatorResponse;
+ }
+
+ public void setSimulatorResponse(SimulatorResponse simulatorResponse) {
+ this.simulatorResponse = simulatorResponse;
+ }
+
+ public Misc getMisc() {
+ return misc == null ? new Misc() : misc;
+ }
+
+ public void setMisc(Misc misc) {
+ this.misc = misc;
+ }
+
+ @Override
+ public String toString() {
+ return "ExpectationModel{" +
+ "simulatorRequest=" + simulatorRequest +
+ ", simulatorResponse=" + simulatorResponse +
+ ", misc=" + misc +
+ '}';
+ }
+}
diff --git a/osam-core-ext-services-simulator/src/main/java/org/onap/simulator/model/SimulatorResponse.java b/osam-core-ext-services-simulator/src/main/java/org/onap/simulator/model/SimulatorResponse.java
new file mode 100644
index 0000000..536be2d
--- /dev/null
+++ b/osam-core-ext-services-simulator/src/main/java/org/onap/simulator/model/SimulatorResponse.java
@@ -0,0 +1,78 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OSAM
+ * ================================================================================
+ * Copyright (C) 2018 AT&T
+ * ================================================================================
+ * 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.simulator.model;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.databind.JsonNode;
+
+import java.util.Map;
+
+public class SimulatorResponse {
+ private int responseCode;
+ private Map<String, String> responseHeaders;
+
+ @JsonInclude(JsonInclude.Include.NON_NULL)
+ private String body;
+
+ @JsonInclude(JsonInclude.Include.NON_NULL)
+ private String file;
+
+ public int getResponseCode() {
+ return responseCode;
+ }
+
+ public void setResponseCode(int responseCode) {
+ this.responseCode = responseCode;
+ }
+
+ public String getBody() {
+ return body;
+ }
+
+ public void setBody(JsonNode body) {
+ this.body = body.isTextual() ? body.textValue() : body.toString();
+ }
+
+ public Map<String, String> getResponseHeaders() {
+ return responseHeaders;
+ }
+
+ public void setResponseHeaders(Map<String, String> responseHeaders) {
+ this.responseHeaders = responseHeaders;
+ }
+
+ public String getFile() {
+ return file;
+ }
+
+ public void setFile(String file) {
+ this.file = file;
+ }
+
+ @Override
+ public String toString() {
+ return "SimulatorResponse{" +
+ "responseCode=" + responseCode +
+ ", body='" + body + '\'' +
+ ", file='" + file + '\'' +
+ ", responseHeaders='" + responseHeaders + '\'' +
+ '}';
+ }
+}
diff --git a/osam-core-ext-services-simulator/src/main/java/org/onap/simulator/service/TranslatorService.java b/osam-core-ext-services-simulator/src/main/java/org/onap/simulator/service/TranslatorService.java
new file mode 100644
index 0000000..4158477
--- /dev/null
+++ b/osam-core-ext-services-simulator/src/main/java/org/onap/simulator/service/TranslatorService.java
@@ -0,0 +1,38 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OSAM
+ * ================================================================================
+ * Copyright (C) 2018 AT&T
+ * ================================================================================
+ * 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.simulator.service;
+//
+//import org.mockserver.model.HttpRequest;
+//import org.mockserver.model.HttpResponse;
+//import org.onap.simulator.model.ExpectationModel;
+//import org.springframework.stereotype.Component;
+//
+//import static org.mockserver.model.HttpRequest.request;
+//@Component
+//public class TranslatorService {
+// public HttpRequest buildRequestByJson(ExpectationModel expectation){
+// return expectation.getExpectationRequest();
+// }
+// public HttpResponse buildResponseByJson(ExpectationModel expectation){
+// return expectation.getExpectationResponse();
+// }
+//
+//
+//}
diff --git a/osam-core-ext-services-simulator/src/main/resources/preset_registration/get_pods.json b/osam-core-ext-services-simulator/src/main/resources/preset_registration/get_pods.json
new file mode 100644
index 0000000..0610eee
--- /dev/null
+++ b/osam-core-ext-services-simulator/src/main/resources/preset_registration/get_pods.json
@@ -0,0 +1,233 @@
+{
+ "simulatorRequest": {
+ "method": "GET",
+ "path": "/aai/v../network/zones"
+ },
+ "simulatorResponse": {
+ "responseCode": 200,
+ "body": {
+ "zone": [
+ {
+ "zone-id": "NFT1",
+ "zone-name": "NFTJSSSS-NFT1"
+ },
+ {
+ "zone-id": "JAG1",
+ "zone-name": "YUDFJULP-JAG1"
+ },
+ {
+ "zone-id": "YYY1",
+ "zone-name": "UUUAIAAI-YYY1"
+ },
+ {
+ "zone-id": "BAN1",
+ "zone-name": "VSDKYUTP-BAN1"
+ },
+ {
+ "zone-id": "DKJ1",
+ "zone-name": "DKJSJDKA-DKJ1"
+ },
+ {
+ "zone-id": "MCS1",
+ "zone-name": "ASACMAMS-MCS1"
+ },
+ {
+ "zone-id": "UIO1",
+ "zone-name": "uioclli1-UIO1"
+ },
+ {
+ "zone-id": "RAJ1",
+ "zone-name": "YGBIJNLQ-RAJ1"
+ },
+ {
+ "zone-id": "OPA1",
+ "zone-name": "opaclli1-OPA1"
+ },
+ {
+ "zone-id": "SDE1",
+ "zone-name": "ZXCVBNMA-SDE1"
+ },
+ {
+ "zone-id": "VEN2",
+ "zone-name": "FGHJUHIL-VEN2"
+ },
+ {
+ "zone-id": "ORL1",
+ "zone-name": "ORLDFLMA-ORL1"
+ },
+ {
+ "zone-id": "JAD1",
+ "zone-name": "JADECLLI-JAD1"
+ },
+ {
+ "zone-id": "ZXL1",
+ "zone-name": "LWLWCANN-ZXL1"
+ },
+ {
+ "zone-id": "CKL1",
+ "zone-name": "CLKSKCKK-CKL1"
+ },
+ {
+ "zone-id": "SDF1",
+ "zone-name": "sdfclli1-SDF1"
+ },
+ {
+ "zone-id": "RAD1",
+ "zone-name": "RADICAL1-RAD1"
+ },
+ {
+ "zone-id": "KIT1",
+ "zone-name": "BHYJFGLN-KIT1"
+ },
+ {
+ "zone-id": "REL1",
+ "zone-name": "INGERFGT-REL1"
+ },
+ {
+ "zone-id": "JNL1",
+ "zone-name": "CJALSDAC-JNL1"
+ },
+ {
+ "zone-id": "OLK1",
+ "zone-name": "OLKOLKLS-OLK1"
+ },
+ {
+ "zone-id": "CHI1",
+ "zone-name": "CHILLIWE-CHI1"
+ },
+ {
+ "zone-id": "UUU4",
+ "zone-name": "UUUAAAUU-UUU4"
+ },
+ {
+ "zone-id": "TUF1",
+ "zone-name": "TUFCLLI1-TUF1"
+ },
+ {
+ "zone-id": "KJN1",
+ "zone-name": "CKALDKSA-KJN1"
+ },
+ {
+ "zone-id": "SAM1",
+ "zone-name": "SNDGCA64-SAN1"
+ },
+ {
+ "zone-id": "SCK1",
+ "zone-name": "SCKSCKSK-SCK1"
+ },
+ {
+ "zone-id": "HJH1",
+ "zone-name": "AOEEQQQD-HJH1"
+ },
+ {
+ "zone-id": "HGD1",
+ "zone-name": "SDFQWHGD-HGD1"
+ },
+ {
+ "zone-id": "KOR1",
+ "zone-name": "HYFLNBVT-KOR1"
+ },
+ {
+ "zone-id": "ATL43",
+ "zone-name": "AICLOCID-ATL43"
+ },
+ {
+ "zone-id": "ATL54",
+ "zone-name": "AICFTAAI-ATL54"
+ },
+ {
+ "zone-id": "ATL66",
+ "zone-name": "CLLIAAII-ATL66"
+ },
+ {
+ "zone-id": "VEL1",
+ "zone-name": "BNMLKUIK-VEL1"
+ },
+ {
+ "zone-id": "ICC1",
+ "zone-name": "SANJITAT-ICC1"
+ },
+ {
+ "zone-id": "MNT11",
+ "zone-name": "WSXEFBTH-MNT11"
+ },
+ {
+ "zone-id": "DEF2",
+ "zone-name": "WSBHGTYL-DEF2"
+ },
+ {
+ "zone-id": "MAD11",
+ "zone-name": "SDFQWGKL-MAD11"
+ },
+ {
+ "zone-id": "OLG1",
+ "zone-name": "OLHOLHOL-OLG1"
+ },
+ {
+ "zone-id": "GAR1",
+ "zone-name": "NGFVSJKO-GAR1"
+ },
+ {
+ "zone-id": "SAN22",
+ "zone-name": "GNVLSCTL-SAN22"
+ },
+ {
+ "zone-id": "HRG1",
+ "zone-name": "HRGHRGGS-HRG1"
+ },
+ {
+ "zone-id": "JCS1",
+ "zone-name": "JCSJSCJS-JCS1"
+ },
+ {
+ "zone-id": "DHA12",
+ "zone-name": "WSXEDECF-DHA12"
+ },
+ {
+ "zone-id": "HJE1",
+ "zone-name": "AOEEWWWD-HJE1"
+ },
+ {
+ "zone-id": "NCA1",
+ "zone-name": "NCANCANN-NCA1"
+ },
+ {
+ "zone-id": "IOP1",
+ "zone-name": "iopclli1-IOP1"
+ },
+ {
+ "zone-id": "RTY1",
+ "zone-name": "rtyclli1-RTY1"
+ },
+ {
+ "zone-id": "KAP1",
+ "zone-name": "HIOUYTRQ-KAP1"
+ },
+ {
+ "zone-id": "ZEN1",
+ "zone-name": "ZENCLLI1-ZEN1"
+ },
+ {
+ "zone-id": "HKA1",
+ "zone-name": "JAKHLASS-HKA1"
+ },
+ {
+ "zone-id": "CQK1",
+ "zone-name": "CQKSCAKK-CQK1"
+ },
+ {
+ "zone-id": "SAI1",
+ "zone-name": "UBEKQLPD-SAI1"
+ },
+ {
+ "zone-id": "ERT1",
+ "zone-name": "ertclli1-ERT1"
+ },
+ {
+ "zone-id": "IBB1",
+ "zone-name": "PLMKOIJU-IBB1"
+ }
+ ]
+ }
+ }
+}
\ No newline at end of file
diff --git a/osam-core-ext-services-simulator/src/main/resources/simulator.properties b/osam-core-ext-services-simulator/src/main/resources/simulator.properties
new file mode 100644
index 0000000..cacccb8
--- /dev/null
+++ b/osam-core-ext-services-simulator/src/main/resources/simulator.properties
@@ -0,0 +1,8 @@
+#MockServer startup details
+
+simulator.mockserver.protocol = http
+simulator.mockserver.host = localhost
+simulator.mockserver.port = 1080
+
+#Simulator proprietary
+simulator.enablePresetRegistration=true
\ No newline at end of file
diff --git a/osam-core-ext-services-simulator/src/main/webapp/WEB-INF/rest-servlet.xml b/osam-core-ext-services-simulator/src/main/webapp/WEB-INF/rest-servlet.xml
new file mode 100644
index 0000000..0f2c0c0
--- /dev/null
+++ b/osam-core-ext-services-simulator/src/main/webapp/WEB-INF/rest-servlet.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--/*-
+ * ============LICENSE_START=======================================================
+ * OSAM Core
+ * ================================================================================
+ * Copyright (C) 2018 AT&T
+ * ================================================================================
+ * 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=========================================================
+ */-->
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:aop="http://www.springframework.org/schema/aop" xmlns:util="http://www.springframework.org/schema/util"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
+ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
+ http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">
+
+
+ <context:component-scan
+ base-package="org.onap.simulator" />
+</beans>
\ No newline at end of file
diff --git a/osam-core-ext-services-simulator/src/main/webapp/WEB-INF/web.xml b/osam-core-ext-services-simulator/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..2826bac
--- /dev/null
+++ b/osam-core-ext-services-simulator/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--/*-
+ * ============LICENSE_START=======================================================
+ * OSAM Core
+ * ================================================================================
+ * Copyright (C) 2018 AT&T
+ * ================================================================================
+ * 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=========================================================
+ */-->
+<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0">
+ <servlet>
+ <servlet-name>rest</servlet-name>
+ <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>rest</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>
\ No newline at end of file
diff --git a/osam-core-ext-services-simulator/version.properties b/osam-core-ext-services-simulator/version.properties
new file mode 100644
index 0000000..c89baa3
--- /dev/null
+++ b/osam-core-ext-services-simulator/version.properties
@@ -0,0 +1,13 @@
+# Versioning variables
+# Note that these variables cannot be structured (e.g. : version.release or version.snapshot etc... )
+# because they are used in Jenkins, whose plug-in doesn't support
+
+major=0
+minor=0
+patch=1
+
+base_version=${major}.${minor}.${patch}
+
+# Release must be completed with git revision # in Jenkins
+release_version=${base_version}
+snapshot_version=${base_version}-SNAPSHOT