8d06b400740793e6d015b29dcd1f55965226c87a
[so.git] / mso-api-handlers / mso-api-handler-infra / src / test / java / org / openecomp / mso / apihandlerinfra / VnfRequestHandlerTest.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.openecomp.mso.apihandlerinfra;
22
23 import static org.junit.Assert.assertTrue;
24
25 import java.lang.reflect.Field;
26 import java.net.URI;
27
28 import mockit.Mock;
29 import mockit.MockUp;
30
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.mockito.Mockito;
34 import org.openecomp.mso.apihandlerinfra.vnfbeans.VnfRequest;
35 import org.openecomp.mso.requestsdb.InfraRequests;
36
37 import javax.ws.rs.core.Response;
38 import javax.ws.rs.core.UriInfo;
39
40 public class VnfRequestHandlerTest {
41         VnfRequestHandler handler = null;
42         UriInfo uriInfo = null;
43         
44         @Before
45         public void setup() throws Exception{
46                 
47                 uriInfo = Mockito.mock(UriInfo.class);
48                 Class<?> clazz = VnfRequestHandler.class;
49                 handler = (VnfRequestHandler)clazz.newInstance();
50                 
51                 Field f1 = handler.getClass().getDeclaredField("uriInfo");
52                 
53                 f1.setAccessible(true);
54         f1.set(handler, uriInfo);
55         }
56         
57         @Test
58         public void manageVnfRequestTest(){
59                 Response resp = handler.manageVnfRequest("<name>Test</name>", "v2");
60                 assertTrue(null != resp);
61         }
62         
63         @Test
64         public void manageVnfRequest2Test(){
65                 Mockito.when(uriInfo.getRequestUri())
66         .thenReturn(URI.create("http://localhost:8080/test"));
67                 
68                 new MockUp<MsoPropertiesUtils>() {
69                         @Mock
70                         public synchronized final boolean getNoPropertiesState() {
71                                 return false;
72                         }
73                 };
74                 Response resp = handler.manageVnfRequest("<name>Test</name>", "v2");
75                 assertTrue(null != resp);
76         }
77         
78         @Test
79         public void fillVnfRequestTest(){
80                 VnfRequest qr = new VnfRequest();
81                 InfraRequests ar = new InfraRequests();
82                 ar.setVnfId("1003");
83                 ar.setVnfName("vnf");
84                 ar.setVnfType("vnt");
85                 ar.setTenantId("48889690");
86                 ar.setProvStatus("uuu");
87                 ar.setVolumeGroupName("volume");
88                 ar.setVolumeGroupId("38838");
89                 ar.setServiceType("vnf");
90                 ar.setAicNodeClli("djerfe");
91                 ar.setAaiServiceId("599499");
92                 ar.setAicCloudRegion("south");
93                 ar.setVfModuleName("m1");
94                 ar.setVfModuleId("39949");
95                 ar.setVfModuleModelName("test");
96                 ar.setAaiServiceId("37728");
97                 ar.setVnfParams("test");
98                 handler.fillVnfRequest(qr, ar, "v1");
99                 String param = (String)qr.getVnfParams();
100                 assertTrue(param.equals("test"));
101         }
102         
103         @Test
104         public void fillVnfRequestTestV2(){
105                 VnfRequest qr = new VnfRequest();
106                 InfraRequests ar = new InfraRequests();
107                 ar.setVnfId("1003");
108                 ar.setVnfName("vnf");
109                 ar.setVnfType("vnt");
110                 ar.setTenantId("48889690");
111                 ar.setProvStatus("uuu");
112                 ar.setVolumeGroupName("volume");
113                 ar.setVolumeGroupId("38838");
114                 ar.setServiceType("vnf");
115                 ar.setAicNodeClli("djerfe");
116                 ar.setAaiServiceId("599499");
117                 ar.setAicCloudRegion("south");
118                 ar.setVfModuleName("m1");
119                 ar.setVfModuleId("39949");
120                 ar.setVfModuleModelName("test");
121                 ar.setAaiServiceId("37728");
122                 ar.setVnfParams("test");
123                 handler.fillVnfRequest(qr, ar, "v2");
124                 String param = (String)qr.getVnfParams();
125                 assertTrue(param.equals("test"));
126         }
127         @Test
128         public void fillVnfRequestTestV3(){
129                 VnfRequest qr = new VnfRequest();
130                 InfraRequests ar = new InfraRequests();
131                 ar.setVnfId("1003");
132                 ar.setVnfName("vnf");
133                 ar.setVnfType("vnt");
134                 ar.setTenantId("48889690");
135                 ar.setProvStatus("uuu");
136                 ar.setVolumeGroupName("volume");
137                 ar.setVolumeGroupId("38838");
138                 ar.setServiceType("vnf");
139                 ar.setAicNodeClli("djerfe");
140                 ar.setAaiServiceId("599499");
141                 ar.setAicCloudRegion("south");
142                 ar.setVfModuleName("m1");
143                 ar.setVfModuleId("39949");
144                 ar.setVfModuleModelName("test");
145                 ar.setAaiServiceId("37728");
146                 ar.setVnfParams("test");
147                 ar.setServiceInstanceId("38829");
148                 handler.fillVnfRequest(qr, ar, "v3");
149                 String param = (String)qr.getVnfParams();
150                 assertTrue(param.equals("test"));
151         }
152
153 }