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