aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/test/java
diff options
context:
space:
mode:
authorsubhash kumar singh <subhash.kumar.singh@huawei.com>2017-08-01 19:56:00 +0530
committerKanagaraj Manickam <kanagaraj.manickam@huawei.com>2017-08-10 05:33:38 +0000
commit2741f49b3b5e92c5c31f44133fd458c4f15b5479 (patch)
treee232e671e11d664787802144532407cae3e08d06 /framework/src/test/java
parent4e2d92bc6c5ae4499f8a583f9b80a1a9172e0c17 (diff)
Populate default param based on no-auth
Based on no-auth customise the default parameter for onap-command. e.g. If "no-auth = true" then command should not add default parameter "onap-username, onap-password, msb-url and no-auth". Issue-Id: CLI-22 Change-Id: Ic9228feb1deb7e6f24eb9b9f0c8f15fd45364e94 Signed-off-by: subhash kumar singh <subhash.kumar.singh@huawei.com>
Diffstat (limited to 'framework/src/test/java')
-rw-r--r--framework/src/test/java/org/onap/cli/fw/OnapCommandRegistrarTest.java10
-rw-r--r--framework/src/test/java/org/onap/cli/fw/TestCommandValidate.java55
-rw-r--r--framework/src/test/java/org/onap/cli/fw/defaultParameter/TestDefaultParameterSection.java39
-rw-r--r--framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterTest.java4
-rw-r--r--framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java12
5 files changed, 106 insertions, 14 deletions
diff --git a/framework/src/test/java/org/onap/cli/fw/OnapCommandRegistrarTest.java b/framework/src/test/java/org/onap/cli/fw/OnapCommandRegistrarTest.java
index 83f3a743..a076eee6 100644
--- a/framework/src/test/java/org/onap/cli/fw/OnapCommandRegistrarTest.java
+++ b/framework/src/test/java/org/onap/cli/fw/OnapCommandRegistrarTest.java
@@ -16,11 +16,6 @@
package org.onap.cli.fw;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
import org.junit.Before;
import org.junit.Test;
import org.onap.cli.fw.error.OnapCommandException;
@@ -31,6 +26,11 @@ import org.onap.cli.fw.error.OnapCommandRegistrationFailed;
import java.io.File;
import java.net.URL;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
public class OnapCommandRegistrarTest {
OnapCommandRegistrar registerar;
diff --git a/framework/src/test/java/org/onap/cli/fw/TestCommandValidate.java b/framework/src/test/java/org/onap/cli/fw/TestCommandValidate.java
new file mode 100644
index 00000000..b8ac72ef
--- /dev/null
+++ b/framework/src/test/java/org/onap/cli/fw/TestCommandValidate.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.cli.fw;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.cli.fw.error.OnapCommandException;
+import org.onap.cli.fw.error.OnapCommandParameterMissing;
+import org.onap.cli.fw.input.OnapCommandParameter;
+import org.onap.cli.fw.utils.OnapCommandUtils;
+
+public class TestCommandValidate {
+
+ OnapCommand cmd;
+
+ @Before
+ public void before() {
+ cmd = new OnapCommand() {
+ @Override
+ protected void run() throws OnapCommandException {}
+ };
+ }
+
+ @Test
+ public void testNoAuthArgumentTrue() throws OnapCommandException {
+
+ OnapCommandUtils.loadSchema(cmd, "sample-test-include-param.yaml", true);
+
+ OnapCommandParameter noAuthParam = cmd.getParameters().stream().filter(p -> p.getName().equalsIgnoreCase("no-auth")).findFirst().get();
+ noAuthParam.setValue(true);
+ OnapCommandParameter msbParam = cmd.getParameters().stream().filter(p -> p.getName().equalsIgnoreCase("msb-url")).findFirst().get();
+ msbParam.setValue("localhost://msbip:msb:port");
+ cmd.validate();
+ }
+
+ @Test(expected = OnapCommandParameterMissing.class)
+ public void testNoAuthArgFalse() throws OnapCommandException {
+ OnapCommandUtils.loadSchema(cmd, "sample-test-include-param.yaml", true);
+ cmd.validate();
+ }
+}
diff --git a/framework/src/test/java/org/onap/cli/fw/defaultParameter/TestDefaultParameterSection.java b/framework/src/test/java/org/onap/cli/fw/defaultParameter/TestDefaultParameterSection.java
index bd2ad0d1..004bf7cf 100644
--- a/framework/src/test/java/org/onap/cli/fw/defaultParameter/TestDefaultParameterSection.java
+++ b/framework/src/test/java/org/onap/cli/fw/defaultParameter/TestDefaultParameterSection.java
@@ -21,6 +21,7 @@ import org.onap.cli.fw.OnapCommand;
import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.error.OnapCommandInvalidDefaultParameter;
import org.onap.cli.fw.error.OnapCommandInvalidSchema;
+import org.onap.cli.fw.input.OnapCommandParameter;
import org.onap.cli.fw.utils.OnapCommandUtils;
import java.util.List;
@@ -54,9 +55,12 @@ public class TestDefaultParameterSection {
OnapCommandUtils.loadSchema(cmd, "sample-test-exclude-param.yaml", true);
List<String> parameters = cmd.getParameters().stream().map(p -> p.getName()).collect(Collectors.toList());
- assertFalse(parameters.contains("onap-username"));
+ assertTrue(parameters.contains("onap-username"));
assertTrue(parameters.contains("onap-password"));
- assertFalse(parameters.contains("msb-url"));
+ assertTrue(parameters.contains("msb-url"));
+ assertFalse(parameters.contains("long"));
+ assertFalse(parameters.contains("format"));
+ assertTrue(parameters.contains("debug"));
}
@Test
@@ -70,8 +74,8 @@ public class TestDefaultParameterSection {
List<String> parameters = cmd.getParameters().stream().map(p -> p.getName()).collect(Collectors.toList());
assertTrue(parameters.contains("onap-username"));
- assertFalse(parameters.contains("onap-password"));
- assertFalse(parameters.contains("msb-url"));
+ assertTrue(parameters.contains("onap-password"));
+ assertTrue(parameters.contains("msb-url"));
}
@Test
@@ -84,9 +88,12 @@ public class TestDefaultParameterSection {
OnapCommandUtils.loadSchema(cmd, "onap-test-schema.yaml", true);
List<String> parameters = cmd.getParameters().stream().map(p -> p.getName()).collect(Collectors.toList());
- assertTrue(parameters.contains("onap-username"));
- assertTrue(parameters.contains("onap-password"));
+ assertFalse(parameters.contains("onap-username"));
+ assertFalse(parameters.contains("onap-password"));
assertTrue(parameters.contains("msb-url"));
+ assertTrue(parameters.contains("debug"));
+ assertTrue(parameters.contains("long"));
+ assertTrue(parameters.contains("format"));
}
@Test(expected = OnapCommandInvalidDefaultParameter.class)
@@ -118,4 +125,24 @@ public class TestDefaultParameterSection {
OnapCommandUtils.loadSchema(cmd, "sample-test-import-def-param-false.yaml", true);
}
+
+ @Test(expected = OnapCommandInvalidDefaultParameter.class)
+ public void checkInvalidIncludeNoAuth() throws OnapCommandException {
+ OnapCommand cmd = new OnapCommand() {
+ @Override
+ protected void run() throws OnapCommandException {}
+ };
+
+ OnapCommandUtils.loadSchema(cmd, "sample-test-invalid-include-noauth.yaml", true);
+ }
+
+ @Test(expected = OnapCommandInvalidDefaultParameter.class)
+ public void checkInvalidExcludeNoAuth() throws OnapCommandException {
+ OnapCommand cmd = new OnapCommand() {
+ @Override
+ protected void run() throws OnapCommandException {}
+ };
+
+ OnapCommandUtils.loadSchema(cmd, "sample-test-invalid-exclude-noauth.yaml", true);
+ }
}
diff --git a/framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterTest.java b/framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterTest.java
index 40b07861..604411ed 100644
--- a/framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterTest.java
+++ b/framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterTest.java
@@ -16,8 +16,6 @@
package org.onap.cli.fw.input;
-import static org.junit.Assert.assertTrue;
-
import org.junit.Test;
import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.error.OnapCommandInvalidParameterValue;
@@ -26,6 +24,8 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
+import static org.junit.Assert.assertTrue;
+
public class OnapCommandParameterTest {
@Test
diff --git a/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java b/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java
index b74027a0..d01e2e77 100644
--- a/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java
+++ b/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java
@@ -179,7 +179,17 @@ public class OnapCommandUtilsTest {
OnapCredentials cre = OnapCommandUtils.fromParameters(cmd.getParameters());
assertTrue(cre != null);
Map<String, OnapCommandParameter> map = OnapCommandUtils.getInputMap(cmd.getParameters());
- assertTrue(map.size() == 19);
+ assertTrue(map.size() == 16);
+ }
+
+ @Test
+ public void loadOnapCommandSchemaAuthRequiredTest() throws OnapCommandException {
+ OnapCommand cmd = new OnapCommandSample();
+ OnapCommandUtils.loadSchema(cmd, "sample-test-schema-auth-required.yaml", true);
+ assertTrue("sample-test".equals(cmd.getName()));
+
+ Map<String, OnapCommandParameter> map = OnapCommandUtils.getInputMap(cmd.getParameters());
+ assertTrue(map.size() == 11);
}
@Test