diff options
author | priyanka.akhade <priyanka.akhade@huawei.com> | 2020-02-28 05:47:34 +0000 |
---|---|---|
committer | priyanka.akhade <priyanka.akhade@huawei.com> | 2020-02-29 11:26:08 +0000 |
commit | 132177fb71c08f157fb42037f9dd26ceb2d0ba43 (patch) | |
tree | f47d3c4d950e98d5bcf104aa8952f39a84e3ba6d /framework/src/test | |
parent | 4f1d279e42a3326cdc97e1eacaf0fdb58ee944e7 (diff) |
Migrate to gson
Issue-ID: CLI-247
Signed-off-by: priyanka.akhade <priyanka.akhade@huawei.com>
Change-Id: If66134db5503382fb45210ece883402fc130ac93
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 |