diff options
author | liamfallon <liam.fallon@est.tech> | 2020-02-25 16:10:08 +0000 |
---|---|---|
committer | liamfallon <liam.fallon@est.tech> | 2020-02-26 08:33:06 +0000 |
commit | 35840d835f581c2d61de1c57fe9963e36eb15c9f (patch) | |
tree | 10b8a6004cad1b4d1d63ebebe2aa26ae2af7f3e4 /context/context-management/src | |
parent | aacc7442f046d44359934ea3d93f425a809e7616 (diff) |
Fix Java 11/Checkstyle/Sonar warnings
A number of Java 11, checkstyle, and SONAR warnings have crept into the
Apex codebase over the last number of reviews. This change fixes those
issues.
Issue-ID: POLICY-1913
Change-Id: I2afd607e80f48323355380fb2fe5e048e18879f9
Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'context/context-management/src')
7 files changed, 140 insertions, 141 deletions
diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/distribution/DistributorFactory.java b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/distribution/DistributorFactory.java index 2a9b8184b..3e7e0e8cb 100644 --- a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/distribution/DistributorFactory.java +++ b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/distribution/DistributorFactory.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. @@ -48,29 +48,27 @@ public class DistributorFactory { * @throws ContextException on context distributor creation errors */ public Distributor getDistributor(final AxArtifactKey key) throws ContextException { - LOGGER.entry("Distributor factory, key=" + key); + LOGGER.debug("Distributor factory, key={}", key); Assertions.argumentOfClassNotNull(key, ContextException.class, "Parameter \"key\" may not be null"); // Get the class for the distributor using reflection - final DistributorParameters distributorParameters = ParameterService - .get(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); + final DistributorParameters distributorParameters = + ParameterService.get(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); final String pluginClass = distributorParameters.getPluginClass(); Object contextDistributorObject = null; try { - contextDistributorObject = Class.forName(pluginClass).newInstance(); - } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { - LOGGER.error("Apex context distributor class not found for context distributor plugin \"" + pluginClass - + "\"", e); - throw new ContextException("Apex context distributor class not found for context distributor plugin \"" - + pluginClass + "\"", e); + contextDistributorObject = Class.forName(pluginClass).getDeclaredConstructor().newInstance(); + } catch (Exception e) { + throw new ContextException( + "Apex context distributor class not found for context distributor plugin \"" + pluginClass + "\"", + e); } // Check the class is a distributor if (!(contextDistributorObject instanceof Distributor)) { final String returnString = "Specified Apex context distributor plugin class \"" + pluginClass - + "\" does not implement the ContextDistributor interface"; - LOGGER.error(returnString); + + "\" does not implement the ContextDistributor interface"; throw new ContextException(returnString); } @@ -80,8 +78,8 @@ public class DistributorFactory { // Lock and load the context distributor contextDistributor.init(key); - LOGGER.exit("Distributor factory, key=" + key + ", selected distributor of class " - + contextDistributor.getClass()); + LOGGER.debug("Distributor factory, key={}, selected distributor of class {}", key, + contextDistributor.getClass()); return contextDistributor; } } diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/locking/LockManagerFactory.java b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/locking/LockManagerFactory.java index 3e9120672..923c83979 100644 --- a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/locking/LockManagerFactory.java +++ b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/locking/LockManagerFactory.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 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. @@ -49,27 +50,29 @@ public class LockManagerFactory { public LockManager createLockManager(final AxArtifactKey key) throws ContextException { LOGGER.entry("Lock Manager factory, key=" + key); - final LockManagerParameters lockManagerParameters = ParameterService - .get(ContextParameterConstants.LOCKING_GROUP_NAME); + final LockManagerParameters lockManagerParameters = + ParameterService.get(ContextParameterConstants.LOCKING_GROUP_NAME); // Get the class for the lock manager using reflection Object lockManagerObject = null; final String pluginClass = lockManagerParameters.getPluginClass(); try { - lockManagerObject = Class.forName(pluginClass).newInstance(); - } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { - LOGGER.error("Apex context lock manager class not found for context lock manager plugin \"" + pluginClass - + "\"", e); - throw new ContextException("Apex context lock manager class not found for context lock manager plugin \"" - + pluginClass + "\"", e); + lockManagerObject = Class.forName(pluginClass).getDeclaredConstructor().newInstance(); + } catch (Exception e) { + LOGGER.error( + "Apex context lock manager class not found for context lock manager plugin \"" + pluginClass + "\"", + e); + throw new ContextException( + "Apex context lock manager class not found for context lock manager plugin \"" + pluginClass + "\"", + e); } // Check the class is a lock manager if (!(lockManagerObject instanceof LockManager)) { LOGGER.error("Specified Apex context lock manager plugin class \"{}\" " - + "does not implement the LockManager interface", pluginClass); + + "does not implement the LockManager interface", pluginClass); throw new ContextException("Specified Apex context lock manager plugin class \"" + pluginClass - + "\" does not implement the LockManager interface"); + + "\" does not implement the LockManager interface"); } // The context lock manager to return diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/persistence/PersistorFactory.java b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/persistence/PersistorFactory.java index 74c067c44..fe06d2fdb 100644 --- a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/persistence/PersistorFactory.java +++ b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/persistence/PersistorFactory.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. @@ -51,27 +51,27 @@ public class PersistorFactory { LOGGER.entry("persistor factory, key=" + key); Assertions.argumentOfClassNotNull(key, ContextException.class, "Parameter \"key\" may not be null"); - final PersistorParameters persistorParameters = ParameterService - .get(ContextParameterConstants.PERSISTENCE_GROUP_NAME); + final PersistorParameters persistorParameters = + ParameterService.get(ContextParameterConstants.PERSISTENCE_GROUP_NAME); // Get the class for the persistor using reflection Object persistorObject = null; final String pluginClass = persistorParameters.getPluginClass(); try { - persistorObject = Class.forName(pluginClass).newInstance(); - } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { + persistorObject = Class.forName(pluginClass).getDeclaredConstructor().newInstance(); + } catch (Exception e) { LOGGER.error("Apex context persistor class not found for context persistor plugin \"" + pluginClass + "\"", - e); - throw new ContextException("Apex context persistor class not found for context persistor plugin \"" - + pluginClass + "\"", e); + e); + throw new ContextException( + "Apex context persistor class not found for context persistor plugin \"" + pluginClass + "\"", e); } // Check the class is a persistor if (!(persistorObject instanceof Persistor)) { LOGGER.error("Specified Apex context persistor plugin class \"{}\" " - + "does not implement the ContextDistributor interface", pluginClass); + + "does not implement the ContextDistributor interface", pluginClass); throw new ContextException("Specified Apex context persistor plugin class \"" + pluginClass - + "\" does not implement the ContextDistributor interface"); + + "\" does not implement the ContextDistributor interface"); } // The persistor to return diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/AbstractSchemaHelper.java b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/AbstractSchemaHelper.java index ca1fa78f4..260482c61 100644 --- a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/AbstractSchemaHelper.java +++ b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/AbstractSchemaHelper.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. @@ -67,9 +67,9 @@ public abstract class AbstractSchemaHelper implements SchemaHelper { @Override public void init(final AxKey incomingUserKey, final AxContextSchema incomingSchema) { Assertions.argumentOfClassNotNull(incomingUserKey, ContextRuntimeException.class, - "incomingUserKey may not be null"); + "incomingUserKey may not be null"); Assertions.argumentOfClassNotNull(incomingSchema, ContextRuntimeException.class, - "incomingSchema may not be null"); + "incomingSchema may not be null"); this.userKey = incomingUserKey; this.schema = incomingSchema; @@ -113,18 +113,18 @@ public abstract class AbstractSchemaHelper implements SchemaHelper { @Override public Object createNewInstance() { if (schemaClass == null) { - final String returnString = userKey.getId() - + ": could not create an instance, schema class for the schema is null"; + final String returnString = + userKey.getId() + ": could not create an instance, schema class for the schema is null"; LOGGER.warn(returnString); throw new ContextRuntimeException(returnString); } try { - return schemaClass.newInstance(); + return schemaClass.getDeclaredConstructor().newInstance(); } catch (final Exception e) { - final String returnString = userKey.getId() + ": could not create an instance of class \"" - + schemaClass.getName() + "\" using the default constructor \"" - + schemaClass.getSimpleName() + "()\""; + final String returnString = + userKey.getId() + ": could not create an instance of class \"" + schemaClass.getName() + + "\" using the default constructor \"" + schemaClass.getSimpleName() + "()\""; LOGGER.warn(returnString, e); throw new ContextRuntimeException(returnString, e); } @@ -136,8 +136,8 @@ public abstract class AbstractSchemaHelper implements SchemaHelper { @Override public Object createNewInstance(final String stringValue) { if (schemaClass == null) { - final String returnString = userKey.getId() - + ": could not create an instance, schema class for the schema is null"; + final String returnString = + userKey.getId() + ": could not create an instance, schema class for the schema is null"; LOGGER.warn(returnString); throw new ContextRuntimeException(returnString); } @@ -149,9 +149,9 @@ public abstract class AbstractSchemaHelper implements SchemaHelper { // Invoke the constructor return stringConstructor.newInstance(stringValue); } catch (final Exception e) { - final String returnString = userKey.getId() + ": could not create an instance of class \"" - + schemaClass.getName() + "\" using the string constructor \"" - + schemaClass.getSimpleName() + "(String)\""; + final String returnString = + userKey.getId() + ": could not create an instance of class \"" + schemaClass.getName() + + "\" using the string constructor \"" + schemaClass.getSimpleName() + "(String)\""; LOGGER.warn(returnString, e); throw new ContextRuntimeException(returnString); } diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/SchemaHelperFactory.java b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/SchemaHelperFactory.java index 4f0c233db..d1cd3b11b 100644 --- a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/SchemaHelperFactory.java +++ b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/SchemaHelperFactory.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. @@ -56,15 +56,15 @@ public class SchemaHelperFactory { public SchemaHelper createSchemaHelper(final AxKey owningEntityKey, final AxArtifactKey schemaKey) { LOGGER.entry("schema helper factory, owningEntityKey=" + owningEntityKey); Assertions.argumentOfClassNotNull(owningEntityKey, ContextRuntimeException.class, - "Parameter \"owningEntityKey\" may not be null"); + "Parameter \"owningEntityKey\" may not be null"); Assertions.argumentOfClassNotNull(schemaKey, ContextRuntimeException.class, - "Parameter \"schemaKey\" may not be null"); + "Parameter \"schemaKey\" may not be null"); // Get the schema for items in the album final AxContextSchema schema = ModelService.getModel(AxContextSchemas.class).get(schemaKey); if (schema == null) { - final String resultString = "schema \"" + schemaKey.getId() + "\" for entity " + owningEntityKey.getId() - + " does not exist"; + final String resultString = + "schema \"" + schemaKey.getId() + "\" for entity " + owningEntityKey.getId() + " does not exist"; LOGGER.warn(resultString); throw new ContextRuntimeException(resultString); } @@ -73,11 +73,11 @@ public class SchemaHelperFactory { final SchemaParameters schemaParameters = ParameterService.get(ContextParameterConstants.SCHEMA_GROUP_NAME); // Get the class for the schema helper from the schema parameters - final SchemaHelperParameters schemaHelperParameters = schemaParameters - .getSchemaHelperParameters(schema.getSchemaFlavour()); + final SchemaHelperParameters schemaHelperParameters = + schemaParameters.getSchemaHelperParameters(schema.getSchemaFlavour()); if (schemaHelperParameters == null) { final String resultString = "context schema helper parameters not found for context schema \"" - + schema.getSchemaFlavour() + "\""; + + schema.getSchemaFlavour() + "\""; LOGGER.warn(resultString); throw new ContextRuntimeException(resultString); } @@ -86,10 +86,10 @@ public class SchemaHelperFactory { Object schemaHelperObject = null; final String pluginClass = schemaHelperParameters.getSchemaHelperPluginClass(); try { - schemaHelperObject = Class.forName(pluginClass).newInstance(); - } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { + schemaHelperObject = Class.forName(pluginClass).getDeclaredConstructor().newInstance(); + } catch (final Exception e) { final String resultString = "Apex context schema helper class not found for context schema helper plugin \"" - + pluginClass + "\""; + + pluginClass + "\""; LOGGER.warn(resultString, e); throw new ContextRuntimeException(resultString, e); } @@ -97,7 +97,7 @@ public class SchemaHelperFactory { // Check the class is a schema helper if (!(schemaHelperObject instanceof SchemaHelper)) { final String resultString = "Specified Apex context schema helper plugin class \"" + pluginClass - + "\" does not implement the SchemaHelper interface"; + + "\" does not implement the SchemaHelper interface"; LOGGER.warn(resultString); throw new ContextRuntimeException(resultString); } @@ -109,7 +109,7 @@ public class SchemaHelperFactory { schemaHelper.init(owningEntityKey.getKey(), schema); LOGGER.exit("Schema Helper factory, owningEntityKey=" + owningEntityKey + ", selected schema helper of class " - + schemaHelper.getClass()); + + schemaHelper.getClass()); return schemaHelper; } } diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelper.java b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelper.java index b36e00899..e4cdd0fdc 100644 --- a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelper.java +++ b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelper.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,7 +83,7 @@ public class JavaSchemaHelper extends AbstractSchemaHelper { } catch (final IllegalArgumentException e) { String resultSting = userKey.getId() + ": class/type " + schema.getSchema() + " for context schema \"" - + schema.getId() + "\" not found."; + + schema.getId() + "\" not found."; if (JavaSchemaHelper.BUILT_IN_MAP.get(javatype) != null) { resultSting += " Primitive types are not supported. Use the appropriate Java boxing type instead."; } else { @@ -104,8 +104,8 @@ public class JavaSchemaHelper extends AbstractSchemaHelper { } if (getSchemaClass() == null) { - final String returnString = getUserKey().getId() - + ": could not create an instance, schema class for the schema is null"; + final String returnString = + getUserKey().getId() + ": could not create an instance, schema class for the schema is null"; LOGGER.warn(returnString); throw new ContextRuntimeException(returnString); } @@ -120,9 +120,8 @@ public class JavaSchemaHelper extends AbstractSchemaHelper { } final String returnString = getUserKey().getId() + ": the object \"" + incomingObject + "\" of type \"" - + incomingObject.getClass().getName() - + "\" is not an instance of JsonObject and is not assignable to \"" + getSchemaClass().getName() - + "\""; + + incomingObject.getClass().getName() + + "\" is not an instance of JsonObject and is not assignable to \"" + getSchemaClass().getName() + "\""; LOGGER.warn(returnString); throw new ContextRuntimeException(returnString); } @@ -168,8 +167,8 @@ public class JavaSchemaHelper extends AbstractSchemaHelper { return getGson().toJson(schemaObject); } else { final String returnString = getUserKey().getId() + ": object \"" + schemaObject.toString() - + "\" of class \"" + schemaObject.getClass().getName() + "\" not compatible with class \"" - + getSchemaClass().getName() + "\""; + + "\" of class \"" + schemaObject.getClass().getName() + "\" not compatible with class \"" + + getSchemaClass().getName() + "\""; LOGGER.warn(returnString); throw new ContextRuntimeException(returnString); } @@ -225,8 +224,8 @@ public class JavaSchemaHelper extends AbstractSchemaHelper { return stringConstructor.newInstance(object.toString()); } catch (final Exception e) { final String returnString = getUserKey().getId() + ": object \"" + object.toString() + "\" of class \"" - + object.getClass().getName() + "\" not compatible with class \"" - + getSchemaClass().getName() + "\""; + + object.getClass().getName() + "\" not compatible with class \"" + getSchemaClass().getName() + + "\""; LOGGER.warn(returnString, e); throw new ContextRuntimeException(returnString); } @@ -243,23 +242,23 @@ public class JavaSchemaHelper extends AbstractSchemaHelper { // Get the Java schema helper parameters from the parameter service SchemaParameters schemaParameters = ParameterService.get(ContextParameterConstants.SCHEMA_GROUP_NAME); - JavaSchemaHelperParameters javaSchemaHelperParmeters = (JavaSchemaHelperParameters) schemaParameters - .getSchemaHelperParameterMap().get("Java"); + JavaSchemaHelperParameters javaSchemaHelperParmeters = + (JavaSchemaHelperParameters) schemaParameters.getSchemaHelperParameterMap().get("Java"); if (javaSchemaHelperParmeters == null) { javaSchemaHelperParmeters = new JavaSchemaHelperParameters(); } for (JavaSchemaHelperJsonAdapterParameters jsonAdapterEntry : javaSchemaHelperParmeters.getJsonAdapters() - .values()) { + .values()) { Object adapterObject; try { - adapterObject = jsonAdapterEntry.getAdaptorClazz().newInstance(); - } catch (InstantiationException | IllegalAccessException e) { + adapterObject = jsonAdapterEntry.getAdaptorClazz().getDeclaredConstructor().newInstance(); + } catch (Exception e) { final String returnString = getUserKey().getId() + ": instantiation of adapter class \"" - + jsonAdapterEntry.getAdaptorClass() + "\" to decode and encode class \"" - + jsonAdapterEntry.getAdaptedClass() + "\" failed: " + e.getMessage(); + + jsonAdapterEntry.getAdaptorClass() + "\" to decode and encode class \"" + + jsonAdapterEntry.getAdaptedClass() + "\" failed: " + e.getMessage(); LOGGER.warn(returnString, e); throw new ContextRuntimeException(returnString); } diff --git a/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperTest.java b/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperTest.java index 16976f268..8cac36385 100644 --- a/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperTest.java +++ b/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 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. @@ -33,7 +34,6 @@ import java.time.Instant; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; - import org.onap.policy.apex.context.ContextRuntimeException; import org.onap.policy.apex.context.SchemaHelper; import org.onap.policy.apex.context.parameters.ContextParameterConstants; @@ -55,7 +55,7 @@ public class JavaSchemaHelperTest { stringAdapterPars.setAdaptorClass("org.onap.policy.apex.context.impl.schema.java.SupportJsonAdapter"); javaSchemaHelperPars.getJsonAdapters().put("String", stringAdapterPars); - + SchemaParameters schemaPars = new SchemaParameters(); schemaPars.getSchemaHelperParameterMap().put("Java", javaSchemaHelperPars); @@ -79,7 +79,7 @@ public class JavaSchemaHelperTest { fail("test should throw an exception here"); } catch (ContextRuntimeException e) { assertEquals("UserKey:0.0.1: class/type java.lang.Rubbish for context schema" - + " \"SchemaKey:0.0.1\" not found. Check the class path of the JVM", e.getMessage()); + + " \"SchemaKey:0.0.1\" not found. Check the class path of the JVM", e.getMessage()); } AxContextSchema builtInJavaTypeSchema = new AxContextSchema(schemaKey, "Java", "short"); @@ -89,8 +89,8 @@ public class JavaSchemaHelperTest { fail("test should throw an exception here"); } catch (ContextRuntimeException e) { assertEquals("UserKey:0.0.1: class/type short for context schema " - + "\"SchemaKey:0.0.1\" not found. Primitive types are not supported." - + " Use the appropriate Java boxing type instead.", e.getMessage()); + + "\"SchemaKey:0.0.1\" not found. Primitive types are not supported." + + " Use the appropriate Java boxing type instead.", e.getMessage()); } } @@ -108,7 +108,7 @@ public class JavaSchemaHelperTest { fail("test should throw an exception here"); } catch (ContextRuntimeException e) { assertEquals("NULL:0.0.0: could not create an instance, schema class for the schema is null", - e.getMessage()); + e.getMessage()); } try { @@ -116,7 +116,7 @@ public class JavaSchemaHelperTest { fail("test should throw an exception here"); } catch (ContextRuntimeException e) { assertEquals("NULL:0.0.0: could not create an instance, schema class for the schema is null", - e.getMessage()); + e.getMessage()); } try { @@ -124,7 +124,7 @@ public class JavaSchemaHelperTest { fail("test should throw an exception here"); } catch (ContextRuntimeException e) { assertEquals("NULL:0.0.0: could not create an instance, schema class for the schema is null", - e.getMessage()); + e.getMessage()); } AxArtifactKey schemaKey = new AxArtifactKey("SchemaKey", "0.0.1"); @@ -142,7 +142,7 @@ public class JavaSchemaHelperTest { fail("test should throw an exception here"); } catch (ContextRuntimeException e) { assertEquals("UserKey:0.0.1: could not create an instance of class " - + "\"java.lang.Integer\" using the default constructor \"Integer()\"", e.getMessage()); + + "\"java.lang.Integer\" using the default constructor \"Integer()\"", e.getMessage()); } try { @@ -150,8 +150,8 @@ public class JavaSchemaHelperTest { fail("test should throw an exception here"); } catch (ContextRuntimeException e) { assertEquals("UserKey:0.0.1: the object \"1.23\" of type " - + "\"java.lang.Float\" is not an instance of JsonObject and is not " - + "assignable to \"java.lang.Integer\"", e.getMessage()); + + "\"java.lang.Float\" is not an instance of JsonObject and is not " + + "assignable to \"java.lang.Integer\"", e.getMessage()); } try { @@ -159,13 +159,13 @@ public class JavaSchemaHelperTest { fail("test should throw an exception here"); } catch (ContextRuntimeException e) { assertEquals("UserKey:0.0.1: could not create an instance of class \"java.lang.Integer\" " - + "using the string constructor \"Integer(String)\"", e.getMessage()); + + "using the string constructor \"Integer(String)\"", e.getMessage()); } JsonElement jsonIntElement = null; assertEquals(null, intSchemaHelper.createNewInstance(jsonIntElement)); - jsonIntElement = new JsonParser().parse("123"); + jsonIntElement = JsonParser.parseString("123"); assertEquals(123, intSchemaHelper.createNewInstance(jsonIntElement)); assertEquals(123, intSchemaHelper.createNewInstance(Integer.parseInt("123"))); @@ -212,40 +212,40 @@ public class JavaSchemaHelperTest { stringSchemaHelper.init(userKey, stringSchema); AxContextSchema myBaseClassSchema = new AxContextSchema(schemaKey, "Java", - "org.onap.policy.apex.context.impl.schema.java.SupportBaseClass"); + "org.onap.policy.apex.context.impl.schema.java.SupportBaseClass"); SchemaHelper myBaseClassSchemaHelper = new JavaSchemaHelper(); myBaseClassSchemaHelper.init(userKey, myBaseClassSchema); assertEquals(null, byteSchemaHelper.unmarshal(null)); - assertEquals(new Byte("123"), byteSchemaHelper.unmarshal("123")); - assertEquals(new Byte("123"), byteSchemaHelper.unmarshal(Integer.parseInt("123"))); - assertEquals(new Byte("123"), byteSchemaHelper.unmarshal(Byte.parseByte("123"))); - assertEquals(new Byte("123"), byteSchemaHelper.unmarshal(Short.parseShort("123"))); - assertEquals(new Byte("123"), byteSchemaHelper.unmarshal(Long.parseLong("123"))); - assertEquals(new Byte("123"), byteSchemaHelper.unmarshal(Float.parseFloat("123"))); - assertEquals(new Byte("123"), byteSchemaHelper.unmarshal(Double.parseDouble("123"))); + assertEquals(Byte.valueOf("123"), byteSchemaHelper.unmarshal("123")); + assertEquals(Byte.valueOf("123"), byteSchemaHelper.unmarshal(Integer.parseInt("123"))); + assertEquals(Byte.valueOf("123"), byteSchemaHelper.unmarshal(Byte.parseByte("123"))); + assertEquals(Byte.valueOf("123"), byteSchemaHelper.unmarshal(Short.parseShort("123"))); + assertEquals(Byte.valueOf("123"), byteSchemaHelper.unmarshal(Long.parseLong("123"))); + assertEquals(Byte.valueOf("123"), byteSchemaHelper.unmarshal(Float.parseFloat("123"))); + assertEquals(Byte.valueOf("123"), byteSchemaHelper.unmarshal(Double.parseDouble("123"))); try { byteSchemaHelper.unmarshal("one two three"); fail("test should throw an exception here"); } catch (ContextRuntimeException e) { assertEquals("UserKey:0.0.1: object \"one two three\" of class \"java.lang.String\" not " - + "compatible with class \"java.lang.Byte\"", e.getMessage()); + + "compatible with class \"java.lang.Byte\"", e.getMessage()); } assertEquals(null, shortSchemaHelper.unmarshal(null)); - assertEquals(new Short("123"), shortSchemaHelper.unmarshal("123")); - assertEquals(new Short("123"), shortSchemaHelper.unmarshal(Integer.parseInt("123"))); - assertEquals(new Short("123"), shortSchemaHelper.unmarshal(Byte.parseByte("123"))); - assertEquals(new Short("123"), shortSchemaHelper.unmarshal(Short.parseShort("123"))); - assertEquals(new Short("123"), shortSchemaHelper.unmarshal(Long.parseLong("123"))); - assertEquals(new Short("123"), shortSchemaHelper.unmarshal(Float.parseFloat("123"))); - assertEquals(new Short("123"), shortSchemaHelper.unmarshal(Double.parseDouble("123"))); + assertEquals(Short.valueOf("123"), shortSchemaHelper.unmarshal("123")); + assertEquals(Short.valueOf("123"), shortSchemaHelper.unmarshal(Integer.parseInt("123"))); + assertEquals(Short.valueOf("123"), shortSchemaHelper.unmarshal(Byte.parseByte("123"))); + assertEquals(Short.valueOf("123"), shortSchemaHelper.unmarshal(Short.parseShort("123"))); + assertEquals(Short.valueOf("123"), shortSchemaHelper.unmarshal(Long.parseLong("123"))); + assertEquals(Short.valueOf("123"), shortSchemaHelper.unmarshal(Float.parseFloat("123"))); + assertEquals(Short.valueOf("123"), shortSchemaHelper.unmarshal(Double.parseDouble("123"))); try { shortSchemaHelper.unmarshal("one two three"); fail("test should throw an exception here"); } catch (ContextRuntimeException e) { assertEquals("UserKey:0.0.1: object \"one two three\" of class \"java.lang.String\" not " - + "compatible with class \"java.lang.Short\"", e.getMessage()); + + "compatible with class \"java.lang.Short\"", e.getMessage()); } assertEquals(null, intSchemaHelper.unmarshal(null)); @@ -261,7 +261,7 @@ public class JavaSchemaHelperTest { fail("test should throw an exception here"); } catch (ContextRuntimeException e) { assertEquals("UserKey:0.0.1: object \"one two three\" of class \"java.lang.String\" not " - + "compatible with class \"java.lang.Integer\"", e.getMessage()); + + "compatible with class \"java.lang.Integer\"", e.getMessage()); } assertEquals(null, longSchemaHelper.unmarshal(null)); @@ -277,40 +277,40 @@ public class JavaSchemaHelperTest { fail("test should throw an exception here"); } catch (ContextRuntimeException e) { assertEquals("UserKey:0.0.1: object \"one two three\" of class \"java.lang.String\" not " - + "compatible with class \"java.lang.Long\"", e.getMessage()); + + "compatible with class \"java.lang.Long\"", e.getMessage()); } assertEquals(null, floatSchemaHelper.unmarshal(null)); - assertEquals(new Float("123"), floatSchemaHelper.unmarshal("123")); - assertEquals(new Float("123"), floatSchemaHelper.unmarshal(Integer.parseInt("123"))); - assertEquals(new Float("123"), floatSchemaHelper.unmarshal(Byte.parseByte("123"))); - assertEquals(new Float("123"), floatSchemaHelper.unmarshal(Short.parseShort("123"))); - assertEquals(new Float("123"), floatSchemaHelper.unmarshal(Long.parseLong("123"))); - assertEquals(new Float("123"), floatSchemaHelper.unmarshal(Float.parseFloat("123"))); - assertEquals(new Float("123"), floatSchemaHelper.unmarshal(Double.parseDouble("123"))); + assertEquals(Float.valueOf("123"), floatSchemaHelper.unmarshal("123")); + assertEquals(Float.valueOf("123"), floatSchemaHelper.unmarshal(Integer.parseInt("123"))); + assertEquals(Float.valueOf("123"), floatSchemaHelper.unmarshal(Byte.parseByte("123"))); + assertEquals(Float.valueOf("123"), floatSchemaHelper.unmarshal(Short.parseShort("123"))); + assertEquals(Float.valueOf("123"), floatSchemaHelper.unmarshal(Long.parseLong("123"))); + assertEquals(Float.valueOf("123"), floatSchemaHelper.unmarshal(Float.parseFloat("123"))); + assertEquals(Float.valueOf("123"), floatSchemaHelper.unmarshal(Double.parseDouble("123"))); try { floatSchemaHelper.unmarshal("one two three"); fail("test should throw an exception here"); } catch (ContextRuntimeException e) { assertEquals("UserKey:0.0.1: object \"one two three\" of class \"java.lang.String\" not " - + "compatible with class \"java.lang.Float\"", e.getMessage()); + + "compatible with class \"java.lang.Float\"", e.getMessage()); } assertEquals(null, doubleSchemaHelper.unmarshal(null)); - assertEquals(new Double("123"), doubleSchemaHelper.unmarshal("123")); - assertEquals(new Double("123"), doubleSchemaHelper.unmarshal(Integer.parseInt("123"))); - assertEquals(new Double("123"), doubleSchemaHelper.unmarshal(Byte.parseByte("123"))); - assertEquals(new Double("123"), doubleSchemaHelper.unmarshal(Short.parseShort("123"))); - assertEquals(new Double("123"), doubleSchemaHelper.unmarshal(Long.parseLong("123"))); - assertEquals(new Double("123"), doubleSchemaHelper.unmarshal(Float.parseFloat("123"))); - assertEquals(new Double("123"), doubleSchemaHelper.unmarshal(Double.parseDouble("123"))); - assertEquals(new Double("123"), doubleSchemaHelper.unmarshal(BigDecimal.valueOf(123))); + assertEquals(Double.valueOf("123"), doubleSchemaHelper.unmarshal("123")); + assertEquals(Double.valueOf("123"), doubleSchemaHelper.unmarshal(Integer.parseInt("123"))); + assertEquals(Double.valueOf("123"), doubleSchemaHelper.unmarshal(Byte.parseByte("123"))); + assertEquals(Double.valueOf("123"), doubleSchemaHelper.unmarshal(Short.parseShort("123"))); + assertEquals(Double.valueOf("123"), doubleSchemaHelper.unmarshal(Long.parseLong("123"))); + assertEquals(Double.valueOf("123"), doubleSchemaHelper.unmarshal(Float.parseFloat("123"))); + assertEquals(Double.valueOf("123"), doubleSchemaHelper.unmarshal(Double.parseDouble("123"))); + assertEquals(Double.valueOf("123"), doubleSchemaHelper.unmarshal(BigDecimal.valueOf(123))); try { doubleSchemaHelper.unmarshal("one two three"); fail("test should throw an exception here"); } catch (ContextRuntimeException e) { assertEquals("UserKey:0.0.1: object \"one two three\" of class \"java.lang.String\" not " - + "compatible with class \"java.lang.Double\"", e.getMessage()); + + "compatible with class \"java.lang.Double\"", e.getMessage()); } assertEquals("123", stringSchemaHelper.unmarshal(123)); @@ -335,7 +335,7 @@ public class JavaSchemaHelperTest { fail("test should throw an exception here"); } catch (ContextRuntimeException e) { assertEquals("UserKey:0.0.1: object \"123.45\" of class \"java.lang.Double\" not " - + "compatible with class \"java.lang.Integer\"", e.getMessage()); + + "compatible with class \"java.lang.Integer\"", e.getMessage()); } JsonPrimitive intJsonPrimitive = (JsonPrimitive) intSchemaHelper.marshal2Object(123); @@ -358,7 +358,7 @@ public class JavaSchemaHelperTest { fail("test should throw an exception here"); } catch (ContextRuntimeException e) { assertEquals("UserKey:0.0.1: object \"1970-01-01T00:00:01Z\" of class \"java.time.Instant\" " - + "not compatible with class \"java.lang.String\"", e.getMessage()); + + "not compatible with class \"java.lang.String\"", e.getMessage()); } JsonPrimitive stringJsonPrimitive = (JsonPrimitive) stringSchemaHelper.marshal2Object("Another String"); @@ -371,11 +371,11 @@ public class JavaSchemaHelperTest { AxArtifactKey userKey = new AxArtifactKey("UserKey", "0.0.1"); SchemaParameters pars = ParameterService.get(ContextParameterConstants.SCHEMA_GROUP_NAME); - - JavaSchemaHelperParameters javaShPars = (JavaSchemaHelperParameters) pars.getSchemaHelperParameterMap() - .get("Java"); + + JavaSchemaHelperParameters javaShPars = + (JavaSchemaHelperParameters) pars.getSchemaHelperParameterMap().get("Java"); javaShPars.getJsonAdapters().get("String") - .setAdaptorClass("org.onap.policy.apex.context.impl.schema.java.SupportBadJsonAdapter"); + .setAdaptorClass("org.onap.policy.apex.context.impl.schema.java.SupportBadJsonAdapter"); AxContextSchema stringSchema = new AxContextSchema(schemaKey, "Java", "java.lang.String"); SchemaHelper stringSchemaHelper = new JavaSchemaHelper(); @@ -386,9 +386,8 @@ public class JavaSchemaHelperTest { fail("test should throw an exception"); } catch (ContextRuntimeException pre) { assertEquals("UserKey:0.0.1: instantiation of adapter class " - + "\"org.onap.policy.apex.context.impl.schema.java.SupportBadJsonAdapter\" " - + "to decode and encode class \"java.lang.String\" failed: Test for Bad Adapter", - pre.getMessage()); + + "\"org.onap.policy.apex.context.impl.schema.java.SupportBadJsonAdapter\" to decode and encode " + + "class \"java.lang.String\" failed: null", pre.getMessage()); } } @@ -396,11 +395,11 @@ public class JavaSchemaHelperTest { public void testJavaSchemaHelperDefaultAdapter() { SchemaParameters pars = ParameterService.get(ContextParameterConstants.SCHEMA_GROUP_NAME); - JavaSchemaHelperParameters javaShPars = (JavaSchemaHelperParameters) pars.getSchemaHelperParameterMap() - .get("Java"); - + JavaSchemaHelperParameters javaShPars = + (JavaSchemaHelperParameters) pars.getSchemaHelperParameterMap().get("Java"); + pars.getSchemaHelperParameterMap().clear(); - + testJavaSchemaHelperAdapters(); pars.getSchemaHelperParameterMap().put("Java", javaShPars); |