diff options
Diffstat (limited to 'plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src')
5 files changed, 41 insertions, 75 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 194856fad..020cc1520 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 @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,8 +44,6 @@ import org.onap.policy.apex.context.impl.schema.AbstractSchemaHelper; import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; import org.onap.policy.apex.model.basicmodel.concepts.AxKey; import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; /** * This class is the implementation of the {@link org.onap.policy.apex.context.SchemaHelper} interface for Avro schemas. @@ -53,7 +52,6 @@ import org.slf4j.ext.XLoggerFactory; */ public class AvroSchemaHelper extends AbstractSchemaHelper { // Get a reference to the logger - private static final XLogger LOGGER = XLoggerFactory.getXLogger(AvroSchemaHelper.class); // Recurring string constants private static final String OBJECT_TAG = ": object \""; @@ -73,9 +71,8 @@ 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(); - LOGGER.warn(resultSting, e); - throw new ContextRuntimeException(resultSting); + + "\" schema is invalid, schema: " + schema.getSchema(); + throw new ContextRuntimeException(resultSting, e); } // Get the object mapper for the schema type to a Java class @@ -128,7 +125,6 @@ public class AvroSchemaHelper extends AbstractSchemaHelper { } else { final String returnString = getUserKey().getId() + ": the object \"" + incomingObject + "\" is not an instance of JsonObject"; - LOGGER.warn(returnString); throw new ContextRuntimeException(returnString); } } @@ -144,7 +140,6 @@ public class AvroSchemaHelper extends AbstractSchemaHelper { } else { final String returnString = getUserKey().getId() + ": the schema \"" + avroSchema.getName() + "\" does not have a subtype of type \"" + subInstanceType + "\""; - LOGGER.warn(returnString); throw new ContextRuntimeException(returnString); } } @@ -232,9 +227,8 @@ public class AvroSchemaHelper extends AbstractSchemaHelper { final JsonDecoder jsonDecoder = DecoderFactory.get().jsonDecoder(avroSchema, objectString); 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(); - LOGGER.warn(returnString, e); + final String returnString = + getUserKey().getId() + OBJECT_TAG + objectString + "\" Avro unmarshalling failed."; throw new ContextRuntimeException(returnString, e); } @@ -259,8 +253,7 @@ public class AvroSchemaHelper extends AbstractSchemaHelper { 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"; - LOGGER.warn(returnString, e); - throw new ContextRuntimeException(returnString); + throw new ContextRuntimeException(returnString, e); } } @@ -311,9 +304,7 @@ 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(); - LOGGER.warn(returnString); + final String returnString = getUserKey().getId() + OBJECT_TAG + object + "\" Avro marshalling failed."; 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/AvroSchemaEnumTest.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaEnumTest.java index e4a336676..d3cd7a482 100644 --- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaEnumTest.java +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaEnumTest.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -121,17 +122,13 @@ public class AvroSchemaEnumTest { testUnmarshalMarshal(schemaHelper, "src/test/resources/data/EnumExampleHearts.json"); assertThatThrownBy(() -> testUnmarshalMarshal(schemaHelper, "src/test/resources/data/EnumExampleNull.json")) - .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: Expected fixed. " - + "Got VALUE_NULL"); + .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed."); assertThatThrownBy(() -> testUnmarshalMarshal(schemaHelper, "src/test/resources/data/EnumExampleNull.json")) - .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: Expected fixed. " - + "Got VALUE_NULL"); + .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed."); assertThatThrownBy(() -> testUnmarshalMarshal(schemaHelper, "src/test/resources/data/EnumExampleBad0.json")) - .hasMessage("AvroTest:0.0.1: object \"\"TWEED\"\" Avro unmarshalling failed: Unknown symbol " - + "in enum TWEED"); + .hasMessage("AvroTest:0.0.1: object \"\"TWEED\"\" Avro unmarshalling failed."); assertThatThrownBy(() -> testUnmarshalMarshal(schemaHelper, "src/test/resources/data/EnumExampleBad1.json")) - .hasMessage("AvroTest:0.0.1: object \"\"Hearts\"\" Avro unmarshalling failed: Unknown symbol " - + "in enum Hearts"); + .hasMessage("AvroTest:0.0.1: object \"\"Hearts\"\" Avro unmarshalling failed."); } /** diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaFixedTest.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaFixedTest.java index 368619ee8..93797fba1 100644 --- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaFixedTest.java +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaFixedTest.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -124,18 +125,15 @@ public class AvroSchemaFixedTest { testUnmarshalMarshal(schemaHelper, "src/test/resources/data/FixedExampleGood.json"); assertThatThrownBy(() -> testUnmarshalMarshal(schemaHelper, "src/test/resources/data/FixedExampleNull.json")) - .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: Expected fixed. " - + "Got VALUE_NULL"); + .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed."); assertThatThrownBy(() -> testUnmarshalMarshal(schemaHelper, "src/test/resources/data/FixedExampleNull.json")) - .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: Expected fixed. " - + "Got VALUE_NULL"); + .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed."); assertThatThrownBy(() -> testUnmarshalMarshal(schemaHelper, "src/test/resources/data/FixedExampleBad0.json")) - .hasMessage("AvroTest:0.0.1: object \"\"BADBAD\"\" " - + "Avro unmarshalling failed: Expected fixed length 64, but got6"); + .hasMessage("AvroTest:0.0.1: object \"\"BADBAD\"\" " + "Avro unmarshalling failed."); assertThatThrownBy(() -> testUnmarshalMarshal(schemaHelper, "src/test/resources/data/FixedExampleBad1.json")) - .hasMessage("AvroTest:0.0.1: object " - + "\"\"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0\"\" " - + "Avro unmarshalling failed: Expected fixed length 64, but got65"); + .hasMessage( + "AvroTest:0.0.1: object " + "\"\"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0\"\" " + + "Avro unmarshalling failed."); } /** 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 d84481da8..06848c9a9 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 @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -109,13 +110,9 @@ public class AvroSchemaHelperMarshalTest { assertEquals("true", schemaHelper1.marshal2String(true)); assertEquals("false", schemaHelper1.marshal2String(false)); assertThatThrownBy(() -> schemaHelper1.marshal2String(0)) - .hasMessage("AvroTest:0.0.1: object \"0\" Avro marshalling failed: " - + "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')"); + .hasMessage("AvroTest:0.0.1: object \"0\" Avro marshalling failed."); assertThatThrownBy(() -> schemaHelper1.marshal2String("0")) - .hasMessage("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')"); + .hasMessage("AvroTest:0.0.1: object \"0\" Avro marshalling failed."); } /** @@ -138,8 +135,7 @@ public class AvroSchemaHelperMarshalTest { assertEquals("2147483647", schemaHelper2.marshal2String(2147483647)); assertEquals("-2147483648", schemaHelper2.marshal2String(-2147483648)); assertThatThrownBy(() -> schemaHelper2.marshal2String("Hello")) - .hasMessageStartingWith("AvroTest:0.0.1: object \"Hello\" Avro marshalling failed: " - + "class java.lang.String cannot be cast to class java.lang.Number"); + .hasMessageStartingWith("AvroTest:0.0.1: object \"Hello\" Avro marshalling failed."); assertThatThrownBy(() -> schemaHelper2.marshal2String(null)) .hasMessageStartingWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Integer\""); } @@ -162,8 +158,7 @@ public class AvroSchemaHelperMarshalTest { assertEquals("9223372036854775807", schemaHelper3.marshal2String(9223372036854775807L)); assertEquals("-9223372036854775808", schemaHelper3.marshal2String(-9223372036854775808L)); assertThatThrownBy(() -> schemaHelper3.marshal2String("Hello")) - .hasMessageStartingWith("AvroTest:0.0.1: object \"Hello\" Avro marshalling failed: " - + "class java.lang.String cannot be cast to class java.lang.Long"); + .hasMessageStartingWith("AvroTest:0.0.1: object \"Hello\" Avro marshalling failed."); assertThatThrownBy(() -> schemaHelper3.marshal2String(null)) .hasMessageStartingWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Long\""); } @@ -190,8 +185,7 @@ public class AvroSchemaHelperMarshalTest { assertEquals("9.223372E18", schemaHelper4.marshal2String(9.223372E18F)); assertEquals("-9.223372E18", schemaHelper4.marshal2String(-9.223372E18F)); assertThatThrownBy(() -> schemaHelper4.marshal2String("Hello")) - .hasMessageStartingWith("AvroTest:0.0.1: object \"Hello\" Avro marshalling failed: " - + "class java.lang.String cannot be cast to class java.lang.Float"); + .hasMessageStartingWith("AvroTest:0.0.1: object \"Hello\" Avro marshalling failed."); assertThatThrownBy(() -> schemaHelper4.marshal2String(null)) .hasMessageStartingWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Float\""); } @@ -218,8 +212,7 @@ public class AvroSchemaHelperMarshalTest { assertEquals("9.223372036854776E18", schemaHelper5.marshal2String(9.223372036854776E18)); assertEquals("-9.223372036854776E18", schemaHelper5.marshal2String(-9.223372036854776E18)); assertThatThrownBy(() -> schemaHelper5.marshal2String("Hello")) - .hasMessageStartingWith("AvroTest:0.0.1: object \"Hello\" Avro marshalling failed: " - + "class java.lang.String cannot be cast to class java.lang.Double"); + .hasMessageStartingWith("AvroTest:0.0.1: object \"Hello\" Avro marshalling failed."); assertThatThrownBy(() -> schemaHelper5.marshal2String(null)) .hasMessageStartingWith("AvroTest:0.0.1: cannot encode a null object of class \"java.lang.Double\""); } diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperUnmarshalTest.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperUnmarshalTest.java index 2b6050acc..23ac9a855 100644 --- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperUnmarshalTest.java +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperUnmarshalTest.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -95,8 +96,7 @@ public class AvroSchemaHelperUnmarshalTest { assertEquals(null, schemaHelper0.unmarshal("null")); assertThatThrownBy(() -> schemaHelper0.unmarshal("123")) - .hasMessage("AvroTest:0.0.1: object \"123\" Avro unmarshalling failed: " - + "Expected null. Got VALUE_NUMBER_INT"); + .hasMessage("AvroTest:0.0.1: object \"123\" Avro unmarshalling failed."); } /** @@ -149,14 +149,11 @@ public class AvroSchemaHelperUnmarshalTest { assertEquals(2147483647, schemaHelper2.unmarshal("2147483647")); assertEquals(-2147483648, schemaHelper2.unmarshal("-2147483648")); assertThatThrownBy(() -> schemaHelper2.unmarshal("2147483648")) - .hasMessageStartingWith("AvroTest:0.0.1: object \"2147483648\" Avro unmarshalling failed: " - + "Numeric value (2147483648) out of range of int"); + .hasMessageStartingWith("AvroTest:0.0.1: object \"2147483648\" Avro unmarshalling failed."); assertThatThrownBy(() -> schemaHelper2.unmarshal("-2147483649")) - .hasMessageStartingWith("AvroTest:0.0.1: object \"-2147483649\" Avro unmarshalling failed: " - + "Numeric value (-2147483649) out of range of int"); + .hasMessageStartingWith("AvroTest:0.0.1: object \"-2147483649\" Avro unmarshalling failed."); assertThatThrownBy(() -> schemaHelper2.unmarshal(null)) - .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: " - + "String to read from cannot be null!"); + .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed."); } /** @@ -184,17 +181,13 @@ public class AvroSchemaHelperUnmarshalTest { assertEquals(9223372036854775807L, schemaHelper3.unmarshal("9223372036854775807")); assertEquals(-9223372036854775808L, schemaHelper3.unmarshal("-9223372036854775808")); assertThatThrownBy(() -> schemaHelper3.unmarshal("9223372036854775808")) - .hasMessageStartingWith("AvroTest:0.0.1: object \"9223372036854775808\" Avro unmarshalling failed: " - + "Numeric value (9223372036854775808) out of range of long"); + .hasMessageStartingWith("AvroTest:0.0.1: object \"9223372036854775808\" Avro unmarshalling failed."); assertThatThrownBy(() -> schemaHelper3.unmarshal("-9223372036854775809")) - .hasMessageStartingWith("AvroTest:0.0.1: object \"-9223372036854775809\" Avro unmarshalling failed: " - + "Numeric value (-9223372036854775809) out of range of long"); + .hasMessageStartingWith("AvroTest:0.0.1: object \"-9223372036854775809\" Avro unmarshalling failed."); assertThatThrownBy(() -> schemaHelper3.unmarshal("\"Hello\"")) - .hasMessage("AvroTest:0.0.1: object \"\"Hello\"\" Avro unmarshalling failed: " - + "Expected long. Got VALUE_STRING"); + .hasMessage("AvroTest:0.0.1: object \"\"Hello\"\" Avro unmarshalling failed."); assertThatThrownBy(() -> schemaHelper3.unmarshal(null)) - .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: " - + "String to read from cannot be null!"); + .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed."); } /** @@ -224,11 +217,9 @@ public class AvroSchemaHelperUnmarshalTest { assertEquals(9.223372E18F, schemaHelper4.unmarshal("9223372036854775808")); assertEquals(-9.223372E18F, schemaHelper4.unmarshal("-9223372036854775809")); assertThatThrownBy(() -> schemaHelper4.unmarshal("\"Hello\"")) - .hasMessage("AvroTest:0.0.1: object \"\"Hello\"\" Avro unmarshalling failed: " - + "Expected float. Got VALUE_STRING"); + .hasMessage("AvroTest:0.0.1: object \"\"Hello\"\" Avro unmarshalling failed."); assertThatThrownBy(() -> schemaHelper4.unmarshal(null)) - .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: " - + "String to read from cannot be null!"); + .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed."); } /** @@ -258,11 +249,9 @@ public class AvroSchemaHelperUnmarshalTest { assertEquals(9.223372036854776E18, schemaHelper5.unmarshal("9223372036854775808")); assertEquals(-9.223372036854776E18, schemaHelper5.unmarshal("-9223372036854775809")); assertThatThrownBy(() -> schemaHelper5.unmarshal("\"Hello\"")) - .hasMessage("AvroTest:0.0.1: object \"\"Hello\"\" Avro unmarshalling failed: " - + "Expected double. Got VALUE_STRING"); + .hasMessage("AvroTest:0.0.1: object \"\"Hello\"\" Avro unmarshalling failed."); assertThatThrownBy(() -> schemaHelper5.unmarshal(null)) - .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: " - + "String to read from cannot be null!"); + .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed."); } /** @@ -292,8 +281,7 @@ public class AvroSchemaHelperUnmarshalTest { assertEquals("Hello", schemaHelper7.unmarshal("Hello")); assertEquals("Hello", schemaHelper7.unmarshal(new Utf8("Hello"))); assertThatThrownBy(() -> schemaHelper7.unmarshal(null)) - .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: " - + "String to read from cannot be null!"); + .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed."); } /** @@ -319,7 +307,6 @@ public class AvroSchemaHelperUnmarshalTest { assertEquals(111, newBytes[4]); assertThatThrownBy(() -> schemaHelper.unmarshal(null)) - .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed: " - + "String to read from cannot be null!"); + .hasMessage("AvroTest:0.0.1: object \"null\" Avro unmarshalling failed."); } } |