aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/test')
-rw-r--r--framework/src/test/java/org/onap/cli/fw/cmd/OnapCreateSwaggerBasedCommand.java100
-rw-r--r--framework/src/test/java/org/onap/cli/fw/cmd/OnapCreateSwaggerBasedCommandTest.java32
-rw-r--r--framework/src/test/java/org/onap/cli/fw/cmd/OnapDeleteSwaggerBasedCommand.java75
-rw-r--r--framework/src/test/java/org/onap/cli/fw/cmd/OnapDeleteSwaggerBasedCommandTest.java21
-rw-r--r--framework/src/test/java/org/onap/cli/fw/cmd/OnapGetSwaggerBasedCommand.java79
-rw-r--r--framework/src/test/java/org/onap/cli/fw/cmd/OnapGetSwaggerBasedCommandTest.java21
-rw-r--r--framework/src/test/java/org/onap/cli/fw/cmd/OnapListSwaggerBasedCommand.java78
-rw-r--r--framework/src/test/java/org/onap/cli/fw/cmd/OnapListSwaggerBasedCommandTest.java21
-rw-r--r--framework/src/test/java/org/onap/cli/fw/cmd/OnapSwaggerCommandTest.java96
-rw-r--r--framework/src/test/java/org/onap/cli/fw/run/OnapCommandExecutorTest.java38
-rw-r--r--framework/src/test/java/org/onap/cli/fw/schema/ValidateSchemaTest.java26
-rw-r--r--framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java66
12 files changed, 30 insertions, 623 deletions
diff --git a/framework/src/test/java/org/onap/cli/fw/cmd/OnapCreateSwaggerBasedCommand.java b/framework/src/test/java/org/onap/cli/fw/cmd/OnapCreateSwaggerBasedCommand.java
deleted file mode 100644
index 89367f1d..00000000
--- a/framework/src/test/java/org/onap/cli/fw/cmd/OnapCreateSwaggerBasedCommand.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * 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.cmd;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.List;
-
-import org.onap.cli.fw.error.OnapCommandException;
-import org.onap.cli.fw.error.OnapCommandExecutionFailed;
-import org.onap.cli.fw.error.OnapCommandExecutorInfoMissing;
-import org.onap.cli.fw.error.OnapCommandResultInitialzationFailed;
-import org.onap.cli.fw.utils.OnapCommandUtils;
-
-public class OnapCreateSwaggerBasedCommand extends OnapSwaggerCommand {
-
- private <T> T initializeEntity(T obj, List<String> prps) throws OnapCommandResultInitialzationFailed {
- for (int i = 1; i < prps.size(); i++) {
- String paramName = prps.get(i).trim();
- String prpName = paramName;
- // paramName(prpName)
- if (prpName.contains("(")) {
- paramName = prpName.substring(0, prpName.indexOf("("));
- prpName = prpName.substring(prpName.indexOf("(") + 1, prpName.indexOf(")"));
- }
- String methodName = OnapCommandUtils.formMethodNameFromAttributeName(prpName, "set");
-
- try {
- Method set = obj.getClass().getMethod(methodName, String.class);
- set.invoke(obj, this.getParametersMap().get(paramName).getValue());
- } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
- | InvocationTargetException e) {
- throw new OnapCommandResultInitialzationFailed(this.getName(), e);
- }
- }
- return obj;
- }
-
- @Override
- protected void run() throws OnapCommandException {
- if (this.getExecutor() == null) {
- throw new OnapCommandExecutorInfoMissing(this.getName());
- }
-
- try {
- // Initialize client
- Class clientClaz = Class.forName(this.getExecutor().getClient());
- Object client = clientClaz.getConstructor().newInstance();
- this.initializeApiClient(client);
-
- // Initialize api
- Class apiCls = Class.forName(this.getExecutor().getApi());
- Object api = apiCls.getConstructor(clientClaz).newInstance(client);
-
- // invoke method
- List<String> methodTokens = Arrays.asList(this.getExecutor().getMethod().split(","));
-
- List<String> entityTokens = Arrays.asList(this.getExecutor().getEntity().split(","));
- Class entityCls = Class.forName(entityTokens.get(0));
- Object entity = entityCls.newInstance();
- Method method = api.getClass().getMethod(methodTokens.get(0), entityCls);
- Object result = method.invoke(api, this.initializeEntity(entity, entityTokens));
-
- // initialize result
- this.initializeResult(result);
- } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException
- | IllegalArgumentException | InvocationTargetException e) {
- throw new OnapCommandExecutionFailed(this.getName(), e);
- } catch (OnapCommandException e) {
- throw e;
- } catch (Exception e) {
- try {
- Class execCls = Class.forName(this.getExecutor().getException());
- Method execMethod = execCls.getClass().getMethod("getCode");
- if (execCls.isInstance(e)) {
- throw new OnapCommandExecutionFailed(this.getName(), e, (Integer) execMethod.invoke(e));
- }
- } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
- | ClassNotFoundException | NoSuchMethodException | SecurityException e1) {
- throw new OnapCommandExecutionFailed(this.getName(), e1.getMessage());
- }
- throw new OnapCommandExecutionFailed(this.getName(), e.getMessage());
- }
- }
-}
diff --git a/framework/src/test/java/org/onap/cli/fw/cmd/OnapCreateSwaggerBasedCommandTest.java b/framework/src/test/java/org/onap/cli/fw/cmd/OnapCreateSwaggerBasedCommandTest.java
deleted file mode 100644
index ec4b91d4..00000000
--- a/framework/src/test/java/org/onap/cli/fw/cmd/OnapCreateSwaggerBasedCommandTest.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.cmd;
-
-import org.junit.Test;
-import org.onap.cli.fw.OnapCommand;
-import org.onap.cli.fw.error.OnapCommandException;
-
-public class OnapCreateSwaggerBasedCommandTest {
-
- @Test
- public void runTest() throws OnapCommandException {
- OnapCommand cmd = new OnapCreateSwaggerBasedCommand();
- cmd.initializeSchema("sample-test-schema-swagger.yaml");
- //cmd.execute();
- }
-
-}
diff --git a/framework/src/test/java/org/onap/cli/fw/cmd/OnapDeleteSwaggerBasedCommand.java b/framework/src/test/java/org/onap/cli/fw/cmd/OnapDeleteSwaggerBasedCommand.java
deleted file mode 100644
index 1db954c6..00000000
--- a/framework/src/test/java/org/onap/cli/fw/cmd/OnapDeleteSwaggerBasedCommand.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * 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.cmd;
-
-import org.onap.cli.fw.error.OnapCommandException;
-import org.onap.cli.fw.error.OnapCommandExecutionFailed;
-import org.onap.cli.fw.error.OnapCommandExecutorInfoMissing;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * Helps to make delete rest calls on top of swagger generated java client. For example following one shows how MSB
- * service list is achieved here exec: ... method: deleteMicroService, [input param name given under Parameters]
- *
- */
-public class OnapDeleteSwaggerBasedCommand extends OnapSwaggerCommand {
-
- @Override
- protected void run() throws OnapCommandException {
- if (this.getExecutor() == null) {
- throw new OnapCommandExecutorInfoMissing(this.getName());
- }
-
- try {
- // Initialize client
- Class clientCls = Class.forName(this.getExecutor().getClient());
- Object client = clientCls.getConstructor().newInstance();
- this.initializeApiClient(client);
-
- // Initialize api
- Class apiCls = Class.forName(this.getExecutor().getApi());
- Object api = apiCls.getConstructor(clientCls).newInstance(client);
-
- // invoke method
- List<String> methodTokens = Arrays.asList(this.getExecutor().getMethod().split(","));
-
- Method method = api.getClass().getMethod(methodTokens.get(0), String.class);
- method.invoke(api, this.getParametersMap().get(methodTokens.get(1)).getValue());
- } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException
- | IllegalArgumentException | InvocationTargetException e) {
- throw new OnapCommandExecutionFailed(this.getName(), e);
- } catch (OnapCommandException e) {
- throw e;
- } catch (Exception e) {
- try {
- Class execCls = Class.forName(this.getExecutor().getException());
- Method execMethod = execCls.getClass().getMethod("getCode");
- if (execCls.isInstance(e)) {
- throw new OnapCommandExecutionFailed(this.getName(), e, (Integer) execMethod.invoke(e));
- }
- } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
- | ClassNotFoundException | NoSuchMethodException | SecurityException e1) {
- throw new OnapCommandExecutionFailed(this.getName(), e1.getMessage());
- }
- throw new OnapCommandExecutionFailed(this.getName(), e.getMessage());
- }
- }
-}
diff --git a/framework/src/test/java/org/onap/cli/fw/cmd/OnapDeleteSwaggerBasedCommandTest.java b/framework/src/test/java/org/onap/cli/fw/cmd/OnapDeleteSwaggerBasedCommandTest.java
deleted file mode 100644
index a242a683..00000000
--- a/framework/src/test/java/org/onap/cli/fw/cmd/OnapDeleteSwaggerBasedCommandTest.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * 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.cmd;
-
-public class OnapDeleteSwaggerBasedCommandTest {
-
-}
diff --git a/framework/src/test/java/org/onap/cli/fw/cmd/OnapGetSwaggerBasedCommand.java b/framework/src/test/java/org/onap/cli/fw/cmd/OnapGetSwaggerBasedCommand.java
deleted file mode 100644
index 8ed86564..00000000
--- a/framework/src/test/java/org/onap/cli/fw/cmd/OnapGetSwaggerBasedCommand.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * 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.cmd;
-
-import org.onap.cli.fw.error.OnapCommandException;
-import org.onap.cli.fw.error.OnapCommandExecutionFailed;
-import org.onap.cli.fw.error.OnapCommandExecutorInfoMissing;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * Helps to make get rest calls on top of swagger generated java client. For example following one shows how MSB service
- * list is achieved here exec: ... method: getMicroService, [input param name given under Parameters]
- *
- */
-public class OnapGetSwaggerBasedCommand extends OnapSwaggerCommand {
-
- @Override
- protected void run() throws OnapCommandException {
- if (this.getExecutor() == null) {
- throw new OnapCommandExecutorInfoMissing(this.getName());
- }
-
- try {
- // Initialize client
- Class clientCls = Class.forName(this.getExecutor().getClient());
- Object client = clientCls.getConstructor().newInstance();
- this.initializeApiClient(client);
-
- // Initialize api
- Class apiCls = Class.forName(this.getExecutor().getApi());
- Object api = apiCls.getConstructor(clientCls).newInstance(client);
-
- // invoke method
- List<String> methodTokens = Arrays.asList(this.getExecutor().getMethod().split(","));
-
- Method method = api.getClass().getMethod(methodTokens.get(0), String.class);
- Object result = method.invoke(api, this.getParametersMap().get(methodTokens.get(1)).getValue());
-
- // initialize result
- this.initializeResult(result);
-
- } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException
- | IllegalArgumentException | InvocationTargetException e) {
- throw new OnapCommandExecutionFailed(this.getName(), e);
- } catch (OnapCommandException e) {
- throw e;
- } catch (Exception e) {
- try {
- Class execCls = Class.forName(this.getExecutor().getException());
- Method execMethod = execCls.getClass().getMethod("getCode");
- if (execCls.isInstance(e)) {
- throw new OnapCommandExecutionFailed(this.getName(), e, (Integer) execMethod.invoke(e));
- }
- } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
- | ClassNotFoundException | NoSuchMethodException | SecurityException e1) {
- throw new OnapCommandExecutionFailed(this.getName(), e1.getMessage());
- }
- throw new OnapCommandExecutionFailed(this.getName(), e.getMessage());
- }
- }
-}
diff --git a/framework/src/test/java/org/onap/cli/fw/cmd/OnapGetSwaggerBasedCommandTest.java b/framework/src/test/java/org/onap/cli/fw/cmd/OnapGetSwaggerBasedCommandTest.java
deleted file mode 100644
index 5c301a62..00000000
--- a/framework/src/test/java/org/onap/cli/fw/cmd/OnapGetSwaggerBasedCommandTest.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * 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.cmd;
-
-public class OnapGetSwaggerBasedCommandTest {
-
-}
diff --git a/framework/src/test/java/org/onap/cli/fw/cmd/OnapListSwaggerBasedCommand.java b/framework/src/test/java/org/onap/cli/fw/cmd/OnapListSwaggerBasedCommand.java
deleted file mode 100644
index a5795e75..00000000
--- a/framework/src/test/java/org/onap/cli/fw/cmd/OnapListSwaggerBasedCommand.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * 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.cmd;
-
-import org.onap.cli.fw.error.OnapCommandException;
-import org.onap.cli.fw.error.OnapCommandExecutionFailed;
-import org.onap.cli.fw.error.OnapCommandExecutorInfoMissing;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-/**
- * Helps to make list rest calls on top of swagger generated java client. For example following one shows how MSB
- * service list is achived here exec: api:
- * org.onap.common_services.microservice_bus.apiroute_service.client.api.MSBServiceResourceApi client:
- * org.onap.common_services.microservice_bus.apiroute_service.client.invoker.ApiClient method: getMicroService
- * exception: org.onap.common_services.microservice_bus.apiroute_service.client.invoker.ApiException
- *
- */
-public class OnapListSwaggerBasedCommand extends OnapSwaggerCommand {
-
- @Override
- protected void run() throws OnapCommandException {
- if (this.getExecutor() == null) {
- throw new OnapCommandExecutorInfoMissing(this.getName());
- }
-
- try {
- // Initialize client
- Class clientCls = Class.forName(this.getExecutor().getClient());
- Object client = clientCls.getConstructor().newInstance();
- this.initializeApiClient(client);
-
- // Initialize api
- Class apiCls = Class.forName(this.getExecutor().getApi());
- Object api = apiCls.getConstructor(clientCls).newInstance(client);
-
- // invoke method
- Method method = api.getClass().getMethod(this.getExecutor().getMethod());
- Object result = method.invoke(api);
-
- // initialize result
- this.initializeResult(result);
-
- } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException
- | IllegalArgumentException | InvocationTargetException e) {
- throw new OnapCommandExecutionFailed(this.getName(), e);
- } catch (OnapCommandException e) {
- throw e;
- } catch (Exception e) {
- try {
- Class execCls = Class.forName(this.getExecutor().getException());
- Method execMethod = execCls.getClass().getMethod("getCode");
- if (execCls.isInstance(e)) {
- throw new OnapCommandExecutionFailed(this.getName(), e, (Integer) execMethod.invoke(e));
- }
- } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
- | ClassNotFoundException | NoSuchMethodException | SecurityException e1) {
- throw new OnapCommandExecutionFailed(this.getName(), e1.getMessage());
- }
- throw new OnapCommandExecutionFailed(this.getName(), e.getMessage());
- }
- }
-}
diff --git a/framework/src/test/java/org/onap/cli/fw/cmd/OnapListSwaggerBasedCommandTest.java b/framework/src/test/java/org/onap/cli/fw/cmd/OnapListSwaggerBasedCommandTest.java
deleted file mode 100644
index 5683153c..00000000
--- a/framework/src/test/java/org/onap/cli/fw/cmd/OnapListSwaggerBasedCommandTest.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * 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.cmd;
-
-public class OnapListSwaggerBasedCommandTest {
-
-}
diff --git a/framework/src/test/java/org/onap/cli/fw/cmd/OnapSwaggerCommandTest.java b/framework/src/test/java/org/onap/cli/fw/cmd/OnapSwaggerCommandTest.java
deleted file mode 100644
index 47e3e050..00000000
--- a/framework/src/test/java/org/onap/cli/fw/cmd/OnapSwaggerCommandTest.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * 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.cmd;
-
-import org.junit.Test;
-import org.onap.cli.fw.OnapCommand;
-import org.onap.cli.fw.error.OnapCommandClientInitialzationFailed;
-import org.onap.cli.fw.error.OnapCommandException;
-import org.onap.cli.fw.error.OnapCommandResultInitialzationFailed;
-import org.onap.cli.fw.input.OnapCommandParameter;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-public class OnapSwaggerCommandTest {
-
- @Test(expected = OnapCommandResultInitialzationFailed.class)
- public void initializeResultTest1() throws OnapCommandException {
- OnapSwaggerCommandImpl swagger = new OnapSwaggerCommandImpl();
- swagger.initializeSchema("onap-test-schema.yaml");
- List<String> obj = new ArrayList<>();
- obj.add("name");
- obj.add("get");
- swagger.initializeResult(obj);
-
- Set<String> obj1 = new HashSet<>();
- obj.add("name");
- obj.add("get");
- swagger.initializeResult(obj1);
- }
-
- @Test(expected = OnapCommandResultInitialzationFailed.class)
- public void initializeResultTest2() throws OnapCommandException {
- OnapSwaggerCommandImpl swagger = new OnapSwaggerCommandImpl();
- swagger.initializeSchema("onap-test-schema.yaml");
- Set<String> obj1 = new HashSet<>();
- obj1.add("name");
- obj1.add("get");
- swagger.initializeResult(obj1);
- }
-
- @Test
- public void initializeResultTest3() throws OnapCommandException {
- OnapSwaggerCommandImpl swagger = new OnapSwaggerCommandImpl();
- swagger.initializeSchema("onap-test-schema.yaml");
- ApiClient cit = new ApiClient();
- cit.setApiKey("apiKey");
- cit.setBasePath("basePath");
- swagger.initializeApiClient(cit);
- }
-
- class OnapSwaggerCommandImpl extends OnapSwaggerCommand {
- protected void run() throws OnapCommandException {
- }
-
- }
-
- class ApiClient {
-
- private String basePath;
- private String apiKey;
-
- public String getBasePath() {
- return basePath;
- }
-
- public void setBasePath(String basePath) {
- this.basePath = basePath;
- }
-
- public String getApiKey() {
- return apiKey;
- }
-
- public void setApiKey(String apiKey) {
- this.apiKey = apiKey;
- }
-
- }
-}
diff --git a/framework/src/test/java/org/onap/cli/fw/run/OnapCommandExecutorTest.java b/framework/src/test/java/org/onap/cli/fw/run/OnapCommandExecutorTest.java
deleted file mode 100644
index 1236365c..00000000
--- a/framework/src/test/java/org/onap/cli/fw/run/OnapCommandExecutorTest.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * 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.run;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-public class OnapCommandExecutorTest {
-
- @Test
- public void commandExecutorTest() {
- OnapCommandExecutor exec = new OnapCommandExecutor();
- exec.setApi("api");
- exec.setClient("client");
- exec.setEntity("entity");
- exec.setException("exception");
- exec.setMethod("method");
-
- Assert.assertTrue(
- exec.getApi().equals("api") && exec.getClient().equals("client") && exec.getEntity().equals("entity")
- && exec.getMethod().equals("method") && exec.getException().equals("exception"));
- }
-
-}
diff --git a/framework/src/test/java/org/onap/cli/fw/schema/ValidateSchemaTest.java b/framework/src/test/java/org/onap/cli/fw/schema/ValidateSchemaTest.java
index 654b20cd..87612e62 100644
--- a/framework/src/test/java/org/onap/cli/fw/schema/ValidateSchemaTest.java
+++ b/framework/src/test/java/org/onap/cli/fw/schema/ValidateSchemaTest.java
@@ -21,7 +21,7 @@ import org.onap.cli.fw.OnapCommand;
import org.onap.cli.fw.cmd.OnapHttpCommand;
import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.error.OnapCommandInvalidSchema;
-import org.onap.cli.fw.utils.OnapCommandUtils;
+import org.onap.cli.fw.utils.OnapCommandSchemaLoader;
import java.util.List;
@@ -36,7 +36,7 @@ public class ValidateSchemaTest {
@Override
protected void run() throws OnapCommandException {}
};
- OnapCommandUtils.loadSchema(cmd, "fdsfds.yaml", true, true);
+ OnapCommandSchemaLoader.loadSchema(cmd, "fdsfds.yaml", true, true);
}
@Test(expected = OnapCommandInvalidSchema.class)
@@ -45,7 +45,7 @@ public class ValidateSchemaTest {
@Override
protected void run() throws OnapCommandException {}
};
- OnapCommandUtils.loadSchema(cmd, "fdsfds", true, true);
+ OnapCommandSchemaLoader.loadSchema(cmd, "fdsfds", true, true);
}
@Test(expected = OnapCommandInvalidSchema.class)
@@ -54,7 +54,7 @@ public class ValidateSchemaTest {
@Override
protected void run() throws OnapCommandException {}
};
- OnapCommandUtils.loadSchema(cmd,
+ OnapCommandSchemaLoader.loadSchema(cmd,
ValidateSchemaTest.class.getClassLoader().getResource("open-cli.properties").getFile(),
true, true);
}
@@ -65,7 +65,7 @@ public class ValidateSchemaTest {
@Override
protected void run() throws OnapCommandException {}
};
- OnapCommandUtils.loadSchema(cmd, "schema-invalid-file-null.yaml", true, true);
+ OnapCommandSchemaLoader.loadSchema(cmd, "schema-invalid-file-null.yaml", true, true);
}
@Test
@@ -74,7 +74,7 @@ public class ValidateSchemaTest {
@Override
protected void run() throws OnapCommandException {}
};
- OnapCommandUtils.loadSchema(cmd, "schema-validate-pass.yaml", true, true);
+ OnapCommandSchemaLoader.loadSchema(cmd, "schema-validate-pass.yaml", true, true);
}
@@ -84,7 +84,7 @@ public class ValidateSchemaTest {
@Override
protected void run() throws OnapCommandException {}
};
- OnapCommandUtils.loadSchema(cmd, "schema-invalid-file.yaml", true, true);
+ OnapCommandSchemaLoader.loadSchema(cmd, "schema-invalid-file.yaml", true, true);
}
@Test
@@ -94,31 +94,31 @@ public class ValidateSchemaTest {
@Override
protected void run() throws OnapCommandException {}
};
- List<String> errorList1 = OnapCommandUtils.loadSchema(cmd1, "schema-validate-http.yaml", true, true);
+ List<String> errorList1 = OnapCommandSchemaLoader.loadSchema(cmd1, "schema-validate-http.yaml", true, true);
assertTrue(errorList1.size() > 0);
OnapCommand cmd2 = new OnapCommand() {
@Override
protected void run() throws OnapCommandException {}
};
- List<String> errorList2 = OnapCommandUtils.loadSchema(cmd2, "schema-validate-basic.yaml", true, true);
+ List<String> errorList2 = OnapCommandSchemaLoader.loadSchema(cmd2, "schema-validate-basic.yaml", true, true);
assertTrue(errorList2.size() > 0);
OnapCommand cmd3 = new OnapCommand() {
@Override
protected void run() throws OnapCommandException {}
};
- List<String> errorList3 = OnapCommandUtils.loadSchema(cmd2, "schema-validate-invalidschematype.yaml", true, true);
+ List<String> errorList3 = OnapCommandSchemaLoader.loadSchema(cmd2, "schema-validate-invalidschematype.yaml", true, true);
assertTrue(errorList3.size() > 0);
OnapCommand cmd4 = new OnapCommand() {
@Override
protected void run() throws OnapCommandException {}
};
- List<String> errorList4 = OnapCommandUtils.loadSchema(cmd2, "schema-validate-invalid.yaml", true, true);
+ List<String> errorList4 = OnapCommandSchemaLoader.loadSchema(cmd2, "schema-validate-invalid.yaml", true, true);
OnapHttpCommand oclipHttpCommand = new OnapHttpCommand();
- errorList4.addAll(OnapCommandUtils.loadHttpSchema(oclipHttpCommand,
+ errorList4.addAll(OnapCommandSchemaLoader.loadHttpSchema(oclipHttpCommand,
"schema-validate-invalid.yaml", true, true));
assertTrue(errorList4.size() > 0);
@@ -126,7 +126,7 @@ public class ValidateSchemaTest {
@Override
protected void run() throws OnapCommandException {}
};
- List<String> errorList5 = OnapCommandUtils.loadSchema(cmd5, "schema-validate-pass.yaml", true, true);
+ List<String> errorList5 = OnapCommandSchemaLoader.loadSchema(cmd5, "schema-validate-pass.yaml", true, true);
assertTrue(errorList5.size() == 0);
}
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 419c4edc..fd0373bd 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
@@ -38,7 +38,6 @@ import org.junit.runners.MethodSorters;
import org.onap.cli.fw.OnapCommand;
import org.onap.cli.fw.OnapCommandSchema;
import org.onap.cli.fw.cmd.OnapHttpCommand;
-import org.onap.cli.fw.cmd.OnapSwaggerCommand;
import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.error.OnapCommandHelpFailed;
import org.onap.cli.fw.error.OnapCommandHttpHeaderNotFound;
@@ -58,7 +57,6 @@ import org.onap.cli.fw.info.OnapCommandInfo;
import org.onap.cli.fw.input.OnapCommandParameter;
import org.onap.cli.fw.input.ParameterType;
import org.onap.cli.fw.output.OnapCommandResult;
-import org.onap.cli.fw.run.OnapCommandExecutor;
import org.springframework.core.io.Resource;
import mockit.Invocation;
@@ -70,12 +68,12 @@ public class OnapCommandUtilsTest {
@Test(expected = OnapCommandInvalidSchema.class)
public void oclipCommandUtilsInputStreamNullTest() throws OnapCommandException {
- OnapCommandUtils.validateSchemaVersion("sample-test1-schema-http1.yaml", "1.0");
+ OnapCommandSchemaLoader.validateSchemaVersion("sample-test1-schema-http1.yaml", "1.0");
}
@Test
public void oclipCommandUtilsInputStreamNotNullTest() throws OnapCommandException {
- Map<String, ?> map = OnapCommandUtils.validateSchemaVersion("sample-test1-schema-http.yaml", "1.0");
+ Map<String, ?> map = OnapCommandSchemaLoader.validateSchemaVersion("sample-test1-schema-http.yaml", "1.0");
assertTrue(map != null);
}
@@ -93,7 +91,7 @@ public class OnapCommandUtilsTest {
@Test
public void schemaFileNotFoundTest() throws OnapCommandException {
- Map<String, ?> map = OnapCommandUtils.validateSchemaVersion("sample-test-schema.yaml", "1.0");
+ Map<String, ?> map = OnapCommandSchemaLoader.validateSchemaVersion("sample-test-schema.yaml", "1.0");
assertTrue(map.size() > 0);
}
@@ -102,7 +100,7 @@ public class OnapCommandUtilsTest {
public void invalidSchemaFileTest() throws OnapCommandException {
Map<String, ?> map = null;
try {
- map = OnapCommandUtils.validateSchemaVersion("sample-test-schema1.yaml", "1.0");
+ map = OnapCommandSchemaLoader.validateSchemaVersion("sample-test-schema1.yaml", "1.0");
} catch (OnapCommandInvalidSchemaVersion e) {
fail("Test should not have thrown this exception : " + e.getMessage());
} catch (OnapCommandInvalidSchema e) {
@@ -116,7 +114,7 @@ public class OnapCommandUtilsTest {
public void validateWrongSchemaVersionTest() throws OnapCommandException {
Map<String, ?> map = null;
try {
- map = OnapCommandUtils.validateSchemaVersion("sample-test-invalid-schema.yaml", "1.0");
+ map = OnapCommandSchemaLoader.validateSchemaVersion("sample-test-invalid-schema.yaml", "1.0");
} catch (OnapCommandInvalidSchemaVersion e) {
fail("Test should not have thrown this exception : " + e.getMessage());
} catch (OnapCommandInvalidSchema e) {
@@ -130,7 +128,7 @@ public class OnapCommandUtilsTest {
public void validateSchemaVersionTest() throws OnapCommandException {
Map<String, ?> map = null;
try {
- map = OnapCommandUtils.validateSchemaVersion("sample-test-schema.yaml", "1.1");
+ map = OnapCommandSchemaLoader.validateSchemaVersion("sample-test-schema.yaml", "1.1");
} catch (OnapCommandInvalidSchemaVersion e) {
assertEquals("0xb003::Command schema open_cli_schema_version 1.0 is invalid or missing", e.getMessage());
} catch (OnapCommandInvalidSchema e) {
@@ -143,32 +141,32 @@ public class OnapCommandUtilsTest {
@Test
public void loadOnapCommandSchemaWithOutDefaultTest() throws OnapCommandException {
OnapCommand cmd = new OnapCommandSample();
- OnapCommandUtils.loadSchema(cmd, "sample-test-schema.yaml", false, false);
+ OnapCommandSchemaLoader.loadSchema(cmd, "sample-test-schema.yaml", false, false);
assertTrue("sample-test".equals(cmd.getName()) && cmd.getParameters().size() == 9);
}
@Test(expected = OnapCommandParameterNameConflict.class)
public void loadOnapCommandSchemaWithDuplicateNameTest() throws OnapCommandException {
OnapCommand cmd = new OnapCommandSample();
- OnapCommandUtils.loadSchema(cmd, "sample-test-invalid-schema-duplicate-name.yaml", false, false);
+ OnapCommandSchemaLoader.loadSchema(cmd, "sample-test-invalid-schema-duplicate-name.yaml", false, false);
}
@Test(expected = OnapCommandParameterOptionConflict.class)
public void loadOnapCommandSchemaWithDuplicateShortOptionTest() throws OnapCommandException {
OnapCommand cmd = new OnapCommandSample();
- OnapCommandUtils.loadSchema(cmd, "sample-test-invalid-schema-duplicate-shortoption.yaml", false, false);
+ OnapCommandSchemaLoader.loadSchema(cmd, "sample-test-invalid-schema-duplicate-shortoption.yaml", false, false);
}
@Test(expected = OnapCommandParameterOptionConflict.class)
public void loadOnapCommandSchemaWithDuplicateLongOptionTest() throws OnapCommandException {
OnapCommand cmd = new OnapCommandSample();
- OnapCommandUtils.loadSchema(cmd, "sample-test-invalid-schema-duplicate-longoption.yaml", false, false);
+ OnapCommandSchemaLoader.loadSchema(cmd, "sample-test-invalid-schema-duplicate-longoption.yaml", false, false);
}
@Test
public void loadOnapCommandSchemaWithDefaultTest() throws OnapCommandException {
OnapCommand cmd = new OnapCommandSample();
- OnapCommandUtils.loadSchema(cmd, "sample-test-schema.yaml", true, false);
+ OnapCommandSchemaLoader.loadSchema(cmd, "sample-test-schema.yaml", true, false);
assertTrue("sample-test".equals(cmd.getName()) && cmd.getParameters().size() > 9);
for (OnapCommandParameter com : cmd.getParameters()) {
@@ -182,7 +180,7 @@ public class OnapCommandUtilsTest {
@Test
public void loadOnapCommandSchemaAuthRequiredTest() throws OnapCommandException {
OnapCommand cmd = new OnapCommandSample();
- OnapCommandUtils.loadSchema(cmd, "sample-test-schema-auth-required.yaml", true, false);
+ OnapCommandSchemaLoader.loadSchema(cmd, "sample-test-schema-auth-required.yaml", true, false);
assertTrue("sample-test".equals(cmd.getName()));
Map<String, OnapCommandParameter> map = OnapCommandUtils.getInputMap(cmd.getParameters());
@@ -190,33 +188,11 @@ public class OnapCommandUtilsTest {
}
@Test
- public void loadSwaggerBasedSchemaExceptionTest() throws OnapCommandException {
- OnapSwaggerCommand cmd = new OnapSwaggerBasedCommandSample();
- try {
- OnapCommandUtils.loadSchema(cmd, "sample-test-schema.yaml");
- } catch (OnapCommandInvalidSchema e) {
- assertEquals("0xb001", e.getErrorCode());
- }
- }
-
- @Test
- public void loadSwaggerBasedSchemaTest() throws OnapCommandException {
- OnapSwaggerCommand cmd = new OnapSwaggerBasedCommandSample();
- try {
- OnapCommandUtils.loadSchema(cmd, "sample-test-schema-swagger.yaml");
- OnapCommandExecutor exe = cmd.getExecutor();
- assertTrue(exe != null);
- } catch (OnapCommandInvalidSchema e) {
- assertTrue(e.getMessage().contains("0xb001::Command schema sample-test-schema.yaml is invalid"));
- }
- }
-
- @Test
public void loadHttpBasedSchemaExceptionTest() throws OnapCommandException {
OnapHttpCommand cmd = new OnapHttpCommandSample();
cmd.setName("sample-test-http");
try {
- OnapCommandUtils.loadHttpSchema(cmd, "sample-test-schema.yaml", true, false);
+ OnapCommandSchemaLoader.loadHttpSchema(cmd, "sample-test-schema.yaml", true, false);
} catch (OnapCommandParameterNameConflict | OnapCommandParameterOptionConflict
| OnapCommandInvalidParameterType | OnapCommandInvalidPrintDirection
| OnapCommandInvalidResultAttributeScope | OnapCommandSchemaNotFound | OnapCommandInvalidSchema
@@ -230,7 +206,7 @@ public class OnapCommandUtilsTest {
OnapHttpCommand cmd = new OnapHttpCommandSample();
cmd.setName("sample-create-http");
try {
- OnapCommandUtils.loadHttpSchema(cmd, "sample-test-schema-http.yaml", true, true);
+ OnapCommandSchemaLoader.loadHttpSchema(cmd, "sample-test-schema-http.yaml", true, true);
assertTrue(cmd.getSuccessStatusCodes().size() == 2);
} catch (OnapCommandParameterNameConflict | OnapCommandParameterOptionConflict
| OnapCommandInvalidParameterType | OnapCommandInvalidPrintDirection
@@ -243,7 +219,7 @@ public class OnapCommandUtilsTest {
@Test
public void helpCommandTest() throws IOException, OnapCommandException {
OnapCommand cmd = new OnapCommandSample();
- OnapCommandUtils.loadSchema(cmd, "sample-test-schema.yaml", true, false);
+ OnapCommandSchemaLoader.loadSchema(cmd, "sample-test-schema.yaml", true, false);
String actualResult = OnapCommandUtils.help(cmd);
@@ -386,7 +362,7 @@ public class OnapCommandUtilsTest {
mockPrintMethodException();
OnapCommand cmd = new OnapCommandSample();
- OnapCommandUtils.loadSchema(cmd, "sample-test-schema.yaml", true, false);
+ OnapCommandSchemaLoader.loadSchema(cmd, "sample-test-schema.yaml", true, false);
OnapCommandUtils.help(cmd);
@@ -396,7 +372,7 @@ public class OnapCommandUtilsTest {
@Test
public void test() throws OnapCommandException {
OnapCommandSampleInfo cmd = new OnapCommandSampleInfo();
- OnapCommandUtils.loadSchema(cmd, "sample-test-info.yaml", true, false);
+ OnapCommandSchemaLoader.loadSchema(cmd, "sample-test-info.yaml", true, false);
OnapCommandInfo info = cmd.getInfo();
assert info != null;
}
@@ -415,14 +391,6 @@ public class OnapCommandUtilsTest {
}
}
- @OnapCommandSchema(schema = "sample-test-schema-swagger.yaml")
- class OnapSwaggerBasedCommandSample extends OnapSwaggerCommand {
-
- @Override
- protected void run() throws OnapCommandException {
- }
- }
-
@OnapCommandSchema(schema = "sample-test-schema-http.yaml")
class OnapHttpCommandSample extends OnapHttpCommand {