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