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