From 62475a30ef2d425fe04df35ef2dac53c7ab5306a Mon Sep 17 00:00:00 2001 From: Parshad Patel Date: Fri, 16 Nov 2018 20:59:14 +0900 Subject: Rename test classes in apex-pdp Make test classes name consistence by putting 'Test' at end Issue-ID: POLICY-1263 Change-Id: I0179388d84826e698276a1995dd8173a40b5fd2b Signed-off-by: Parshad Patel --- .../contextmodel/concepts/ContextAlbumsTest.java | 212 +++++++++++++++++++++ .../contextmodel/concepts/ContextModelTest.java | 96 ++++++++++ .../contextmodel/concepts/ContextSchemasTest.java | 195 +++++++++++++++++++ .../contextmodel/concepts/TestContextAlbums.java | 212 --------------------- .../contextmodel/concepts/TestContextModel.java | 96 ---------- .../contextmodel/concepts/TestContextSchemas.java | 195 ------------------- .../handling/ApexContextModelTest.java | 153 +++++++++++++++ .../handling/ContextComparisonTest.java | 189 ++++++++++++++++++ .../handling/TestApexContextModel.java | 153 --------------- .../handling/TestContextComparison.java | 189 ------------------ 10 files changed, 845 insertions(+), 845 deletions(-) create mode 100644 model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextAlbumsTest.java create mode 100644 model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextModelTest.java create mode 100644 model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextSchemasTest.java delete mode 100644 model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/TestContextAlbums.java delete mode 100644 model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/TestContextModel.java delete mode 100644 model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/TestContextSchemas.java create mode 100644 model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/ApexContextModelTest.java create mode 100644 model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/ContextComparisonTest.java delete mode 100644 model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/TestApexContextModel.java delete mode 100644 model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/TestContextComparison.java (limited to 'model/context-model') 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 new file mode 100644 index 000000000..eb0db0da7 --- /dev/null +++ b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextAlbumsTest.java @@ -0,0 +1,212 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.model.contextmodel.concepts; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; +import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; +import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums; + +/** + * Context album tests. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class ContextAlbumsTest { + + @Test + public void testContextAlbums() { + assertNotNull(new AxContextAlbum()); + assertNotNull(new AxContextAlbum(new AxArtifactKey())); + assertNotNull(new AxContextAlbum(new AxArtifactKey(), "AlbumScope", false, new AxArtifactKey())); + + final AxArtifactKey albumKey = new AxArtifactKey("AlbumName", "0.0.1"); + final AxArtifactKey albumSchemaKey = new AxArtifactKey("AlbumSchemaName", "0.0.1"); + + final AxContextAlbum album = new AxContextAlbum(albumKey, "AlbumScope", false, albumSchemaKey); + assertNotNull(album); + + final AxArtifactKey newKey = new AxArtifactKey("NewAlbumName", "0.0.1"); + album.setKey(newKey); + assertEquals("NewAlbumName:0.0.1", album.getKey().getId()); + assertEquals("NewAlbumName:0.0.1", album.getKeys().get(0).getId()); + album.setKey(albumKey); + + try { + album.setScope(""); + fail("test should throw an exception here"); + } catch (final Exception e) { + assertEquals("parameter \"scope\": value \"\", does not match regular expression \"[A-Za-z0-9\\-_]+\"", + e.getMessage()); + } + + album.setScope("NewAlbumScope"); + assertEquals("NewAlbumScope", album.getScope()); + + assertEquals(false, album.isWritable()); + album.setWritable(true); + assertEquals(true, album.isWritable()); + + final AxArtifactKey newSchemaKey = new AxArtifactKey("NewAlbumSchemaName", "0.0.1"); + album.setItemSchema(newSchemaKey); + assertEquals("NewAlbumSchemaName:0.0.1", album.getItemSchema().getId()); + album.setItemSchema(albumSchemaKey); + + AxValidationResult result = new AxValidationResult(); + result = album.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + album.setKey(AxArtifactKey.getNullKey()); + result = new AxValidationResult(); + result = album.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + album.setKey(newKey); + result = new AxValidationResult(); + result = album.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + album.setScope("UNDEFINED"); + result = new AxValidationResult(); + result = album.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + album.setScope("NewAlbumScope"); + result = new AxValidationResult(); + result = album.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + album.setItemSchema(AxArtifactKey.getNullKey()); + result = new AxValidationResult(); + result = album.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + album.setItemSchema(albumSchemaKey); + result = new AxValidationResult(); + result = album.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + album.clean(); + + final AxContextAlbum clonedAlbum = new AxContextAlbum(album); + assertEquals("AxContextAlbum:(key=AxArtifactKey:(name=NewAlbumName,version=0.0.1)," + + "scope=NewAlbumScope,isWritable=true,itemSchema=" + + "AxArtifactKey:(name=AlbumSchemaName,version=0.0.1))", clonedAlbum.toString()); + + assertFalse(album.hashCode() == 0); + + assertTrue(album.equals(album)); + assertTrue(album.equals(clonedAlbum)); + assertFalse(album.equals(null)); + assertFalse(album.equals("Hello")); + assertFalse(album.equals(new AxContextAlbum(new AxArtifactKey(), "Scope", false, AxArtifactKey.getNullKey()))); + assertFalse(album.equals(new AxContextAlbum(newKey, "Scope", false, AxArtifactKey.getNullKey()))); + assertFalse(album.equals(new AxContextAlbum(newKey, "NewAlbumScope", false, AxArtifactKey.getNullKey()))); + assertFalse(album.equals(new AxContextAlbum(newKey, "NewAlbumScope", true, AxArtifactKey.getNullKey()))); + assertTrue(album.equals(new AxContextAlbum(newKey, "NewAlbumScope", true, albumSchemaKey))); + + assertEquals(0, album.compareTo(album)); + assertEquals(0, album.compareTo(clonedAlbum)); + assertNotEquals(0, album.compareTo(null)); + assertNotEquals(0, album.compareTo(new AxArtifactKey())); + assertNotEquals(0, album.compareTo( + new AxContextAlbum(new AxArtifactKey(), "Scope", false, AxArtifactKey.getNullKey()))); + assertNotEquals(0, album.compareTo(new AxContextAlbum(newKey, "Scope", false, AxArtifactKey.getNullKey()))); + assertNotEquals(0, album + .compareTo(new AxContextAlbum(newKey, "NewAlbumScope", false, AxArtifactKey.getNullKey()))); + assertNotEquals(0, + album.compareTo(new AxContextAlbum(newKey, "NewAlbumScope", true, AxArtifactKey.getNullKey()))); + assertEquals(0, album.compareTo(new AxContextAlbum(newKey, "NewAlbumScope", true, albumSchemaKey))); + + final AxContextAlbums albums = new AxContextAlbums(); + result = new AxValidationResult(); + result = albums.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + // Observation, no albums in album map + albums.setKey(new AxArtifactKey("AlbumsKey", "0.0.1")); + result = new AxValidationResult(); + result = albums.validate(result); + assertEquals(ValidationResult.OBSERVATION, result.getValidationResult()); + + albums.getAlbumsMap().put(newKey, album); + result = new AxValidationResult(); + result = albums.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + albums.getAlbumsMap().put(AxArtifactKey.getNullKey(), null); + result = new AxValidationResult(); + result = albums.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + albums.getAlbumsMap().remove(AxArtifactKey.getNullKey()); + result = new AxValidationResult(); + result = albums.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + albums.getAlbumsMap().put(new AxArtifactKey("NullValueKey", "0.0.1"), null); + result = new AxValidationResult(); + result = albums.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + albums.getAlbumsMap().remove(new AxArtifactKey("NullValueKey", "0.0.1")); + result = new AxValidationResult(); + result = albums.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + albums.clean(); + + final AxContextAlbums clonedAlbums = new AxContextAlbums(albums); + assertTrue(clonedAlbums.toString().startsWith( + "AxContextAlbums:(AxContextAlbums:(key=AxArtifactKey:(name=AlbumsKey,version=0.0.1)")); + + assertFalse(albums.hashCode() == 0); + + assertTrue(albums.equals(albums)); + assertTrue(albums.equals(clonedAlbums)); + assertFalse(albums.equals(null)); + assertFalse(albums.equals("Hello")); + assertFalse(albums.equals(new AxContextAlbums(new AxArtifactKey()))); + + assertEquals(0, albums.compareTo(albums)); + assertEquals(0, albums.compareTo(clonedAlbums)); + assertNotEquals(0, albums.compareTo(null)); + assertNotEquals(0, albums.compareTo(new AxArtifactKey())); + assertNotEquals(0, albums.compareTo(new AxContextAlbums(new AxArtifactKey()))); + + clonedAlbums.get(newKey).setScope("YetAnotherScope"); + assertNotEquals(0, albums.compareTo(clonedAlbums)); + + assertEquals("NewAlbumName", albums.get("NewAlbumName").getKey().getName()); + assertEquals("NewAlbumName", albums.get("NewAlbumName", "0.0.1").getKey().getName()); + assertEquals(1, albums.getAll("NewAlbumName", "0.0.1").size()); + assertEquals(0, albums.getAll("NonExistantAlbumName").size()); + } +} diff --git a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextModelTest.java b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextModelTest.java new file mode 100644 index 000000000..fbf97881f --- /dev/null +++ b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextModelTest.java @@ -0,0 +1,96 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.model.contextmodel.concepts; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; +import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextModel; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; + +/** + * Context model tests. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class ContextModelTest { + + @Test + public void test() { + assertNotNull(new AxContextModel()); + assertNotNull(new AxContextModel(new AxArtifactKey())); + assertNotNull(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(), new AxKeyInformation())); + assertNotNull(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(), new AxContextAlbums(), + new AxKeyInformation())); + + final AxArtifactKey modelKey = new AxArtifactKey("ModelKey", "0.0.1"); + final AxArtifactKey schemasKey = new AxArtifactKey("SchemasKey", "0.0.1"); + final AxArtifactKey albumsKey = new AxArtifactKey("SchemasKey", "0.0.1"); + final AxArtifactKey keyInfoKey = new AxArtifactKey("SchemasKey", "0.0.1"); + final AxContextModel model = new AxContextModel(modelKey, new AxContextSchemas(schemasKey), + new AxContextAlbums(albumsKey), new AxKeyInformation(keyInfoKey)); + model.register(); + + model.clean(); + assertNotNull(model); + assertEquals("AxContextModel:(AxContextModel:(key=AxArtifactKey:", model.toString().substring(0, 50)); + + final AxContextModel clonedModel = new AxContextModel(model); + + assertFalse(model.hashCode() == 0); + + assertTrue(model.equals(model)); + assertTrue(model.equals(clonedModel)); + assertFalse(model.equals("Hello")); + assertFalse(model.equals(new AxContextModel(new AxArtifactKey()))); + assertFalse(model.equals(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(), new AxContextAlbums(), + new AxKeyInformation()))); + assertFalse(model.equals(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(), + new AxKeyInformation()))); + assertFalse(model.equals(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(), + new AxKeyInformation(keyInfoKey)))); + assertFalse(model.equals(new AxContextModel(modelKey, new AxContextSchemas(schemasKey), new AxContextAlbums(), + new AxKeyInformation(keyInfoKey)))); + assertTrue(model.equals(new AxContextModel(modelKey, new AxContextSchemas(schemasKey), + new AxContextAlbums(albumsKey), new AxKeyInformation(keyInfoKey)))); + + assertEquals(0, model.compareTo(model)); + assertEquals(0, model.compareTo(clonedModel)); + assertNotEquals(0, model.compareTo(new AxArtifactKey())); + assertNotEquals(0, model.compareTo(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(), + new AxContextAlbums(), new AxKeyInformation()))); + assertNotEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(), + new AxKeyInformation()))); + assertNotEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(), + new AxKeyInformation(keyInfoKey)))); + assertNotEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(schemasKey), + new AxContextAlbums(), new AxKeyInformation(keyInfoKey)))); + assertEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(schemasKey), + new AxContextAlbums(albumsKey), new AxKeyInformation(keyInfoKey)))); + } +} 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 new file mode 100644 index 000000000..73f4c3086 --- /dev/null +++ b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextSchemasTest.java @@ -0,0 +1,195 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.model.contextmodel.concepts; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; +import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; +import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; + +/** + * Context schema tests. + */ +public class ContextSchemasTest { + + @Test + public void testContextSchemas() { + assertNotNull(new AxContextSchema()); + assertNotNull(new AxContextSchema(new AxArtifactKey(), "SchemaFlavour", "SchemaDefinition")); + + final AxContextSchema schema = new AxContextSchema(new AxArtifactKey("SchemaName", "0.0.1"), "SchemaFlavour", + "SchemaDefinition"); + assertNotNull(schema); + + final AxArtifactKey newKey = new AxArtifactKey("NewSchemaName", "0.0.1"); + schema.setKey(newKey); + assertEquals("NewSchemaName:0.0.1", schema.getKey().getId()); + assertEquals("NewSchemaName:0.0.1", schema.getKeys().get(0).getId()); + + try { + schema.setSchemaFlavour(""); + fail("test should throw an exception here"); + } catch (final Exception e) { + assertEquals("parameter \"schemaFlavour\": value \"\", " + + "does not match regular expression \"[A-Za-z0-9\\-_]+\"", e.getMessage()); + } + + schema.setSchemaFlavour("NewSchemaFlavour"); + assertEquals("NewSchemaFlavour", schema.getSchemaFlavour()); + + schema.setSchema("NewSchemaDefinition"); + assertEquals("NewSchemaDefinition", schema.getSchema()); + + AxValidationResult result = new AxValidationResult(); + result = schema.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + schema.setKey(AxArtifactKey.getNullKey()); + result = new AxValidationResult(); + result = schema.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + schema.setKey(newKey); + result = new AxValidationResult(); + result = schema.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + schema.setSchemaFlavour("UNDEFINED"); + result = new AxValidationResult(); + result = schema.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + schema.setSchemaFlavour("NewSchemaFlavour"); + result = new AxValidationResult(); + result = schema.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + schema.setSchema(""); + result = new AxValidationResult(); + result = schema.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + schema.setSchema("NewSchemaDefinition"); + result = new AxValidationResult(); + result = schema.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + schema.clean(); + + final AxContextSchema clonedSchema = new AxContextSchema(schema); + assertEquals("AxContextSchema:(key=AxArtifactKey:(name=NewSchemaName,version=0.0.1)," + + "schemaFlavour=NewSchemaFlavour,schemaDefinition=NewSchemaDefinition)", + clonedSchema.toString()); + + assertFalse(schema.hashCode() == 0); + + assertTrue(schema.equals(schema)); + assertTrue(schema.equals(clonedSchema)); + assertFalse(schema.equals(null)); + assertFalse(schema.equals((Object) "Hello")); + assertFalse(schema.equals(new AxContextSchema(new AxArtifactKey(), "Flavour", "Def"))); + assertFalse(schema.equals(new AxContextSchema(newKey, "Flavour", "Def"))); + assertFalse(schema.equals(new AxContextSchema(newKey, "NewSchemaFlavour", "Def"))); + assertTrue(schema.equals(new AxContextSchema(newKey, "NewSchemaFlavour", "NewSchemaDefinition"))); + + assertEquals(0, schema.compareTo(schema)); + assertEquals(0, schema.compareTo(clonedSchema)); + assertNotEquals(0, schema.compareTo(null)); + assertNotEquals(0, schema.compareTo(new AxArtifactKey())); + assertNotEquals(0, schema.compareTo(new AxContextSchema(new AxArtifactKey(), "Flavour", "Def"))); + 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"))); + + final AxContextSchemas schemas = new AxContextSchemas(); + result = new AxValidationResult(); + result = schemas.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + // Still invalid, no schemas in schema map + schemas.setKey(new AxArtifactKey("SchemasKey", "0.0.1")); + result = new AxValidationResult(); + result = schemas.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + schemas.getSchemasMap().put(newKey, schema); + result = new AxValidationResult(); + result = schemas.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + schemas.getSchemasMap().put(AxArtifactKey.getNullKey(), null); + result = new AxValidationResult(); + result = schemas.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + schemas.getSchemasMap().remove(AxArtifactKey.getNullKey()); + result = new AxValidationResult(); + result = schemas.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + schemas.getSchemasMap().put(new AxArtifactKey("NullValueKey", "0.0.1"), null); + result = new AxValidationResult(); + result = schemas.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + schemas.getSchemasMap().remove(new AxArtifactKey("NullValueKey", "0.0.1")); + result = new AxValidationResult(); + result = schemas.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + schemas.clean(); + + final AxContextSchemas clonedSchemas = new AxContextSchemas(schemas); + assertTrue(clonedSchemas.toString() + .startsWith("AxContextSchemas:(key=AxArtifactKey:(name=SchemasKey,version=0.0.1),")); + + assertFalse(schemas.hashCode() == 0); + + assertTrue(schemas.equals(schemas)); + assertTrue(schemas.equals(clonedSchemas)); + assertFalse(schemas.equals(null)); + assertFalse(schemas.equals((Object) "Hello")); + assertFalse(schemas.equals(new AxContextSchemas(new AxArtifactKey()))); + + assertEquals(0, schemas.compareTo(schemas)); + assertEquals(0, schemas.compareTo(clonedSchemas)); + assertNotEquals(0, schemas.compareTo(null)); + assertNotEquals(0, schemas.compareTo(new AxArtifactKey())); + assertNotEquals(0, schemas.compareTo(new AxContextSchemas(new AxArtifactKey()))); + + clonedSchemas.get(newKey).setSchemaFlavour("YetAnotherFlavour"); + assertNotEquals(0, schemas.compareTo(clonedSchemas)); + + assertEquals("NewSchemaName", schemas.get("NewSchemaName").getKey().getName()); + assertEquals("NewSchemaName", schemas.get("NewSchemaName", "0.0.1").getKey().getName()); + assertEquals(1, schemas.getAll("NewSchemaName", "0.0.1").size()); + assertEquals(0, schemas.getAll("NonExistantSchemaName").size()); + } +} diff --git a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/TestContextAlbums.java b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/TestContextAlbums.java deleted file mode 100644 index 6ba0b2fa6..000000000 --- a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/TestContextAlbums.java +++ /dev/null @@ -1,212 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.contextmodel.concepts; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; -import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums; - -/** - * Context album tests. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class TestContextAlbums { - - @Test - public void testContextAlbums() { - assertNotNull(new AxContextAlbum()); - assertNotNull(new AxContextAlbum(new AxArtifactKey())); - assertNotNull(new AxContextAlbum(new AxArtifactKey(), "AlbumScope", false, new AxArtifactKey())); - - final AxArtifactKey albumKey = new AxArtifactKey("AlbumName", "0.0.1"); - final AxArtifactKey albumSchemaKey = new AxArtifactKey("AlbumSchemaName", "0.0.1"); - - final AxContextAlbum album = new AxContextAlbum(albumKey, "AlbumScope", false, albumSchemaKey); - assertNotNull(album); - - final AxArtifactKey newKey = new AxArtifactKey("NewAlbumName", "0.0.1"); - album.setKey(newKey); - assertEquals("NewAlbumName:0.0.1", album.getKey().getId()); - assertEquals("NewAlbumName:0.0.1", album.getKeys().get(0).getId()); - album.setKey(albumKey); - - try { - album.setScope(""); - fail("test should throw an exception here"); - } catch (final Exception e) { - assertEquals("parameter \"scope\": value \"\", does not match regular expression \"[A-Za-z0-9\\-_]+\"", - e.getMessage()); - } - - album.setScope("NewAlbumScope"); - assertEquals("NewAlbumScope", album.getScope()); - - assertEquals(false, album.isWritable()); - album.setWritable(true); - assertEquals(true, album.isWritable()); - - final AxArtifactKey newSchemaKey = new AxArtifactKey("NewAlbumSchemaName", "0.0.1"); - album.setItemSchema(newSchemaKey); - assertEquals("NewAlbumSchemaName:0.0.1", album.getItemSchema().getId()); - album.setItemSchema(albumSchemaKey); - - AxValidationResult result = new AxValidationResult(); - result = album.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - album.setKey(AxArtifactKey.getNullKey()); - result = new AxValidationResult(); - result = album.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - album.setKey(newKey); - result = new AxValidationResult(); - result = album.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - album.setScope("UNDEFINED"); - result = new AxValidationResult(); - result = album.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - album.setScope("NewAlbumScope"); - result = new AxValidationResult(); - result = album.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - album.setItemSchema(AxArtifactKey.getNullKey()); - result = new AxValidationResult(); - result = album.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - album.setItemSchema(albumSchemaKey); - result = new AxValidationResult(); - result = album.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - album.clean(); - - final AxContextAlbum clonedAlbum = new AxContextAlbum(album); - assertEquals("AxContextAlbum:(key=AxArtifactKey:(name=NewAlbumName,version=0.0.1)," - + "scope=NewAlbumScope,isWritable=true,itemSchema=" - + "AxArtifactKey:(name=AlbumSchemaName,version=0.0.1))", clonedAlbum.toString()); - - assertFalse(album.hashCode() == 0); - - assertTrue(album.equals(album)); - assertTrue(album.equals(clonedAlbum)); - assertFalse(album.equals(null)); - assertFalse(album.equals("Hello")); - assertFalse(album.equals(new AxContextAlbum(new AxArtifactKey(), "Scope", false, AxArtifactKey.getNullKey()))); - assertFalse(album.equals(new AxContextAlbum(newKey, "Scope", false, AxArtifactKey.getNullKey()))); - assertFalse(album.equals(new AxContextAlbum(newKey, "NewAlbumScope", false, AxArtifactKey.getNullKey()))); - assertFalse(album.equals(new AxContextAlbum(newKey, "NewAlbumScope", true, AxArtifactKey.getNullKey()))); - assertTrue(album.equals(new AxContextAlbum(newKey, "NewAlbumScope", true, albumSchemaKey))); - - assertEquals(0, album.compareTo(album)); - assertEquals(0, album.compareTo(clonedAlbum)); - assertNotEquals(0, album.compareTo(null)); - assertNotEquals(0, album.compareTo(new AxArtifactKey())); - assertNotEquals(0, album.compareTo( - new AxContextAlbum(new AxArtifactKey(), "Scope", false, AxArtifactKey.getNullKey()))); - assertNotEquals(0, album.compareTo(new AxContextAlbum(newKey, "Scope", false, AxArtifactKey.getNullKey()))); - assertNotEquals(0, album - .compareTo(new AxContextAlbum(newKey, "NewAlbumScope", false, AxArtifactKey.getNullKey()))); - assertNotEquals(0, - album.compareTo(new AxContextAlbum(newKey, "NewAlbumScope", true, AxArtifactKey.getNullKey()))); - assertEquals(0, album.compareTo(new AxContextAlbum(newKey, "NewAlbumScope", true, albumSchemaKey))); - - final AxContextAlbums albums = new AxContextAlbums(); - result = new AxValidationResult(); - result = albums.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - // Observation, no albums in album map - albums.setKey(new AxArtifactKey("AlbumsKey", "0.0.1")); - result = new AxValidationResult(); - result = albums.validate(result); - assertEquals(ValidationResult.OBSERVATION, result.getValidationResult()); - - albums.getAlbumsMap().put(newKey, album); - result = new AxValidationResult(); - result = albums.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - albums.getAlbumsMap().put(AxArtifactKey.getNullKey(), null); - result = new AxValidationResult(); - result = albums.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - albums.getAlbumsMap().remove(AxArtifactKey.getNullKey()); - result = new AxValidationResult(); - result = albums.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - albums.getAlbumsMap().put(new AxArtifactKey("NullValueKey", "0.0.1"), null); - result = new AxValidationResult(); - result = albums.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - albums.getAlbumsMap().remove(new AxArtifactKey("NullValueKey", "0.0.1")); - result = new AxValidationResult(); - result = albums.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - albums.clean(); - - final AxContextAlbums clonedAlbums = new AxContextAlbums(albums); - assertTrue(clonedAlbums.toString().startsWith( - "AxContextAlbums:(AxContextAlbums:(key=AxArtifactKey:(name=AlbumsKey,version=0.0.1)")); - - assertFalse(albums.hashCode() == 0); - - assertTrue(albums.equals(albums)); - assertTrue(albums.equals(clonedAlbums)); - assertFalse(albums.equals(null)); - assertFalse(albums.equals("Hello")); - assertFalse(albums.equals(new AxContextAlbums(new AxArtifactKey()))); - - assertEquals(0, albums.compareTo(albums)); - assertEquals(0, albums.compareTo(clonedAlbums)); - assertNotEquals(0, albums.compareTo(null)); - assertNotEquals(0, albums.compareTo(new AxArtifactKey())); - assertNotEquals(0, albums.compareTo(new AxContextAlbums(new AxArtifactKey()))); - - clonedAlbums.get(newKey).setScope("YetAnotherScope"); - assertNotEquals(0, albums.compareTo(clonedAlbums)); - - assertEquals("NewAlbumName", albums.get("NewAlbumName").getKey().getName()); - assertEquals("NewAlbumName", albums.get("NewAlbumName", "0.0.1").getKey().getName()); - assertEquals(1, albums.getAll("NewAlbumName", "0.0.1").size()); - assertEquals(0, albums.getAll("NonExistantAlbumName").size()); - } -} diff --git a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/TestContextModel.java b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/TestContextModel.java deleted file mode 100644 index 290183e5f..000000000 --- a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/TestContextModel.java +++ /dev/null @@ -1,96 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.contextmodel.concepts; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextModel; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; - -/** - * Context model tests. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class TestContextModel { - - @Test - public void test() { - assertNotNull(new AxContextModel()); - assertNotNull(new AxContextModel(new AxArtifactKey())); - assertNotNull(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(), new AxKeyInformation())); - assertNotNull(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(), new AxContextAlbums(), - new AxKeyInformation())); - - final AxArtifactKey modelKey = new AxArtifactKey("ModelKey", "0.0.1"); - final AxArtifactKey schemasKey = new AxArtifactKey("SchemasKey", "0.0.1"); - final AxArtifactKey albumsKey = new AxArtifactKey("SchemasKey", "0.0.1"); - final AxArtifactKey keyInfoKey = new AxArtifactKey("SchemasKey", "0.0.1"); - final AxContextModel model = new AxContextModel(modelKey, new AxContextSchemas(schemasKey), - new AxContextAlbums(albumsKey), new AxKeyInformation(keyInfoKey)); - model.register(); - - model.clean(); - assertNotNull(model); - assertEquals("AxContextModel:(AxContextModel:(key=AxArtifactKey:", model.toString().substring(0, 50)); - - final AxContextModel clonedModel = new AxContextModel(model); - - assertFalse(model.hashCode() == 0); - - assertTrue(model.equals(model)); - assertTrue(model.equals(clonedModel)); - assertFalse(model.equals("Hello")); - assertFalse(model.equals(new AxContextModel(new AxArtifactKey()))); - assertFalse(model.equals(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(), new AxContextAlbums(), - new AxKeyInformation()))); - assertFalse(model.equals(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(), - new AxKeyInformation()))); - assertFalse(model.equals(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(), - new AxKeyInformation(keyInfoKey)))); - assertFalse(model.equals(new AxContextModel(modelKey, new AxContextSchemas(schemasKey), new AxContextAlbums(), - new AxKeyInformation(keyInfoKey)))); - assertTrue(model.equals(new AxContextModel(modelKey, new AxContextSchemas(schemasKey), - new AxContextAlbums(albumsKey), new AxKeyInformation(keyInfoKey)))); - - assertEquals(0, model.compareTo(model)); - assertEquals(0, model.compareTo(clonedModel)); - assertNotEquals(0, model.compareTo(new AxArtifactKey())); - assertNotEquals(0, model.compareTo(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(), - new AxContextAlbums(), new AxKeyInformation()))); - assertNotEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(), - new AxKeyInformation()))); - assertNotEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(), - new AxKeyInformation(keyInfoKey)))); - assertNotEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(schemasKey), - new AxContextAlbums(), new AxKeyInformation(keyInfoKey)))); - assertEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(schemasKey), - new AxContextAlbums(albumsKey), new AxKeyInformation(keyInfoKey)))); - } -} diff --git a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/TestContextSchemas.java b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/TestContextSchemas.java deleted file mode 100644 index a8dde7781..000000000 --- a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/TestContextSchemas.java +++ /dev/null @@ -1,195 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.contextmodel.concepts; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; -import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; - -/** - * Context schema tests. - */ -public class TestContextSchemas { - - @Test - public void testContextSchemas() { - assertNotNull(new AxContextSchema()); - assertNotNull(new AxContextSchema(new AxArtifactKey(), "SchemaFlavour", "SchemaDefinition")); - - final AxContextSchema schema = new AxContextSchema(new AxArtifactKey("SchemaName", "0.0.1"), "SchemaFlavour", - "SchemaDefinition"); - assertNotNull(schema); - - final AxArtifactKey newKey = new AxArtifactKey("NewSchemaName", "0.0.1"); - schema.setKey(newKey); - assertEquals("NewSchemaName:0.0.1", schema.getKey().getId()); - assertEquals("NewSchemaName:0.0.1", schema.getKeys().get(0).getId()); - - try { - schema.setSchemaFlavour(""); - fail("test should throw an exception here"); - } catch (final Exception e) { - assertEquals("parameter \"schemaFlavour\": value \"\", " - + "does not match regular expression \"[A-Za-z0-9\\-_]+\"", e.getMessage()); - } - - schema.setSchemaFlavour("NewSchemaFlavour"); - assertEquals("NewSchemaFlavour", schema.getSchemaFlavour()); - - schema.setSchema("NewSchemaDefinition"); - assertEquals("NewSchemaDefinition", schema.getSchema()); - - AxValidationResult result = new AxValidationResult(); - result = schema.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - schema.setKey(AxArtifactKey.getNullKey()); - result = new AxValidationResult(); - result = schema.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - schema.setKey(newKey); - result = new AxValidationResult(); - result = schema.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - schema.setSchemaFlavour("UNDEFINED"); - result = new AxValidationResult(); - result = schema.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - schema.setSchemaFlavour("NewSchemaFlavour"); - result = new AxValidationResult(); - result = schema.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - schema.setSchema(""); - result = new AxValidationResult(); - result = schema.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - schema.setSchema("NewSchemaDefinition"); - result = new AxValidationResult(); - result = schema.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - schema.clean(); - - final AxContextSchema clonedSchema = new AxContextSchema(schema); - assertEquals("AxContextSchema:(key=AxArtifactKey:(name=NewSchemaName,version=0.0.1)," - + "schemaFlavour=NewSchemaFlavour,schemaDefinition=NewSchemaDefinition)", - clonedSchema.toString()); - - assertFalse(schema.hashCode() == 0); - - assertTrue(schema.equals(schema)); - assertTrue(schema.equals(clonedSchema)); - assertFalse(schema.equals(null)); - assertFalse(schema.equals((Object) "Hello")); - assertFalse(schema.equals(new AxContextSchema(new AxArtifactKey(), "Flavour", "Def"))); - assertFalse(schema.equals(new AxContextSchema(newKey, "Flavour", "Def"))); - assertFalse(schema.equals(new AxContextSchema(newKey, "NewSchemaFlavour", "Def"))); - assertTrue(schema.equals(new AxContextSchema(newKey, "NewSchemaFlavour", "NewSchemaDefinition"))); - - assertEquals(0, schema.compareTo(schema)); - assertEquals(0, schema.compareTo(clonedSchema)); - assertNotEquals(0, schema.compareTo(null)); - assertNotEquals(0, schema.compareTo(new AxArtifactKey())); - assertNotEquals(0, schema.compareTo(new AxContextSchema(new AxArtifactKey(), "Flavour", "Def"))); - 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"))); - - final AxContextSchemas schemas = new AxContextSchemas(); - result = new AxValidationResult(); - result = schemas.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - // Still invalid, no schemas in schema map - schemas.setKey(new AxArtifactKey("SchemasKey", "0.0.1")); - result = new AxValidationResult(); - result = schemas.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - schemas.getSchemasMap().put(newKey, schema); - result = new AxValidationResult(); - result = schemas.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - schemas.getSchemasMap().put(AxArtifactKey.getNullKey(), null); - result = new AxValidationResult(); - result = schemas.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - schemas.getSchemasMap().remove(AxArtifactKey.getNullKey()); - result = new AxValidationResult(); - result = schemas.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - schemas.getSchemasMap().put(new AxArtifactKey("NullValueKey", "0.0.1"), null); - result = new AxValidationResult(); - result = schemas.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - schemas.getSchemasMap().remove(new AxArtifactKey("NullValueKey", "0.0.1")); - result = new AxValidationResult(); - result = schemas.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - schemas.clean(); - - final AxContextSchemas clonedSchemas = new AxContextSchemas(schemas); - assertTrue(clonedSchemas.toString() - .startsWith("AxContextSchemas:(key=AxArtifactKey:(name=SchemasKey,version=0.0.1),")); - - assertFalse(schemas.hashCode() == 0); - - assertTrue(schemas.equals(schemas)); - assertTrue(schemas.equals(clonedSchemas)); - assertFalse(schemas.equals(null)); - assertFalse(schemas.equals((Object) "Hello")); - assertFalse(schemas.equals(new AxContextSchemas(new AxArtifactKey()))); - - assertEquals(0, schemas.compareTo(schemas)); - assertEquals(0, schemas.compareTo(clonedSchemas)); - assertNotEquals(0, schemas.compareTo(null)); - assertNotEquals(0, schemas.compareTo(new AxArtifactKey())); - assertNotEquals(0, schemas.compareTo(new AxContextSchemas(new AxArtifactKey()))); - - clonedSchemas.get(newKey).setSchemaFlavour("YetAnotherFlavour"); - assertNotEquals(0, schemas.compareTo(clonedSchemas)); - - assertEquals("NewSchemaName", schemas.get("NewSchemaName").getKey().getName()); - assertEquals("NewSchemaName", schemas.get("NewSchemaName", "0.0.1").getKey().getName()); - assertEquals(1, schemas.getAll("NewSchemaName", "0.0.1").size()); - assertEquals(0, schemas.getAll("NonExistantSchemaName").size()); - } -} diff --git a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/ApexContextModelTest.java b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/ApexContextModelTest.java new file mode 100644 index 000000000..948c2024c --- /dev/null +++ b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/ApexContextModelTest.java @@ -0,0 +1,153 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.model.contextmodel.handling; + +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.sql.Connection; +import java.sql.DriverManager; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; +import org.onap.policy.apex.model.basicmodel.dao.DaoParameters; +import org.onap.policy.apex.model.basicmodel.test.TestApexModel; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextModel; + +/** + * Apex context model tests. + * + * @author liam + * + */ +public class ApexContextModelTest { + private Connection connection; + TestApexModel testApexModel; + + /** + * Set up tests. + * + * @throws Exception a testing exception + */ + @Before + public void setup() throws Exception { + Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance(); + connection = DriverManager.getConnection("jdbc:derby:memory:apex_test;create=true"); + + testApexModel = new TestApexModel(AxContextModel.class, new TestApexContextModelCreator()); + } + + @After + public void teardown() throws Exception { + connection.close(); + new File("derby.log").delete(); + } + + @Test + public void testModelValid() throws Exception { + final AxValidationResult result = testApexModel.testApexModelValid(); + assertTrue(result.toString().equals(VALID_MODEL_STRING)); + } + + @Test + public void testApexModelVaidateObservation() throws Exception { + final AxValidationResult result = testApexModel.testApexModelVaidateObservation(); + assertTrue(result.toString().equals(OBSERVATION_MODEL_STRING)); + } + + @Test + public void testApexModelVaidateWarning() throws Exception { + final AxValidationResult result = testApexModel.testApexModelVaidateWarning(); + assertTrue(result.toString().equals(WARNING_MODEL_STRING)); + } + + @Test + public void testModelVaidateInvalidModel() throws Exception { + final AxValidationResult result = testApexModel.testApexModelVaidateInvalidModel(); + assertTrue(result.toString().equals(INVALID_MODEL_STRING)); + } + + @Test + public void testModelVaidateMalstructured() throws Exception { + final AxValidationResult result = testApexModel.testApexModelVaidateMalstructured(); + assertTrue(result.toString().equals(INVALID_MODEL_MALSTRUCTURED_STRING)); + } + + @Test + public void testModelWriteReadXml() throws Exception { + testApexModel.testApexModelWriteReadXml(); + } + + @Test + public void testModelWriteReadJson() throws Exception { + testApexModel.testApexModelWriteReadJson(); + } + + @Test + public void testModelWriteReadJpa() throws Exception { + final DaoParameters DaoParameters = new DaoParameters(); + DaoParameters.setPluginClass("org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao"); + DaoParameters.setPersistenceUnit("DAOTest"); + + testApexModel.testApexModelWriteReadJpa(DaoParameters); + } + + private static final String VALID_MODEL_STRING = "***validation of model successful***"; + + private static final String OBSERVATION_MODEL_STRING = "\n" + + "***observations noted during validation of model***\n" + + "AxArtifactKey:(name=contextAlbum1,version=0.0.1):" + + "org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo:OBSERVATION:description is blank\n" + + "********************************"; + + private static final String WARNING_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n" + + "AxArtifactKey:(name=contextAlbum1,version=0.0.1):" + + "org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo:WARNING:" + + "UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n" + + "********************************"; + + private static final String INVALID_MODEL_STRING = "\n" + "***validation of model failed***\n" + + "AxArtifactKey:(name=StringType,version=0.0.1):" + + "org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema:INVALID:" + + "no schemaDefinition specified, schemaDefinition may not be blank\n" + + "AxArtifactKey:(name=contextAlbum0,version=0.0.1):" + + "org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum:INVALID:" + + "scope is not defined\n" + "********************************"; + + private static final String INVALID_MODEL_MALSTRUCTURED_STRING = "\n" + "***validation of model failed***\n" + + "AxArtifactKey:(name=ContextModel,version=0.0.1):" + + "org.onap.policy.apex.model.contextmodel.concepts.AxContextModel:INVALID:" + + "key information not found for key AxArtifactKey:(name=contextAlbum1,version=0.0.2)\n" + + "AxArtifactKey:(name=contextAlbum1,version=0.0.1):" + + "org.onap.policy.apex.model.contextmodel.concepts.AxContextModel:WARNING:" + + "key not found for key information entry\n" + "AxArtifactKey:(name=ContextSchemas,version=0.0.1):" + + "org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas:INVALID:" + + "key on schemas entry AxArtifactKey:(name=MapType,version=0.0.1) " + + "does not equal entry key AxArtifactKey:(name=MapType,version=0.0.2)\n" + + "AxArtifactKey:(name=contextAlbums,version=0.0.1):" + + "org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums:INVALID:" + + "key on context album entry key AxArtifactKey:(name=contextAlbum1,version=0.0.1) " + + "does not equal context album value key AxArtifactKey:(name=contextAlbum1,version=0.0.2)\n" + + "********************************"; + +} diff --git a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/ContextComparisonTest.java b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/ContextComparisonTest.java new file mode 100644 index 000000000..81609cacf --- /dev/null +++ b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/ContextComparisonTest.java @@ -0,0 +1,189 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.model.contextmodel.handling; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextModel; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; +import org.onap.policy.apex.model.contextmodel.handling.ContextComparer; +import org.onap.policy.apex.model.utilities.comparison.KeyedMapDifference; + +/** + * Test context comparisons. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class ContextComparisonTest { + private AxContextModel emptyModel; + private AxContextModel fullModel; + private AxContextModel noGlobalContextModel; + private AxContextModel shellModel; + private AxContextModel singleEntryModel; + + /** + * Set up tests. + */ + @Before + public void getContext() { + final TestContextComparisonFactory factory = new TestContextComparisonFactory(); + emptyModel = factory.getEmptyModel(); + fullModel = factory.getFullModel(); + noGlobalContextModel = factory.getNoGlobalContextModel(); + shellModel = factory.getShellModel(); + singleEntryModel = factory.getSingleEntryModel(); + } + + @Test + public void testEmptyEmpty() { + final KeyedMapDifference schemaResult = new ContextComparer() + .compare(emptyModel.getSchemas(), emptyModel.getSchemas()); + assertNotNull(schemaResult); + assertTrue(emptyModel.getSchemas().getSchemasMap().equals(schemaResult.getIdenticalValues())); + + final KeyedMapDifference albumResult = new ContextComparer() + .compare(emptyModel.getAlbums(), emptyModel.getAlbums()); + assertNotNull(albumResult); + assertTrue(emptyModel.getAlbums().getAlbumsMap().equals(albumResult.getIdenticalValues())); + } + + @Test + public void testEmptyFull() { + final KeyedMapDifference schemaResult = new ContextComparer() + .compare(emptyModel.getSchemas(), fullModel.getSchemas()); + assertNotNull(schemaResult); + assertTrue(fullModel.getSchemas().getSchemasMap().equals(schemaResult.getRightOnly())); + + final KeyedMapDifference albumResult = new ContextComparer() + .compare(emptyModel.getAlbums(), fullModel.getAlbums()); + assertNotNull(albumResult); + assertTrue(fullModel.getAlbums().getAlbumsMap().equals(albumResult.getRightOnly())); + } + + @Test + public void testFullEmpty() { + final KeyedMapDifference schemaResult = new ContextComparer() + .compare(fullModel.getSchemas(), emptyModel.getSchemas()); + assertNotNull(schemaResult); + assertTrue(fullModel.getSchemas().getSchemasMap().equals(schemaResult.getLeftOnly())); + + final KeyedMapDifference albumResult = new ContextComparer() + .compare(fullModel.getAlbums(), emptyModel.getAlbums()); + assertNotNull(albumResult); + assertTrue(fullModel.getAlbums().getAlbumsMap().equals(albumResult.getLeftOnly())); + } + + @Test + public void testEmptyNoGlobalContext() { + final KeyedMapDifference schemaResult = new ContextComparer() + .compare(emptyModel.getSchemas(), noGlobalContextModel.getSchemas()); + assertNotNull(schemaResult); + assertTrue(noGlobalContextModel.getSchemas().getSchemasMap().equals(schemaResult.getRightOnly())); + + final KeyedMapDifference albumResult = new ContextComparer() + .compare(emptyModel.getAlbums(), noGlobalContextModel.getAlbums()); + assertNotNull(albumResult); + assertTrue(noGlobalContextModel.getAlbums().getAlbumsMap().equals(albumResult.getRightOnly())); + } + + @Test + public void testNoGlobalContextEmpty() { + final KeyedMapDifference schemaResult = new ContextComparer() + .compare(noGlobalContextModel.getSchemas(), emptyModel.getSchemas()); + assertNotNull(schemaResult); + assertTrue(noGlobalContextModel.getSchemas().getSchemasMap().equals(schemaResult.getLeftOnly())); + + final KeyedMapDifference albumResult = new ContextComparer() + .compare(noGlobalContextModel.getAlbums(), emptyModel.getAlbums()); + assertNotNull(albumResult); + assertTrue(noGlobalContextModel.getAlbums().getAlbumsMap().equals(albumResult.getLeftOnly())); + } + + @Test + public void testEmptyShell() { + final KeyedMapDifference schemaResult = new ContextComparer() + .compare(emptyModel.getSchemas(), shellModel.getSchemas()); + assertNotNull(schemaResult); + assertTrue(shellModel.getSchemas().getSchemasMap().equals(schemaResult.getRightOnly())); + + final KeyedMapDifference albumResult = new ContextComparer() + .compare(emptyModel.getAlbums(), shellModel.getAlbums()); + assertNotNull(albumResult); + assertTrue(shellModel.getAlbums().getAlbumsMap().equals(albumResult.getRightOnly())); + } + + @Test + public void testShellEmpty() { + final KeyedMapDifference schemaResult = new ContextComparer() + .compare(shellModel.getSchemas(), emptyModel.getSchemas()); + assertNotNull(schemaResult); + assertTrue(shellModel.getSchemas().getSchemasMap().equals(schemaResult.getLeftOnly())); + + final KeyedMapDifference albumResult = new ContextComparer() + .compare(shellModel.getAlbums(), emptyModel.getAlbums()); + assertNotNull(albumResult); + assertTrue(shellModel.getAlbums().getAlbumsMap().equals(albumResult.getLeftOnly())); + } + + @Test + public void testEmptySingleEntry() { + final KeyedMapDifference schemaResult = new ContextComparer() + .compare(emptyModel.getSchemas(), singleEntryModel.getSchemas()); + assertNotNull(schemaResult); + assertTrue(singleEntryModel.getSchemas().getSchemasMap().equals(schemaResult.getRightOnly())); + + final KeyedMapDifference albumResult = new ContextComparer() + .compare(emptyModel.getAlbums(), singleEntryModel.getAlbums()); + assertNotNull(albumResult); + assertTrue(singleEntryModel.getAlbums().getAlbumsMap().equals(albumResult.getRightOnly())); + } + + @Test + public void testSingleEntryEmpty() { + final KeyedMapDifference schemaResult = new ContextComparer() + .compare(singleEntryModel.getSchemas(), emptyModel.getSchemas()); + assertNotNull(schemaResult); + assertTrue(singleEntryModel.getSchemas().getSchemasMap().equals(schemaResult.getLeftOnly())); + + final KeyedMapDifference albumResult = new ContextComparer() + .compare(singleEntryModel.getAlbums(), emptyModel.getAlbums()); + assertNotNull(albumResult); + assertTrue(singleEntryModel.getAlbums().getAlbumsMap().equals(albumResult.getLeftOnly())); + } + + @Test + public void testFullFull() { + final KeyedMapDifference schemaResult = new ContextComparer() + .compare(fullModel.getSchemas(), fullModel.getSchemas()); + assertNotNull(schemaResult); + assertTrue(fullModel.getSchemas().getSchemasMap().equals(schemaResult.getIdenticalValues())); + + final KeyedMapDifference albumResult = new ContextComparer() + .compare(fullModel.getAlbums(), fullModel.getAlbums()); + assertNotNull(albumResult); + assertTrue(fullModel.getAlbums().getAlbumsMap().equals(albumResult.getIdenticalValues())); + } +} diff --git a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/TestApexContextModel.java b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/TestApexContextModel.java deleted file mode 100644 index 94a36844f..000000000 --- a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/TestApexContextModel.java +++ /dev/null @@ -1,153 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.contextmodel.handling; - -import static org.junit.Assert.assertTrue; - -import java.io.File; -import java.sql.Connection; -import java.sql.DriverManager; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; -import org.onap.policy.apex.model.basicmodel.dao.DaoParameters; -import org.onap.policy.apex.model.basicmodel.test.TestApexModel; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextModel; - -/** - * Apex context model tests. - * - * @author liam - * - */ -public class TestApexContextModel { - private Connection connection; - TestApexModel testApexModel; - - /** - * Set up tests. - * - * @throws Exception a testing exception - */ - @Before - public void setup() throws Exception { - Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance(); - connection = DriverManager.getConnection("jdbc:derby:memory:apex_test;create=true"); - - testApexModel = new TestApexModel(AxContextModel.class, new TestApexContextModelCreator()); - } - - @After - public void teardown() throws Exception { - connection.close(); - new File("derby.log").delete(); - } - - @Test - public void testModelValid() throws Exception { - final AxValidationResult result = testApexModel.testApexModelValid(); - assertTrue(result.toString().equals(VALID_MODEL_STRING)); - } - - @Test - public void testApexModelVaidateObservation() throws Exception { - final AxValidationResult result = testApexModel.testApexModelVaidateObservation(); - assertTrue(result.toString().equals(OBSERVATION_MODEL_STRING)); - } - - @Test - public void testApexModelVaidateWarning() throws Exception { - final AxValidationResult result = testApexModel.testApexModelVaidateWarning(); - assertTrue(result.toString().equals(WARNING_MODEL_STRING)); - } - - @Test - public void testModelVaidateInvalidModel() throws Exception { - final AxValidationResult result = testApexModel.testApexModelVaidateInvalidModel(); - assertTrue(result.toString().equals(INVALID_MODEL_STRING)); - } - - @Test - public void testModelVaidateMalstructured() throws Exception { - final AxValidationResult result = testApexModel.testApexModelVaidateMalstructured(); - assertTrue(result.toString().equals(INVALID_MODEL_MALSTRUCTURED_STRING)); - } - - @Test - public void testModelWriteReadXml() throws Exception { - testApexModel.testApexModelWriteReadXml(); - } - - @Test - public void testModelWriteReadJson() throws Exception { - testApexModel.testApexModelWriteReadJson(); - } - - @Test - public void testModelWriteReadJpa() throws Exception { - final DaoParameters DaoParameters = new DaoParameters(); - DaoParameters.setPluginClass("org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao"); - DaoParameters.setPersistenceUnit("DAOTest"); - - testApexModel.testApexModelWriteReadJpa(DaoParameters); - } - - private static final String VALID_MODEL_STRING = "***validation of model successful***"; - - private static final String OBSERVATION_MODEL_STRING = "\n" - + "***observations noted during validation of model***\n" - + "AxArtifactKey:(name=contextAlbum1,version=0.0.1):" - + "org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo:OBSERVATION:description is blank\n" - + "********************************"; - - private static final String WARNING_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n" - + "AxArtifactKey:(name=contextAlbum1,version=0.0.1):" - + "org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo:WARNING:" - + "UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n" - + "********************************"; - - private static final String INVALID_MODEL_STRING = "\n" + "***validation of model failed***\n" - + "AxArtifactKey:(name=StringType,version=0.0.1):" - + "org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema:INVALID:" - + "no schemaDefinition specified, schemaDefinition may not be blank\n" - + "AxArtifactKey:(name=contextAlbum0,version=0.0.1):" - + "org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum:INVALID:" - + "scope is not defined\n" + "********************************"; - - private static final String INVALID_MODEL_MALSTRUCTURED_STRING = "\n" + "***validation of model failed***\n" - + "AxArtifactKey:(name=ContextModel,version=0.0.1):" - + "org.onap.policy.apex.model.contextmodel.concepts.AxContextModel:INVALID:" - + "key information not found for key AxArtifactKey:(name=contextAlbum1,version=0.0.2)\n" - + "AxArtifactKey:(name=contextAlbum1,version=0.0.1):" - + "org.onap.policy.apex.model.contextmodel.concepts.AxContextModel:WARNING:" - + "key not found for key information entry\n" + "AxArtifactKey:(name=ContextSchemas,version=0.0.1):" - + "org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas:INVALID:" - + "key on schemas entry AxArtifactKey:(name=MapType,version=0.0.1) " - + "does not equal entry key AxArtifactKey:(name=MapType,version=0.0.2)\n" - + "AxArtifactKey:(name=contextAlbums,version=0.0.1):" - + "org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums:INVALID:" - + "key on context album entry key AxArtifactKey:(name=contextAlbum1,version=0.0.1) " - + "does not equal context album value key AxArtifactKey:(name=contextAlbum1,version=0.0.2)\n" - + "********************************"; - -} diff --git a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/TestContextComparison.java b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/TestContextComparison.java deleted file mode 100644 index 65295c13b..000000000 --- a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/TestContextComparison.java +++ /dev/null @@ -1,189 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.contextmodel.handling; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import org.junit.Before; -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextModel; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; -import org.onap.policy.apex.model.contextmodel.handling.ContextComparer; -import org.onap.policy.apex.model.utilities.comparison.KeyedMapDifference; - -/** - * Test context comparisons. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class TestContextComparison { - private AxContextModel emptyModel; - private AxContextModel fullModel; - private AxContextModel noGlobalContextModel; - private AxContextModel shellModel; - private AxContextModel singleEntryModel; - - /** - * Set up tests. - */ - @Before - public void getContext() { - final TestContextComparisonFactory factory = new TestContextComparisonFactory(); - emptyModel = factory.getEmptyModel(); - fullModel = factory.getFullModel(); - noGlobalContextModel = factory.getNoGlobalContextModel(); - shellModel = factory.getShellModel(); - singleEntryModel = factory.getSingleEntryModel(); - } - - @Test - public void testEmptyEmpty() { - final KeyedMapDifference schemaResult = new ContextComparer() - .compare(emptyModel.getSchemas(), emptyModel.getSchemas()); - assertNotNull(schemaResult); - assertTrue(emptyModel.getSchemas().getSchemasMap().equals(schemaResult.getIdenticalValues())); - - final KeyedMapDifference albumResult = new ContextComparer() - .compare(emptyModel.getAlbums(), emptyModel.getAlbums()); - assertNotNull(albumResult); - assertTrue(emptyModel.getAlbums().getAlbumsMap().equals(albumResult.getIdenticalValues())); - } - - @Test - public void testEmptyFull() { - final KeyedMapDifference schemaResult = new ContextComparer() - .compare(emptyModel.getSchemas(), fullModel.getSchemas()); - assertNotNull(schemaResult); - assertTrue(fullModel.getSchemas().getSchemasMap().equals(schemaResult.getRightOnly())); - - final KeyedMapDifference albumResult = new ContextComparer() - .compare(emptyModel.getAlbums(), fullModel.getAlbums()); - assertNotNull(albumResult); - assertTrue(fullModel.getAlbums().getAlbumsMap().equals(albumResult.getRightOnly())); - } - - @Test - public void testFullEmpty() { - final KeyedMapDifference schemaResult = new ContextComparer() - .compare(fullModel.getSchemas(), emptyModel.getSchemas()); - assertNotNull(schemaResult); - assertTrue(fullModel.getSchemas().getSchemasMap().equals(schemaResult.getLeftOnly())); - - final KeyedMapDifference albumResult = new ContextComparer() - .compare(fullModel.getAlbums(), emptyModel.getAlbums()); - assertNotNull(albumResult); - assertTrue(fullModel.getAlbums().getAlbumsMap().equals(albumResult.getLeftOnly())); - } - - @Test - public void testEmptyNoGlobalContext() { - final KeyedMapDifference schemaResult = new ContextComparer() - .compare(emptyModel.getSchemas(), noGlobalContextModel.getSchemas()); - assertNotNull(schemaResult); - assertTrue(noGlobalContextModel.getSchemas().getSchemasMap().equals(schemaResult.getRightOnly())); - - final KeyedMapDifference albumResult = new ContextComparer() - .compare(emptyModel.getAlbums(), noGlobalContextModel.getAlbums()); - assertNotNull(albumResult); - assertTrue(noGlobalContextModel.getAlbums().getAlbumsMap().equals(albumResult.getRightOnly())); - } - - @Test - public void testNoGlobalContextEmpty() { - final KeyedMapDifference schemaResult = new ContextComparer() - .compare(noGlobalContextModel.getSchemas(), emptyModel.getSchemas()); - assertNotNull(schemaResult); - assertTrue(noGlobalContextModel.getSchemas().getSchemasMap().equals(schemaResult.getLeftOnly())); - - final KeyedMapDifference albumResult = new ContextComparer() - .compare(noGlobalContextModel.getAlbums(), emptyModel.getAlbums()); - assertNotNull(albumResult); - assertTrue(noGlobalContextModel.getAlbums().getAlbumsMap().equals(albumResult.getLeftOnly())); - } - - @Test - public void testEmptyShell() { - final KeyedMapDifference schemaResult = new ContextComparer() - .compare(emptyModel.getSchemas(), shellModel.getSchemas()); - assertNotNull(schemaResult); - assertTrue(shellModel.getSchemas().getSchemasMap().equals(schemaResult.getRightOnly())); - - final KeyedMapDifference albumResult = new ContextComparer() - .compare(emptyModel.getAlbums(), shellModel.getAlbums()); - assertNotNull(albumResult); - assertTrue(shellModel.getAlbums().getAlbumsMap().equals(albumResult.getRightOnly())); - } - - @Test - public void testShellEmpty() { - final KeyedMapDifference schemaResult = new ContextComparer() - .compare(shellModel.getSchemas(), emptyModel.getSchemas()); - assertNotNull(schemaResult); - assertTrue(shellModel.getSchemas().getSchemasMap().equals(schemaResult.getLeftOnly())); - - final KeyedMapDifference albumResult = new ContextComparer() - .compare(shellModel.getAlbums(), emptyModel.getAlbums()); - assertNotNull(albumResult); - assertTrue(shellModel.getAlbums().getAlbumsMap().equals(albumResult.getLeftOnly())); - } - - @Test - public void testEmptySingleEntry() { - final KeyedMapDifference schemaResult = new ContextComparer() - .compare(emptyModel.getSchemas(), singleEntryModel.getSchemas()); - assertNotNull(schemaResult); - assertTrue(singleEntryModel.getSchemas().getSchemasMap().equals(schemaResult.getRightOnly())); - - final KeyedMapDifference albumResult = new ContextComparer() - .compare(emptyModel.getAlbums(), singleEntryModel.getAlbums()); - assertNotNull(albumResult); - assertTrue(singleEntryModel.getAlbums().getAlbumsMap().equals(albumResult.getRightOnly())); - } - - @Test - public void testSingleEntryEmpty() { - final KeyedMapDifference schemaResult = new ContextComparer() - .compare(singleEntryModel.getSchemas(), emptyModel.getSchemas()); - assertNotNull(schemaResult); - assertTrue(singleEntryModel.getSchemas().getSchemasMap().equals(schemaResult.getLeftOnly())); - - final KeyedMapDifference albumResult = new ContextComparer() - .compare(singleEntryModel.getAlbums(), emptyModel.getAlbums()); - assertNotNull(albumResult); - assertTrue(singleEntryModel.getAlbums().getAlbumsMap().equals(albumResult.getLeftOnly())); - } - - @Test - public void testFullFull() { - final KeyedMapDifference schemaResult = new ContextComparer() - .compare(fullModel.getSchemas(), fullModel.getSchemas()); - assertNotNull(schemaResult); - assertTrue(fullModel.getSchemas().getSchemasMap().equals(schemaResult.getIdenticalValues())); - - final KeyedMapDifference albumResult = new ContextComparer() - .compare(fullModel.getAlbums(), fullModel.getAlbums()); - assertNotNull(albumResult); - assertTrue(fullModel.getAlbums().getAlbumsMap().equals(albumResult.getIdenticalValues())); - } -} -- cgit 1.2.3-korg