summaryrefslogtreecommitdiffstats
path: root/model/context-model/src/test/java/org
diff options
context:
space:
mode:
authorlapentafd <francesco.lapenta@est.tech>2021-06-15 11:09:52 +0100
committerlapentafd <francesco.lapenta@est.tech>2021-06-15 14:34:42 +0100
commit12f634160f11d03265fac84c8d10cb8765e16187 (patch)
treebd2e0d26085100001670a2e25b06ae6ee67fdb85 /model/context-model/src/test/java/org
parent2b04e4d3bae9567e85f383d34033aa57ac83d64e (diff)
Fix Sonar issues in apex-pdp
Issue-ID: POLICY-3093 Change-Id: I4def597b054a9ab2f3cc9a4665df04dd1d515ebf Signed-off-by: lapentafd <francesco.lapenta@est.tech>
Diffstat (limited to 'model/context-model/src/test/java/org')
-rw-r--r--model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextAlbumsTest.java50
-rw-r--r--model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextSchemasTest.java46
2 files changed, 89 insertions, 7 deletions
diff --git a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextAlbumsTest.java b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextAlbumsTest.java
index 154739b90..8293feb5b 100644
--- a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextAlbumsTest.java
+++ b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextAlbumsTest.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-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);
diff --git a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextSchemasTest.java b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextSchemasTest.java
index 6de0a5214..fbca04d7e 100644
--- a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextSchemasTest.java
+++ b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextSchemasTest.java
@@ -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);