e88054f3efa426c24f0c6c3de9578fadb83cb5c3
[vfc/nfvo/driver/vnfm/gvnfm.git] / juju / juju-vnfmadapter / Juju-vnfmadapterService / service / src / test / java / org / openo / nfvo / jujuvnfmadapter / service / rest / VnfRoaTest.java
1 /*
2  * Copyright 2016 Huawei Technologies Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.openo.nfvo.jujuvnfmadapter.service.rest;
17
18 import static org.junit.Assert.*;
19
20 import javax.servlet.http.HttpServletRequest;
21 import javax.servlet.http.HttpServletResponse;
22 import javax.ws.rs.PathParam;
23 import javax.ws.rs.core.Context;
24
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.openo.baseservice.remoteservice.exception.ServiceException;
28 import org.openo.nfvo.jujuvnfmadapter.common.StringUtil;
29 import org.openo.nfvo.jujuvnfmadapter.service.entity.JujuVnfmInfo;
30 import org.openo.nfvo.jujuvnfmadapter.service.process.VnfMgr;
31 import org.springframework.mock.web.MockHttpServletResponse;
32
33 import mockit.Mock;
34 import mockit.MockUp;
35 import net.sf.json.JSONObject;
36
37 public class VnfRoaTest {
38     
39     VnfRoa roa = new VnfRoa();
40     @Before
41     public void setUp(){
42         roa.setVnfMgr(new VnfMgr());
43     }
44     
45     @Test
46     public void addVnfTestNull() throws ServiceException{
47         new MockUp<StringUtil>(){
48             @Mock
49             public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
50                 return null;
51             }
52         };
53         HttpServletRequest context = null;
54         HttpServletResponse resp = new MockHttpServletResponse();
55         String vnfmId = "1234";
56         String res = roa.addVnf(context, resp, vnfmId);
57         assertNotNull(res);
58     }
59     
60     @Test
61     public void addVnfTest() throws ServiceException{
62         new MockUp<StringUtil>(){
63             @Mock
64             public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
65                 String vnfJsonStr = "{}";
66                 return (T)JSONObject.fromObject(vnfJsonStr);
67             }
68         };
69         HttpServletRequest context = null;
70         HttpServletResponse resp = new MockHttpServletResponse();
71         String vnfmId = "1234";
72         String res = roa.addVnf(context, resp, vnfmId);
73         assertNotNull(res);
74     }
75     @Test
76     public void delVnfTestNull() throws ServiceException{
77         new MockUp<StringUtil>(){
78             @Mock
79             public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
80                 return null;
81             }
82         };
83         new MockUp<VnfMgr>(){
84             @Mock
85             private JujuVnfmInfo findByVnfId(String vnfId){
86                 JujuVnfmInfo info = new JujuVnfmInfo();
87                 info.setVnfmId("1234");
88                 return info;
89             }
90         };
91         HttpServletRequest context = null;
92         HttpServletResponse resp = new MockHttpServletResponse();
93         String vnfmId = "1234";
94         String res = roa.delVnf("vnfmId", resp, "vnfInstanceId",context);
95         assertNotNull(res);
96     }
97     @Test
98     public void delVnf2TestNull() throws ServiceException{
99         new MockUp<StringUtil>(){
100             @Mock
101             public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
102                 return null;
103             }
104         };
105         HttpServletRequest context = null;
106         HttpServletResponse resp = new MockHttpServletResponse();
107         String vnfmId = "1234";
108         String res = roa.delVnf(null, resp, "vnfInstanceId",context);
109         assertNotNull(res);
110     }
111     @Test
112     public void delVnf3TestNull() throws ServiceException{
113         new MockUp<StringUtil>(){
114             @Mock
115             public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
116                 return null;
117             }
118         };
119         HttpServletRequest context = null;
120         HttpServletResponse resp = new MockHttpServletResponse();
121         String vnfmId = "1234";
122         String res = roa.delVnf(vnfmId, resp, null,context);
123         assertNotNull(res);
124     }
125     @Test
126     public void getVnf1TestNull() throws ServiceException{
127         new MockUp<StringUtil>(){
128             @Mock
129             public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
130                 return null;
131             }
132         };
133         new MockUp<VnfMgr>(){
134             @Mock
135             private JujuVnfmInfo findByVnfId(String vnfId){
136                 JujuVnfmInfo info = new JujuVnfmInfo();
137                 info.setVnfmId("1234");
138                 return info;
139             }
140         };
141         HttpServletRequest context = null;
142         HttpServletResponse resp = new MockHttpServletResponse();
143         String vnfmId = "1234";
144         String res = roa.getVnf(vnfmId, resp, "vnfInstanceId",context);
145         assertNotNull(res);
146     }
147     @Test
148     public void getVnf2TestNull() throws ServiceException{
149         new MockUp<StringUtil>(){
150             @Mock
151             public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
152                 return null;
153             }
154         };
155         HttpServletRequest context = null;
156         HttpServletResponse resp = new MockHttpServletResponse();
157         String vnfmId = "1234";
158         String res = roa.getVnf(null, resp, "vnfInstanceId",context);
159         assertNotNull(res);
160     }
161     @Test
162     public void getVnf3TestNull() throws ServiceException{
163         new MockUp<StringUtil>(){
164             @Mock
165             public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
166                 return null;
167             }
168         };
169         HttpServletRequest context = null;
170         HttpServletResponse resp = new MockHttpServletResponse();
171         String vnfmId = "1234";
172         String res = roa.getVnf(vnfmId, resp, null,context);
173         assertNotNull(res);
174     }
175     @Test
176     public void getJobTestNull() throws ServiceException{
177         HttpServletResponse resp = new MockHttpServletResponse();
178         String res = roa.getJob("jobId", "vnfmId", resp,"responseId");
179         assertNotNull(res);
180     }
181     @Test
182     public void getJobTest2Null() throws ServiceException{
183         HttpServletResponse resp = new MockHttpServletResponse();
184         String res = roa.getJob(null, "vnfmId", resp,"responseId");
185         assertNotNull(res);
186     }
187     @Test
188     public void getJobTest3Null() throws ServiceException{
189         HttpServletResponse resp = new MockHttpServletResponse();
190         String res = roa.getJob("jobId", null, resp,"responseId");
191         assertNotNull(res);
192     }
193     
194     @Test
195     public void getJobTestNormal() throws ServiceException{
196         new MockUp<VnfMgr>(){
197             @Mock
198             public JSONObject getJob(String jobId, String vnfmId) {
199                 JSONObject obj = new JSONObject();
200                 JSONObject dataObj = new JSONObject();
201                 dataObj.put("id", "1234");
202                 dataObj.put("status", "Success");
203                 obj.put("data", dataObj);
204                 obj.put("retCode", 1);
205                 return obj;
206             }
207             
208         };
209         HttpServletResponse resp = new MockHttpServletResponse();
210         String res = roa.getJob("jobId", "vnfmId", resp,"responseId");
211         assertNotNull(res);
212     }
213     
214
215 }