From 55d93a12cc5575c872724f48585304b5eec77fea Mon Sep 17 00:00:00 2001 From: "waqas.ikram" Date: Mon, 28 May 2018 10:58:07 +0100 Subject: Adding policy-model, model-api & engine-model Change-Id: I56702b8f0953457d493f894d155b2a6ddc87b10c Issue-ID: POLICY-856 Signed-off-by: waqas.ikram --- .../enginemodel/concepts/TestEngineModel.java | 187 ++++++++++++++++++++ .../enginemodel/concepts/TestEngineStats.java | 193 +++++++++++++++++++++ .../enginemodel/handling/TestApexEngineModel.java | 102 +++++++++++ .../handling/TestApexEngineModelCreator.java | 127 ++++++++++++++ 4 files changed, 609 insertions(+) create mode 100644 model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/TestEngineModel.java create mode 100644 model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/TestEngineStats.java create mode 100644 model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/TestApexEngineModel.java create mode 100644 model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/TestApexEngineModelCreator.java (limited to 'model/engine-model/src/test/java') diff --git a/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/TestEngineModel.java b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/TestEngineModel.java new file mode 100644 index 000000000..86530462c --- /dev/null +++ b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/TestEngineModel.java @@ -0,0 +1,187 @@ +/*- + * ============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.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.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; + +/** + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class TestEngineModel { + + @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(); + + try { + model.setKey(null); + fail("test should throw an exception here"); + } catch (final Exception e) { + assertEquals("key may not be null", e.getMessage()); + } + + 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}")); + + try { + model.setState(null); + fail("test should throw an exception here"); + } catch (final Exception e) { + assertEquals("state may not be null", e.getMessage()); + } + + for (final AxEngineState state : AxEngineState.values()) { + model.setState(state); + assertEquals(state, model.getState()); + } + + model.setState(AxEngineState.READY); + assertEquals(AxEngineState.READY, model.getState()); + + try { + model.setStats(null); + fail("test should throw an exception here"); + } catch (final Exception e) { + assertEquals("stats may not be null", e.getMessage()); + } + + model.setStats(stats); + assertEquals(stats, model.getStats()); + + model.clean(); + assertNotNull(model); + assertEquals("AxEngineModel:(AxEngineModel:(AxEngineModel:(key=A", model.toString().substring(0, 50)); + + final AxEngineModel clonedModel = new AxEngineModel(model); + + assertFalse(model.hashCode() == 0); + + assertTrue(model.equals(model)); + assertTrue(model.equals(clonedModel)); + assertFalse(model.equals("Hello")); + assertFalse(model.equals(new AxEngineModel(new AxArtifactKey()))); + assertFalse(model.equals(new AxEngineModel(new AxArtifactKey(), new AxContextSchemas(schemasKey), + new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats))); + assertFalse(model.equals(new AxEngineModel(modelKey, new AxContextSchemas(), new AxKeyInformation(keyInfoKey), + new AxContextAlbums(albumKey), AxEngineState.READY, stats))); + assertFalse(model.equals(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), new AxKeyInformation(), + new AxContextAlbums(albumKey), AxEngineState.READY, stats))); + assertFalse(model.equals(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), + new AxKeyInformation(keyInfoKey), new AxContextAlbums(), AxEngineState.READY, stats))); + assertFalse(model.equals(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), + new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.STOPPED, stats))); + assertFalse(model.equals(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), + new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, otherStats))); + model.setTimestamp(timestamp); + assertFalse(model.equals(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), + new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats))); + model.setTimestamp(0); + assertTrue(model.equals(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())); + assertFalse(model.equals(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/TestEngineStats.java b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/TestEngineStats.java new file mode 100644 index 000000000..f5fdcbb1f --- /dev/null +++ b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/TestEngineStats.java @@ -0,0 +1,193 @@ +/*- + * ============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.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.AxReferenceKey; +import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; +import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult; + +/** + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class TestEngineStats { + + @Test + public void testEngineStats() { + assertNotNull(new AxEngineStats()); + assertNotNull(new AxEngineStats(new AxReferenceKey())); + + final AxReferenceKey statsKey = new AxReferenceKey("EngineKey", "0.0.1", "EngineStats"); + final AxEngineStats stats = new AxEngineStats(statsKey); + + try { + stats.setKey(null); + fail("test should throw an exception here"); + } catch (final Exception e) { + assertEquals("key may not be null", e.getMessage()); + } + + 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(new Double(123.45), new Double(stats.getAverageExecutionTime())); + + stats.setEventCount(987); + assertEquals(987, stats.getEventCount()); + + final long lastExecutionTime = System.currentTimeMillis(); + stats.setLastExecutionTime(lastExecutionTime); + assertEquals(lastExecutionTime, stats.getLastExecutionTime()); + + 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()); + + stats.engineStart(); + assertTrue(stats.getUpTime() > -1); + stats.engineStop(); + assertTrue(stats.getUpTime() >= 0); + + stats.engineStop(); + + stats.reset(); + + stats.setEventCount(-2); + stats.executionEnter(new AxArtifactKey()); + assertEquals(2, stats.getEventCount()); + + stats.setEventCount(10); + stats.executionEnter(new AxArtifactKey()); + assertEquals(11, stats.getEventCount()); + + stats.reset(); + stats.engineStart(); + stats.setEventCount(4); + stats.executionEnter(new AxArtifactKey()); + try { + Thread.sleep(10); + } catch (final Exception e) { + fail("test should not throw an exeption"); + } + stats.executionExit(); + final double avExecutionTime = stats.getAverageExecutionTime(); + System.err.println(avExecutionTime); + assertTrue(avExecutionTime >= 2.0 && avExecutionTime < 3.0); + stats.engineStop(); + + 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(); + + final AxEngineStats clonedStats = new AxEngineStats(stats); + assertEquals("AxEngineStats:(engineKey=AxReferenceKey:(parentKey", clonedStats.toString().substring(0, 50)); + + assertNotNull(stats.getKeys()); + + assertFalse(stats.hashCode() == 0); + + assertTrue(stats.equals(stats)); + assertTrue(stats.equals(clonedStats)); + assertFalse(stats.equals(null)); + assertFalse(stats.equals("Hello")); + assertFalse(stats.equals(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); + assertFalse(stats.equals(new AxEngineStats(statsKey))); + assertNotEquals(0, stats.compareTo(new AxEngineStats(statsKey))); + stats.setTimeStamp(0); + assertTrue(stats.equals(new AxEngineStats(statsKey))); + assertEquals(0, stats.compareTo(new AxEngineStats(statsKey))); + + stats.setEventCount(1); + assertFalse(stats.equals(new AxEngineStats(statsKey))); + assertNotEquals(0, stats.compareTo(new AxEngineStats(statsKey))); + stats.setEventCount(0); + assertTrue(stats.equals(new AxEngineStats(statsKey))); + assertEquals(0, stats.compareTo(new AxEngineStats(statsKey))); + + stats.setLastExecutionTime(1); + assertFalse(stats.equals(new AxEngineStats(statsKey))); + assertNotEquals(0, stats.compareTo(new AxEngineStats(statsKey))); + stats.setLastExecutionTime(0); + assertTrue(stats.equals(new AxEngineStats(statsKey))); + assertEquals(0, stats.compareTo(new AxEngineStats(statsKey))); + + stats.setAverageExecutionTime(1); + assertFalse(stats.equals(new AxEngineStats(statsKey))); + assertNotEquals(0, stats.compareTo(new AxEngineStats(statsKey))); + stats.setAverageExecutionTime(0); + assertTrue(stats.equals(new AxEngineStats(statsKey))); + assertEquals(0, stats.compareTo(new AxEngineStats(statsKey))); + + stats.setUpTime(1); + assertFalse(stats.equals(new AxEngineStats(statsKey))); + assertNotEquals(0, stats.compareTo(new AxEngineStats(statsKey))); + stats.setUpTime(0); + assertTrue(stats.equals(new AxEngineStats(statsKey))); + assertEquals(0, stats.compareTo(new AxEngineStats(statsKey))); + + stats.engineStart(); + assertFalse(stats.equals(new AxEngineStats(statsKey))); + final AxEngineStats newStats = new AxEngineStats(statsKey); + newStats.setTimeStamp(stats.getTimeStamp()); + assertFalse(stats.equals(newStats)); + assertNotEquals(0, stats.compareTo(newStats)); + stats.engineStop(); + stats.reset(); + assertTrue(stats.equals(new AxEngineStats(statsKey))); + assertEquals(0, stats.compareTo(new AxEngineStats(statsKey))); + } +} diff --git a/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/TestApexEngineModel.java b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/TestApexEngineModel.java new file mode 100644 index 000000000..c1e6f3f37 --- /dev/null +++ b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/TestApexEngineModel.java @@ -0,0 +1,102 @@ +/*- + * ============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 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.enginemodel.concepts.AxEngineModel; + +public class TestApexEngineModel { + private Connection connection; + TestApexModel testApexModel; + + @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(AxEngineModel.class, new TestApexEngineModelCreator()); + } + + @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 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 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" + + "********************************"; +} diff --git a/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/TestApexEngineModelCreator.java b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/TestApexEngineModelCreator.java new file mode 100644 index 000000000..4a4a0cc88 --- /dev/null +++ b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/TestApexEngineModelCreator.java @@ -0,0 +1,127 @@ +/*- + * ============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 TestApexEngineModelCreator implements TestApexModelCreator { + + @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; + } + + 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; + } +} -- cgit 1.2.3-korg