Merge "Fix issue where user cannot create a recipe via"
[so.git] / adapters / mso-catalog-db-adapter / src / test / java / org / onap / so / adapters / catalogdb / catalogrest / CatalogDBRestTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.adapters.catalogdb.catalogrest;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.onap.logging.ref.slf4j.ONAPLogConstants.MDCs.INVOCATION_ID;
26 import static org.onap.logging.ref.slf4j.ONAPLogConstants.MDCs.LOG_TIMESTAMP;
27 import static org.onap.logging.ref.slf4j.ONAPLogConstants.MDCs.PARTNER_NAME;
28 import static org.onap.logging.ref.slf4j.ONAPLogConstants.MDCs.RESPONSE_CODE;
29 import static org.onap.logging.ref.slf4j.ONAPLogConstants.MDCs.RESPONSE_DESCRIPTION;
30 import static org.onap.logging.ref.slf4j.ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE;
31 import static org.onap.logging.ref.slf4j.ONAPLogConstants.MDCs.SERVICE_NAME;
32 import java.io.IOException;
33 import java.util.Map;
34 import javax.ws.rs.core.MediaType;
35 import javax.ws.rs.core.Response;
36 import org.json.JSONException;
37 import org.junit.Test;
38 import org.onap.logging.ref.slf4j.ONAPLogConstants;
39 import org.onap.so.adapters.catalogdb.CatalogDbAdapterBaseTest;
40 import org.onap.so.db.catalog.beans.ServiceRecipe;
41 import org.skyscreamer.jsonassert.JSONAssert;
42 import org.skyscreamer.jsonassert.JSONCompareMode;
43 import org.springframework.boot.test.web.client.TestRestTemplate;
44 import org.springframework.http.HttpEntity;
45 import org.springframework.http.HttpHeaders;
46 import org.springframework.http.HttpMethod;
47 import org.springframework.http.ResponseEntity;
48 import org.springframework.web.util.UriComponentsBuilder;
49 import ch.qos.logback.classic.spi.ILoggingEvent;
50
51
52 public class CatalogDBRestTest extends CatalogDbAdapterBaseTest {
53
54     private static final String ECOMP_MSO_CATALOG_V2_VF_MODULES = "ecomp/mso/catalog/v2/vfModules";
55
56     private static final String SERVICE_RECIPE = "serviceRecipe";
57
58     private static final String ECOMP_MSO_CATALOG_V2_SERVICE_ALLOTTED_RESOURCES =
59             "ecomp/mso/catalog/v2/serviceAllottedResources";
60
61     private static final String ECOMP_MSO_CATALOG_V2_RESOURCE_RECEIPE = "ecomp/mso/catalog/v2/resourceRecipe";
62
63     private static final String ECOMP_MSO_CATALOG_V2_SERVICE_NETWORKS = "ecomp/mso/catalog/v2/serviceNetworks";
64
65     private static final String ECOMP_MSO_CATALOG_V2_SERVICE_VNFS = "ecomp/mso/catalog/v2/serviceVnfs";
66
67     private static final String ECOMP_MSO_CATALOG_V2_SERVICE_RESOURCES = "ecomp/mso/catalog/v2/serviceResources";
68
69     TestRestTemplate restTemplate = new TestRestTemplate("test", "test");
70
71     HttpHeaders headers = new HttpHeaders();
72
73     private final String expectedServiceResourceResponse =
74             "{\r\n\"serviceResources\": {\r\n\"modelInfo\": {\r\n\"modelName\": \"MSOTADevInfra_vSAMP10a_Service\",\r\n\"modelUuid\": \"5df8b6de-2083-11e7-93ae-92361f002671\",\r\n\"modelInvariantUuid\": \"9647dfc4-2083-11e7-93ae-92361f002671\",\r\n\"modelVersion\": \"1.0\"\r\n},\r\n\"serviceType\": \"NA\",\r\n\"serviceRole\": \"NA\",\r\n\"environmentContext\": \"Luna\",\r\n\"workloadContext\": \"Oxygen\",\r\n\"serviceVnfs\": [\r\n{\r\n\"modelInfo\": {\r\n\"modelName\": \"vSAMP10a\",\r\n\"modelUuid\": \"ff2ae348-214a-11e7-93ae-92361f002671\",\r\n\"modelInvariantUuid\": \"2fff5b20-214b-11e7-93ae-92361f002671\",\r\n\"modelVersion\": \"1.0\",\r\n\"modelCustomizationUuid\": \"68dc9a92-214c-11e7-93ae-92361f002671\",\r\n\"modelInstanceName\": \"vSAMP10a 1\"\r\n},\r\n\"toscaNodeType\": \"VF\",\r\n\"nfFunction\": \"vSAMP\",\r\n\"nfType\": \"vSAMP\",\r\n\"nfRole\": \"vSAMP\",\r\n\"nfNamingCode\": \"vSAMP\",\r\n\"multiStageDesign\": null,\r\n\"vfModules\": [\r\n{\r\n\"modelInfo\": {\r\n\"modelName\": \"vSAMP10aDEV::base::module-0\",\r\n\"modelUuid\": \"20c4431c-246d-11e7-93ae-92361f002671\",\r\n\"modelInvariantUuid\": \"78ca26d0-246d-11e7-93ae-92361f002671\",\r\n\"modelVersion\": \"2\",\r\n\"modelCustomizationUuid\": \"cb82ffd8-252a-11e7-93ae-92361f002671\"\r\n},\r\n\"isBase\": true,\r\n\"vfModuleLabel\": \"base\",\r\n\"initialCount\": 1,\r\n\"hasVolumeGroup\": false\r\n},\r\n{\r\n\"modelInfo\": {\r\n\"modelName\": \"vSAMP10aDEV::PCM::module-1\",\r\n\"modelUuid\": \"066de97e-253e-11e7-93ae-92361f002671\",\r\n\"modelInvariantUuid\": \"64efd51a-2544-11e7-93ae-92361f002671\",\r\n\"modelVersion\": \"2\",\r\n\"modelCustomizationUuid\": \"b4ea86b4-253f-11e7-93ae-92361f002671\"\r\n},\r\n\"isBase\": false,\r\n\"vfModuleLabel\": \"PCM\",\r\n\"initialCount\": 0,\r\n\"hasVolumeGroup\": false\r\n}\r\n]\r\n}\r\n],\r\n\"serviceNetworks\": [\r\n{\r\n\"modelInfo\": {\r\n\"modelName\": \"CONTRAIL30_GNDIRECT\",\r\n\"modelUuid\": \"10b36f65-f4e6-4be6-ae49-9596dc1c47fc\",\r\n\"modelInvariantUuid\": \"ce4ff476-9641-4e60-b4d5-b4abbec1271d\",\r\n\"modelVersion\": \"1.0\",\r\n\"modelCustomizationUuid\": \"3bdbb104-476c-483e-9f8b-c095b3d308ac\",\r\n\"modelInstanceName\": \"CONTRAIL30_GNDIRECT 9\"\r\n},\r\n\"toscaNodeType\": \"\",\r\n\"networkType\": \"\",\r\n\"networkTechnology\": \"\",\r\n\"networkRole\": \"\",\r\n\"networkScope\": \"\"\r\n}\r\n],\r\n\"serviceAllottedResources\": [\r\n{\r\n\"modelInfo\": {\r\n\"modelName\": \"Tunnel_Xconn\",\r\n\"modelUuid\": \"f6b7d4c6-e8a4-46e2-81bc-31cad5072842\",\r\n\"modelInvariantUuid\": \"b7a1b78e-6b6b-4b36-9698-8c9530da14af\",\r\n\"modelVersion\": \"1.0\",\r\n\"modelCustomizationUuid\": \"367a8ba9-057a-4506-b106-fbae818597c6\",\r\n\"modelInstanceName\": \"Sec_Tunnel_Xconn 11\"\r\n},\r\n\"toscaNodeType\": \"\",\r\n\"allottedResourceType\": \"\",\r\n\"allottedResourceRole\": null,\r\n\"providingServiceModelName\": null,\r\n\"providingServiceModelInvariantUuid\": null,\r\n\"providingServiceModelUuid\": null,\r\n\"nfFunction\": null,\r\n\"nfType\": null,\r\n\"nfRole\": null,\r\n\"nfNamingCode\": null\r\n}\r\n]\r\n}\r\n}";
75
76     private final String expectedServiceResourceResponsev2 =
77             "{\r\n\"serviceResources\": {\r\n\"modelInfo\": {\r\n\"modelName\": \"MSOTADevInfra_vSAMP10a_Service\",\r\n\"modelUuid\": \"5df8b6de-2083-11e7-93ae-92361f002672\",\r\n\"modelInvariantUuid\": \"9647dfc4-2083-11e7-93ae-92361f002671\",\r\n\"modelVersion\": \"2.0\"\r\n},\r\n\"serviceType\": \"NA\",\r\n\"serviceRole\": \"NA\",\r\n\"environmentContext\": \"Luna\",\r\n\"workloadContext\": \"Oxygen\",\r\n\"serviceVnfs\": [\r\n{\r\n\"modelInfo\": {\r\n\"modelName\": \"vSAMP10a\",\r\n\"modelUuid\": \"ff2ae348-214a-11e7-93ae-92361f002672\",\r\n\"modelInvariantUuid\": \"2fff5b20-214b-11e7-93ae-92361f002671\",\r\n\"modelVersion\": \"2.0\",\r\n\"modelCustomizationUuid\": \"68dc9a92-214c-11e7-93ae-92361f002672\",\r\n\"modelInstanceName\": \"vSAMP10a 2\"\r\n},\r\n\"toscaNodeType\": \"VF\",\r\n\"nfFunction\": \"vSAMP\",\r\n\"nfType\": \"vSAMP\",\r\n\"nfRole\": \"vSAMP\",\r\n\"nfNamingCode\": \"vSAMP\",\r\n\"multiStageDesign\": null,\r\n\"vfModules\": [\r\n{\r\n\"modelInfo\": {\r\n\"modelName\": \"vSAMP10aDEV::base::module-0\",\r\n\"modelUuid\": \"20c4431c-246d-11e7-93ae-92361f002672\",\r\n\"modelInvariantUuid\": \"78ca26d0-246d-11e7-93ae-92361f002671\",\r\n\"modelVersion\": \"2\",\r\n\"modelCustomizationUuid\": \"cb82ffd8-252a-11e7-93ae-92361f002672\"\r\n},\r\n\"isBase\": true,\r\n\"vfModuleLabel\": \"base\",\r\n\"initialCount\": 1,\r\n\"hasVolumeGroup\": false\r\n},\r\n{\r\n\"modelInfo\": {\r\n\"modelName\": \"vSAMP10aDEV::PCM::module-1\",\r\n\"modelUuid\": \"066de97e-253e-11e7-93ae-92361f002672\",\r\n\"modelInvariantUuid\": \"64efd51a-2544-11e7-93ae-92361f002671\",\r\n\"modelVersion\": \"2\",\r\n\"modelCustomizationUuid\": \"b4ea86b4-253f-11e7-93ae-92361f002672\"\r\n},\r\n\"isBase\": false,\r\n\"vfModuleLabel\": \"PCM\",\r\n\"initialCount\": 0,\r\n\"hasVolumeGroup\": false\r\n}\r\n]\r\n}\r\n],\r\n\"serviceNetworks\": [\r\n{\r\n\"modelInfo\": {\r\n\"modelName\": \"CONTRAIL30_GNDIRECT\",\r\n\"modelUuid\": \"10b36f65-f4e6-4be6-ae49-9596dc1c47fc\",\r\n\"modelInvariantUuid\": \"ce4ff476-9641-4e60-b4d5-b4abbec1271d\",\r\n\"modelVersion\": \"1.0\",\r\n\"modelCustomizationUuid\": \"3bdbb104-476c-483e-9f8b-c095b3d308ac\",\r\n\"modelInstanceName\": \"CONTRAIL30_GNDIRECT 9\"\r\n},\r\n\"toscaNodeType\": \"\",\r\n\"networkType\": \"\",\r\n\"networkTechnology\": \"\",\r\n\"networkRole\": \"\",\r\n\"networkScope\": \"\"\r\n}\r\n],\r\n\"serviceAllottedResources\": [\r\n{\r\n\"modelInfo\": {\r\n\"modelName\": \"Tunnel_Xconn\",\r\n\"modelUuid\": \"f6b7d4c6-e8a4-46e2-81bc-31cad5072842\",\r\n\"modelInvariantUuid\": \"b7a1b78e-6b6b-4b36-9698-8c9530da14af\",\r\n\"modelVersion\": \"1.0\",\r\n\"modelCustomizationUuid\": \"367a8ba9-057a-4506-b106-fbae818597c6\",\r\n\"modelInstanceName\": \"Sec_Tunnel_Xconn 11\"\r\n},\r\n\"toscaNodeType\": \"\",\r\n\"allottedResourceType\": \"\",\r\n\"allottedResourceRole\": null,\r\n\"providingServiceModelName\": null,\r\n\"providingServiceModelInvariantUuid\": null,\r\n\"providingServiceModelUuid\": null,\r\n\"nfFunction\": null,\r\n\"nfType\": null,\r\n\"nfRole\": null,\r\n\"nfNamingCode\": null\r\n}\r\n]\r\n}\r\n}";
78
79
80     private final String expectedServiceVnfResponse =
81             "{\r\n\"serviceVnfs\": [\r\n{\r\n\"modelInfo\": {\r\n\"modelName\": \"vSAMP10a\",\r\n\"modelUuid\": \"ff2ae348-214a-11e7-93ae-92361f002671\",\r\n\"modelInvariantUuid\": \"2fff5b20-214b-11e7-93ae-92361f002671\",\r\n\"modelVersion\": \"1.0\",\r\n\"modelCustomizationUuid\": \"68dc9a92-214c-11e7-93ae-92361f002671\",\r\n\"modelInstanceName\": \"vSAMP10a 1\"\r\n},\r\n\"toscaNodeType\": \"VF\",\r\n\"nfFunction\": \"vSAMP\",\r\n\"nfType\": \"vSAMP\",\r\n\"nfRole\": \"vSAMP\",\r\n\"nfNamingCode\": \"vSAMP\",\r\n\"multiStageDesign\": null,\r\n\"vfModules\": [\r\n{\r\n\"modelInfo\": {\r\n\"modelName\": \"vSAMP10aDEV::base::module-0\",\r\n\"modelUuid\": \"20c4431c-246d-11e7-93ae-92361f002671\",\r\n\"modelInvariantUuid\": \"78ca26d0-246d-11e7-93ae-92361f002671\",\r\n\"modelVersion\": \"2\",\r\n\"modelCustomizationUuid\": \"cb82ffd8-252a-11e7-93ae-92361f002671\"\r\n},\r\n\"isBase\": true,\r\n\"vfModuleLabel\": \"base\",\r\n\"initialCount\": 1,\r\n\"hasVolumeGroup\": false\r\n},\r\n{\r\n\"modelInfo\": {\r\n\"modelName\": \"vSAMP10aDEV::PCM::module-1\",\r\n\"modelUuid\": \"066de97e-253e-11e7-93ae-92361f002671\",\r\n\"modelInvariantUuid\": \"64efd51a-2544-11e7-93ae-92361f002671\",\r\n\"modelVersion\": \"2\",\r\n\"modelCustomizationUuid\": \"b4ea86b4-253f-11e7-93ae-92361f002671\"\r\n},\r\n\"isBase\": false,\r\n\"vfModuleLabel\": \"PCM\",\r\n\"initialCount\": 0,\r\n\"hasVolumeGroup\": false\r\n}\r\n]\r\n}\r\n]\r\n}";
82
83     private final String expectedServiceVnfResponseV3 =
84             "{\r\n\"serviceVnfs\": [\r\n{\r\n\"modelInfo\": {\r\n\"modelName\": \"vSAMP10a\",\r\n\"modelUuid\": \"ff2ae348-214a-11e7-93ae-92361f002672\",\r\n\"modelInvariantUuid\": \"2fff5b20-214b-11e7-93ae-92361f002671\",\r\n\"modelVersion\": \"2.0\",\r\n\"modelCustomizationUuid\": \"68dc9a92-214c-11e7-93ae-92361f002672\",\r\n\"modelInstanceName\": \"vSAMP10a 2\"\r\n},\r\n\"toscaNodeType\": \"VF\",\r\n\"nfFunction\": \"vSAMP\",\r\n\"nfType\": \"vSAMP\",\r\n\"nfRole\": \"vSAMP\",\r\n\"nfNamingCode\": \"vSAMP\",\r\n\"multiStageDesign\": null,\r\n\"vfModules\": [\r\n{\r\n\"modelInfo\": {\r\n\"modelName\": \"vSAMP10aDEV::base::module-0\",\r\n\"modelUuid\": \"20c4431c-246d-11e7-93ae-92361f002672\",\r\n\"modelInvariantUuid\": \"78ca26d0-246d-11e7-93ae-92361f002671\",\r\n\"modelVersion\": \"2\",\r\n\"modelCustomizationUuid\": \"cb82ffd8-252a-11e7-93ae-92361f002672\"\r\n},\r\n\"isBase\": true,\r\n\"vfModuleLabel\": \"base\",\r\n\"initialCount\": 1,\r\n\"hasVolumeGroup\": false\r\n},\r\n{\r\n\"modelInfo\": {\r\n\"modelName\": \"vSAMP10aDEV::PCM::module-1\",\r\n\"modelUuid\": \"066de97e-253e-11e7-93ae-92361f002672\",\r\n\"modelInvariantUuid\": \"64efd51a-2544-11e7-93ae-92361f002671\",\r\n\"modelVersion\": \"2\",\r\n\"modelCustomizationUuid\": \"b4ea86b4-253f-11e7-93ae-92361f002672\"\r\n},\r\n\"isBase\": false,\r\n\"vfModuleLabel\": \"PCM\",\r\n\"initialCount\": 0,\r\n\"hasVolumeGroup\": false\r\n}\r\n]\r\n}\r\n]\r\n}";
85
86     private final String expectedServiceNetworkResourceResponse =
87             "{\r\n\"serviceNetworks\": [\r\n{\r\n\"modelInfo\": {\r\n\"modelName\": \"CONTRAIL30_GNDIRECT\",\r\n\"modelUuid\": \"10b36f65-f4e6-4be6-ae49-9596dc1c47fc\",\r\n\"modelInvariantUuid\": \"ce4ff476-9641-4e60-b4d5-b4abbec1271d\",\r\n\"modelVersion\": \"1.0\",\r\n\"modelCustomizationUuid\": \"3bdbb104-476c-483e-9f8b-c095b3d308ac\",\r\n\"modelInstanceName\": \"CONTRAIL30_GNDIRECT 9\"\r\n},\r\n\"toscaNodeType\": \"\",\r\n\"networkType\": \"\",\r\n\"networkTechnology\": \"\",\r\n\"networkRole\": \"\",\r\n\"networkScope\": \"\"\r\n}\r\n]\r\n}";
88
89     private final String badQueryParamResponse =
90             "{\"messageId\":null,\"message\":\"no matching parameters\",\"category\":\"INTERNAL\",\"rolledBack\":false}\"";
91
92     private final String expectedAllottedResponse =
93             "{\r\n\"serviceAllottedResources\": [\r\n{\r\n\"modelInfo\": {\r\n\"modelName\": \"Tunnel_Xconn\",\r\n\"modelUuid\": \"f6b7d4c6-e8a4-46e2-81bc-31cad5072842\",\r\n\"modelInvariantUuid\": \"b7a1b78e-6b6b-4b36-9698-8c9530da14af\",\r\n\"modelVersion\": \"1.0\",\r\n\"modelCustomizationUuid\": \"367a8ba9-057a-4506-b106-fbae818597c6\",\r\n\"modelInstanceName\": \"Sec_Tunnel_Xconn 11\"\r\n},\r\n\"toscaNodeType\": \"\",\r\n\"allottedResourceType\": \"\",\r\n\"allottedResourceRole\": null,\r\n\"providingServiceModelName\": null,\r\n\"providingServiceModelInvariantUuid\": null,\r\n\"providingServiceModelUuid\": null,\r\n\"nfFunction\": null,\r\n\"nfType\": null,\r\n\"nfRole\": null,\r\n\"nfNamingCode\": null\r\n}\r\n]\r\n}";
94
95     private final String serviceUUID = "5df8b6de-2083-11e7-93ae-92361f002671";
96
97     private final String arResourceUUID = "25e2d69b-3b22-47b8-b4c9-7b14fd4a80df";
98
99     private final String serviceInvariantUUID = "9647dfc4-2083-11e7-93ae-92361f002671";
100
101     /* Health Check Resources Endpoint */
102
103     @Test
104     public void testHealthcheck() throws JSONException {
105
106         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
107
108         ResponseEntity<String> response =
109                 restTemplate.exchange(createURLWithPort("/manage/health"), HttpMethod.GET, entity, String.class);
110
111         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
112         for (ILoggingEvent logEvent : TestAppender.events)
113             if (logEvent.getLoggerName().equals("org.onap.so.logging.spring.interceptor.LoggingInterceptor")
114                     && logEvent.getMarker() != null && logEvent.getMarker().getName().equals("ENTRY")) {
115                 Map<String, String> mdc = logEvent.getMDCPropertyMap();
116                 assertNotNull(mdc.get(ONAPLogConstants.MDCs.INSTANCE_UUID));
117                 assertNotNull(mdc.get(ONAPLogConstants.MDCs.REQUEST_ID));
118                 assertNotNull(mdc.get(ONAPLogConstants.MDCs.INVOCATION_ID));
119                 assertEquals("", mdc.get(ONAPLogConstants.MDCs.PARTNER_NAME));
120                 assertEquals("/manage/health", mdc.get(ONAPLogConstants.MDCs.SERVICE_NAME));
121                 assertEquals("INPROGRESS", mdc.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE));
122             } else if (logEvent.getLoggerName().equals("org.onap.so.logging.spring.interceptor.LoggingInterceptor")
123                     && logEvent.getMarker() != null && logEvent.getMarker().getName().equals("EXIT")) {
124                 Map<String, String> mdc = logEvent.getMDCPropertyMap();
125                 assertNotNull(mdc.get(ONAPLogConstants.MDCs.REQUEST_ID));
126                 assertNotNull(mdc.get(ONAPLogConstants.MDCs.INVOCATION_ID));
127                 assertEquals("200", mdc.get(ONAPLogConstants.MDCs.RESPONSE_CODE));
128                 assertEquals("", mdc.get(ONAPLogConstants.MDCs.PARTNER_NAME));
129                 assertEquals("/manage/health", mdc.get(ONAPLogConstants.MDCs.SERVICE_NAME));
130                 assertEquals("COMPLETED", mdc.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE));
131             }
132     }
133
134     /* Service Resources Endpoint */
135
136     @Test
137     public void testGetServiceModelUUID() throws JSONException {
138         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
139         headers.set("Accept", MediaType.APPLICATION_JSON);
140
141         UriComponentsBuilder builder =
142                 UriComponentsBuilder.fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_V2_SERVICE_RESOURCES))
143                         .queryParam("serviceModelUuid", serviceUUID);
144
145         ResponseEntity<String> response =
146                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
147
148         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
149         JSONAssert.assertEquals(expectedServiceResourceResponse, response.getBody().toString(),
150                 JSONCompareMode.LENIENT);
151     }
152
153     @Test
154     public void testGetServiceInvariantUUIDAndVersion() throws JSONException {
155         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
156         headers.set("Accept", MediaType.APPLICATION_JSON);
157         UriComponentsBuilder builder =
158                 UriComponentsBuilder.fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_V2_SERVICE_RESOURCES))
159                         .queryParam("serviceModelInvariantUuid", "9647dfc4-2083-11e7-93ae-92361f002671")
160                         .queryParam("serviceModelVersion", "1.0");
161
162         ResponseEntity<String> response =
163                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
164
165         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
166         JSONAssert.assertEquals(expectedServiceResourceResponse, response.getBody().toString(), false);
167     }
168
169     @Test
170     public void testGetServiceInvariantUUID() throws JSONException {
171         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
172         headers.set("Accept", MediaType.APPLICATION_JSON);
173         UriComponentsBuilder builder =
174                 UriComponentsBuilder.fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_V2_SERVICE_RESOURCES))
175                         .queryParam("serviceModelInvariantUuid", "9647dfc4-2083-11e7-93ae-92361f002671");
176
177         ResponseEntity<String> response =
178                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
179
180         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
181         JSONAssert.assertEquals(expectedServiceResourceResponsev2, response.getBody().toString(), false);
182     }
183
184     @Test
185     public void testGetServiceInvariantUUIDEmtpyModelVer() throws JSONException {
186         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
187         headers.set("Accept", MediaType.APPLICATION_JSON);
188         UriComponentsBuilder builder =
189                 UriComponentsBuilder.fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_V2_SERVICE_RESOURCES))
190                         .queryParam("serviceModelInvariantUuid", "9647dfc4-2083-11e7-93ae-92361f002671")
191                         .queryParam("serviceModelVersion", "");;
192
193         ResponseEntity<String> response =
194                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
195
196         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
197         JSONAssert.assertEquals(expectedServiceResourceResponsev2, response.getBody().toString(), false);
198     }
199
200     @Test
201     public void testGetServiceModelUUID404() throws JSONException {
202         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
203         headers.set("Accept", MediaType.APPLICATION_JSON);
204         String expectedResponse = "\"serviceResources\": null";
205         UriComponentsBuilder builder =
206                 UriComponentsBuilder.fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_V2_SERVICE_RESOURCES))
207                         .queryParam("serviceModelUuid", "5df8b6de-2083-11e7-93");
208
209         ResponseEntity<String> response =
210                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
211
212         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatusCode().value());
213         JSONAssert.assertEquals(expectedResponse, response.getBody().toString(), false);
214     }
215
216     @Test
217     public void testGetServiceBadQueryParams() throws JSONException {
218         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
219         headers.set("Accept", MediaType.APPLICATION_JSON);
220         UriComponentsBuilder builder =
221                 UriComponentsBuilder.fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_V2_SERVICE_RESOURCES))
222                         .queryParam("BadQueryParam", "5df8b6de-2083-11e7-93");
223
224         ResponseEntity<String> response =
225                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
226
227         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
228         JSONAssert.assertEquals(badQueryParamResponse, response.getBody().toString(), false);
229     }
230
231     /* VNF Resources Endpoint */
232
233     @Test
234     public void testGetVNFResourcesByCustomizationUUID() throws JSONException {
235         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
236         headers.set("Accept", MediaType.APPLICATION_JSON);
237         String expectedResponse =
238                 "{\r\n\"modelInfo\": {\r\n\"modelName\": \"vSAMP10a\",\r\n\"modelUuid\": \"ff2ae348-214a-11e7-93ae-92361f002671\",\r\n\"modelInvariantUuid\": \"2fff5b20-214b-11e7-93ae-92361f002671\",\r\n\"modelVersion\": \"1.0\",\r\n\"modelCustomizationUuid\": \"68dc9a92-214c-11e7-93ae-92361f002671\",\r\n\"modelInstanceName\": \"vSAMP10a 1\"\r\n},\r\n\"toscaNodeType\": \"VF\",\r\n\"nfFunction\": \"vSAMP\",\r\n\"nfType\": \"vSAMP\",\r\n\"nfRole\": \"vSAMP\",\r\n\"nfNamingCode\": \"vSAMP\",\r\n\"multiStageDesign\": null,\r\n\"vfModules\": [\r\n{\r\n\"modelInfo\": {\r\n\"modelName\": \"vSAMP10aDEV::base::module-0\",\r\n\"modelUuid\": \"20c4431c-246d-11e7-93ae-92361f002671\",\r\n\"modelInvariantUuid\": \"78ca26d0-246d-11e7-93ae-92361f002671\",\r\n\"modelVersion\": \"2\",\r\n\"modelCustomizationUuid\": \"cb82ffd8-252a-11e7-93ae-92361f002671\"\r\n},\r\n\"isBase\": true,\r\n\"vfModuleLabel\": \"base\",\r\n\"initialCount\": 1,\r\n\"hasVolumeGroup\": false\r\n},\r\n{\r\n\"modelInfo\": {\r\n\"modelName\": \"vSAMP10aDEV::PCM::module-1\",\r\n\"modelUuid\": \"066de97e-253e-11e7-93ae-92361f002671\",\r\n\"modelInvariantUuid\": \"64efd51a-2544-11e7-93ae-92361f002671\",\r\n\"modelVersion\": \"2\",\r\n\"modelCustomizationUuid\": \"b4ea86b4-253f-11e7-93ae-92361f002671\"\r\n},\r\n\"isBase\": false,\r\n\"vfModuleLabel\": \"PCM\",\r\n\"initialCount\": 0,\r\n\"hasVolumeGroup\": false\r\n}\r\n]\r\n}";
239         UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(
240                 createURLWithPort("ecomp/mso/catalog/v2/vnfResources/68dc9a92-214c-11e7-93ae-92361f002671"));
241
242         ResponseEntity<String> response =
243                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
244
245         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
246         JSONAssert.assertEquals(expectedResponse, response.getBody().toString(), false);
247     }
248
249
250
251     @Test
252     public void testGetVNFResources404() throws JSONException {
253         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
254         headers.set("Accept", MediaType.APPLICATION_JSON);
255
256         UriComponentsBuilder builder = UriComponentsBuilder
257                 .fromHttpUrl(createURLWithPort("ecomp/mso/catalog/v2/vnfResources/68dc-11e7-93ae-92361f002671"));
258
259         ResponseEntity<String> response =
260                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
261
262         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatusCode().value());
263
264     }
265
266     @Test
267     public void testGetServiceVNFResourcesByCustomizationUUID() throws JSONException {
268         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
269         headers.set("Accept", MediaType.APPLICATION_JSON);
270
271         UriComponentsBuilder builder =
272                 UriComponentsBuilder.fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_V2_SERVICE_VNFS))
273                         .queryParam("vnfModelCustomizationUuid", "68dc9a92-214c-11e7-93ae-92361f002671");
274
275         ResponseEntity<String> response =
276                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
277
278         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
279         JSONAssert.assertEquals(expectedServiceVnfResponse, response.getBody().toString(), false);
280     }
281
282     @Test
283     public void testGetServiceVNFResourcesByServiceModelUUID() throws JSONException {
284         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
285         headers.set("Accept", MediaType.APPLICATION_JSON);
286
287         UriComponentsBuilder builder =
288                 UriComponentsBuilder.fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_V2_SERVICE_VNFS))
289                         .queryParam("serviceModelUuid", serviceUUID);
290
291         ResponseEntity<String> response =
292                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
293
294         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
295         JSONAssert.assertEquals(expectedServiceVnfResponse, response.getBody().toString(), false);
296     }
297
298     @Test
299     public void testGetServiceVNFResourcesByServiceModelInvariantUUIDAndVersion() throws JSONException {
300         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
301         headers.set("Accept", MediaType.APPLICATION_JSON);
302
303         UriComponentsBuilder builder =
304                 UriComponentsBuilder.fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_V2_SERVICE_VNFS))
305                         .queryParam("serviceModelInvariantUuid", "9647dfc4-2083-11e7-93ae-92361f002671")
306                         .queryParam("serviceModelVersion", "1.0");
307
308         ResponseEntity<String> response =
309                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
310
311         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
312         JSONAssert.assertEquals(expectedServiceVnfResponse, response.getBody().toString(), false);
313     }
314
315     @Test
316     public void testGetServiceVNFResourcesByServiceModelInvariantUUIDEmptyVersion() throws JSONException {
317         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
318         headers.set("Accept", MediaType.APPLICATION_JSON);
319
320         UriComponentsBuilder builder =
321                 UriComponentsBuilder.fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_V2_SERVICE_VNFS))
322                         .queryParam("serviceModelInvariantUuid", "9647dfc4-2083-11e7-93ae-92361f002671")
323                         .queryParam("serviceModelVersion", "");
324
325         ResponseEntity<String> response =
326                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
327
328         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
329         JSONAssert.assertEquals(expectedServiceVnfResponseV3, response.getBody().toString(), false);
330     }
331
332
333     @Test
334     public void testGetServiceVNFResourcesByServiceModelInvariantUUID() throws JSONException {
335         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
336         headers.set("Accept", MediaType.APPLICATION_JSON);
337
338         UriComponentsBuilder builder =
339                 UriComponentsBuilder.fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_V2_SERVICE_VNFS))
340                         .queryParam("serviceModelInvariantUuid", "9647dfc4-2083-11e7-93ae-92361f002671");
341
342         ResponseEntity<String> response =
343                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
344
345         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
346         JSONAssert.assertEquals(expectedServiceVnfResponseV3, response.getBody().toString(), false);
347     }
348
349     @Test
350     public void testGetServiceVNFResourcesByServiceModelName() throws JSONException {
351         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
352         headers.set("Accept", MediaType.APPLICATION_JSON);
353
354         UriComponentsBuilder builder =
355                 UriComponentsBuilder.fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_V2_SERVICE_VNFS))
356                         .queryParam("serviceModelName", "MSOTADevInfra_vSAMP10a_Service");
357
358         ResponseEntity<String> response =
359                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
360
361         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
362         JSONAssert.assertEquals(expectedServiceVnfResponseV3, response.getBody().toString(), false);
363     }
364
365     @Test
366     public void testGetServiceVNFResourcesByServiceModelNameEmptyVersion() throws JSONException {
367         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
368         headers.set("Accept", MediaType.APPLICATION_JSON);
369
370         UriComponentsBuilder builder = UriComponentsBuilder
371                 .fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_V2_SERVICE_VNFS))
372                 .queryParam("serviceModelName", "MSOTADevInfra_vSAMP10a_Service").queryParam("serviceModelVersion", "");
373
374         ResponseEntity<String> response =
375                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
376
377         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
378         JSONAssert.assertEquals(expectedServiceVnfResponseV3, response.getBody().toString(), false);
379     }
380
381     @Test
382     public void testGetServiceVNFResourcesByServiceModelNameAndVersion() throws JSONException {
383         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
384         headers.set("Accept", MediaType.APPLICATION_JSON);
385
386         UriComponentsBuilder builder =
387                 UriComponentsBuilder.fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_V2_SERVICE_VNFS))
388                         .queryParam("serviceModelName", "MSOTADevInfra_vSAMP10a_Service")
389                         .queryParam("serviceModelVersion", "1.0");
390
391         ResponseEntity<String> response =
392                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
393
394         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
395         JSONAssert.assertEquals(expectedServiceVnfResponse, response.getBody().toString(), false);
396     }
397
398     @Test
399     public void testSerfviceVNFResources404() throws JSONException {
400         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
401         headers.set("Accept", MediaType.APPLICATION_JSON);
402
403         UriComponentsBuilder builder =
404                 UriComponentsBuilder.fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_V2_SERVICE_VNFS))
405                         .queryParam("serviceModelName", "BADNAME").queryParam("serviceModelVersion", "1.0");
406
407         ResponseEntity<String> response =
408                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
409
410         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatusCode().value());
411
412     }
413
414
415     @Test
416     public void testSerfviceVNFBadParams() throws JSONException {
417         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
418         headers.set("Accept", MediaType.APPLICATION_JSON);
419
420         UriComponentsBuilder builder =
421                 UriComponentsBuilder.fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_V2_SERVICE_VNFS))
422                         .queryParam("BadParamName", "BADNAME");
423
424         ResponseEntity<String> response =
425                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
426         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
427         JSONAssert.assertEquals(badQueryParamResponse, response.getBody().toString(), false);
428
429
430     }
431
432
433
434     /* Network Resources Endpoint */
435
436     @Test
437     public void testGetNetworkResourcesByCustomizationUUID() throws JSONException {
438         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
439         headers.set("Accept", MediaType.APPLICATION_JSON);
440         String expectedResponse =
441                 "{\r\n\"modelInfo\": {\r\n\"modelName\": \"CONTRAIL30_GNDIRECT\",\r\n\"modelUuid\": \"10b36f65-f4e6-4be6-ae49-9596dc1c47fc\",\r\n\"modelInvariantUuid\": \"ce4ff476-9641-4e60-b4d5-b4abbec1271d\",\r\n\"modelVersion\": \"1.0\",\r\n\"modelCustomizationUuid\": \"3bdbb104-476c-483e-9f8b-c095b3d308ac\",\r\n\"modelInstanceName\": \"CONTRAIL30_GNDIRECT 9\"\r\n},\r\n\"toscaNodeType\": \"\",\r\n\"networkType\": \"\",\r\n\"networkTechnology\": \"\",\r\n\"networkRole\": \"\",\r\n\"networkScope\": \"\"\r\n}";
442         UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(
443                 createURLWithPort("ecomp/mso/catalog/v2/networkResources/3bdbb104-476c-483e-9f8b-c095b3d308ac"));
444
445         ResponseEntity<String> response =
446                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
447
448         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
449         JSONAssert.assertEquals(expectedResponse, response.getBody().toString(), false);
450     }
451
452
453
454     @Test
455     public void testGetNetworkResources404() throws JSONException {
456         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
457         headers.set("Accept", MediaType.APPLICATION_JSON);
458
459         UriComponentsBuilder builder = UriComponentsBuilder
460                 .fromHttpUrl(createURLWithPort("ecomp/mso/catalog/v2/networkResources/3bdbb104-4asdf"));
461
462         ResponseEntity<String> response =
463                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
464
465         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatusCode().value());
466
467     }
468
469     /* Service Network Resources Endpoints */
470
471     @Test
472     public void testGetServiceNetworkResourcesByUnknownQueryParam() throws JSONException {
473         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
474         headers.set("Accept", MediaType.APPLICATION_JSON);
475
476         UriComponentsBuilder builder =
477                 UriComponentsBuilder.fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_V2_SERVICE_NETWORKS))
478                         .queryParam("serviceModelName", "PROVIDER NETWORK").queryParam("serviceModelVersion", "2.0");
479
480         ResponseEntity<String> response =
481                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
482
483         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
484         JSONAssert.assertEquals(badQueryParamResponse, response.getBody().toString(), false);
485     }
486
487     @Test
488     public void testGetServiceNetworkResourcesByServiceModelUUID() throws JSONException {
489         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
490         headers.set("Accept", MediaType.APPLICATION_JSON);
491
492         UriComponentsBuilder builder =
493                 UriComponentsBuilder.fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_V2_SERVICE_NETWORKS))
494                         .queryParam("serviceModelUuid", serviceUUID);
495
496         ResponseEntity<String> response =
497                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
498
499         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
500         JSONAssert.assertEquals(expectedServiceNetworkResourceResponse, response.getBody().toString(), false);
501     }
502
503     @Test
504     public void testGetServiceNetworkResourcesByServiceModelUUIDNotExist() throws JSONException {
505         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
506         headers.set("Accept", MediaType.APPLICATION_JSON);
507
508         UriComponentsBuilder builder =
509                 UriComponentsBuilder.fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_V2_SERVICE_NETWORKS))
510                         .queryParam("serviceModelUuid", "doesNotExist");
511
512         ResponseEntity<String> response =
513                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
514
515         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatusCode().value());
516
517     }
518
519     @Test
520     public void testGetServiceNetworkResourcesByNetworkCustomizationUUIDNotExist() throws JSONException {
521         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
522         headers.set("Accept", MediaType.APPLICATION_JSON);
523
524         UriComponentsBuilder builder =
525                 UriComponentsBuilder.fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_V2_SERVICE_NETWORKS))
526                         .queryParam("networkModelCustomizationUuid", "06b8966e-097c-4d63-afda-e0d");
527
528         ResponseEntity<String> response =
529                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
530
531         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatusCode().value());
532
533     }
534
535     @Test
536     public void testGetServiceNetworkResourcesByServiceModelInvariantUUID() throws JSONException {
537         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
538         headers.set("Accept", MediaType.APPLICATION_JSON);
539
540         UriComponentsBuilder builder =
541                 UriComponentsBuilder.fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_V2_SERVICE_NETWORKS))
542                         .queryParam("serviceModelInvariantUuid", serviceInvariantUUID);
543
544         ResponseEntity<String> response =
545                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
546
547         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
548         JSONAssert.assertEquals(expectedServiceNetworkResourceResponse, response.getBody().toString(), false);
549     }
550
551     @Test
552     public void testGetServiceNetworkResourcesByServiceModelInvariantUUIDAndVersion() throws JSONException {
553         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
554         headers.set("Accept", MediaType.APPLICATION_JSON);
555
556         UriComponentsBuilder builder = UriComponentsBuilder
557                 .fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_V2_SERVICE_NETWORKS))
558                 .queryParam("serviceModelInvariantUuid", serviceInvariantUUID).queryParam("serviceModelVersion", "2.0");
559
560         ResponseEntity<String> response =
561                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
562
563         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
564         JSONAssert.assertEquals(expectedServiceNetworkResourceResponse, response.getBody().toString(), false);
565     }
566
567     @Test
568     public void testGetServiceNetworkResourcesByServiceModelInvariantAndEmptyVersion() throws JSONException {
569         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
570         headers.set("Accept", MediaType.APPLICATION_JSON);
571
572         UriComponentsBuilder builder = UriComponentsBuilder
573                 .fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_V2_SERVICE_NETWORKS))
574                 .queryParam("serviceModelInvariantUuid", serviceInvariantUUID).queryParam("serviceModelVersion", "");
575         ResponseEntity<String> response =
576                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
577
578         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
579         JSONAssert.assertEquals(expectedServiceNetworkResourceResponse, response.getBody().toString(), false);
580     }
581
582
583     @Test
584     public void testGetServiceNetworkResourcesByNetworkCustomizationUUID() throws JSONException {
585         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
586         headers.set("Accept", MediaType.APPLICATION_JSON);
587
588         UriComponentsBuilder builder =
589                 UriComponentsBuilder.fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_V2_SERVICE_NETWORKS))
590                         .queryParam("networkModelCustomizationUuid", "3bdbb104-476c-483e-9f8b-c095b3d308ac");
591
592         ResponseEntity<String> response =
593                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
594
595         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
596         JSONAssert.assertEquals(expectedServiceNetworkResourceResponse, response.getBody().toString(), false);
597     }
598
599     @Test
600     public void testGetServiceNetworkResourcesByNetworkModelName() throws JSONException {
601         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
602         headers.set("Accept", MediaType.APPLICATION_JSON);
603
604         UriComponentsBuilder builder =
605                 UriComponentsBuilder.fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_V2_SERVICE_NETWORKS))
606                         .queryParam("networkModelName", "CONTRAIL30_GNDIRECT");
607
608         ResponseEntity<String> response =
609                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
610
611         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
612         JSONAssert.assertEquals(expectedServiceNetworkResourceResponse, response.getBody().toString(), false);
613     }
614
615     /* Allotted endpoints */
616
617     @Test
618     public void testGetAllottedResourcesByCustomizationUUID() throws JSONException {
619         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
620         headers.set("Accept", MediaType.APPLICATION_JSON);
621         String expectedResponse =
622                 "{\r\n\"modelInfo\": {\r\n\"modelName\": \"Tunnel_Xconn\",\r\n\"modelUuid\": \"f6b7d4c6-e8a4-46e2-81bc-31cad5072842\",\r\n\"modelInvariantUuid\": \"b7a1b78e-6b6b-4b36-9698-8c9530da14af\",\r\n\"modelVersion\": \"1.0\",\r\n\"modelCustomizationUuid\": \"367a8ba9-057a-4506-b106-fbae818597c6\",\r\n\"modelInstanceName\": \"Sec_Tunnel_Xconn 11\"\r\n},\r\n\"toscaNodeType\": \"\",\r\n\"allottedResourceType\": \"\",\r\n\"allottedResourceRole\": null,\r\n\"providingServiceModelName\": null,\r\n\"providingServiceModelInvariantUuid\": null,\r\n\"providingServiceModelUuid\": null,\r\n\"nfFunction\": null,\r\n\"nfType\": null,\r\n\"nfRole\": null,\r\n\"nfNamingCode\": null\r\n}";
623
624         UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(
625                 createURLWithPort("ecomp/mso/catalog/v2/allottedResources/367a8ba9-057a-4506-b106-fbae818597c6"));
626
627
628         ResponseEntity<String> response =
629                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
630
631         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
632         JSONAssert.assertEquals(expectedResponse, response.getBody().toString(), false);
633     }
634
635
636     @Test
637     public void testGetAllottedResourcesByServiceModelUuuid() throws JSONException {
638         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
639         headers.set("Accept", MediaType.APPLICATION_JSON);
640
641         UriComponentsBuilder builder =
642                 UriComponentsBuilder.fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_V2_SERVICE_ALLOTTED_RESOURCES))
643                         .queryParam("serviceModelUuid", serviceUUID);
644
645         ResponseEntity<String> response =
646                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
647
648         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
649         JSONAssert.assertEquals(expectedAllottedResponse, response.getBody().toString(), false);
650     }
651
652     @Test
653     public void testResourceReceipe() throws JSONException {
654         String expectedResourceRecipe =
655                 "{\"orchestrationUri\":\"/mso/async/services/CreateSDNCNetworkResource\",\"action\":\"createInstance\",\"description\":\"sotnvpnattachmentvF\",\"id\":\"1\",\"recipeTimeout\":\"180\",\"paramXSD\":\"\"}";
656
657         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
658         headers.set("Accept", MediaType.APPLICATION_JSON);
659
660         UriComponentsBuilder builder =
661                 UriComponentsBuilder.fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_V2_RESOURCE_RECEIPE))
662                         .queryParam("resourceModelUuid", arResourceUUID).queryParam("action", "createInstance");
663
664         ResponseEntity<String> response =
665                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
666
667         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
668         JSONAssert.assertEquals(expectedResourceRecipe, response.getBody().toString(), false);
669     }
670
671     @Test
672     public void testResourceReceipeNotMatched() throws JSONException {
673
674         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
675         headers.set("Accept", MediaType.APPLICATION_JSON);
676
677         UriComponentsBuilder builder =
678                 UriComponentsBuilder.fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_V2_RESOURCE_RECEIPE))
679                         .queryParam("resourceModelUuid", arResourceUUID).queryParam("action", "invalid_action");
680
681         ResponseEntity<String> response =
682                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
683
684         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatusCode().value());
685     }
686
687     @Test
688     public void testGetServiceAllottedResourcesByServiceModelInvariantUuid() throws JSONException {
689         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
690         headers.set("Accept", MediaType.APPLICATION_JSON);
691
692         UriComponentsBuilder builder =
693                 UriComponentsBuilder.fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_V2_SERVICE_ALLOTTED_RESOURCES))
694                         .queryParam("serviceModelInvariantUuid", serviceInvariantUUID);
695
696         ResponseEntity<String> response =
697                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
698
699         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
700         JSONAssert.assertEquals(expectedAllottedResponse, response.getBody().toString(), false);
701     }
702
703     @Test
704     public void testGetServiceAllottedResourcesByServiceModelInvariantUuidModelVersion() throws JSONException {
705         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
706         headers.set("Accept", MediaType.APPLICATION_JSON);
707
708         UriComponentsBuilder builder = UriComponentsBuilder
709                 .fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_V2_SERVICE_ALLOTTED_RESOURCES))
710                 .queryParam("serviceModelInvariantUuid", serviceInvariantUUID).queryParam("serviceModelVersion", "1.0");
711
712         ResponseEntity<String> response =
713                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
714
715         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
716         JSONAssert.assertEquals(expectedAllottedResponse, response.getBody().toString(), false);
717     }
718
719     @Test
720     public void testGetServiceAllottedResourcesByServiceModelInvariantUuidModelVersionEmpty() throws JSONException {
721         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
722         headers.set("Accept", MediaType.APPLICATION_JSON);
723
724         UriComponentsBuilder builder = UriComponentsBuilder
725                 .fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_V2_SERVICE_ALLOTTED_RESOURCES))
726                 .queryParam("serviceModelInvariantUuid", serviceInvariantUUID).queryParam("serviceModelVersion", "1.0");
727
728         ResponseEntity<String> response =
729                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
730
731         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
732         JSONAssert.assertEquals(expectedAllottedResponse, response.getBody().toString(), false);
733     }
734
735     @Test
736     public void testGetAllottedResourcesByAllottedCustomizationId() throws JSONException {
737         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
738         headers.set("Accept", MediaType.APPLICATION_JSON);
739
740         UriComponentsBuilder builder =
741                 UriComponentsBuilder.fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_V2_SERVICE_ALLOTTED_RESOURCES))
742                         .queryParam("arModelCustomizationUuid", "367a8ba9-057a-4506-b106-fbae818597c6");
743
744         ResponseEntity<String> response =
745                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
746
747         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
748         JSONAssert.assertEquals(expectedAllottedResponse, response.getBody().toString(), false);
749     }
750
751
752     @Test
753     public void testGetAllottedResourcesResourcesNonExistResource() throws JSONException {
754         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
755         headers.set("Accept", MediaType.APPLICATION_JSON);
756
757         UriComponentsBuilder builder =
758                 UriComponentsBuilder.fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_V2_SERVICE_ALLOTTED_RESOURCES))
759                         .queryParam("arModelCustomizationUuid", "NOTEXIST");
760
761         ResponseEntity<String> response =
762                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
763
764         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatusCode().value());
765
766     }
767
768     /* VF Modules Endpoint */
769
770     @Test
771     public void testGetVFModulesNonExistResource() throws JSONException {
772         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
773         headers.set("Accept", MediaType.APPLICATION_JSON);
774
775         UriComponentsBuilder builder =
776                 UriComponentsBuilder.fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_V2_VF_MODULES))
777                         .queryParam("vfModuleModelName", "NEUTRON_BASIC");
778
779         ResponseEntity<String> response =
780                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
781
782         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatusCode().value());
783
784     }
785
786     @Test
787     public void testGetVFModulesByVfModuleModelName() throws JSONException {
788         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
789         headers.set("Accept", MediaType.APPLICATION_JSON);
790         String expectedResponse =
791                 "{\r\n\"modelInfo\": {\r\n\"modelName\": \"vSAMP10aDEV::base::module-0\",\r\n\"modelUuid\": \"20c4431c-246d-11e7-93ae-92361f002671\",\r\n\"modelInvariantUuid\": \"78ca26d0-246d-11e7-93ae-92361f002671\",\r\n\"modelVersion\": \"2\",\r\n\"modelCustomizationUuid\": \"cb82ffd8-252a-11e7-93ae-92361f002671\"\r\n},\r\n\"isBase\": true,\r\n\"vfModuleLabel\": \"base\",\r\n\"initialCount\": 1,\r\n\"hasVolumeGroup\": false\r\n}";
792         UriComponentsBuilder builder =
793                 UriComponentsBuilder.fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_V2_VF_MODULES))
794                         .queryParam("vfModuleModelName", "vSAMP10aDEV::base::module-0");
795
796         ResponseEntity<String> response =
797                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
798
799         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
800         JSONAssert.assertEquals(expectedResponse, response.getBody().toString(), false);
801
802     }
803
804     @Test
805     public void testGetVFModulesBadQueryParam() throws JSONException, IOException {
806         TestAppender.events.clear();
807         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
808         headers.set("Accept", MediaType.APPLICATION_JSON);
809
810         UriComponentsBuilder builder = UriComponentsBuilder
811                 .fromHttpUrl(createURLWithPort(ECOMP_MSO_CATALOG_V2_VF_MODULES)).queryParam("ADASD", "NEUTRON_BASIC");
812
813         ResponseEntity<String> response =
814                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
815
816         assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value());
817         JSONAssert.assertEquals(badQueryParamResponse, response.getBody().toString(), false);
818
819
820         for (ILoggingEvent logEvent : TestAppender.events)
821             if (logEvent.getLoggerName().equals("org.onap.so.logging.jaxrs.filter.SOAuditLogContainerFilter")
822                     && logEvent.getMarker().getName().equals("ENTRY")) {
823                 Map<String, String> mdc = logEvent.getMDCPropertyMap();
824                 assertNotNull(mdc.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP));
825                 assertNotNull(mdc.get(ONAPLogConstants.MDCs.REQUEST_ID));
826                 assertNotNull(mdc.get(INVOCATION_ID));
827                 assertEquals("UNKNOWN", mdc.get(PARTNER_NAME));
828                 assertEquals("v2/vfModules", mdc.get(SERVICE_NAME));
829                 assertEquals("INPROGRESS", mdc.get(RESPONSE_STATUS_CODE));
830             } else if (logEvent.getLoggerName().equals("org.onap.so.logging.jaxrs.filter.SOAuditLogContainerFilter")
831                     && logEvent.getMarker().getName().equals("EXIT")) {
832                 Map<String, String> mdc = logEvent.getMDCPropertyMap();
833                 assertNotNull(mdc.get(ONAPLogConstants.MDCs.ENTRY_TIMESTAMP));
834                 assertNotNull(mdc.get(LOG_TIMESTAMP));
835                 assertNotNull(mdc.get(ONAPLogConstants.MDCs.REQUEST_ID));
836                 assertNotNull(mdc.get(INVOCATION_ID));
837                 assertEquals("500", mdc.get(RESPONSE_CODE));
838                 assertEquals("UNKNOWN", mdc.get(PARTNER_NAME));
839                 assertEquals("v2/vfModules", mdc.get(SERVICE_NAME));
840                 assertEquals("ERROR", mdc.get(RESPONSE_STATUS_CODE));
841                 assertNotNull(mdc.get(RESPONSE_DESCRIPTION));
842             }
843     }
844
845     @Test
846     public void testCreateServiceRecipe() throws JSONException {
847         ServiceRecipe recipe = new ServiceRecipe();
848         recipe.setAction("action");
849         recipe.setDescription("description");
850         recipe.setOrchestrationUri("http://test");
851         recipe.setRecipeTimeout(120);
852         recipe.setServiceModelUUID(serviceUUID);
853         HttpEntity<ServiceRecipe> entity = new HttpEntity<ServiceRecipe>(recipe, headers);
854         headers.set("Accept", MediaType.APPLICATION_JSON);
855
856         UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(SERVICE_RECIPE));
857
858         ResponseEntity<String> response =
859                 restTemplate.exchange(builder.toUriString(), HttpMethod.POST, entity, String.class);
860
861         assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusCode().value());
862     }
863
864     private String createURLWithPort(String uri) {
865         return "http://localhost:" + port + uri;
866     }
867 }