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