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