From 755eb9df282d80273043a2e902e2a51bf6eaab24 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Wed, 22 Jan 2020 12:11:11 +0000 Subject: Run apex-pdp in Java 11: base changes This change brings in the minimum changes to get apex-pdp running in Java 11. Other reviews will bring in changes to remove Java 11 warnings and to convert apex-pdp Javascript handling from the now deprecated nashorn engine. Issue-ID: POLICY-1581 Change-Id: I879bbae08d4e67aca3f1bfeedeca639d8dbbc281 Signed-off-by: liamfallon --- .../schema/avro/AvroSchemaHelperMarshalTest.java | 93 +++++++++++----------- 1 file changed, 47 insertions(+), 46 deletions(-) (limited to 'plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test') 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;\"")); } } } -- cgit 1.2.3-korg