diff options
author | liamfallon <liam.fallon@ericsson.com> | 2018-09-27 16:52:23 +0100 |
---|---|---|
committer | liamfallon <liam.fallon@ericsson.com> | 2018-09-27 16:52:34 +0100 |
commit | afd3a44e210de3c1aed9f6f7278913b2a2f2f6d2 (patch) | |
tree | 3b7c6038ec3d526549e4795032ea1c8baf2fcc0a /tools/model-generator | |
parent | 3595f7c277778a64d1d828b66ed8127d92c010b5 (diff) |
Add JUnit for web service client tool
JUnit, SOnar fixes, and some minor bug fixes.
Issue-ID: POLICY-1034
Change-Id: I72f46e944051f7d65d6b106afe33c759975283af
Signed-off-by: liamfallon <liam.fallon@ericsson.com>
Diffstat (limited to 'tools/model-generator')
-rw-r--r-- | tools/model-generator/src/main/java/org/onap/policy/apex/tools/model/generator/model2event/Model2JsonEventSchema.java | 66 |
1 files changed, 51 insertions, 15 deletions
diff --git a/tools/model-generator/src/main/java/org/onap/policy/apex/tools/model/generator/model2event/Model2JsonEventSchema.java b/tools/model-generator/src/main/java/org/onap/policy/apex/tools/model/generator/model2event/Model2JsonEventSchema.java index cfd7cb357..86a826bd1 100644 --- a/tools/model-generator/src/main/java/org/onap/policy/apex/tools/model/generator/model2event/Model2JsonEventSchema.java +++ b/tools/model-generator/src/main/java/org/onap/policy/apex/tools/model/generator/model2event/Model2JsonEventSchema.java @@ -26,6 +26,7 @@ import java.util.Set; import org.apache.avro.Schema; import org.apache.avro.Schema.Field; +import org.apache.avro.Schema.Type; import org.apache.commons.lang3.Validate; import org.onap.policy.apex.context.parameters.SchemaParameters; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; @@ -40,6 +41,7 @@ import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; import org.onap.policy.apex.model.policymodel.concepts.AxState; import org.onap.policy.apex.model.policymodel.concepts.AxStateOutput; import org.onap.policy.apex.plugins.context.schema.avro.AvroSchemaHelperParameters; +import org.onap.policy.apex.service.engine.event.ApexEventException; import org.onap.policy.apex.tools.model.generator.SchemaUtils; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; @@ -97,19 +99,14 @@ public class Model2JsonEventSchema { */ protected ST addFieldType(final Schema schema, final STGroup stg) { ST ret = null; - switch (schema.getType()) { - case BOOLEAN: - case BYTES: - case DOUBLE: - case FIXED: - case FLOAT: - case INT: - case LONG: - case STRING: - ret = stg.getInstanceOf("fieldTypeAtomic"); - ret.add("type", schema.getType()); - break; + if (isSimpleType(schema.getType())) { + ret = stg.getInstanceOf("fieldTypeAtomic"); + ret.add("type", schema.getType()); + return ret; + } + + switch (schema.getType()) { case ARRAY: ret = stg.getInstanceOf("fieldTypeArray"); ret.add("array", this.addFieldType(schema.getElementType(), stg)); @@ -139,6 +136,31 @@ public class Model2JsonEventSchema { } /** + * Check if a schema is a simple type. + * + * @param schemaType the type of the schema + * @return true if the schema is a simple type + */ + private boolean isSimpleType(Type schemaType) { + switch (schemaType) { + case BOOLEAN: + case BYTES: + case DOUBLE: + case FIXED: + case FLOAT: + case INT: + case LONG: + case STRING: { + return true; + } + + default: { + return false; + } + } + } + + /** * Process a record entry. * @param schema the schema to add a type for * @param stg the STG @@ -208,6 +230,22 @@ public class Model2JsonEventSchema { } } + String renderMessage = renderEvents(stg, stEvents, events); + LOGGER.error(renderMessage); + return 0; + } + + /** + * Render the events. + * + * @param stg the string template + * @param stEvents the event template + * @param events the events to render + * @return the rendered events + * @throws ApexEventException on rendering exceptions + */ + private String renderEvents(final STGroupFile stg, final ST stEvents, final Set<AxEvent> events) + throws ApexEventException { for (final AxEvent event : events) { final ST stEvent = stg.getInstanceOf("event"); stEvent.add("name", event.getKey().getName()); @@ -232,9 +270,7 @@ public class Model2JsonEventSchema { } stEvents.add("event", stEvent); } - String renderMessage = stEvents.render(); - LOGGER.error(renderMessage); - return 0; + return stEvents.render(); } /** |