diff options
author | waqas.ikram <waqas.ikram@ericsson.com> | 2018-05-28 10:58:07 +0100 |
---|---|---|
committer | waqas.ikram <waqas.ikram@ericsson.com> | 2018-05-28 14:35:30 +0100 |
commit | 55d93a12cc5575c872724f48585304b5eec77fea (patch) | |
tree | ac5e44c5670bbcc5e68cceb1694f87348c371e1b /model/engine-model/src/test | |
parent | 6029d25f5f3ad43fe02ffe1a4beb1eda0a6ae5e3 (diff) |
Adding policy-model, model-api & engine-model
Change-Id: I56702b8f0953457d493f894d155b2a6ddc87b10c
Issue-ID: POLICY-856
Signed-off-by: waqas.ikram <waqas.ikram@ericsson.com>
Diffstat (limited to 'model/engine-model/src/test')
6 files changed, 750 insertions, 0 deletions
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<AxEngineModel> 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>(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<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; + } + + 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/META-INF/persistence.xml b/model/engine-model/src/test/resources/META-INF/persistence.xml new file mode 100644 index 000000000..717d1a540 --- /dev/null +++ b/model/engine-model/src/test/resources/META-INF/persistence.xml @@ -0,0 +1,71 @@ +<?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========================================================= +--> + +<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0"> + <persistence-unit name="DAOTest" transaction-type="RESOURCE_LOCAL"> + <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> + + <class>org.onap.policy.apex.model.basicmodel.dao.converters.CDATAConditioner</class> + <class>org.onap.policy.apex.model.basicmodel.dao.converters.UUID2String</class> + <class>org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey</class> + <class>org.onap.policy.apex.model.basicmodel.concepts.AxConcept</class> + <class>org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo</class> + <class>org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation</class> + <class>org.onap.policy.apex.model.basicmodel.concepts.AxModel</class> + <class>org.onap.policy.apex.model.basicmodel.concepts.TestEntity</class> + <class>org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema</class> + <class>org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas</class> + <class>org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum</class> + <class>org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums</class> + <class>org.onap.policy.apex.model.contextmodel.concepts.AxContextModel</class> + <class>org.onap.policy.apex.model.eventmodel.concepts.AxField</class> + <class>org.onap.policy.apex.model.eventmodel.concepts.AxInputField</class> + <class>org.onap.policy.apex.model.eventmodel.concepts.AxOutputField</class> + <class>org.onap.policy.apex.model.eventmodel.concepts.AxEvent</class> + <class>org.onap.policy.apex.model.eventmodel.concepts.AxEvents</class> + <class>org.onap.policy.apex.model.eventmodel.concepts.AxEventModel</class> + <class>org.onap.policy.apex.model.policymodel.concepts.AxLogic</class> + <class>org.onap.policy.apex.model.policymodel.concepts.AxTaskParameter</class> + <class>org.onap.policy.apex.model.policymodel.concepts.AxTaskLogic</class> + <class>org.onap.policy.apex.model.policymodel.concepts.AxTask</class> + <class>org.onap.policy.apex.model.policymodel.concepts.AxTasks</class> + <class>org.onap.policy.apex.model.policymodel.concepts.AxTaskSelectionLogic</class> + <class>org.onap.policy.apex.model.policymodel.concepts.AxStateFinalizerLogic</class> + <class>org.onap.policy.apex.model.policymodel.concepts.AxStateOutput</class> + <class>org.onap.policy.apex.model.policymodel.concepts.AxStateTaskReference</class> + <class>org.onap.policy.apex.model.policymodel.concepts.AxState</class> + <class>org.onap.policy.apex.model.policymodel.concepts.AxPolicy</class> + <class>org.onap.policy.apex.model.policymodel.concepts.AxPolicies</class> + <class>org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel</class> + <class>org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel</class> + <class>org.onap.policy.apex.model.enginemodel.concepts.AxEngineStats</class> + + <properties> + <property name="javax.persistence.jdbc.url" value="jdbc:derby:memory:apex_test" /> + <property name="javax.persistence.target-database" value="Derby" /> + <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" /> + + <property name="eclipselink.ddl-generation" value="drop-and-create-tables" /> + <property name="eclipselink.ddl-generation.output-mode" value="database" /> + <property name="eclipselink.logging.level" value="INFO" /> + </properties> + </persistence-unit> +</persistence> diff --git a/model/engine-model/src/test/resources/logback-test.xml b/model/engine-model/src/test/resources/logback-test.xml new file mode 100644 index 000000000..034511335 --- /dev/null +++ b/model/engine-model/src/test/resources/logback-test.xml @@ -0,0 +1,70 @@ +<?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="TRACE" 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> |