2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
20 package org.openecomp.mso.apihandlerinfra;
\r
22 import static org.junit.Assert.assertEquals;
\r
24 import java.io.IOException;
\r
26 import javax.ws.rs.core.Response;
\r
28 import org.apache.http.HttpStatus;
\r
29 import org.junit.Test;
\r
30 import org.mockito.Mockito;
\r
31 import org.openecomp.mso.apihandler.common.ValidationException;
\r
33 import com.fasterxml.jackson.core.JsonParseException;
\r
34 import com.fasterxml.jackson.databind.JsonMappingException;
\r
36 public class ServiceInstancesTest {
\r
38 private static final String requestJSONCreate = "{ \"requestDetails\": { \"modelInfo\": { \"modelType\": \"service\", "
\r
39 + "\"modelInvariantId\": \"ff3514e3-5a33-55df-13ab-12abad84e7ff\","
\r
40 + " \"modelVersionId\": \"fe6985cd-ea33-3346-ac12-ab121484a3fe\", \"modelName\": \"Test\","
\r
41 + " \"modelVersion\": \"1.0\" }, \"cloudConfiguration\": "
\r
42 + "{ \"lcpCloudRegionId\": \"mdt1\", \"tenantId\": \"88a6ca3ee0394ade9403f075db23167e\" },"
\r
43 + " \"subscriberInfo\": { \"globalSubscriberId\": \"{some subscriber id}\","
\r
44 + " \"subscriberName\": \"{some subscriber name}\" },"
\r
45 + " \"requestInfo\": { \"productFamilyId\": \"a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb\", "
\r
46 + "\"source\": \"VID\", \"suppressRollback\": true, \"requestorId\": \"az2016\" },"
\r
47 + " \"requestParameters\": { \"subscriptionServiceType\": \"MOG\", \"aLaCarte\": false,"
\r
48 + " \"userParams\": [ { \"name\": \"someUserParam\", \"value\": \"someValue\" } ] } } } ";
\r
50 private static final String requestJSONActivateDeacivate =
\r
51 "{ \"requestDetails\": { \"modelInfo\": { \"modelType\": \"service\","
\r
52 + " \"modelInvariantId\": \"ff3514e3-5a33-55df-13ab-12abad84e7ff\", "
\r
53 + "\"modelVersionId\": \"fe6985cd-ea33-3346-ac12-ab121484a3fe\", "
\r
54 + "\"modelName\": \"Test\", \"modelVersion\": \"1.0\" }, "
\r
55 + "\"requestInfo\": { \"source\": \"VID\", \"requestorId\": \"az2016\" }, "
\r
56 + "\"requestParameters\": { \"userParams\": [ { \"name\": \"aic_zone\", "
\r
57 + "\"value\": \"someValue\" } ] } } } ";
\r
59 private static final String requestJSONDelete =
\r
60 "{ \"requestDetails\": { \"modelInfo\": { \"modelType\":\"network\", "
\r
61 + "\"modelName\":\"CONTRAIL30_BASIC\" }, \"cloudConfiguration\": { \"lcpCloudRegionId\":\"mdt1\", "
\r
62 + "\"tenantId\":\"8b1df54faa3b49078e3416e21370a3ba\" }, "
\r
63 + "\"requestInfo\": { \"source\":\"VID\", \"requestorId\":\"az2016\" } } }";
\r
66 public void testCreateServiceInstance()
\r
67 throws JsonParseException, JsonMappingException, IOException, ValidationException {
\r
68 final String CHECK_HTML = "<!DOCTYPE html><html><head><meta charset=\"ISO-8859-1\"><title></title></head><body></body></html>";
\r
69 final Response SERVICE_RESPONSE = Response.status(HttpStatus.SC_OK).entity(CHECK_HTML).build();
\r
72 ServiceInstances sir = Mockito.mock(ServiceInstances.class);
\r
73 sir.createServiceInstance(requestJSONCreate, "v3");
\r
74 Mockito.when(sir.createServiceInstance(requestJSONCreate, "v3")).thenReturn(SERVICE_RESPONSE);
\r
75 Response resp = sir.createServiceInstance(requestJSONCreate, "v3");
\r
76 assertEquals(resp.getStatus(), HttpStatus.SC_OK);
\r
77 } catch (Exception e) {
\r
79 e.printStackTrace();
\r
84 public void testActivateServiceInstance()
\r
85 throws JsonParseException, JsonMappingException, IOException, ValidationException {
\r
86 final String CHECK_HTML = "<!DOCTYPE html><html><head><meta charset=\"ISO-8859-1\"><title></title></head><body></body></html>";
\r
87 final Response SERVICE_RESPONSE = Response.status(HttpStatus.SC_OK).entity(CHECK_HTML).build();
\r
89 ServiceInstances sir = Mockito.mock(ServiceInstances.class);
\r
90 Mockito.when(sir.activateServiceInstance(requestJSONActivateDeacivate, "v5", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc"))
\r
91 .thenReturn(SERVICE_RESPONSE);
\r
92 Response resp = sir.activateServiceInstance(requestJSONActivateDeacivate, "v5", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
\r
93 assertEquals(resp.getStatus(), HttpStatus.SC_OK);
\r
94 } catch (Exception e) {
\r
96 e.printStackTrace();
\r
101 public void testDeactivateServiceInstance()
\r
102 throws JsonParseException, JsonMappingException, IOException, ValidationException {
\r
103 final String CHECK_HTML = "<!DOCTYPE html><html><head><meta charset=\"ISO-8859-1\"><title></title></head><body></body></html>";
\r
104 final Response SERVICE_RESPONSE = Response.status(HttpStatus.SC_OK).entity(CHECK_HTML).build();
\r
106 ServiceInstances sir = Mockito.mock(ServiceInstances.class);
\r
107 Mockito.when(sir.deactivateServiceInstance(requestJSONActivateDeacivate, "v5", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc"))
\r
108 .thenReturn(SERVICE_RESPONSE);
\r
109 Response resp = sir.deactivateServiceInstance(requestJSONActivateDeacivate, "v5", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
\r
110 assertEquals(resp.getStatus(), HttpStatus.SC_OK);
\r
111 } catch (Exception e) {
\r
113 e.printStackTrace();
\r
118 public void testDeleteServiceInstance()
\r
119 throws JsonParseException, JsonMappingException, IOException, ValidationException {
\r
120 final String CHECK_HTML = "<!DOCTYPE html><html><head><meta charset=\"ISO-8859-1\"><title>Health Check</title></head><body>Application ready</body></html>";
\r
121 final Response SERVICE_RESPONSE = Response.status(HttpStatus.SC_OK).entity(CHECK_HTML).build();
\r
123 ServiceInstances sir = Mockito.mock(ServiceInstances.class);
\r
124 Mockito.when(sir.deleteServiceInstance(requestJSONDelete, "v5", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc"))
\r
125 .thenReturn(SERVICE_RESPONSE);
\r
126 Response resp = sir.deleteServiceInstance(requestJSONDelete, "v5", "3eecada1-83a4-4f33-9ed2-7937e7b8dbbc");
\r
127 assertEquals(resp.getStatus(), HttpStatus.SC_OK);
\r
128 } catch (Exception e) {
\r
130 e.printStackTrace();
\r