Skip to content

Commit

Permalink
KAA-1551: add primitive and complex types to test schema in 'save CTL…
Browse files Browse the repository at this point in the history
… schema' test
  • Loading branch information
Rybachenko Andrey committed Nov 17, 2016
1 parent 5413b20 commit 4b525d2
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 17 deletions.
Expand Up @@ -52,7 +52,7 @@ public class CtlServiceImplTest extends AbstractTest {
private static final String TEST_CTL_SCHEMA_ALPHA_FLAT = "dao/ctl/alphaFlat.json"; private static final String TEST_CTL_SCHEMA_ALPHA_FLAT = "dao/ctl/alphaFlat.json";
private static final String TEST_CTL_SCHEMA_BETA = "dao/ctl/beta.json"; private static final String TEST_CTL_SCHEMA_BETA = "dao/ctl/beta.json";
private static final String TEST_CTL_SCHEMA_GAMMA = "dao/ctl/gamma.json"; private static final String TEST_CTL_SCHEMA_GAMMA = "dao/ctl/gamma.json";
private static final String TEST_CTL_SCHEMA_NO_DEPENDENCIES = "dao/ctl/noDependenciesCtl.json"; private static final String TEST_CTL_SCHEMA_FLAT = "dao/ctl/flatCtlExample.json";
private ExecutorService executorService = Executors.newFixedThreadPool(10); private ExecutorService executorService = Executors.newFixedThreadPool(10);
private TenantDto tenant; private TenantDto tenant;
private ApplicationDto appDto; private ApplicationDto appDto;
Expand Down Expand Up @@ -149,18 +149,30 @@ public void before() throws Exception {
} }


@Test @Test
public void testSaveCtlSchemaWithNoDependencies() throws IOException { public void testSaveFlatCtlSchema() throws IOException {


CTLSchemaDto testCtl = new CTLSchemaDto(); CTLSchemaDto testCtl = new CTLSchemaDto();
CtlSchemaMetaInfoDto ctlMetaInfo = new CtlSchemaMetaInfoDto("org.kaaproject.kaa.NoDependenciesCtlExample", tenant.getId()); CtlSchemaMetaInfoDto ctlMetaInfo = new CtlSchemaMetaInfoDto("org.kaaproject.kaa.NoDependenciesCtlExample", tenant.getId());
testCtl.setMetaInfo(ctlMetaInfo); testCtl.setMetaInfo(ctlMetaInfo);
testCtl.setVersion(1); testCtl.setVersion(1);
testCtl.setBody(readSchemaFileAsString(TEST_CTL_SCHEMA_NO_DEPENDENCIES)); testCtl.setBody(readSchemaFileAsString(TEST_CTL_SCHEMA_FLAT));
testCtl = ctlService.saveCtlSchema(testCtl); testCtl = ctlService.saveCtlSchema(testCtl);


CTLSchemaDto foundCtl = ctlService.findCtlSchemaById(testCtl.getId()); CTLSchemaDto foundCtl = ctlService.findCtlSchemaById(testCtl.getId());
String defaultRecord = foundCtl.getDefaultRecord();


Assert.assertNotNull(foundCtl); Assert.assertNotNull(foundCtl);
Assert.assertTrue(defaultRecord.contains("\"bytesField\":\"\""));
Assert.assertTrue(defaultRecord.contains("\"booleanField\":false"));
Assert.assertTrue(defaultRecord.contains("\"intField\":0"));
Assert.assertTrue(defaultRecord.contains("\"longField\":0"));
Assert.assertTrue(defaultRecord.contains("\"floatField\":0.0"));
Assert.assertTrue(defaultRecord.contains("\"doubleField\":0.0"));
Assert.assertTrue(defaultRecord.contains("\"stringField\":\"\""));
Assert.assertTrue(defaultRecord.contains("\"enumField\":\"SPADES\""));
Assert.assertTrue(defaultRecord.contains("\"arrayField\":[]"));
Assert.assertTrue(defaultRecord.contains("\"recordsArrayField\":[]"));
Assert.assertTrue(defaultRecord.contains("\"recordField\":{\"bytesFieldInRecord\":\"\",\"booleanFieldInRecord\":false,\"intFieldInRecord\":0,\"floatFieldInRecord\":0.0}"));
} }


@Test @Test
Expand Down
112 changes: 112 additions & 0 deletions server/common/dao/src/test/resources/dao/ctl/flatCtlExample.json
@@ -0,0 +1,112 @@
{
"type" : "record",
"name" : "NoDependenciesCtlExample",
"namespace" : "org.kaaproject.kaa",
"displayName" : "example schema",
"version" : 1,
"fields" : [
{
"name" : "bytesField",
"type" : "bytes"
},
{
"name" : "booleanField",
"type" : "boolean"
},
{
"name" : "intField",
"type" : "int"
},
{
"name" : "longField",
"type" : "long"
},
{
"name" : "floatField",
"type" : "float"
},
{
"name" : "doubleField",
"type" : "double"
},
{
"name" : "stringField",
"type" : "string"
},
{
"name" : "enumField",
"type" : {
"type" : "enum",
"name" : "TestEnum",
"namespace" : "org.kaaproject.kaa",
"symbols" : [
"SPADES",
"HEARTS",
"DIAMONDS",
"CLUBS"
]
}
},
{
"name" : "arrayField",
"type" : {
"type" : "array",
"items" : "string"
}
},
{
"name" : "recordsArrayField",
"type" : {
"type" : "array",
"items" : {
"type" : "record",
"name" : "TestArrayRecord",
"fields" : [
{
"name" : "bytesFieldInArrayRecord",
"type" : "bytes"
},
{
"name" : "booleanFieldInArrayRecord",
"type" : "boolean"
},
{
"name" : "intFieldInArrayRecord",
"type" : "int"
},
{
"name" : "floatFieldInArrayRecord",
"type" : "float"
}
]
}
}
},
{
"name" : "recordField",
"type" : {
"type" : "record",
"name" : "NestedRecord",
"fields": [
{
"name": "bytesFieldInRecord",
"type": "bytes"
},
{
"name": "booleanFieldInRecord",
"type": "boolean"
},
{
"name": "intFieldInRecord",
"type": "int"
},
{
"name": "floatFieldInRecord",
"type": "float"
}
]
}
}
],
"dependencies" : [ ]
}

This file was deleted.

0 comments on commit 4b525d2

Please sign in to comment.