be41944b31072f2067ec5b1ec4ac31a06270766f
[so.git] / mso-api-handlers / mso-api-handler-infra / src / test / java / org / openecomp / mso / apihandlerinfra / VolumeRequestHandlerTest.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
38 public class VolumeRequestHandlerTest {
39         VolumeRequestHandler handler = null;
40         
41     UriInfo uriInfo = null;
42         
43         @Before
44         public void setup() throws Exception{
45                 
46                 uriInfo = Mockito.mock(UriInfo.class);
47                 Class<?> clazz = VolumeRequestHandler.class;
48                 handler = (VolumeRequestHandler)clazz.newInstance();
49                 
50                 Field f1 = handler.getClass().getDeclaredField("uriInfo");
51                 
52                 f1.setAccessible(true);
53         f1.set(handler, uriInfo);
54         }
55         
56         @Test
57         public void manageVnfRequestTest(){
58                 Response resp = handler.manageVolumeRequest("<name>Test</name>", "v2");
59                 assertTrue(null != resp);
60         }
61         
62         @Test
63         public void manageVnfRequest2Test(){
64                 Mockito.when(uriInfo.getRequestUri())
65         .thenReturn(URI.create("http://localhost:8080/test"));
66                 
67                 new MockUp<MsoPropertiesUtils>() {
68                         @Mock
69                         public synchronized final boolean getNoPropertiesState() {
70                                 return false;
71                         }
72                 };
73                 Response resp = handler.manageVolumeRequest("<name>Test</name>", "v2");
74                 assertTrue(null != resp);
75         }
76 }