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