2 * Copyright 2016 Huawei Technologies Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.process;
19 import static org.junit.Assert.assertEquals;
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;
29 import net.sf.json.JSONObject;
31 public class AuthMgrTest {
34 public void testAuthTokenByDomainNameByJSONException() {
35 AuthMgr authMgr = new AuthMgr();
36 String data = "{\"auth\":{}}";
37 JSONObject params = JSONObject.fromObject(data);
39 JSONObject result = authMgr.authToken(params);
41 JSONObject restJson = new JSONObject();
42 restJson.put("retCode", Constant.REST_FAIL);
43 restJson.put("data", "JSONException");
44 assertEquals(restJson, result);
48 public void testAuthToken() {
49 new MockUp<VnfmRestfulUtil>() {
52 public RestfulResponse getRestResByDefault(String auth, String method, JSONObject authParams) {
53 RestfulResponse response = null;
58 AuthMgr authMgr = new AuthMgr();
59 String data = "{\"auth\":{\"identity\":{\"password\":{\"user\":{\"name\":\"om_team\",\"password\":\"123\"}}}}}";
60 JSONObject params = JSONObject.fromObject(data);
62 JSONObject result = authMgr.authToken(params);
63 assertEquals(Constant.REST_SUCCESS, result.getInt("retCode"));