diff options
author | jitendra sharma <jitendra.sharma1@huawei.com> | 2019-08-16 06:36:27 +0000 |
---|---|---|
committer | jitendra sharma <jitendra.sharma1@huawei.com> | 2019-08-19 10:16:00 +0000 |
commit | 1cbd3bfd4a7f676e69ee7b71c21da97c6e3a072b (patch) | |
tree | ce4709f960c47ad8715b7038b3f1753e34b076bb | |
parent | f618ecbba21f5331b8d3f9df3fdff91ec93170ad (diff) |
add Junit test cases wth cleanup code for OnapCommandExecutionStoreTest and OnapCommandProfileStoreTest
Issue-ID: CLI-169
Signed-off-by: jitendra sharma <jitendra.sharma1@huawei.com>
Change-Id: Id08d83f0560b14b32cda4979b12e18a48d929da6
-rw-r--r-- | framework/src/test/java/org/onap/cli/fw/store/OnapCommandExecutionStoreTest.java | 69 | ||||
-rw-r--r-- | framework/src/test/java/org/onap/cli/fw/store/OnapCommandProfileStoreTest.java | 43 |
2 files changed, 75 insertions, 37 deletions
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 |