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