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