diff options
Diffstat (limited to 'plugins/plugins-context')
2 files changed, 59 insertions, 59 deletions
diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java index 94841301d..bc427b9c9 100644 --- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -75,7 +75,7 @@ public class AvroSchemaHelper extends AbstractSchemaHelper { avroSchema = new Schema.Parser().parse(schema.getSchema()); } catch (final Exception e) { final String resultSting = userKey.getId() + ": avro context schema \"" + schema.getId() - + "\" schema is invalid: " + e.getMessage() + ", schema: " + schema.getSchema(); + + "\" schema is invalid: " + e.getMessage() + ", schema: " + schema.getSchema(); LOGGER.warn(resultSting, e); throw new ContextRuntimeException(resultSting); } @@ -128,8 +128,8 @@ public class AvroSchemaHelper extends AbstractSchemaHelper { return createNewInstance(elementJsonString); } else { - final String returnString = getUserKey().getId() + ": the object \"" + incomingObject - + "\" is not an instance of JsonObject"; + final String returnString = + getUserKey().getId() + ": the object \"" + incomingObject + "\" is not an instance of JsonObject"; LOGGER.warn(returnString); throw new ContextRuntimeException(returnString); } @@ -145,7 +145,7 @@ public class AvroSchemaHelper extends AbstractSchemaHelper { return subInstance; } else { final String returnString = getUserKey().getId() + ": the schema \"" + avroSchema.getName() - + "\" does not have a subtype of type \"" + subInstanceType + "\""; + + "\" does not have a subtype of type \"" + subInstanceType + "\""; LOGGER.warn(returnString); throw new ContextRuntimeException(returnString); } @@ -196,7 +196,7 @@ public class AvroSchemaHelper extends AbstractSchemaHelper { * @return an instance of the type or null if it is the incorrect type */ private Object instantiateSubInstance(final String subInstanceType, final Schema subSchema, - final Set<String> foundTypes) { + final Set<String> foundTypes) { if (subSchema == null) { return null; } @@ -211,7 +211,7 @@ public class AvroSchemaHelper extends AbstractSchemaHelper { if (subSchema.getName().equals(subInstanceType)) { return new AvroObjectMapperFactory().get(AxArtifactKey.getNullKey(), subSchema) - .createNewInstance(subSchema); + .createNewInstance(subSchema); } return createNewSubInstance(subSchema, subInstanceType, foundTypes); } @@ -235,7 +235,7 @@ public class AvroSchemaHelper extends AbstractSchemaHelper { decodedObject = new GenericDatumReader<GenericRecord>(avroSchema).read(null, jsonDecoder); } catch (final Exception e) { final String returnString = getUserKey().getId() + OBJECT_TAG + objectString - + "\" Avro unmarshalling failed: " + e.getMessage(); + + "\" Avro unmarshalling failed: " + e.getMessage(); LOGGER.warn(returnString, e); throw new ContextRuntimeException(returnString, e); } @@ -259,9 +259,8 @@ public class AvroSchemaHelper extends AbstractSchemaHelper { } } catch (final ClassCastException e) { final String returnString = getUserKey().getId() + OBJECT_TAG + object + "\" of type \"" - + (object != null ? object.getClass().getName() : "null") + "\" must be assignable to \"" - + getSchemaClass().getName() - + "\" or be a Json string representation of it for Avro unmarshalling"; + + (object != null ? object.getClass().getName() : "null") + "\" must be assignable to \"" + + getSchemaClass().getName() + "\" or be a Json string representation of it for Avro unmarshalling"; LOGGER.warn(returnString, e); throw new ContextRuntimeException(returnString); } @@ -314,8 +313,8 @@ public class AvroSchemaHelper extends AbstractSchemaHelper { jsonEncoder.flush(); return new String(output.toByteArray()); } catch (final Exception e) { - final String returnString = getUserKey().getId() + OBJECT_TAG + object + "\" Avro marshalling failed: " - + e.getMessage(); + final String returnString = + getUserKey().getId() + OBJECT_TAG + object + "\" Avro marshalling failed: " + e.getMessage(); LOGGER.warn(returnString); throw new ContextRuntimeException(returnString, e); } diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperMarshalTest.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperMarshalTest.java index 778573939..004521c6c 100644 --- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperMarshalTest.java +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperMarshalTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -83,12 +83,12 @@ public class AvroSchemaHelperMarshalTest { */ @Test public void testNullMarshal() { - final AxContextSchema avroNullSchema = new AxContextSchema(new AxArtifactKey("AvroNull", "0.0.1"), "AVRO", - "{\"type\": \"null\"}"); + final AxContextSchema avroNullSchema = + new AxContextSchema(new AxArtifactKey("AvroNull", "0.0.1"), "AVRO", "{\"type\": \"null\"}"); schemas.getSchemasMap().put(avroNullSchema.getKey(), avroNullSchema); - final SchemaHelper schemaHelper0 = new SchemaHelperFactory().createSchemaHelper(testKey, - avroNullSchema.getKey()); + final SchemaHelper schemaHelper0 = + new SchemaHelperFactory().createSchemaHelper(testKey, avroNullSchema.getKey()); assertEquals("null", schemaHelper0.marshal2String(null)); assertEquals("null", schemaHelper0.marshal2String(123)); @@ -100,12 +100,12 @@ public class AvroSchemaHelperMarshalTest { */ @Test public void testBooleanMarshal() { - final AxContextSchema avroBooleanSchema = new AxContextSchema(new AxArtifactKey("AvroBoolean", "0.0.1"), "AVRO", - "{\"type\": \"boolean\"}"); + final AxContextSchema avroBooleanSchema = + new AxContextSchema(new AxArtifactKey("AvroBoolean", "0.0.1"), "AVRO", "{\"type\": \"boolean\"}"); schemas.getSchemasMap().put(avroBooleanSchema.getKey(), avroBooleanSchema); - final SchemaHelper schemaHelper1 = new SchemaHelperFactory().createSchemaHelper(testKey, - avroBooleanSchema.getKey()); + final SchemaHelper schemaHelper1 = + new SchemaHelperFactory().createSchemaHelper(testKey, avroBooleanSchema.getKey()); assertEquals("true", schemaHelper1.marshal2String(true)); assertEquals("false", schemaHelper1.marshal2String(false)); @@ -115,15 +115,17 @@ public class AvroSchemaHelperMarshalTest { } catch (final Exception e) { e.printStackTrace(); assertEquals("AvroTest:0.0.1: object \"0\" Avro marshalling failed: " - + "java.lang.Integer cannot be cast to java.lang.Boolean", e.getMessage()); + + "class java.lang.Integer cannot be cast to class java.lang.Boolean (java.lang.Integer and " + + "java.lang.Boolean are in module java.base of loader 'bootstrap')", e.getMessage()); } try { schemaHelper1.marshal2String("0"); fail("Test should throw an exception here"); } catch (final Exception e) { e.printStackTrace(); - assertEquals("AvroTest:0.0.1: object \"0\" Avro marshalling failed: " - + "java.lang.String cannot be cast to java.lang.Boolean", e.getMessage()); + assertEquals("AvroTest:0.0.1: object \"0\" Avro marshalling failed: class java.lang.String cannot be cast " + + "to class java.lang.Boolean (java.lang.String and java.lang.Boolean are in module java.base of " + + "loader 'bootstrap')", e.getMessage()); } } @@ -132,12 +134,12 @@ public class AvroSchemaHelperMarshalTest { */ @Test public void testIntMarshal() { - final AxContextSchema avroIntSchema = new AxContextSchema(new AxArtifactKey("AvroInt", "0.0.1"), "AVRO", - "{\"type\": \"int\"}"); + final AxContextSchema avroIntSchema = + new AxContextSchema(new AxArtifactKey("AvroInt", "0.0.1"), "AVRO", "{\"type\": \"int\"}"); schemas.getSchemasMap().put(avroIntSchema.getKey(), avroIntSchema); - final SchemaHelper schemaHelper2 = new SchemaHelperFactory().createSchemaHelper(testKey, - avroIntSchema.getKey()); + final SchemaHelper schemaHelper2 = + new SchemaHelperFactory().createSchemaHelper(testKey, avroIntSchema.getKey()); assertEquals("0", schemaHelper2.marshal2String(0)); assertEquals("1", schemaHelper2.marshal2String(1)); @@ -151,14 +153,14 @@ public class AvroSchemaHelperMarshalTest { fail("Test should throw an exception here"); } catch (final Exception e) { assertTrue(e.getMessage().startsWith("AvroTest:0.0.1: object \"Hello\" Avro marshalling failed: " - + "java.lang.String cannot be cast to java.lang.Number")); + + "class java.lang.String cannot be cast to class java.lang.Number")); } try { schemaHelper2.marshal2String(null); fail("Test should throw an exception here"); } catch (final Exception e) { assertTrue(e.getMessage() - .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Integer\"")); + .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Integer\"")); } } @@ -167,12 +169,12 @@ public class AvroSchemaHelperMarshalTest { */ @Test public void testLongMarshal() { - final AxContextSchema avroLongSchema = new AxContextSchema(new AxArtifactKey("AvroLong", "0.0.1"), "AVRO", - "{\"type\": \"long\"}"); + final AxContextSchema avroLongSchema = + new AxContextSchema(new AxArtifactKey("AvroLong", "0.0.1"), "AVRO", "{\"type\": \"long\"}"); schemas.getSchemasMap().put(avroLongSchema.getKey(), avroLongSchema); - final SchemaHelper schemaHelper3 = new SchemaHelperFactory().createSchemaHelper(testKey, - avroLongSchema.getKey()); + final SchemaHelper schemaHelper3 = + new SchemaHelperFactory().createSchemaHelper(testKey, avroLongSchema.getKey()); assertEquals("0", schemaHelper3.marshal2String(0L)); assertEquals("1", schemaHelper3.marshal2String(1L)); @@ -184,14 +186,14 @@ public class AvroSchemaHelperMarshalTest { fail("Test should throw an exception here"); } catch (final Exception e) { assertTrue(e.getMessage().startsWith("AvroTest:0.0.1: object \"Hello\" Avro marshalling failed: " - + "java.lang.String cannot be cast to java.lang.Long")); + + "class java.lang.String cannot be cast to class java.lang.Long")); } try { schemaHelper3.marshal2String(null); fail("Test should throw an exception here"); } catch (final Exception e) { assertTrue(e.getMessage() - .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Long\"")); + .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Long\"")); } } @@ -200,12 +202,12 @@ public class AvroSchemaHelperMarshalTest { */ @Test public void testFloatMarshal() { - final AxContextSchema avroFloatSchema = new AxContextSchema(new AxArtifactKey("AvroFloat", "0.0.1"), "AVRO", - "{\"type\": \"float\"}"); + final AxContextSchema avroFloatSchema = + new AxContextSchema(new AxArtifactKey("AvroFloat", "0.0.1"), "AVRO", "{\"type\": \"float\"}"); schemas.getSchemasMap().put(avroFloatSchema.getKey(), avroFloatSchema); - final SchemaHelper schemaHelper4 = new SchemaHelperFactory().createSchemaHelper(testKey, - avroFloatSchema.getKey()); + final SchemaHelper schemaHelper4 = + new SchemaHelperFactory().createSchemaHelper(testKey, avroFloatSchema.getKey()); assertEquals("0.0", schemaHelper4.marshal2String(0F)); assertEquals("1.0", schemaHelper4.marshal2String(1F)); @@ -221,14 +223,14 @@ public class AvroSchemaHelperMarshalTest { fail("Test should throw an exception here"); } catch (final Exception e) { assertTrue(e.getMessage().startsWith("AvroTest:0.0.1: object \"Hello\" Avro marshalling failed: " - + "java.lang.String cannot be cast to java.lang.Float")); + + "class java.lang.String cannot be cast to class java.lang.Float")); } try { schemaHelper4.marshal2String(null); fail("Test should throw an exception here"); } catch (final Exception e) { assertTrue(e.getMessage() - .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Float\"")); + .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Float\"")); } } @@ -237,12 +239,12 @@ public class AvroSchemaHelperMarshalTest { */ @Test public void testDoubleMarshal() { - final AxContextSchema avroDoubleSchema = new AxContextSchema(new AxArtifactKey("AvroDouble", "0.0.1"), "AVRO", - "{\"type\": \"double\"}"); + final AxContextSchema avroDoubleSchema = + new AxContextSchema(new AxArtifactKey("AvroDouble", "0.0.1"), "AVRO", "{\"type\": \"double\"}"); schemas.getSchemasMap().put(avroDoubleSchema.getKey(), avroDoubleSchema); - final SchemaHelper schemaHelper5 = new SchemaHelperFactory().createSchemaHelper(testKey, - avroDoubleSchema.getKey()); + final SchemaHelper schemaHelper5 = + new SchemaHelperFactory().createSchemaHelper(testKey, avroDoubleSchema.getKey()); assertEquals("0.0", schemaHelper5.marshal2String(0D)); assertEquals("1.0", schemaHelper5.marshal2String(1D)); @@ -258,14 +260,14 @@ public class AvroSchemaHelperMarshalTest { fail("Test should throw an exception here"); } catch (final Exception e) { assertTrue(e.getMessage().startsWith("AvroTest:0.0.1: object \"Hello\" Avro marshalling failed: " - + "java.lang.String cannot be cast to java.lang.Double")); + + "class java.lang.String cannot be cast to class java.lang.Double")); } try { schemaHelper5.marshal2String(null); fail("Test should throw an exception here"); } catch (final Exception e) { assertTrue(e.getMessage() - .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Double\"")); + .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Double\"")); } } @@ -274,12 +276,12 @@ public class AvroSchemaHelperMarshalTest { */ @Test public void testStringMarshal() { - final AxContextSchema avroStringSchema = new AxContextSchema(new AxArtifactKey("AvroString", "0.0.1"), "AVRO", - "{\"type\": \"string\"}"); + final AxContextSchema avroStringSchema = + new AxContextSchema(new AxArtifactKey("AvroString", "0.0.1"), "AVRO", "{\"type\": \"string\"}"); schemas.getSchemasMap().put(avroStringSchema.getKey(), avroStringSchema); - final SchemaHelper schemaHelper7 = new SchemaHelperFactory().createSchemaHelper(testKey, - avroStringSchema.getKey()); + final SchemaHelper schemaHelper7 = + new SchemaHelperFactory().createSchemaHelper(testKey, avroStringSchema.getKey()); assertEquals("\"0\"", schemaHelper7.marshal2String("0")); assertEquals("\"1\"", schemaHelper7.marshal2String("1")); @@ -296,7 +298,7 @@ public class AvroSchemaHelperMarshalTest { fail("Test should throw an exception here"); } catch (final Exception e) { assertTrue(e.getMessage() - .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.String\"")); + .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.String\"")); } } @@ -305,14 +307,13 @@ public class AvroSchemaHelperMarshalTest { */ @Test public void testBytesMarshal() { - final AxContextSchema avroSchema = new AxContextSchema(new AxArtifactKey("AvroString", "0.0.1"), "AVRO", - "{\"type\": \"bytes\"}"); + final AxContextSchema avroSchema = + new AxContextSchema(new AxArtifactKey("AvroString", "0.0.1"), "AVRO", "{\"type\": \"bytes\"}"); schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema); final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey()); - final byte[] helloBytes = - { 104, 101, 108, 108, 111 }; + final byte[] helloBytes = {104, 101, 108, 108, 111}; final String helloOut = schemaHelper.marshal2String(helloBytes); assertEquals("\"hello\"", helloOut); @@ -321,7 +322,7 @@ public class AvroSchemaHelperMarshalTest { fail("Test should throw an exception here"); } catch (final Exception e) { assertTrue(e.getMessage() - .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"[Ljava.lang.Byte;\"")); + .startsWith("AvroTest:0.0.1: cannot encode a null object of class \"[Ljava.lang.Byte;\"")); } } } |