diff options
author | 2024-06-18 15:12:56 +0100 | |
---|---|---|
committer | 2024-06-19 17:25:08 +0100 | |
commit | a23bd8c218d7044e1d79e240fdb74f00947a3108 (patch) | |
tree | 064323adf3c19a5346c108d905495363cce45adf /context | |
parent | 6040233dcbe4a64b977ee750c6d0d12b2d513c4c (diff) |
Convert junit4 to junit5
- clean up any references to junit4
- clean up some sonar complaints
- remove not used integration tests
Issue-ID: POLICY-5041
Change-Id: I67e7a8f00df5b6c5ba514f4ea2ecd96bf942d4c7
Signed-off-by: adheli.tavares <adheli.tavares@est.tech>
Diffstat (limited to 'context')
2 files changed, 51 insertions, 50 deletions
diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/ContextAlbumImpl.java b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/ContextAlbumImpl.java index e45c47952..096e68889 100644 --- a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/ContextAlbumImpl.java +++ b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/ContextAlbumImpl.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, 2024 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -30,6 +30,7 @@ import java.util.Map; import java.util.Set; import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.NonNull; import lombok.Setter; import org.onap.policy.apex.context.ContextAlbum; import org.onap.policy.apex.context.ContextException; @@ -88,12 +89,12 @@ public final class ContextAlbumImpl implements ContextAlbum, Comparable<ContextA * Constructor, instantiate the context album. * * @param albumDefinition The model definition of this context album - * @param distributor The context distributor passed to us to distribute context across ContextAlbum instances - * @param albumMap the album map + * @param distributor The context distributor passed to us to distribute context across ContextAlbum instances + * @param albumMap the album map * @throws ContextException on errors creating context albums */ public ContextAlbumImpl(final AxContextAlbum albumDefinition, final Distributor distributor, - final Map<String, Object> albumMap) throws ContextException { + final Map<String, Object> albumMap) throws ContextException { Assertions.argumentNotNull(albumDefinition, "Context album definition may not be null"); Assertions.argumentNotNull(distributor, "Distributor may not be null"); Assertions.argumentNotNull(albumMap, "Album map may not be null"); @@ -109,7 +110,7 @@ public final class ContextAlbumImpl implements ContextAlbum, Comparable<ContextA try { // Get a schema helper to manage the translations between objects on the album map for this album schemaHelper = new SchemaHelperFactory().createSchemaHelper(albumDefinition.getKey(), - albumDefinition.getItemSchema()); + albumDefinition.getItemSchema()); } catch (final ContextRuntimeException e) { final var resultString = "could not initiate schema management for context album " + albumDefinition; LOGGER.warn(resultString, e); @@ -144,7 +145,7 @@ public final class ContextAlbumImpl implements ContextAlbum, Comparable<ContextA public void lockForReading(final String keyOnAlbum) throws ContextException { distributor.lockForReading(albumDefinition.getKey(), keyOnAlbum); monitor.monitorReadLock(albumDefinition.getKey(), albumDefinition.getItemSchema(), keyOnAlbum, - userArtifactStack); + userArtifactStack); } /** @@ -154,7 +155,7 @@ public final class ContextAlbumImpl implements ContextAlbum, Comparable<ContextA public void lockForWriting(final String keyOnAlbum) throws ContextException { distributor.lockForWriting(albumDefinition.getKey(), keyOnAlbum); monitor.monitorWriteLock(albumDefinition.getKey(), albumDefinition.getItemSchema(), keyOnAlbum, - userArtifactStack); + userArtifactStack); } /** @@ -164,7 +165,7 @@ public final class ContextAlbumImpl implements ContextAlbum, Comparable<ContextA public void unlockForReading(final String keyOnAlbum) throws ContextException { distributor.unlockForReading(albumDefinition.getKey(), keyOnAlbum); monitor.monitorReadUnlock(albumDefinition.getKey(), albumDefinition.getItemSchema(), keyOnAlbum, - userArtifactStack); + userArtifactStack); } /** @@ -174,7 +175,7 @@ public final class ContextAlbumImpl implements ContextAlbum, Comparable<ContextA public void unlockForWriting(final String keyOnAlbum) throws ContextException { distributor.unlockForWriting(albumDefinition.getKey(), keyOnAlbum); monitor.monitorWriteUnlock(albumDefinition.getKey(), albumDefinition.getItemSchema(), keyOnAlbum, - userArtifactStack); + userArtifactStack); } /** @@ -238,7 +239,7 @@ public final class ContextAlbumImpl implements ContextAlbum, Comparable<ContextA public Object get(final Object key) { if (key == null) { final var returnString = - ALBUM + albumDefinition.getId() + "\" null keys are illegal on keys for get()"; + ALBUM + albumDefinition.getId() + "\" null keys are illegal on keys for get()"; LOGGER.warn(returnString); throw new ContextRuntimeException(returnString); } @@ -250,7 +251,7 @@ public final class ContextAlbumImpl implements ContextAlbum, Comparable<ContextA // Get the context value and monitor it monitor.monitorGet(albumDefinition.getKey(), albumDefinition.getItemSchema(), key.toString(), item, - userArtifactStack); + userArtifactStack); return item; } @@ -273,7 +274,7 @@ public final class ContextAlbumImpl implements ContextAlbum, Comparable<ContextA for (final Entry<String, Object> contextAlbumEntry : albumMap.entrySet()) { final Object item = contextAlbumEntry.getValue(); monitor.monitorGet(albumDefinition.getKey(), albumDefinition.getItemSchema(), contextAlbumEntry.getKey(), - item, userArtifactStack); + item, userArtifactStack); valueList.add(contextAlbumEntry.getValue()); } @@ -291,7 +292,7 @@ public final class ContextAlbumImpl implements ContextAlbum, Comparable<ContextA for (final Entry<String, Object> contextAlbumEntry : albumMap.entrySet()) { final Object item = contextAlbumEntry.getValue(); monitor.monitorGet(albumDefinition.getKey(), albumDefinition.getItemSchema(), contextAlbumEntry.getKey(), - item, userArtifactStack); + item, userArtifactStack); entrySet.add(new SimpleEntry<>(contextAlbumEntry.getKey(), contextAlbumEntry.getValue())); } @@ -305,21 +306,21 @@ public final class ContextAlbumImpl implements ContextAlbum, Comparable<ContextA public Object put(final String key, final Object incomingValue) { if (key == null) { final var returnString = - ALBUM + albumDefinition.getId() + "\" null keys are illegal on keys for put()"; + ALBUM + albumDefinition.getId() + "\" null keys are illegal on keys for put()"; LOGGER.warn(returnString); throw new ContextRuntimeException(returnString); } if (incomingValue == null) { final var returnString = ALBUM + albumDefinition.getId() + "\" null values are illegal on key \"" - + key + "\" for put()"; + + key + "\" for put()"; LOGGER.warn(returnString); throw new ContextRuntimeException(returnString); } if (!albumDefinition.isWritable()) { final var returnString = ALBUM + albumDefinition.getId() - + "\" put() not allowed on read only albums for key=\"" + key + "\", value=\"" + incomingValue; + + "\" put() not allowed on read only albums for key=\"" + key + "\", value=\"" + incomingValue; LOGGER.warn(returnString); throw new ContextRuntimeException(returnString); } @@ -332,18 +333,18 @@ public final class ContextAlbumImpl implements ContextAlbum, Comparable<ContextA if (albumMap.containsKey(key)) { // Update the value in the context item and in the context value map monitor.monitorSet(albumDefinition.getKey(), albumDefinition.getItemSchema(), key, incomingValue, - userArtifactStack); + userArtifactStack); } else { // Update the value in the context item and in the context value map monitor.monitorInit(albumDefinition.getKey(), albumDefinition.getItemSchema(), key, incomingValue, - userArtifactStack); + userArtifactStack); } // Put the translated value on the map and return the old map value return albumMap.put(key, valueToPut); } catch (final ContextRuntimeException e) { final var returnString = "Failed to set context value for key \"" + key + "\" in album \"" - + albumDefinition.getId() + "\": " + e.getMessage(); + + albumDefinition.getId() + "\": " + e.getMessage(); LOGGER.warn(returnString); throw new ContextRuntimeException(returnString, e); } @@ -353,17 +354,17 @@ public final class ContextAlbumImpl implements ContextAlbum, Comparable<ContextA * {@inheritDoc}. */ @Override - public void putAll(final Map<? extends String, ? extends Object> incomingContextAlbum) { + public void putAll(@NonNull final Map<? extends String, ?> incomingContextAlbum) { if (!albumDefinition.isWritable()) { final var returnString = - ALBUM + albumDefinition.getId() + "\" putAll() not allowed on read only albums"; + ALBUM + albumDefinition.getId() + "\" putAll() not allowed on read only albums"; LOGGER.warn(returnString); throw new ContextRuntimeException(returnString); } // Sanity check on incoming context Assertions.argumentOfClassNotNull(incomingContextAlbum, ContextRuntimeException.class, - "cannot update context, context album is null"); + "cannot update context, context album is null"); // Iterate over the incoming context for (final Entry<String, Object> entry : albumMap.entrySet()) { @@ -378,7 +379,7 @@ public final class ContextAlbumImpl implements ContextAlbum, Comparable<ContextA } // Put all the objects on the context album - for (final Entry<? extends String, ? extends Object> incomingMapEntry : incomingContextAlbum.entrySet()) { + for (final Entry<? extends String, ?> incomingMapEntry : incomingContextAlbum.entrySet()) { // NOSONAR // Put the entry on the map this.put(incomingMapEntry.getKey(), incomingMapEntry.getValue()); } @@ -391,7 +392,7 @@ public final class ContextAlbumImpl implements ContextAlbum, Comparable<ContextA public Object remove(final Object key) { if (!albumDefinition.isWritable()) { final var returnString = ALBUM + albumDefinition.getId() - + "\" remove() not allowed on read only albums for key=\"" + key + "\""; + + "\" remove() not allowed on read only albums for key=\"" + key + "\""; LOGGER.warn(returnString); throw new ContextRuntimeException(returnString); } @@ -404,7 +405,7 @@ public final class ContextAlbumImpl implements ContextAlbum, Comparable<ContextA // Delete the item final Object removedValue = albumMap.remove(key); monitor.monitorDelete(albumDefinition.getKey(), albumDefinition.getItemSchema(), key.toString(), removedValue, - userArtifactStack); + userArtifactStack); // Return the value of the deleted item return removedValue; @@ -417,7 +418,7 @@ public final class ContextAlbumImpl implements ContextAlbum, Comparable<ContextA public void clear() { if (!albumDefinition.isWritable()) { final var returnString = - ALBUM + albumDefinition.getId() + "\" clear() not allowed on read only albums"; + ALBUM + albumDefinition.getId() + "\" clear() not allowed on read only albums"; LOGGER.warn(returnString); throw new ContextRuntimeException(returnString); } @@ -426,7 +427,7 @@ public final class ContextAlbumImpl implements ContextAlbum, Comparable<ContextA for (final Entry<String, Object> contextAlbumEntry : albumMap.entrySet()) { final Object item = contextAlbumEntry.getValue(); monitor.monitorDelete(albumDefinition.getKey(), albumDefinition.getItemSchema(), contextAlbumEntry.getKey(), - item, userArtifactStack); + item, userArtifactStack); } // Clear the map 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 f601062bb..b1a1d36df 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-2020 Nordix Foundation. + * Modifications Copyright (C) 2019-2020, 2024 Nordix Foundation. * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -49,7 +49,7 @@ public class JavaSchemaHelper extends AbstractSchemaHelper { // Get a reference to the logger private static final XLogger LOGGER = XLoggerFactory.getXLogger(JavaSchemaHelper.class); - // This map defines the built in types in types in Java + // This map defines the built-in types in Java // @formatter:off private static final Map<String, Class<?>> BUILT_IN_MAP = new HashMap<>(); @@ -81,7 +81,7 @@ public class JavaSchemaHelper extends AbstractSchemaHelper { } catch (final Exception 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 { @@ -103,13 +103,13 @@ public class JavaSchemaHelper extends AbstractSchemaHelper { if (getSchemaClass() == null) { final var returnString = - getUserKey().getId() + ": could not create an instance, schema class for the schema is null"; + getUserKey().getId() + ": could not create an instance, schema class for the schema is null"; LOGGER.warn(returnString); throw new ContextRuntimeException(returnString); } - if (incomingObject instanceof JsonElement) { - final var elementJsonString = getGson().toJson((JsonElement) incomingObject); + if (incomingObject instanceof JsonElement jsonObject) { + final var elementJsonString = getGson().toJson(jsonObject); return getGson().fromJson(elementJsonString, this.getSchemaClass()); } @@ -118,8 +118,8 @@ public class JavaSchemaHelper extends AbstractSchemaHelper { } final var 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); } @@ -165,8 +165,8 @@ public class JavaSchemaHelper extends AbstractSchemaHelper { return getGson().toJson(schemaObject); } else { final var 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); } @@ -189,19 +189,19 @@ public class JavaSchemaHelper extends AbstractSchemaHelper { */ private Object numericConversion(final Object object) { // Check if the incoming object is a number, if not do a string conversion - if (object instanceof Number) { + if (object instanceof Number myNumber) { if (getSchemaClass().isAssignableFrom(Byte.class)) { - return ((Number) object).byteValue(); + return myNumber.byteValue(); } else if (getSchemaClass().isAssignableFrom(Short.class)) { - return ((Number) object).shortValue(); + return myNumber.shortValue(); } else if (getSchemaClass().isAssignableFrom(Integer.class)) { - return ((Number) object).intValue(); + return myNumber.intValue(); } else if (getSchemaClass().isAssignableFrom(Long.class)) { - return ((Number) object).longValue(); + return myNumber.longValue(); } else if (getSchemaClass().isAssignableFrom(Float.class)) { - return ((Number) object).floatValue(); + return myNumber.floatValue(); } else if (getSchemaClass().isAssignableFrom(Double.class)) { - return ((Number) object).doubleValue(); + return myNumber.doubleValue(); } } @@ -222,8 +222,8 @@ public class JavaSchemaHelper extends AbstractSchemaHelper { return stringConstructor.newInstance(object.toString()); } catch (final Exception e) { final var 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); } @@ -241,22 +241,22 @@ public class JavaSchemaHelper extends AbstractSchemaHelper { var schemaParameters = (SchemaParameters) ParameterService.get(ContextParameterConstants.SCHEMA_GROUP_NAME); JavaSchemaHelperParameters javaSchemaHelperParmeters = - (JavaSchemaHelperParameters) schemaParameters.getSchemaHelperParameterMap().get("Java"); + (JavaSchemaHelperParameters) schemaParameters.getSchemaHelperParameterMap().get("Java"); if (javaSchemaHelperParmeters == null) { javaSchemaHelperParmeters = new JavaSchemaHelperParameters(); } for (JavaSchemaHelperJsonAdapterParameters jsonAdapterEntry : javaSchemaHelperParmeters.getJsonAdapters() - .values()) { + .values()) { Object adapterObject; try { adapterObject = jsonAdapterEntry.getAdaptorClazz().getDeclaredConstructor().newInstance(); } catch (Exception e) { final var 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); } |