diff options
Diffstat (limited to 'model/engine-model/src/test')
5 files changed, 0 insertions, 723 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; - } -} diff --git a/model/engine-model/src/test/resources/logback-test.xml b/model/engine-model/src/test/resources/logback-test.xml deleted file mode 100644 index c52f2ded6..000000000 --- a/model/engine-model/src/test/resources/logback-test.xml +++ /dev/null @@ -1,70 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ============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========================================================= ---> - -<configuration> - - <contextName>Apex</contextName> - <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" /> - <property name="LOG_DIR" value="${java.io.tmpdir}/apex_logging/" /> - - <!-- USE FOR STD OUT ONLY --> - <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> - <encoder> - <Pattern>%d %contextName [%t] %level %logger{36} - %msg%n</Pattern> - </encoder> - </appender> - - <root level="INFO"> - <appender-ref ref="STDOUT" /> - </root> - - <logger name="org.infinispan" level="INFO" additivity="false"> - <appender-ref ref="STDOUT" /> - </logger> - - <logger name="org.apache.zookeeper.ClientCnxn" level="OFF" additivity="false"> - <appender-ref ref="STDOUT" /> - </logger> - - <appender name="FILE" class="ch.qos.logback.core.FileAppender"> - <file>${LOG_DIR}/apex.log</file> - <encoder> - <pattern>%d %-5relative [procId=${processId}] [%thread] %-5level - %logger{26} - %msg %n %ex{full}</pattern> - </encoder> - </appender> - - <appender name="CTXT_FILE" class="ch.qos.logback.core.FileAppender"> - <file>${LOG_DIR}/apex_ctxt.log</file> - <encoder> - <pattern>%d %-5relative [procId=${processId}] [%thread] %-5level - %logger{26} - %msg %n %ex{full}</pattern> - </encoder> - </appender> - - <logger name="org.onap.policy.apex.core.context.impl.monitoring" level="INFO" additivity="false"> - <appender-ref ref="CTXT_FILE" /> - </logger> - - <logger name="org.onap.policy.apex.core.context" level="INFO" additivity="false"> - <appender-ref ref="STDOUT" /> - </logger> -</configuration> |