c593ca58f2444f8408bae93a75f2019a75f31a0a
[vfc/nfvo/driver/vnfm/svnfm.git] / huawei / vnfmadapter / VnfmadapterService / service / src / test / java / org / onap / vfc / nfvo / vnfm / svnfm / vnfmadapter / service / process / AuthMgrTest.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
17 package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.process;
18
19 import static org.junit.Assert.assertEquals;
20
21 import org.junit.Test;
22 import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.restclient.RestfulResponse;
23 import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.servicetoken.VnfmRestfulUtil;
24 import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.Constant;
25
26 import mockit.Mock;
27 import mockit.MockUp;
28 import net.sf.json.JSONObject;
29
30 public class AuthMgrTest {
31
32     @Test
33     public void testAuthTokenByDomainNameByJSONException() {
34         AuthMgr authMgr = new AuthMgr();
35         String data = "{\"auth\":{}}";
36         JSONObject params = JSONObject.fromObject(data);
37
38         JSONObject result = authMgr.authToken(params);
39
40         JSONObject restJson = new JSONObject();
41         restJson.put("retCode", Constant.REST_FAIL);
42         restJson.put("data", "JSONException");
43         assertEquals(restJson, result);
44     }
45
46     @Test
47     public void testAuthToken() {
48         new MockUp<VnfmRestfulUtil>() {
49
50             @Mock
51             public RestfulResponse getRestResByDefault(String auth, String method, JSONObject authParams) {
52                 RestfulResponse response = null;
53                 return response;
54             }
55         };
56
57         AuthMgr authMgr = new AuthMgr();
58         String data = "{\"auth\":{\"identity\":{\"password\":{\"user\":{\"name\":\"om_team\",\"password\":\"123\"}}}}}";
59         JSONObject params = JSONObject.fromObject(data);
60
61         JSONObject result = authMgr.authToken(params);
62         assertEquals(Constant.REST_FAIL, result.getInt("retCode"));
63     }
64 }