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