diff options
Diffstat (limited to 'framework/src')
5 files changed, 246 insertions, 37 deletions
diff --git a/framework/src/test/java/org/onap/cli/fw/cmd/schema/OnapSchemaListCommandTest.java b/framework/src/test/java/org/onap/cli/fw/cmd/schema/OnapSchemaListCommandTest.java new file mode 100644 index 00000000..92bdad0b --- /dev/null +++ b/framework/src/test/java/org/onap/cli/fw/cmd/schema/OnapSchemaListCommandTest.java @@ -0,0 +1,56 @@ +/* + * Copyright 2019 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.schema; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.cli.fw.cmd.execution.OnapCommandExceutionListCommandTest; +import org.onap.cli.fw.error.OnapCommandException; +import org.onap.cli.fw.output.OnapCommandResultAttribute; +import org.onap.cli.fw.store.OnapCommandExecutionStoreTest; +import org.onap.cli.fw.utils.FileUtil; + +import java.io.File; +import java.util.List; +import static org.junit.Assert.*; + +public class OnapSchemaListCommandTest { + static OnapCommandExecutionStoreTest executionStoreTest; + @BeforeClass + public static void setUp() throws Exception { + executionStoreTest= new OnapCommandExecutionStoreTest(); + executionStoreTest.setUp(); + executionStoreTest.storeExectutionStartTest(); + } + @Test + public void runTest() throws OnapCommandException { + OnapSchemaListCommand cmd=new OnapSchemaListCommand(); + cmd.initializeSchema("schema-list.yaml"); + cmd.getParametersMap().get("product").setValue("open-cli"); + cmd.execute(); + List<OnapCommandResultAttribute> oclipCommandResultAttributes = cmd.getResult() + .getRecords(); + assertTrue(oclipCommandResultAttributes.size()>1); + } + @AfterClass + public static void tearDown() throws Exception { + String dirPathForExecutions = System.getProperty("user.dir") + File.separator + "data/executions"; + File executionsFile = new File(dirPathForExecutions); + assertTrue(OnapCommandExceutionListCommandTest.deleteDirectory(executionsFile)); + } + +}
\ No newline at end of file diff --git a/framework/src/test/java/org/onap/cli/fw/cmd/schema/OnapSchemaShowCommandTest.java b/framework/src/test/java/org/onap/cli/fw/cmd/schema/OnapSchemaShowCommandTest.java new file mode 100644 index 00000000..279d30d6 --- /dev/null +++ b/framework/src/test/java/org/onap/cli/fw/cmd/schema/OnapSchemaShowCommandTest.java @@ -0,0 +1,57 @@ + /* + * Copyright 2019 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.schema; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.cli.fw.cmd.execution.OnapCommandExceutionListCommandTest; +import org.onap.cli.fw.error.OnapCommandException; +import org.onap.cli.fw.output.OnapCommandResultAttribute; +import org.onap.cli.fw.store.OnapCommandExecutionStoreTest; +import org.onap.cli.fw.utils.FileUtil; + +import java.io.File; +import java.util.List; +import static org.junit.Assert.*; + +public class OnapSchemaShowCommandTest { + static OnapCommandExecutionStoreTest executionStoreTest; + @BeforeClass + public static void setUp() throws Exception { + executionStoreTest= new OnapCommandExecutionStoreTest(); + executionStoreTest.setUp(); + executionStoreTest.storeExectutionStartTest(); + } + @Test + public void runTest() throws OnapCommandException { + OnapSchemaShowCommand cmd = new OnapSchemaShowCommand (); + cmd.initializeSchema("schema-show.yaml"); + cmd.getParametersMap().get("product").setValue("open-cli"); + cmd.getParametersMap().get("command").setValue("schema-show"); + cmd.execute(); + List<OnapCommandResultAttribute> oclipCommandResultAttributes = cmd.getResult() + .getRecords(); + assertTrue(oclipCommandResultAttributes.size()>0); + } + @AfterClass + public static void tearDown() throws Exception { + String dirPathForExecutions = System.getProperty("user.dir") + File.separator + "data/executions"; + File executionsFile = new File(dirPathForExecutions); + assertTrue(OnapCommandExceutionListCommandTest.deleteDirectory(executionsFile)); + } + }
\ No newline at end of file diff --git a/framework/src/test/java/org/onap/cli/fw/cmd/schema/OnapSchemaValidateCommandTest.java b/framework/src/test/java/org/onap/cli/fw/cmd/schema/OnapSchemaValidateCommandTest.java new file mode 100644 index 00000000..d87c63b5 --- /dev/null +++ b/framework/src/test/java/org/onap/cli/fw/cmd/schema/OnapSchemaValidateCommandTest.java @@ -0,0 +1,58 @@ +/* + * Copyright 2019 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.schema; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.cli.fw.cmd.execution.OnapCommandExceutionListCommandTest; +import org.onap.cli.fw.error.OnapCommandException; +import org.onap.cli.fw.output.OnapCommandResultAttribute; +import org.onap.cli.fw.store.OnapCommandExecutionStoreTest; +import org.onap.cli.fw.utils.FileUtil; + +import java.io.File; +import java.util.List; + +import static org.junit.Assert.*; + +public class OnapSchemaValidateCommandTest +{ + static OnapCommandExecutionStoreTest executionStoreTest; + @BeforeClass + public static void setUp() throws Exception { + executionStoreTest= new OnapCommandExecutionStoreTest(); + executionStoreTest.setUp(); + executionStoreTest.storeExectutionStartTest(); + } + + @Test + public void runTest() throws OnapCommandException { + OnapSchemaValidateCommand cmd = new OnapSchemaValidateCommand(); + cmd.initializeSchema("schema-validate.yaml"); + cmd.getParametersMap().get("schema-location").setValue(System.getProperty("user.dir")+ File.separator+"src/main/resources/open-cli-schema/schema/schema-validate.yaml"); + cmd.execute(); + List<OnapCommandResultAttribute> oclipCommandResultAttributes = cmd.getResult() + .getRecords(); + assertTrue(oclipCommandResultAttributes.size()>0); + } + @AfterClass + public static void tearDown() throws Exception { + String dirPathForExecutions = System.getProperty("user.dir") + File.separator + "data/executions"; + File executionsFile = new File(dirPathForExecutions); + assertTrue(OnapCommandExceutionListCommandTest.deleteDirectory(executionsFile)); + } +}
\ No newline at end of file diff --git a/framework/src/test/java/org/onap/cli/fw/store/OnapCommandExecutionStoreTest.java b/framework/src/test/java/org/onap/cli/fw/store/OnapCommandExecutionStoreTest.java index 6b69f0b0..639f6239 100644 --- a/framework/src/test/java/org/onap/cli/fw/store/OnapCommandExecutionStoreTest.java +++ b/framework/src/test/java/org/onap/cli/fw/store/OnapCommandExecutionStoreTest.java @@ -16,8 +16,10 @@ package org.onap.cli.fw.store; +import org.junit.AfterClass; import org.junit.Before; import org.junit.Test; +import org.onap.cli.fw.cmd.execution.OnapCommandExceutionListCommandTest; import org.onap.cli.fw.error.OnapCommandExecutionFailed; import java.io.File; @@ -28,58 +30,77 @@ import static org.junit.Assert.*; public class OnapCommandExecutionStoreTest { OnapCommandExecutionStore executionStore; + @Before public void setUp() throws Exception { - executionStore=OnapCommandExecutionStore.getStore(); + executionStore = OnapCommandExecutionStore.getStore(); } + @Test - public void storeExectutionStartTest(){ - assertNotNull(executionStore.storeExectutionStart("requestId","product","service","cmd","profile","input")); + public void storeExectutionStartTest() { + assertNotNull(executionStore.storeExectutionStart("requestId", "product", "service", "cmd", "profile", "input")); } + @Test public void listExecutionsTest() throws OnapCommandExecutionFailed { - Map<String,String> search=new HashMap<>(); - search.put("startTime","12"); - search.put("endTime","12"); - search.put("execution-id","abc"); - search.put("request-id","abc"); + Map<String, String> search = new HashMap<>(); + search.put("startTime", "12"); + search.put("endTime", "12"); + search.put("execution-id", "abc"); + search.put("request-id", "abc"); assertNotNull(executionStore.listExecutions(search)); } + @Test - public void storeExectutionEndTest(){ - OnapCommandExecutionStore.ExecutionStoreContext store=new OnapCommandExecutionStore.ExecutionStoreContext(); + public void storeExectutionEndTest() { + OnapCommandExecutionStore.ExecutionStoreContext store = new OnapCommandExecutionStore.ExecutionStoreContext(); store.setExecutionId("abc"); store.setRequestId("abc"); store.setStorePath("abc"); - executionStore.storeExectutionEnd(store,"abc","abc","abc",true); - assertTrue(new File(System.getProperty("user.dir")+File.separator+"abc").exists()); + executionStore.storeExectutionEnd(store, "abc", "abc", "abc", true); + assertTrue(new File(System.getProperty("user.dir") + File.separator + "abc").exists()); } + @Test - public void storeExectutionProgressTest(){ - OnapCommandExecutionStore.ExecutionStoreContext store=new OnapCommandExecutionStore.ExecutionStoreContext(); + public void storeExectutionProgressTest() { + OnapCommandExecutionStore.ExecutionStoreContext store = new OnapCommandExecutionStore.ExecutionStoreContext(); store.setExecutionId("abc"); store.setRequestId("abc"); store.setStorePath("abc"); - executionStore.storeExectutionProgress(store,"abc","abc","abc"); - assertTrue(new File(System.getProperty("user.dir")+File.separator+"abc").exists()); + executionStore.storeExectutionProgress(store, "abc", "abc", "abc"); + assertTrue(new File(System.getProperty("user.dir") + File.separator + "abc").exists()); } + @Test - public void storeExectutionDebugTest(){ - OnapCommandExecutionStore.ExecutionStoreContext store=new OnapCommandExecutionStore.ExecutionStoreContext(); + public void storeExectutionDebugTest() { + OnapCommandExecutionStore.ExecutionStoreContext store = new OnapCommandExecutionStore.ExecutionStoreContext(); store.setExecutionId("abc"); store.setRequestId("abc"); store.setStorePath("abc"); - executionStore.storeExectutionDebug(store,"abc"); - assertTrue(new File(System.getProperty("user.dir")+File.separator+"abc").exists()); + executionStore.storeExectutionDebug(store, "abc"); + assertTrue(new File(System.getProperty("user.dir") + File.separator + "abc").exists()); } + @Test - public void storeExectutionOutputTest(){ - OnapCommandExecutionStore.ExecutionStoreContext store=new OnapCommandExecutionStore.ExecutionStoreContext(); + public void storeExectutionOutputTest() { + OnapCommandExecutionStore.ExecutionStoreContext store = new OnapCommandExecutionStore.ExecutionStoreContext(); store.setExecutionId("abc"); store.setRequestId("abc"); store.setStorePath("abc"); - executionStore.storeExectutionOutput(store,"abc"); - assertTrue(new File(System.getProperty("user.dir")+File.separator+"abc").exists()); + executionStore.storeExectutionOutput(store, "abc"); + assertTrue(new File(System.getProperty("user.dir") + File.separator + "abc").exists()); + } + + + + @AfterClass + public static void tearDown() throws Exception { + String dirPath = System.getProperty("user.dir") + File.separator + "abc"; + String dirPathForExecutions = System.getProperty("user.dir") + File.separator + "data/executions"; + File file = new File(dirPath); + File executionsDir = new File(dirPathForExecutions); + assertTrue(OnapCommandExceutionListCommandTest.deleteDirectory(file)); + assertTrue(OnapCommandExceutionListCommandTest.deleteDirectory(executionsDir)); } }
\ No newline at end of file diff --git a/framework/src/test/java/org/onap/cli/fw/store/OnapCommandProfileStoreTest.java b/framework/src/test/java/org/onap/cli/fw/store/OnapCommandProfileStoreTest.java index f98f518d..3ffd45c0 100644 --- a/framework/src/test/java/org/onap/cli/fw/store/OnapCommandProfileStoreTest.java +++ b/framework/src/test/java/org/onap/cli/fw/store/OnapCommandProfileStoreTest.java @@ -15,11 +15,14 @@ */ package org.onap.cli.fw.store; +import org.junit.AfterClass; import org.junit.Before; import org.junit.Test; +import org.onap.cli.fw.cmd.execution.OnapCommandExceutionListCommandTest; import org.onap.cli.fw.error.OnapCommandException; import org.onap.cli.fw.error.OnapCommandPersistProfileFailed; import org.onap.cli.fw.input.cache.OnapCommandParamEntity; +import org.onap.cli.fw.utils.FileUtil; import java.io.File; import java.util.ArrayList; @@ -29,39 +32,53 @@ import static org.junit.Assert.*; public class OnapCommandProfileStoreTest { OnapCommandProfileStore onapCommandProfileStore; + @Before public void setUp() throws Exception { - onapCommandProfileStore=OnapCommandProfileStore.getInstance(); + onapCommandProfileStore = OnapCommandProfileStore.getInstance(); } + @Test public void includeProfileTest() throws OnapCommandException { onapCommandProfileStore.includeProfile("profiles"); - assertTrue(new File(System.getProperty("user.dir")+File.separator+"data/profiles").exists()); + assertTrue(new File(System.getProperty("user.dir") + File.separator + "data/profiles").exists()); } + @Test public void persistProfileAndgetProfilesTest() throws OnapCommandPersistProfileFailed { - OnapCommandParamEntity onapCommandParamEntity=new OnapCommandParamEntity(); + OnapCommandParamEntity onapCommandParamEntity = new OnapCommandParamEntity(); onapCommandParamEntity.setName("schema-list"); onapCommandParamEntity.setProduct("open-cli"); onapCommandParamEntity.setValue("value"); - List<OnapCommandParamEntity> paramEntityList=new ArrayList<>(); + List<OnapCommandParamEntity> paramEntityList = new ArrayList<>(); paramEntityList.add(onapCommandParamEntity); - onapCommandProfileStore.persistProfile(paramEntityList,"abc"); - assertTrue(new File(System.getProperty("user.dir")+File.separator+"data/profiles/abc-profile.json").exists()); + onapCommandProfileStore.persistProfile(paramEntityList, "abc"); + assertTrue(new File(System.getProperty("user.dir") + File.separator + "data/profiles/abc-profile.json").exists()); assertNotNull(onapCommandProfileStore.getProfiles()); } + @Test - public void removeProfileTest(){ + public void removeProfileTest() { onapCommandProfileStore.removeProfile("abc"); - assertFalse(new File(System.getProperty("user.dir")+File.separator+"data/profiles/abc-profile.json").exists()); + assertFalse(new File(System.getProperty("user.dir") + File.separator + "data/profiles/abc-profile.json").exists()); } + @Test - public void addTest(){ - onapCommandProfileStore.add("abc","abc","abc"); + public void addTest() { + onapCommandProfileStore.add("abc", "abc", "abc"); } -@Test - public void getParamsTest(){ + + @Test + public void getParamsTest() { assertNotNull(onapCommandProfileStore.getParams("abc")); -} + } + + + @AfterClass + public static void tearDown() throws Exception { + String dirPathForData = System.getProperty("user.dir") + File.separator + "data"; + File dataDir = new File(dirPathForData); + assertTrue(OnapCommandExceutionListCommandTest.deleteDirectory(dataDir)); + } }
\ No newline at end of file |