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