Fix Sonar issues in apex-pdp 31/121931/1
authorlapentafd <francesco.lapenta@est.tech>
Tue, 15 Jun 2021 10:09:52 +0000 (11:09 +0100)
committerlapentafd <francesco.lapenta@est.tech>
Tue, 15 Jun 2021 13:34:42 +0000 (14:34 +0100)
Issue-ID: POLICY-3093
Change-Id: I4def597b054a9ab2f3cc9a4665df04dd1d515ebf
Signed-off-by: lapentafd <francesco.lapenta@est.tech>
model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextAlbum.java
model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextAlbums.java
model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextModel.java
model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextSchema.java
model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextSchemas.java
model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextAlbumsTest.java
model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextSchemasTest.java

index 629e255..85a6ab8 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
- *  Modifications Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 2019-2021 Nordix Foundation.
  *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -264,7 +264,7 @@ public class AxContextAlbum extends AxConcept {
                             "scope is not defined"));
         }
 
-        String stringCheckResult = Assertions.getStringParameterValidationMessage(SCOPE_STRING, scope, SCOPE_REGEXP);
+        var stringCheckResult = Assertions.getStringParameterValidationMessage(SCOPE_STRING, scope, SCOPE_REGEXP);
         if (stringCheckResult != null) {
             result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
                             "scope invalid-" + stringCheckResult));
