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