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