diff options
author | liamfallon <liam.fallon@est.tech> | 2022-02-10 12:06:25 +0000 |
---|---|---|
committer | liamfallon <liam.fallon@est.tech> | 2022-02-10 13:48:15 +0000 |
commit | 8534756d13531ffec9c2d7b2ffe0a53ee1d3aaef (patch) | |
tree | a35f6b3f7766d47900ee6691111acff1418bb747 /model/engine-model/src/test/java | |
parent | 2f2c5465cd23c8c3300a5c3d185806bb3e7d73c1 (diff) |
Collapse apex-pdp maven model submodules
This review collapses all the code in six podel submodules into a single
model module. There are no code changes, just files moved around.
This change reduces the complexity of the code structure and speeds up
the build.
Issue-ID: POLICY-1820
Change-Id: Ifb644e8ec85ae6d0987378f4616fbc8a8858a9a8
Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'model/engine-model/src/test/java')
4 files changed, 0 insertions, 653 deletions
diff --git a/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineModelTest.java b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineModelTest.java deleted file mode 100644 index c23687bb1..000000000 --- a/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineModelTest.java +++ /dev/null @@ -1,176 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2020 Nordix Foundation. - * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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.enginemodel.concepts; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -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.basicmodel.concepts.AxReferenceKey; -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.AxContextAlbums; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; - -/** - * Test engine models. - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class EngineModelTest { - - @Test - public void testEnginetModel() { - assertNotNull(new AxEngineModel()); - assertNotNull(new AxEngineModel(new AxArtifactKey())); - assertNotNull(new AxEngineModel(new AxArtifactKey(), new AxContextSchemas(), new AxKeyInformation(), - new AxContextAlbums())); - assertNotNull(new AxEngineModel(new AxArtifactKey(), new AxContextSchemas(), new AxKeyInformation(), - new AxContextAlbums(), AxEngineState.UNDEFINED, new AxEngineStats())); - - final AxArtifactKey modelKey = new AxArtifactKey("ModelName", "0.0.1"); - final AxArtifactKey schemasKey = new AxArtifactKey("SchemasKey", "0.0.1"); - final AxArtifactKey albumKey = new AxArtifactKey("AlbumKey", "0.0.1"); - final AxArtifactKey keyInfoKey = new AxArtifactKey("SchemasKey", "0.0.1"); - final AxEngineStats stats = new AxEngineStats(new AxReferenceKey(modelKey, "EngineStats")); - final AxEngineStats otherStats = new AxEngineStats(); - otherStats.setAverageExecutionTime(100); - - final AxEngineModel model = new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), - new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats); - model.register(); - - assertThatThrownBy(() -> model.setKey(null)) - .hasMessage("key may not be null"); - model.setKey(modelKey); - assertEquals("ModelName:0.0.1", model.getKey().getId()); - assertEquals("ModelName:0.0.1", model.getKeys().get(0).getId()); - - final long timestamp = System.currentTimeMillis(); - model.setTimestamp(timestamp); - assertEquals(timestamp, model.getTimestamp()); - model.setTimestamp(-1); - assertTrue(model.getTimeStampString().matches("\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}.\\d{3}")); - - assertThatThrownBy(() -> model.setState(null)) - .hasMessage("state may not be null"); - for (final AxEngineState state : AxEngineState.values()) { - model.setState(state); - assertEquals(state, model.getState()); - } - - model.setState(AxEngineState.READY); - assertEquals(AxEngineState.READY, model.getState()); - - assertThatThrownBy(() -> model.setStats(null)) - .hasMessage("stats may not be null"); - model.setStats(stats); - assertEquals(stats, model.getStats()); - - model.clean(); - assertNotNull(model); - assertThat(model.toString()).startsWith("AxEngineModel:(AxContextModel(super=AxEngineModel:(key=A"); - - final AxEngineModel clonedModel = new AxEngineModel(model); - - assertNotEquals(0, model.hashCode()); - - // disabling sonar because this code tests the equals() method - assertEquals(model, model); // NOSONAR - assertEquals(model, clonedModel); - assertNotEquals(model, (Object) "Hello"); - assertNotEquals(model, new AxEngineModel(new AxArtifactKey())); - assertNotEquals(model, new AxEngineModel(new AxArtifactKey(), new AxContextSchemas(schemasKey), - new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats)); - assertNotEquals(model, new AxEngineModel(modelKey, new AxContextSchemas(), new AxKeyInformation(keyInfoKey), - new AxContextAlbums(albumKey), AxEngineState.READY, stats)); - assertNotEquals(model, new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), new AxKeyInformation(), - new AxContextAlbums(albumKey), AxEngineState.READY, stats)); - assertNotEquals(model, new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), - new AxKeyInformation(keyInfoKey), new AxContextAlbums(), AxEngineState.READY, stats)); - assertNotEquals(model, new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), - new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.STOPPED, stats)); - assertNotEquals(model, new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), - new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, otherStats)); - model.setTimestamp(timestamp); - assertNotEquals(model, new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), - new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats)); - model.setTimestamp(0); - assertEquals(model, new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), - new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats)); - - model.setTimestamp(-1); - assertEquals(0, model.compareTo(model)); - assertEquals(0, model.compareTo(clonedModel)); - assertNotEquals(0, model.compareTo(new AxArtifactKey())); - assertNotEquals(model, new AxEngineModel(new AxArtifactKey())); - assertNotEquals(0, model.compareTo(new AxEngineModel(new AxArtifactKey(), new AxContextSchemas(schemasKey), - new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats))); - assertNotEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(), - new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats))); - assertNotEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), - new AxKeyInformation(), new AxContextAlbums(albumKey), AxEngineState.READY, stats))); - assertNotEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), - new AxKeyInformation(keyInfoKey), new AxContextAlbums(), AxEngineState.READY, stats))); - assertNotEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), - new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.STOPPED, stats))); - assertNotEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), - new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, otherStats))); - model.setTimestamp(timestamp); - assertNotEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), - new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats))); - model.setTimestamp(0); - assertEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), - new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats))); - - model.setTimestamp(timestamp); - AxValidationResult result = new AxValidationResult(); - result = model.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - model.setTimestamp(-1); - result = new AxValidationResult(); - result = model.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - model.setTimestamp(timestamp); - result = new AxValidationResult(); - result = model.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - model.setState(AxEngineState.UNDEFINED); - result = new AxValidationResult(); - result = model.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - model.setState(AxEngineState.READY); - result = new AxValidationResult(); - result = model.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - } -} diff --git a/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineStatsTest.java b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineStatsTest.java deleted file mode 100644 index 3eca27c08..000000000 --- a/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineStatsTest.java +++ /dev/null @@ -1,267 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2020 Nordix Foundation. - * Modifications Copyright (C) 2022 Bell Canada. - * ================================================================================ - * 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.enginemodel.concepts; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -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 io.prometheus.client.CollectorRegistry; -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; -import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult; - -/** - * Test the engine statistics. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class EngineStatsTest { - private static final Object WAIT_LOCK = new Object(); - private static final String ENGINE_KEY = "EngineKey"; - private static final String ENGINE_VERSION = "0.0.1"; - - @Test - public void testEngineStats() { - assertNotNull(new AxEngineStats()); - assertNotNull(new AxEngineStats(new AxReferenceKey())); - - final AxReferenceKey statsKey = new AxReferenceKey(ENGINE_KEY, ENGINE_VERSION, "EngineStats"); - final AxEngineStats stats = new AxEngineStats(statsKey); - - assertThatThrownBy(() -> stats.setKey(null)) - .hasMessage("key may not be null"); - stats.setKey(statsKey); - assertEquals("EngineKey:0.0.1:NULL:EngineStats", stats.getKey().getId()); - assertEquals("EngineKey:0.0.1:NULL:EngineStats", stats.getKeys().get(0).getId()); - - stats.setAverageExecutionTime(123.45); - assertEquals(Double.valueOf(123.45), Double.valueOf(stats.getAverageExecutionTime())); - checkAvgExecTimeMetric(stats); - - stats.setEventCount(987); - assertEquals(987, stats.getEventCount()); - checkEventsCountMetric(stats); - - final long lastExecutionTime = System.currentTimeMillis(); - stats.setLastExecutionTime(lastExecutionTime); - assertEquals(lastExecutionTime, stats.getLastExecutionTime()); - checkLastExecTimeMetric(stats); - - final long timestamp = System.currentTimeMillis(); - stats.setTimeStamp(timestamp); - assertEquals(timestamp, stats.getTimeStamp()); - assertNotNull(stats.getTimeStampString()); - - final long upTime = System.currentTimeMillis() - timestamp; - stats.setUpTime(upTime); - assertEquals(upTime, stats.getUpTime()); - checkUpTimeMetric(stats); - - stats.engineStart(); - assertTrue(stats.getUpTime() > -1); - checkEngineStartTimestampMetric(stats); - checkLastExecTimeMetric(stats); - stats.engineStop(); - assertTrue(stats.getUpTime() >= 0); - - stats.engineStop(); - checkUpTimeMetric(stats); - checkEngineStartTimestampMetric(stats); - - stats.reset(); - - stats.setEventCount(-2); - stats.executionEnter(new AxArtifactKey()); - assertEquals(2, stats.getEventCount()); - checkEventsCountMetric(stats); - - stats.setEventCount(10); - stats.executionEnter(new AxArtifactKey()); - assertEquals(11, stats.getEventCount()); - checkEventsCountMetric(stats); - - stats.reset(); - stats.engineStart(); - stats.setEventCount(4); - checkUpTimeMetric(stats); - stats.executionEnter(new AxArtifactKey()); - checkEventsCountMetric(stats); - checkAvgExecTimeMetric(stats); - checkEngineStartTimestampMetric(stats); - - synchronized (WAIT_LOCK) { - try { - WAIT_LOCK.wait(10); - } catch (InterruptedException e) { - fail("test should not throw an exception"); - } - } - - stats.executionExit(); - final double avExecutionTime = stats.getAverageExecutionTime(); - assertTrue(avExecutionTime >= 2.0 && avExecutionTime < 10.0); - stats.engineStop(); - checkUpTimeMetric(stats); - - AxValidationResult result = new AxValidationResult(); - result = stats.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - stats.setKey(new AxReferenceKey()); - result = new AxValidationResult(); - result = stats.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - stats.setKey(statsKey); - result = new AxValidationResult(); - result = stats.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - stats.clean(); - stats.reset(); - checkAllPrometheusMetrics(stats); - - final AxEngineStats clonedStats = new AxEngineStats(stats); - assertEquals("AxEngineStats:(engineKey=AxReferenceKey:(parentKey", clonedStats.toString().substring(0, 50)); - - assertNotNull(stats.getKeys()); - - assertNotEquals(0, stats.hashCode()); - - // disabling sonar because this code tests the equals() method - assertEquals(stats, stats); // NOSONAR - assertEquals(stats, clonedStats); - assertNotNull(stats); - checkAllPrometheusMetrics(clonedStats); - - Object helloObject = "Hello"; - assertNotEquals(stats, helloObject); - assertNotEquals(stats, new AxEngineStats(new AxReferenceKey())); - - assertEquals(0, stats.compareTo(stats)); - assertEquals(0, stats.compareTo(clonedStats)); - assertNotEquals(0, stats.compareTo(new AxArtifactKey())); - assertNotEquals(0, stats.compareTo(null)); - assertNotEquals(0, stats.compareTo(new AxEngineStats(new AxReferenceKey()))); - - stats.setTimeStamp(1); - assertNotEquals(stats, new AxEngineStats(statsKey)); - assertNotEquals(0, stats.compareTo(new AxEngineStats(statsKey))); - stats.setTimeStamp(0); - assertEquals(stats, new AxEngineStats(statsKey)); - assertEquals(0, stats.compareTo(new AxEngineStats(statsKey))); - checkAllPrometheusMetrics(clonedStats); - - stats.setEventCount(1); - assertNotEquals(stats, new AxEngineStats(statsKey)); - assertNotEquals(0, stats.compareTo(new AxEngineStats(statsKey))); - stats.setEventCount(0); - assertEquals(stats, new AxEngineStats(statsKey)); - assertEquals(0, stats.compareTo(new AxEngineStats(statsKey))); - - stats.setLastExecutionTime(1); - assertNotEquals(stats, new AxEngineStats(statsKey)); - assertNotEquals(0, stats.compareTo(new AxEngineStats(statsKey))); - stats.setLastExecutionTime(0); - assertEquals(stats, new AxEngineStats(statsKey)); - assertEquals(0, stats.compareTo(new AxEngineStats(statsKey))); - - stats.setAverageExecutionTime(1); - assertNotEquals(stats, new AxEngineStats(statsKey)); - assertNotEquals(0, stats.compareTo(new AxEngineStats(statsKey))); - stats.setAverageExecutionTime(0); - assertEquals(stats, new AxEngineStats(statsKey)); - assertEquals(0, stats.compareTo(new AxEngineStats(statsKey))); - - stats.setUpTime(1); - assertNotEquals(stats, new AxEngineStats(statsKey)); - assertNotEquals(0, stats.compareTo(new AxEngineStats(statsKey))); - stats.setUpTime(0); - assertEquals(stats, new AxEngineStats(statsKey)); - assertEquals(0, stats.compareTo(new AxEngineStats(statsKey))); - - assertEquals(-1, stats.compareTo(new AxEngineStats(statsKey, 0, 0, 0, 0.0, 0, 1))); - - stats.engineStart(); - assertNotEquals(stats, new AxEngineStats(statsKey)); - final AxEngineStats newStats = new AxEngineStats(statsKey); - newStats.setTimeStamp(stats.getTimeStamp()); - assertNotEquals(stats, newStats); - assertNotEquals(0, stats.compareTo(newStats)); - stats.engineStop(); - checkUpTimeMetric(stats); - checkEngineStartTimestampMetric(stats); - stats.reset(); - assertEquals(stats, new AxEngineStats(statsKey)); - assertEquals(0, stats.compareTo(new AxEngineStats(statsKey))); - checkAllPrometheusMetrics(stats); - } - - private void checkUpTimeMetric(AxEngineStats stats) { - Double upTimeMetric = CollectorRegistry.defaultRegistry.getSampleValue("pdpa_engine_uptime", - new String[]{AxEngineStats.ENGINE_INSTANCE_ID}, new String[]{ENGINE_KEY + ":" + ENGINE_VERSION}) * 1000d; - assertEquals(upTimeMetric.longValue(), stats.getUpTime()); - } - - private void checkEventsCountMetric(AxEngineStats stats) { - Double eventsCountMetric = CollectorRegistry.defaultRegistry.getSampleValue("pdpa_engine_event_executions", - new String[]{AxEngineStats.ENGINE_INSTANCE_ID}, new String[]{ENGINE_KEY + ":" + ENGINE_VERSION}); - assertEquals(eventsCountMetric.longValue(), stats.getEventCount()); - } - - private void checkLastExecTimeMetric(AxEngineStats stats) { - Double lastExecTimeMetric = CollectorRegistry.defaultRegistry - .getSampleValue("pdpa_engine_last_execution_time_sum", new String[]{AxEngineStats.ENGINE_INSTANCE_ID}, - new String[]{ENGINE_KEY + ":" + ENGINE_VERSION}) * 1000d; - assertEquals(lastExecTimeMetric.longValue(), stats.getLastExecutionTime()); - } - - private void checkEngineStartTimestampMetric(AxEngineStats stats) { - Double engineStartTimestampMetric = CollectorRegistry.defaultRegistry - .getSampleValue("pdpa_engine_last_start_timestamp_epoch", - new String[]{AxEngineStats.ENGINE_INSTANCE_ID}, new String[]{ENGINE_KEY + ":" + ENGINE_VERSION}); - assertEquals(engineStartTimestampMetric.longValue(), stats.getLastStart()); - } - - private void checkAvgExecTimeMetric(AxEngineStats stats) { - Double avgExecTimeMetric = CollectorRegistry.defaultRegistry - .getSampleValue("pdpa_engine_average_execution_time_seconds", - new String[]{AxEngineStats.ENGINE_INSTANCE_ID}, - new String[]{ENGINE_KEY + ":" + ENGINE_VERSION}) * 1000d; - assertEquals(avgExecTimeMetric, Double.valueOf(stats.getAverageExecutionTime())); - } - - private void checkAllPrometheusMetrics(AxEngineStats stats) { - checkEventsCountMetric(stats); - checkUpTimeMetric(stats); - checkAvgExecTimeMetric(stats); - checkEngineStartTimestampMetric(stats); - checkEngineStartTimestampMetric(stats); - } -}
\ No newline at end of file diff --git a/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/ApexEngineModelTest.java b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/ApexEngineModelTest.java deleted file mode 100644 index e7fdd2d93..000000000 --- a/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/ApexEngineModelTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020,2022 Nordix Foundation. - * ================================================================================ - * 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.enginemodel.handling; - -import static org.junit.Assert.assertEquals; - -import org.junit.Before; -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; -import org.onap.policy.apex.model.basicmodel.test.TestApexModel; -import org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel; - -public class ApexEngineModelTest { - private static final String VALID_MODEL_STRING = "***validation of model successful***"; - - private static final String INVALID_MODEL_STRING = "\n" + "***validation of model failed***\n" - + "AxArtifactKey:(name=AnEngine,version=0.0.1):" - + "org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel:INVALID:" - + "AxEngineModel - state is UNDEFINED\n" + "********************************"; - - private static final String INVALID_MODEL_MALSTRUCTURED_STRING = "\n" + "***validation of model failed***\n" - + "AxArtifactKey:(name=AnEngine,version=0.0.1):" - + "org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel:INVALID:" - + "AxEngineModel - timestamp is not set\n" + "AxArtifactKey:(name=AnEngine,version=0.0.1):" - + "org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel:INVALID:" - + "AxEngineModel - state is UNDEFINED\n" + "********************************"; - - TestApexModel<AxEngineModel> testApexModel; - - /** - * Set up the test. - * - * @throws Exception errors from test setup - */ - @Before - public void setup() throws Exception { - testApexModel = new TestApexModel<AxEngineModel>(AxEngineModel.class, new DummyTestApexEngineModelCreator()); - } - - @Test - public void testModelValid() throws Exception { - final AxValidationResult result = testApexModel.testApexModelValid(); - assertEquals(VALID_MODEL_STRING, result.toString()); - } - - @Test - public void testModelVaidateInvalidModel() throws Exception { - final AxValidationResult result = testApexModel.testApexModelVaidateInvalidModel(); - assertEquals(INVALID_MODEL_STRING, result.toString()); - } - - @Test - public void testModelVaidateMalstructured() throws Exception { - final AxValidationResult result = testApexModel.testApexModelVaidateMalstructured(); - assertEquals(INVALID_MODEL_MALSTRUCTURED_STRING, result.toString()); - } - - @Test - public void testModelWriteReadJson() throws Exception { - testApexModel.testApexModelWriteReadJson(); - } -} diff --git a/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/DummyTestApexEngineModelCreator.java b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/DummyTestApexEngineModelCreator.java deleted file mode 100644 index 9e7d99b72..000000000 --- a/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/DummyTestApexEngineModelCreator.java +++ /dev/null @@ -1,129 +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.enginemodel.handling; - -import java.util.UUID; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo; -import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; -import org.onap.policy.apex.model.basicmodel.test.TestApexModelCreator; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; -import org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel; -import org.onap.policy.apex.model.enginemodel.concepts.AxEngineState; -import org.onap.policy.apex.model.enginemodel.concepts.AxEngineStats; - -public class DummyTestApexEngineModelCreator implements TestApexModelCreator<AxEngineModel> { - - @Override - public AxEngineModel getModel() { - final AxContextSchema schema0 = new AxContextSchema(new AxArtifactKey("StringType", "0.0.1"), "Java", - "org.onap.policy.apex.model.enginemodel.concepts.TestContextItem000"); - final AxContextSchema schema1 = new AxContextSchema(new AxArtifactKey("MapType", "0.0.1"), "Java", - "org.onap.policy.apex.model.enginemodel.concepts.TestContextItem00A"); - - final AxContextSchemas schemas = new AxContextSchemas(new AxArtifactKey("ContextSchemas", "0.0.1")); - schemas.getSchemasMap().put(schema0.getKey(), schema0); - schemas.getSchemasMap().put(schema1.getKey(), schema1); - - final AxContextAlbum album0 = - new AxContextAlbum(new AxArtifactKey("contextAlbum0", "0.0.1"), "APPLICATION", true, schema1.getKey()); - - final AxContextAlbums albums = new AxContextAlbums(new AxArtifactKey("context", "0.0.1")); - albums.getAlbumsMap().put(album0.getKey(), album0); - - final AxEngineModel engineModel = new AxEngineModel(new AxArtifactKey("AnEngine", "0.0.1")); - engineModel.setSchemas(schemas); - engineModel.setAlbums(albums); - engineModel.setTimestamp(System.currentTimeMillis()); - engineModel.setState(AxEngineState.EXECUTING); - engineModel.setStats(new AxEngineStats(new AxReferenceKey(engineModel.getKey(), "EngineStats"), - System.currentTimeMillis(), 100, 205, 200, 12345, 9876)); - engineModel.getKeyInformation().generateKeyInfo(engineModel); - - final AxValidationResult result = new AxValidationResult(); - engineModel.validate(result); - - return engineModel; - } - - @Override - public AxEngineModel getInvalidModel() { - final AxEngineModel engineModel = getModel(); - - engineModel.setTimestamp(System.currentTimeMillis()); - engineModel.setState(AxEngineState.UNDEFINED); - engineModel.setStats(new AxEngineStats(new AxReferenceKey(engineModel.getKey(), "EngineStats"), - System.currentTimeMillis(), 100, 205, 200, 12345, 9876)); - engineModel.getKeyInformation().generateKeyInfo(engineModel); - - return engineModel; - } - - /** - * Get a malstructured model. - */ - public AxEngineModel getMalstructuredModel() { - final AxEngineModel engineModel = getModel(); - - engineModel.setTimestamp(-1); - engineModel.setState(AxEngineState.UNDEFINED); - - return engineModel; - } - - @Override - public AxEngineModel getObservationModel() { - final AxEngineModel engineModel = getModel(); - - final AxContextSchema schema0 = new AxContextSchema(new AxArtifactKey("StringType", "0.0.1"), "Java", - "org.onap.policy.apex.model.enginemodel.concepts.TestContextItem000"); - final AxContextSchema schema1 = new AxContextSchema(new AxArtifactKey("MapType", "0.0.1"), "Java", - "org.onap.policy.apex.model.enginemodel.concepts.TestContextItem00A"); - - engineModel.getKeyInformation().getKeyInfoMap().put(schema0.getKey(), - new AxKeyInfo(schema0.getKey(), UUID.fromString("00000000-0000-0000-0000-000000000001"), "")); - engineModel.getKeyInformation().getKeyInfoMap().put(schema1.getKey(), - new AxKeyInfo(schema1.getKey(), UUID.fromString("00000000-0000-0000-0000-000000000002"), "")); - - return engineModel; - } - - @Override - public AxEngineModel getWarningModel() { - final AxEngineModel engineModel = getModel(); - - final AxContextSchema schema0 = new AxContextSchema(new AxArtifactKey("StringType", "0.0.1"), "Java", - "org.onap.policy.apex.model.enginemodel.concepts.TestContextItem000"); - final AxContextSchema schema1 = new AxContextSchema(new AxArtifactKey("MapType", "0.0.1"), "Java", - "org.onap.policy.apex.model.enginemodel.concepts.TestContextItem00A"); - - engineModel.getKeyInformation().getKeyInfoMap().put(schema0.getKey(), - new AxKeyInfo(schema0.getKey(), UUID.fromString("00000000-0000-0000-0000-000000000000"), "")); - engineModel.getKeyInformation().getKeyInfoMap().put(schema1.getKey(), - new AxKeyInfo(schema1.getKey(), UUID.fromString("00000000-0000-0000-0000-000000000001"), "")); - - return engineModel; - } -} |