diff options
Diffstat (limited to 'framework/src/test')
3 files changed, 96 insertions, 1 deletions
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 18959e8e..1bf42e00 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 @@ -129,4 +129,33 @@ public class OnapCommandParameterTest { param.validate(); } + @Test + public void parameterObjTestForGson() throws OnapCommandInvalidParameterValue { + OnapCommandParameter param = new OnapCommandParameter(); + param.setDefaultValue("defaultValue"); + param.setDescription("description"); + param.setLongOption("longOption"); + param.setName("name"); + param.setOptional(true); + param.setParameterType(OnapCommandParameterType.JSON); + param.setSecured(false); + param.setShortOption("shortOption"); + param.setValue("value"); + + param.setParameterType(OnapCommandParameterType.ARRAY); + List<String> list = Arrays.asList("1", "2", "3"); + param.setValue(list); + assertTrue(((List)param.getValue()).containsAll(list)); + + param.setRawDefaultValue("[\"1\", \"2\", \"3\", \"4\"]"); + assertTrue(((List<String>)param.getDefaultValue()) + .containsAll(Arrays.asList("1", "2", "3", "4"))); + + param.setParameterType(OnapCommandParameterType.MAP); + param.setRawDefaultValue("{\"testKey\":\"testValue\"}"); + assertTrue(((Map<String, String>)param.getDefaultValue()).values().containsAll( + Arrays.asList("testValue") + )); + } + } diff --git a/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultTest.java b/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultTest.java index a4458670..97fc9e01 100644 --- a/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultTest.java +++ b/framework/src/test/java/org/onap/cli/fw/output/OnapCommandResultTest.java @@ -28,7 +28,11 @@ import org.junit.Test; import org.onap.cli.fw.error.OnapCommandException; import org.onap.cli.fw.input.OnapCommandParameterType; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + public class OnapCommandResultTest { + private static Gson gson = new GsonBuilder().serializeNulls().create(); @Test @Ignore @@ -206,5 +210,30 @@ public class OnapCommandResultTest { assertEquals(expRes, result); } + @Test + public void commandResultPrintLandscapeJsonTestForGson() throws OnapCommandException { + OnapCommandResult res = new OnapCommandResult(); + res.setDebugInfo("debugInfo"); + res.setIncludeSeparator(true); + res.setIncludeTitle(true); + res.setOutput("Output"); + res.setPrintDirection(OnapCommandPrintDirection.LANDSCAPE); + OnapCommandResultAttribute att = new OnapCommandResultAttribute(); + att.setName("param"); + att.setDescription("description"); + att.setType(OnapCommandParameterType.JSON); + att.setValues( + new ArrayList<String>(Arrays.asList(new String[] { "{\"id\": \"0001\",\"value\": \"result\"}" }))); + List<OnapCommandResultAttribute> list = new ArrayList<OnapCommandResultAttribute>(); + list.add(att); + res.setRecords(list); + res.setScope(OnapCommandResultAttributeScope.LONG); + res.setType(OnapCommandResultType.JSON); + + String result = res.print(); + String expRes="[{\"param\":{\"id\":\"0001\",\"value\":\"result\"}}]"; + assertEquals(gson.toJson(expRes),result); + + } } diff --git a/framework/src/test/java/org/onap/cli/fw/store/OnapCommandArtifactStoreTest.java b/framework/src/test/java/org/onap/cli/fw/store/OnapCommandArtifactStoreTest.java index 1a4d982a..45186b38 100644 --- a/framework/src/test/java/org/onap/cli/fw/store/OnapCommandArtifactStoreTest.java +++ b/framework/src/test/java/org/onap/cli/fw/store/OnapCommandArtifactStoreTest.java @@ -28,7 +28,13 @@ import java.io.File; import java.util.HashMap; import java.util.Map; -import static org.junit.Assert.*; +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertNotNull; public class OnapCommandArtifactStoreTest { OnapCommandArtifactStore onapCommandArtifactStore; @@ -83,4 +89,35 @@ public class OnapCommandArtifactStoreTest { public void listArtifactTest() throws OnapCommandArtifactNotFound { assertNotNull(onapCommandArtifactStore.listArtifact("category","namePattern")); } + @Test + public void createArtifactTestForGson() throws OnapCommandArtifactContentChecksumNotMatch, OnapCommandArtifactAlreadyExist, OnapCommandArtifactContentNotExist, OnapCommandArtifactNotFound { + assertNotNull(onapCommandArtifactStore.createArtifact(artifact)); + String artifactPath=System.getProperty("user.dir")+File.separator+"data/artifacts"; + File artifactFile= new File(artifactPath+File.separator+"artifact__category.json"); + assertTrue(artifactFile.exists()); + onapCommandArtifactStore.deleteArtifact("artifact","category"); + + } + + @Test + public void listArtifactTestForGson() throws OnapCommandArtifactNotFound { + String basePath= System.getProperty("user.dir")+File.separator+"data/artifacts/testFile.json"; + File testFile = new File(basePath); + if (!testFile.exists()) { + try { + testFile.createNewFile(); + try(BufferedWriter writer = new BufferedWriter(new FileWriter(testFile))) { + String content = "{\"name\": \"name\",\"description\": \"description\",\"categoty\": \"categoty\"," + + "\"checksum\": \"checksum\",\"size\": 100,\"createAt\": \"createAt\"" + + ",\"lastUpdatedAt\":\"lastUpdatedAt\",\"path\": \"path\",\"metadata\": {}}"; + writer.write(content); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + assertNotNull(onapCommandArtifactStore.listArtifact("category","namePattern")); + + testFile.delete(); + } }
\ No newline at end of file |