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