2 * Copyright 2017 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.cli.fw.ad;
19 import static org.junit.Assert.fail;
21 import org.junit.Test;
22 import org.onap.cli.fw.OnapCommand;
23 import org.onap.cli.fw.OnapCommandRegistrar;
24 import org.onap.cli.fw.cmd.OnapHttpCommand;
25 import org.onap.cli.fw.conf.Constants;
26 import org.onap.cli.fw.conf.OnapCommandConfg;
27 import org.onap.cli.fw.error.OnapCommandException;
29 public class OnapAuthClientCommandBasedTest {
32 public void internalCommandTest() {
34 OnapCommand cmd = OnapCommandRegistrar.getRegistrar().get("sample-test");
35 cmd.getInfo().setService(OnapCommandConfg.getProductName());
38 } catch (OnapCommandException e) {
39 fail("Internal command failed to run");
45 public void yesCatalogYesAuthTest() throws OnapCommandException {
47 OnapHttpCommand cmd = getCommand("sample-test-schema-yes-auth-yes-catalog.yaml");
48 cmd.getParametersMap().get(Constants.DEAFULT_PARAMETER_HOST_URL).setValue("http://localhost:8080");
49 cmd.getParametersMap().get(Constants.DEAFULT_PARAMETER_USERNAME).setValue("test");
50 cmd.getParametersMap().get(Constants.DEAFULT_PARAMETER_PASSWORD).setValue("password");
53 } catch (OnapCommandException e) {
54 fail("External command Yes Auth Yes Catalog failed to run");
60 public void yesCatalogNoAuthTest() throws OnapCommandException {
62 OnapHttpCommand cmd = getCommand("sample-test-schema-no-auth-yes-catalog.yaml");
63 cmd.getParametersMap().get(Constants.DEAFULT_PARAMETER_HOST_URL).setValue("http://localhost:8080");
66 } catch (OnapCommandException e) {
67 fail("External command Yes Auth No Catalog failed to run");
73 public void noCatalogYesAuthTest() throws OnapCommandException {
75 OnapHttpCommand cmd = getCommand("sample-test-schema-yes-auth-no-catalog.yaml");
76 cmd.getParametersMap().get(Constants.DEAFULT_PARAMETER_HOST_URL).setValue("http://localhost:8080");
77 cmd.getParametersMap().get(Constants.DEAFULT_PARAMETER_USERNAME).setValue("test");
78 cmd.getParametersMap().get(Constants.DEAFULT_PARAMETER_PASSWORD).setValue("password");
81 } catch (OnapCommandException e) {
82 fail("External command Yes Auth No Catalog failed to run");
88 public void noCatalogNoAuthTest() throws OnapCommandException {
90 OnapHttpCommand cmd = getCommand("sample-test-schema-no-auth-no-catalog.yaml");
91 cmd.getParametersMap().get(Constants.DEAFULT_PARAMETER_HOST_URL).setValue("http://localhost:8080");
94 } catch (OnapCommandException e) {
95 fail("External command No Auth No Catalog failed to run");
100 private OnapHttpCommand getCommand(String yaml) throws OnapCommandException {
101 OnapHttpCommand cmd = new OnapHttpCommand() {
103 protected void processRequest() throws OnapCommandException {
104 if (!this.getService().isModeDirect()) {
105 String url = this.authClient.getServiceUrl();
106 assert url.equals(this.getParametersMap().get(Constants.DEAFULT_PARAMETER_HOST_URL).getValue() + "/");
111 cmd.initializeSchema(yaml);