summaryrefslogtreecommitdiffstats
path: root/context/context-test-utils/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'context/context-test-utils/src/test')
-rw-r--r--context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/TestContextAlbumUpdate.java65
-rw-r--r--context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/TestContextInstantiation.java75
-rw-r--r--context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/TestContextUpdate.java62
-rw-r--r--context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/TestSequentialContextInstantiation.java73
-rw-r--r--context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/locking/TestConcurrentContext.java96
-rw-r--r--context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/persistence/TestPersistentContextInstantiation.java185
-rw-r--r--context/context-test-utils/src/test/resources/META-INF/persistence.xml50
7 files changed, 606 insertions, 0 deletions
diff --git a/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/TestContextAlbumUpdate.java b/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/TestContextAlbumUpdate.java
new file mode 100644
index 000000000..105b59e8e
--- /dev/null
+++ b/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/TestContextAlbumUpdate.java
@@ -0,0 +1,65 @@
+/*-
+ * ============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.context.test.distribution;
+
+
+import java.io.IOException;
+
+import org.junit.After;
+import org.junit.Test;
+import org.onap.policy.apex.context.impl.distribution.jvmlocal.JVMLocalDistributor;
+import org.onap.policy.apex.context.parameters.ContextParameters;
+import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
+import org.onap.policy.apex.model.basicmodel.handling.ApexModelException;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
+public class TestContextAlbumUpdate {
+ // Logger for this class
+ private static final XLogger logger = XLoggerFactory.getXLogger(TestContextAlbumUpdate.class);
+
+ @Test
+ public void testContextAlbumUpdateJVMLocalVarSet() throws ApexModelException, IOException, ApexException {
+ logger.debug("Running testContextAlbumUpdateJVMLocalVarSet test . . .");
+
+ final ContextParameters contextParameters = new ContextParameters();
+ contextParameters.getDistributorParameters().setPluginClass(JVMLocalDistributor.class.getCanonicalName());
+ new ContextAlbumUpdate().testContextAlbumUpdate();
+
+ logger.debug("Ran testContextAlbumUpdateJVMLocalVarSet test");
+ }
+
+ @Test
+ public void testContextAlbumUpdateJVMLocalVarNotSet() throws ApexModelException, IOException, ApexException {
+ logger.debug("Running testContextAlbumUpdateJVMLocalVarNotSet test . . .");
+
+ new ContextParameters();
+ new ContextAlbumUpdate().testContextAlbumUpdate();
+
+ logger.debug("Ran testContextAlbumUpdateJVMLocalVarNotSet test");
+ }
+
+ /**
+ * Test context update cleardown.
+ */
+ @After
+ public void testContextAlbumUpdateCleardown() {}
+}
diff --git a/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/TestContextInstantiation.java b/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/TestContextInstantiation.java
new file mode 100644
index 000000000..565a39f97
--- /dev/null
+++ b/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/TestContextInstantiation.java
@@ -0,0 +1,75 @@
+/*-
+ * ============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.context.test.distribution;
+
+
+import java.io.IOException;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.apex.context.impl.distribution.jvmlocal.JVMLocalDistributor;
+import org.onap.policy.apex.context.parameters.ContextParameters;
+import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
+import org.onap.policy.apex.model.basicmodel.handling.ApexModelException;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
+/**
+ * The Class TestContextInstantiation.
+ *
+ * @author Sergey Sachkov (sergey.sachkov@ericsson.com)
+ */
+public class TestContextInstantiation {
+ // Logger for this class
+ private static final XLogger logger = XLoggerFactory.getXLogger(TestContextInstantiation.class);
+
+ @Before
+ public void beforeTest() {}
+
+ /**
+ * Test context instantiation clear down.
+ */
+ @After
+ public void afterTest() {}
+
+ @Test
+ public void testContextInstantiationJVMLocalVarSet() throws ApexModelException, IOException, ApexException {
+ logger.debug("Running testContextInstantiationJVMLocalVarSet test . . .");
+
+ final ContextParameters contextParameters = new ContextParameters();
+ contextParameters.getDistributorParameters().setPluginClass(JVMLocalDistributor.class.getCanonicalName());
+ new ContextInstantiation().testContextInstantiation();
+
+ logger.debug("Ran testContextInstantiationJVMLocalVarSet test");
+ }
+
+ @Test
+ public void testContextInstantiationJVMLocalVarNotSet() throws ApexModelException, IOException, ApexException {
+ logger.debug("Running testContextInstantiationJVMLocalVarNotSet test . . .");
+
+ new ContextParameters();
+ new ContextInstantiation().testContextInstantiation();
+
+ logger.debug("Ran testContextInstantiationJVMLocalVarNotSet test");
+ }
+
+}
diff --git a/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/TestContextUpdate.java b/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/TestContextUpdate.java
new file mode 100644
index 000000000..1a9bc29f1
--- /dev/null
+++ b/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/TestContextUpdate.java
@@ -0,0 +1,62 @@
+/*-
+ * ============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.context.test.distribution;
+
+import java.io.IOException;
+
+import org.junit.Test;
+import org.onap.policy.apex.context.impl.distribution.jvmlocal.JVMLocalDistributor;
+import org.onap.policy.apex.context.parameters.ContextParameters;
+import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
+import org.onap.policy.apex.model.basicmodel.handling.ApexModelException;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
+/**
+ * The Class TestContextUpdate.
+ *
+ * @author Sergey Sachkov (sergey.sachkov@ericsson.com)
+ */
+public class TestContextUpdate {
+ // Logger for this class
+ private static final XLogger logger = XLoggerFactory.getXLogger(TestContextUpdate.class);
+
+ @Test
+ public void testContextUpdateJVMLocalVarSet() throws ApexModelException, IOException, ApexException {
+ logger.debug("Running testContextUpdateJVMLocalVarSet test . . .");
+
+ final ContextParameters contextParameters = new ContextParameters();
+ contextParameters.getDistributorParameters().setPluginClass(JVMLocalDistributor.class.getCanonicalName());
+ new ContextUpdate().testContextUpdate();
+
+ logger.debug("Ran testContextUpdateJVMLocalVarSet test");
+ }
+
+ @Test
+ public void testContextUpdateJVMLocalVarNotSet() throws ApexModelException, IOException, ApexException {
+ logger.debug("Running testContextUpdateJVMLocalVarNotSet test . . .");
+
+ new ContextParameters();
+ new ContextUpdate().testContextUpdate();
+
+ logger.debug("Ran testContextUpdateJVMLocalVarNotSet test");
+ }
+}
diff --git a/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/TestSequentialContextInstantiation.java b/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/TestSequentialContextInstantiation.java
new file mode 100644
index 000000000..28bd7eb01
--- /dev/null
+++ b/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/TestSequentialContextInstantiation.java
@@ -0,0 +1,73 @@
+/*-
+ * ============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.context.test.distribution;
+
+
+import java.io.IOException;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.apex.context.impl.distribution.jvmlocal.JVMLocalDistributor;
+import org.onap.policy.apex.context.parameters.ContextParameters;
+import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
+import org.onap.policy.apex.model.basicmodel.handling.ApexModelException;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
+/**
+ * The Class TestContextInstantiation.
+ *
+ * @author Sergey Sachkov (sergey.sachkov@ericsson.com)
+ */
+public class TestSequentialContextInstantiation {
+ // Logger for this class
+ private static final XLogger logger = XLoggerFactory.getXLogger(TestSequentialContextInstantiation.class);
+
+ @Before
+ public void beforeTest() {}
+
+ @After
+ public void afterTest() {}
+
+ @Test
+ public void testSequentialContextInstantiationJVMLocalVarSet()
+ throws ApexModelException, IOException, ApexException {
+ logger.debug("Running testSequentialContextInstantiationJVMLocalVarSet test . . .");
+
+ final ContextParameters contextParameters = new ContextParameters();
+ contextParameters.getDistributorParameters().setPluginClass(JVMLocalDistributor.class.getCanonicalName());
+ new SequentialContextInstantiation().testSequentialContextInstantiation();
+
+ logger.debug("Ran testSequentialContextInstantiationJVMLocalVarSet test");
+ }
+
+ @Test
+ public void testSequentialContextInstantiationJVMLocalVarNotSet()
+ throws ApexModelException, IOException, ApexException {
+ logger.debug("Running testSequentialContextInstantiationJVMLocalVarNotSet test . . .");
+
+ new ContextParameters();
+ new SequentialContextInstantiation().testSequentialContextInstantiation();
+
+ logger.debug("Ran testSequentialContextInstantiationJVMLocalVarNotSet test");
+ }
+}
diff --git a/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/locking/TestConcurrentContext.java b/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/locking/TestConcurrentContext.java
new file mode 100644
index 000000000..7788fb411
--- /dev/null
+++ b/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/locking/TestConcurrentContext.java
@@ -0,0 +1,96 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.context.test.locking;
+
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+
+import org.junit.Test;
+import org.onap.policy.apex.context.impl.distribution.jvmlocal.JVMLocalDistributor;
+import org.onap.policy.apex.context.impl.locking.jvmlocal.JVMLocalLockManager;
+import org.onap.policy.apex.context.parameters.ContextParameters;
+import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
+import org.onap.policy.apex.model.basicmodel.handling.ApexModelException;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
+/**
+ * The Class TestConcurrentContext tests concurrent use of context.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class TestConcurrentContext {
+ // Logger for this class
+ private static final XLogger logger = XLoggerFactory.getXLogger(TestConcurrentContext.class);
+
+ // Test parameters
+ private static final int TEST_JVM_COUNT_SINGLE_JVM = 1;
+ private static final int TEST_JVM_COUNT_MULTI_JVM = 3;
+ private static final int TEST_THREAD_COUNT_SINGLE_JVM = 64;
+ private static final int TEST_THREAD_COUNT_MULTI_JVM = 20;
+ private static final int TEST_THREAD_LOOPS = 100;
+
+ @Test
+ public void testConcurrentContextJVMLocalVarSet() throws ApexModelException, IOException, ApexException {
+ logger.debug("Running testConcurrentContextJVMLocalVarSet test . . .");
+
+ final ContextParameters contextParameters = new ContextParameters();
+ contextParameters.getLockManagerParameters().setPluginClass(JVMLocalLockManager.class.getCanonicalName());
+ final long result = new ConcurrentContext().testConcurrentContext("JVMLocalVarSet", TEST_JVM_COUNT_SINGLE_JVM,
+ TEST_THREAD_COUNT_SINGLE_JVM, TEST_THREAD_LOOPS);
+
+ assertEquals(TEST_JVM_COUNT_SINGLE_JVM * TEST_THREAD_COUNT_SINGLE_JVM * TEST_THREAD_LOOPS, result);
+
+ logger.debug("Ran testConcurrentContextJVMLocalVarSet test");
+ }
+
+ @Test
+ public void testConcurrentContextJVMLocalNoVarSet() throws ApexModelException, IOException, ApexException {
+ logger.debug("Running testConcurrentContextJVMLocalNoVarSet test . . .");
+
+ new ContextParameters();
+ final long result = new ConcurrentContext().testConcurrentContext("JVMLocalNoVarSet", TEST_JVM_COUNT_SINGLE_JVM,
+ TEST_THREAD_COUNT_SINGLE_JVM, TEST_THREAD_LOOPS);
+
+ assertEquals(TEST_JVM_COUNT_SINGLE_JVM * TEST_THREAD_COUNT_SINGLE_JVM * TEST_THREAD_LOOPS, result);
+
+ logger.debug("Ran testConcurrentContextJVMLocalNoVarSet test");
+ }
+
+ @Test
+ public void testConcurrentContextMultiJVMNoLock() throws ApexModelException, IOException, ApexException {
+ logger.debug("Running testConcurrentContextMultiJVMNoLock test . . .");
+
+ final ContextParameters contextParameters = new ContextParameters();
+ contextParameters.getDistributorParameters().setPluginClass(JVMLocalDistributor.class.getCanonicalName());
+ contextParameters.getLockManagerParameters().setPluginClass(JVMLocalLockManager.class.getCanonicalName());
+
+ final long result = new ConcurrentContext().testConcurrentContext("testConcurrentContextMultiJVMNoLock",
+ TEST_JVM_COUNT_MULTI_JVM, TEST_THREAD_COUNT_MULTI_JVM, TEST_THREAD_LOOPS);
+
+ // No concurrent map so result will be zero
+ assertEquals(0, result);
+
+ logger.debug("Ran testConcurrentContextMultiJVMNoLock test");
+ }
+}
diff --git a/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/persistence/TestPersistentContextInstantiation.java b/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/persistence/TestPersistentContextInstantiation.java
new file mode 100644
index 000000000..a05928591
--- /dev/null
+++ b/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/persistence/TestPersistentContextInstantiation.java
@@ -0,0 +1,185 @@
+/*-
+ * ============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.context.test.persistence;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.File;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.TimeZone;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.apex.context.ContextAlbum;
+import org.onap.policy.apex.context.Distributor;
+import org.onap.policy.apex.context.impl.distribution.DistributorFactory;
+import org.onap.policy.apex.context.parameters.ContextParameters;
+import org.onap.policy.apex.context.parameters.PersistorParameters;
+import org.onap.policy.apex.context.test.concepts.TestContextLongItem;
+import org.onap.policy.apex.context.test.concepts.TestContextDateItem;
+import org.onap.policy.apex.context.test.concepts.TestContextDateLocaleItem;
+import org.onap.policy.apex.context.test.concepts.TestContextTreeMapItem;
+import org.onap.policy.apex.context.test.factory.TestContextAlbumFactory;
+import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.basicmodel.dao.ApexDao;
+import org.onap.policy.apex.model.basicmodel.dao.ApexDaoFactory;
+import org.onap.policy.apex.model.basicmodel.dao.DAOParameters;
+import org.onap.policy.apex.model.basicmodel.handling.ApexModelException;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum;
+import org.onap.policy.apex.model.contextmodel.concepts.AxContextModel;
+
+/**
+ * The Class TestContextInstantiation.
+ *
+ * @author Sergey Sachkov (sergey.sachkov@ericsson.com)
+ */
+public class TestPersistentContextInstantiation {
+ // Logger for this class
+ // private static final XLogger logger =
+ // XLoggerFactory.getXLogger(TestPersistentContextInstantiation.class);
+
+ private Connection connection;
+
+ @Before
+ public void setup() throws Exception {
+ Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
+ connection = DriverManager.getConnection("jdbc:derby:memory:apex_test;create=true");
+ }
+
+ @After
+ public void teardown() throws Exception {
+ connection.close();
+ new File("derby.log").delete();
+ }
+
+ @After
+ public void afterTest() throws IOException {}
+
+ @Test
+ public void testContextPersistentInstantiation() throws ApexModelException, IOException, ApexException {
+
+ final ContextParameters contextParameters = new ContextParameters();
+ contextParameters.setPersistorParameters(new PersistorParameters());
+
+ final AxArtifactKey distributorKey = new AxArtifactKey("AbstractDistributor", "0.0.1");
+ final Distributor contextDistributor = new DistributorFactory().getDistributor(distributorKey);
+
+ final AxArtifactKey[] usedArtifactStackArray = {new AxArtifactKey("testC-top", "0.0.1"),
+ new AxArtifactKey("testC-next", "0.0.1"), new AxArtifactKey("testC-bot", "0.0.1")};
+
+ final DAOParameters daoParameters = new DAOParameters();
+ daoParameters.setPluginClass("org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao");
+ daoParameters.setPersistenceUnit("DAOTest");
+ final ApexDao apexDao = new ApexDaoFactory().createApexDao(daoParameters);
+ apexDao.init(daoParameters);
+
+ final AxContextModel someContextModel = TestContextAlbumFactory.createMultiAlbumsContextModel();
+
+ // Context for Storing Map values
+ final AxContextAlbum axContextAlbumForMap =
+ someContextModel.getAlbums().getAlbumsMap().get(new AxArtifactKey("MapContextAlbum", "0.0.1"));
+ apexDao.create(axContextAlbumForMap);
+ contextDistributor.registerModel(someContextModel);
+ final ContextAlbum contextAlbumForMap = contextDistributor.createContextAlbum(axContextAlbumForMap.getKey());
+ assertNotNull(contextAlbumForMap);
+ contextAlbumForMap.setUserArtifactStack(usedArtifactStackArray);
+
+ final Map<String, String> testMap = new HashMap<String, String>();
+ testMap.put("key", "This is a policy context string");
+
+ final Map<String, Object> valueMap0 = new HashMap<String, Object>();
+ valueMap0.put("TestPolicyContextItem000", new TestContextTreeMapItem(testMap));
+
+ contextAlbumForMap.putAll(valueMap0);
+
+ assertEquals(((TestContextTreeMapItem) contextAlbumForMap.get("TestPolicyContextItem000")).getMapValue().get("key"),
+ "This is a policy context string");
+
+ contextAlbumForMap.flush();
+
+ // Context for Storing Date values
+ final AxContextAlbum axContextAlbumForDate =
+ someContextModel.getAlbums().getAlbumsMap().get(new AxArtifactKey("DateContextAlbum", "0.0.1"));
+ apexDao.create(axContextAlbumForDate);
+ contextDistributor.registerModel(someContextModel);
+ final ContextAlbum contextAlbumForDate = contextDistributor.createContextAlbum(axContextAlbumForDate.getKey());
+ assertNotNull(contextAlbumForDate);
+ contextAlbumForDate.setUserArtifactStack(usedArtifactStackArray);
+
+ final TestContextDateItem testDate = new TestContextDateItem(new Date());
+ final TestContextDateLocaleItem tci00A = new TestContextDateLocaleItem();
+ tci00A.setDateValue(testDate);
+ tci00A.setTZValue(TimeZone.getTimeZone("Europe/Dublin").toString());
+ tci00A.setDST(true);
+
+ final Map<String, Object> valueMap1 = new HashMap<String, Object>();
+ valueMap1.put("TestPolicyContextItem00A", tci00A);
+
+ contextAlbumForDate.putAll(valueMap1);
+
+ assertEquals(((TestContextDateLocaleItem) contextAlbumForDate.get("TestPolicyContextItem00A")).getDateValue(),
+ testDate);
+ assertEquals(((TestContextDateLocaleItem) contextAlbumForDate.get("TestPolicyContextItem00A")).getDST(), true);
+
+ contextAlbumForDate.flush();
+
+ // Context for Storing Long values
+ final AxContextAlbum axContextAlbumForLong =
+ someContextModel.getAlbums().getAlbumsMap().get(new AxArtifactKey("LTypeContextAlbum", "0.0.1"));
+ apexDao.create(axContextAlbumForLong);
+ contextDistributor.registerModel(someContextModel);
+ final ContextAlbum contextAlbumForLong = contextDistributor.createContextAlbum(axContextAlbumForLong.getKey());
+ assertNotNull(contextAlbumForLong);
+ contextAlbumForLong.setUserArtifactStack(usedArtifactStackArray);
+
+ final Map<String, Object> valueMap2 = new HashMap<String, Object>();
+ valueMap2.put("TestPolicyContextItem0031", new TestContextLongItem(0xFFFFFFFFFFFFFFFFL));
+ valueMap2.put("TestPolicyContextItem0032", new TestContextLongItem(0xFFFFFFFFFFFFFFFEL));
+ valueMap2.put("TestPolicyContextItem0033", new TestContextLongItem(0xFFFFFFFFFFFFFFFDL));
+ valueMap2.put("TestPolicyContextItem0034", new TestContextLongItem(0xFFFFFFFFFFFFFFFCL));
+ valueMap2.put("TestPolicyContextItem0035", new TestContextLongItem(0xFFFFFFFFFFFFFFFBL));
+
+ contextAlbumForLong.putAll(valueMap2);
+
+ assertEquals(((TestContextLongItem) contextAlbumForLong.get("TestPolicyContextItem0031")).getLongValue(),
+ 0xFFFFFFFFFFFFFFFFL);
+ assertEquals(((TestContextLongItem) contextAlbumForLong.get("TestPolicyContextItem0032")).getLongValue(),
+ 0xFFFFFFFFFFFFFFFEL);
+ assertEquals(((TestContextLongItem) contextAlbumForLong.get("TestPolicyContextItem0033")).getLongValue(),
+ 0xFFFFFFFFFFFFFFFDL);
+ assertEquals(((TestContextLongItem) contextAlbumForLong.get("TestPolicyContextItem0034")).getLongValue(),
+ 0xFFFFFFFFFFFFFFFCL);
+ assertEquals(((TestContextLongItem) contextAlbumForLong.get("TestPolicyContextItem0035")).getLongValue(),
+ 0xFFFFFFFFFFFFFFFBL);
+
+ contextAlbumForLong.flush();
+ contextDistributor.clear();
+
+ }
+}
diff --git a/context/context-test-utils/src/test/resources/META-INF/persistence.xml b/context/context-test-utils/src/test/resources/META-INF/persistence.xml
new file mode 100644
index 000000000..ec9357851
--- /dev/null
+++ b/context/context-test-utils/src/test/resources/META-INF/persistence.xml
@@ -0,0 +1,50 @@
+<?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>
+
+ <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>