add Junit test cases wth cleanup code for OnapCommandExecutionStoreTest and OnapComma... 61/93661/2
authorjitendra sharma <jitendra.sharma1@huawei.com>
Fri, 16 Aug 2019 06:36:27 +0000 (06:36 +0000)
committerjitendra sharma <jitendra.sharma1@huawei.com>
Mon, 19 Aug 2019 10:16:00 +0000 (10:16 +0000)
Issue-ID: CLI-169

Signed-off-by: jitendra sharma <jitendra.sharma1@huawei.com>
Change-Id: Id08d83f0560b14b32cda4979b12e18a48d929da6

framework/src/test/java/org/onap/cli/fw/store/OnapCommandExecutionStoreTest.java
framework/src/test/java/org/onap/cli/fw/store/OnapCommandProfileStoreTest.java

index 6b69f0b..639f623 100644 (file)
 
 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
index f98f518..3ffd45c 100644 (file)
  */
 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