@@ -294,7 +294,7 @@ public class AxContextAlbum extends AxConcept {
      */
     @Override
     public String toString() {
-        final StringBuilder builder = new StringBuilder();
+        final var builder = new StringBuilder();
         builder.append(this.getClass().getSimpleName());
         builder.append(":(");
         builder.append("key=");
@@ -333,8 +333,8 @@ public class AxContextAlbum extends AxConcept {
      */
     @Override
     public int hashCode() {
-        final int prime = 31;
-        int result = 1;
+        final var prime = 31;
+        var result = 1;
         result = prime * result + key.hashCode();
         result = prime * result + scope.hashCode();
         result = prime * result + (isWritable ? HASH_PRIME_0 : HASH_PRIME_1);
index 99e5300..6165996 100644 (file)
@@ -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-2021 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -213,7 +213,7 @@ public final class AxContextAlbums extends AxConcept implements AxConceptGetter<
      */
     @Override
     public String toString() {
-        final StringBuilder builder = new StringBuilder();
+        final var builder = new StringBuilder();
         builder.append(this.getClass().getSimpleName());
         builder.append(":(");
         builder.append(this.getClass().getSimpleName());
@@ -300,8 +300,8 @@ public final class AxContextAlbums extends AxConcept implements AxConceptGetter<
      */
     @Override
     public int hashCode() {
-        final int prime = 31;
-        int result = 1;
+        final var prime = 31;
+        var result = 1;
         result = prime * result + key.hashCode();
         result = prime * result + albums.hashCode();
         return result;
index 9fbcc81..c5919c0 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
- *  Modifications Copyright (C) 2019 Nordix Foundation.
+ *  Modifications Copyright (C) 2019-2021 Nordix Foundation.
  *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -224,7 +224,7 @@ public class AxContextModel extends AxModel {
      */
     @Override
     public String toString() {
-        final StringBuilder builder = new StringBuilder();
+        final var builder = new StringBuilder();
         builder.append(this.getClass().getSimpleName());
         builder.append(":(");
         builder.append(super.toString());
@@ -259,8 +259,8 @@ public class AxContextModel extends AxModel {
      */
     @Override
     public int hashCode() {
-        final int prime = 31;
-        int result = 1;
+        final var prime = 31;
+        var result = 1;
         result = prime * result + super.hashCode();
         result = prime * result + schemas.hashCode();
         result = prime * result + albums.hashCode();
index 00baebe..bca3691 100644 (file)
@@ -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-2021 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -226,7 +226,7 @@ public class AxContextSchema extends AxConcept {
                             "schema flavour is not defined"));
         }
 
-        String flavourValidationResult = Assertions.getStringParameterValidationMessage(SCHEMA_FLAVOUR, schemaFlavour,
+        var flavourValidationResult = Assertions.getStringParameterValidationMessage(SCHEMA_FLAVOUR, schemaFlavour,
                         SCHEMA_FLAVOUR_REGEXP);
         if (flavourValidationResult != null) {
             result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID,
@@ -256,7 +256,7 @@ public class AxContextSchema extends AxConcept {
      */
     @Override
     public String toString() {
-        final StringBuilder builder = new StringBuilder();
+        final var builder = new StringBuilder();
         builder.append(this.getClass().getSimpleName());
         builder.append(":(");
         builder.append("key=");
@@ -292,8 +292,8 @@ public class AxContextSchema extends AxConcept {
      */
     @Override
     public int hashCode() {
-        final int prime = 31;
-        int result = 1;
+        final var prime = 31;
+        var result = 1;
         result = prime * result + key.hashCode();
         result = prime * result + schemaFlavour.hashCode();
         result = prime * result + schemaDefinition.hashCode();
index 8c4110b..705691c 100644 (file)
@@ -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-2021 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -253,7 +253,7 @@ public class AxContextSchemas extends AxConcept implements AxConceptGetter<AxCon
      */
     @Override
     public String toString() {
-        final StringBuilder builder = new StringBuilder();
+        final var builder = new StringBuilder();
         builder.append(this.getClass().getSimpleName());
         builder.append(":(");
         builder.append("key=");
@@ -292,8 +292,8 @@ public class AxContextSchemas extends AxConcept implements AxConceptGetter<AxCon
      */
     @Override
     public int hashCode() {
-        final int prime = 31;
-        int result = 1;
+        final var prime = 31;
+        var result = 1;
         result = prime * result + key.hashCode();
         result = prime * result + schemas.hashCode();
         return result;
index 154739b..8293feb 100644 (file)
@@ -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-2021 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -40,11 +40,14 @@ import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.Validat
 public class ContextAlbumsTest {
 
     @Test
-    public void testContextAlbums() {
+    public void testNewAxContectAlbum() {
         assertNotNull(new AxContextAlbum());
         assertNotNull(new AxContextAlbum(new AxArtifactKey()));
         assertNotNull(new AxContextAlbum(new AxArtifactKey(), "AlbumScope", false, new AxArtifactKey()));
+    }
 
+    @Test
+    public void testContextAlbums() {
         final AxArtifactKey albumKey = new AxArtifactKey("AlbumName", "0.0.1");
         final AxArtifactKey albumSchemaKey = new AxArtifactKey("AlbumSchemaName", "0.0.1");
 
@@ -72,7 +75,23 @@ public class ContextAlbumsTest {
         album.setItemSchema(newSchemaKey);
         assertEquals("NewAlbumSchemaName:0.0.1", album.getItemSchema().getId());
         album.setItemSchema(albumSchemaKey);
+    }
+
+    private AxContextAlbum setTestAlbum() {
+        final AxArtifactKey newKey = new AxArtifactKey("NewAlbumName", "0.0.1");
+        final AxArtifactKey newSchemaKey = new AxArtifactKey("NewAlbumSchemaName", "0.0.1");
+
+        final AxContextAlbum album = new AxContextAlbum(newKey, "AlbumScope", false, newSchemaKey);
 
+        album.setScope("NewAlbumScope");
+        album.setWritable(true);
+
+        return album;
+    }
+
+    @Test
+    public void testAxvalidationAlbum() {
+        final AxContextAlbum album = setTestAlbum();
         AxValidationResult result = new AxValidationResult();
         result = album.validate(result);
         assertEquals(ValidationResult.VALID, result.getValidationResult());
@@ -82,6 +101,7 @@ public class ContextAlbumsTest {
         result = album.validate(result);
         assertEquals(ValidationResult.INVALID, result.getValidationResult());
 
+        final AxArtifactKey newKey = new AxArtifactKey("NewAlbumName", "0.0.1");
         album.setKey(newKey);
         result = new AxValidationResult();
         result = album.validate(result);
@@ -102,12 +122,20 @@ public class ContextAlbumsTest {
         result = album.validate(result);
         assertEquals(ValidationResult.INVALID, result.getValidationResult());
 
+        final AxArtifactKey albumSchemaKey = new AxArtifactKey("AlbumSchemaName", "0.0.1");
         album.setItemSchema(albumSchemaKey);
         result = new AxValidationResult();
         result = album.validate(result);
         assertEquals(ValidationResult.VALID, result.getValidationResult());
 
-        album.clean();
+    }
+
+    @Test
+    public void testEqualsAlbum() {
+        final AxContextAlbum album = setTestAlbum();
+        final AxArtifactKey newKey = new AxArtifactKey("NewAlbumName", "0.0.1");
+        final AxArtifactKey albumSchemaKey = new AxArtifactKey("AlbumSchemaName", "0.0.1");
+        album.setItemSchema(albumSchemaKey);
 
         final AxContextAlbum clonedAlbum = new AxContextAlbum(album);
         assertEquals("AxContextAlbum:(key=AxArtifactKey:(name=NewAlbumName,version=0.0.1),"
@@ -138,9 +166,14 @@ public class ContextAlbumsTest {
         assertNotEquals(0,
                         album.compareTo(new AxContextAlbum(newKey, "NewAlbumScope", true, AxArtifactKey.getNullKey())));
         assertEquals(0, album.compareTo(new AxContextAlbum(newKey, "NewAlbumScope", true, albumSchemaKey)));
+    }
 
+    @Test
+    public void testMultipleAlbums() {
         final AxContextAlbums albums = new AxContextAlbums();
-        result = new AxValidationResult();
+        final AxContextAlbum album = setTestAlbum();
+        final AxArtifactKey newKey = new AxArtifactKey("NewAlbumName", "0.0.1");
+        AxValidationResult result = new AxValidationResult();
         result = albums.validate(result);
         assertEquals(ValidationResult.INVALID, result.getValidationResult());
 
@@ -175,6 +208,15 @@ public class ContextAlbumsTest {
         result = albums.validate(result);
         assertEquals(ValidationResult.VALID, result.getValidationResult());
 
+    }
+
+    @Test
+    public void testClonedAlbums() {
+        final AxContextAlbums albums = new AxContextAlbums();
+        final AxContextAlbum album = setTestAlbum();
+        final AxArtifactKey newKey = new AxArtifactKey("NewAlbumName", "0.0.1");
+        albums.setKey(new AxArtifactKey("AlbumsKey", "0.0.1"));
+        albums.getAlbumsMap().put(newKey, album);
         albums.clean();
 
         final AxContextAlbums clonedAlbums = new AxContextAlbums(albums);
index 6de0a52..fbca04d 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
- *  Modifications Copyright (C) 2020 Nordix Foundation.
+ *  Modifications Copyright (C) 2020-2021 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -38,10 +38,14 @@ import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.Validat
 public class ContextSchemasTest {
 
     @Test
-    public void testContextSchemas() {
+    public void testNewAxContextSchema() {
         assertNotNull(new AxContextSchema());
         assertNotNull(new AxContextSchema(new AxArtifactKey(), "SchemaFlavour", "SchemaDefinition"));
 
+    }
+
+    @Test
+    public void testContextSchemas() {
         final AxContextSchema schema = new AxContextSchema(new AxArtifactKey("SchemaName", "0.0.1"), "SchemaFlavour",
                         "SchemaDefinition");
         assertNotNull(schema);
@@ -59,7 +63,22 @@ public class ContextSchemasTest {
 
         schema.setSchema("NewSchemaDefinition");
         assertEquals("NewSchemaDefinition", schema.getSchema());
+    }
+
+    private AxContextSchema setTestSchema() {
+        final AxContextSchema schema = new AxContextSchema(new AxArtifactKey("SchemaName", "0.0.1"), "SchemaFlavour",
+                "SchemaDefinition");
+        final AxArtifactKey newKey = new AxArtifactKey("NewSchemaName", "0.0.1");
+        schema.setKey(newKey);
+        schema.setSchemaFlavour("NewSchemaFlavour");
+        schema.setSchema("NewSchemaDefinition");
 
+        return schema;
+    }
+
+    @Test
+    public void testAxvalidationSchema() {
+        AxContextSchema schema = setTestSchema();
         AxValidationResult result = new AxValidationResult();
         result = schema.validate(result);
         assertEquals(ValidationResult.VALID, result.getValidationResult());
@@ -69,6 +88,7 @@ public class ContextSchemasTest {
         result = schema.validate(result);
         assertEquals(ValidationResult.INVALID, result.getValidationResult());
 
+        final AxArtifactKey newKey = new AxArtifactKey("NewSchemaName", "0.0.1");
         schema.setKey(newKey);
         result = new AxValidationResult();
         result = schema.validate(result);
@@ -93,7 +113,11 @@ public class ContextSchemasTest {
         result = new AxValidationResult();
         result = schema.validate(result);
         assertEquals(ValidationResult.VALID, result.getValidationResult());
+    }
 
+    @Test
+    public void testEqualsSchema() {
+        AxContextSchema schema = setTestSchema();
         schema.clean();
 
         final AxContextSchema clonedSchema = new AxContextSchema(schema);
@@ -109,6 +133,8 @@ public class ContextSchemasTest {
         assertNotNull(schema);
         assertNotEquals(schema, (Object) "Hello");
         assertNotEquals(schema, new AxContextSchema(new AxArtifactKey(), "Flavour", "Def"));
+
+        final AxArtifactKey newKey = new AxArtifactKey("NewSchemaName", "0.0.1");
         assertNotEquals(schema, new AxContextSchema(newKey, "Flavour", "Def"));
         assertNotEquals(schema, new AxContextSchema(newKey, "NewSchemaFlavour", "Def"));
         assertEquals(schema, new AxContextSchema(newKey, "NewSchemaFlavour", "NewSchemaDefinition"));
@@ -121,9 +147,12 @@ public class ContextSchemasTest {
         assertNotEquals(0, schema.compareTo(new AxContextSchema(newKey, "Flavour", "Def")));
         assertNotEquals(0, schema.compareTo(new AxContextSchema(newKey, "NewSchemaFlavour", "Def")));
         assertEquals(0, schema.compareTo(new AxContextSchema(newKey, "NewSchemaFlavour", "NewSchemaDefinition")));
+    }
 
+    @Test
+    public void testMultipleSchemas() {
         final AxContextSchemas schemas = new AxContextSchemas();
-        result = new AxValidationResult();
+        AxValidationResult result = new AxValidationResult();
         result = schemas.validate(result);
         assertEquals(ValidationResult.INVALID, result.getValidationResult());
 
@@ -133,6 +162,8 @@ public class ContextSchemasTest {
         result = schemas.validate(result);
         assertEquals(ValidationResult.INVALID, result.getValidationResult());
 
+        AxContextSchema schema = setTestSchema();
+        final AxArtifactKey newKey = new AxArtifactKey("NewSchemaName", "0.0.1");
         schemas.getSchemasMap().put(newKey, schema);
         result = new AxValidationResult();
         result = schemas.validate(result);
@@ -158,6 +189,15 @@ public class ContextSchemasTest {
         result = schemas.validate(result);
         assertEquals(ValidationResult.VALID, result.getValidationResult());
 
+    }
+
+    @Test
+    public void testClonedSchemas() {
+        final AxContextSchemas schemas = new AxContextSchemas();
+        AxContextSchema schema = setTestSchema();
+        final AxArtifactKey newKey = new AxArtifactKey("NewSchemaName", "0.0.1");
+        schemas.setKey(new AxArtifactKey("SchemasKey", "0.0.1"));
+        schemas.getSchemasMap().put(newKey, schema);
         schemas.clean();
 
         final AxContextSchemas clonedSchemas = new AxContextSchemas(schemas);