From 62475a30ef2d425fe04df35ef2dac53c7ab5306a Mon Sep 17 00:00:00 2001 From: Parshad Patel Date: Fri, 16 Nov 2018 20:59:14 +0900 Subject: Rename test classes in apex-pdp Make test classes name consistence by putting 'Test' at end Issue-ID: POLICY-1263 Change-Id: I0179388d84826e698276a1995dd8173a40b5fd2b Signed-off-by: Parshad Patel --- .../test/distribution/ContextAlbumUpdateTest.java | 100 +++++++++ .../distribution/ContextInstantiationTest.java | 105 ++++++++++ .../test/distribution/ContextUpdateTest.java | 106 ++++++++++ .../SequentialContextInstantiationTest.java | 109 ++++++++++ .../test/distribution/TestContextAlbumUpdate.java | 100 --------- .../distribution/TestContextInstantiation.java | 105 ---------- .../test/distribution/TestContextUpdate.java | 106 ---------- .../TestSequentialContextInstantiation.java | 109 ---------- .../test/locking/ConcurrentContextTest.java | 181 +++++++++++++++++ .../test/locking/TestConcurrentContext.java | 181 ----------------- .../PersistentContextInstantiationTest.java | 224 +++++++++++++++++++++ .../TestPersistentContextInstantiation.java | 224 --------------------- 12 files changed, 825 insertions(+), 825 deletions(-) create mode 100644 context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/ContextAlbumUpdateTest.java create mode 100644 context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/ContextInstantiationTest.java create mode 100644 context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/ContextUpdateTest.java create mode 100644 context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/SequentialContextInstantiationTest.java delete mode 100644 context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/TestContextAlbumUpdate.java delete mode 100644 context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/TestContextInstantiation.java delete mode 100644 context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/TestContextUpdate.java delete mode 100644 context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/TestSequentialContextInstantiation.java create mode 100644 context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/locking/ConcurrentContextTest.java delete mode 100644 context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/locking/TestConcurrentContext.java create mode 100644 context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/persistence/PersistentContextInstantiationTest.java delete mode 100644 context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/persistence/TestPersistentContextInstantiation.java (limited to 'context/context-test-utils/src') diff --git a/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/ContextAlbumUpdateTest.java b/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/ContextAlbumUpdateTest.java new file mode 100644 index 000000000..218a8f9af --- /dev/null +++ b/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/ContextAlbumUpdateTest.java @@ -0,0 +1,100 @@ +/*- + * ============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.impl.schema.java.JavaSchemaHelperParameters; +import org.onap.policy.apex.context.parameters.ContextParameterConstants; +import org.onap.policy.apex.context.parameters.ContextParameters; +import org.onap.policy.apex.context.parameters.SchemaParameters; +import org.onap.policy.apex.model.basicmodel.concepts.ApexException; +import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; +import org.onap.policy.common.parameters.ParameterService; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +public class ContextAlbumUpdateTest { + // Logger for this class + private static final XLogger logger = XLoggerFactory.getXLogger(ContextAlbumUpdateTest.class); + + private SchemaParameters schemaParameters; + private ContextParameters contextParameters; + + /** + * Set up context data. + */ + @Before + public void beforeTest() { + contextParameters = new ContextParameters(); + + contextParameters.setName(ContextParameterConstants.MAIN_GROUP_NAME); + contextParameters.getDistributorParameters().setName(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); + contextParameters.getLockManagerParameters().setName(ContextParameterConstants.LOCKING_GROUP_NAME); + contextParameters.getPersistorParameters().setName(ContextParameterConstants.PERSISTENCE_GROUP_NAME); + + ParameterService.register(contextParameters); + ParameterService.register(contextParameters.getDistributorParameters()); + ParameterService.register(contextParameters.getLockManagerParameters()); + ParameterService.register(contextParameters.getPersistorParameters()); + + schemaParameters = new SchemaParameters(); + schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME); + schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters()); + + ParameterService.register(schemaParameters); + } + + /** + * Clear down context data. + */ + @After + public void afterTest() { + ParameterService.deregister(schemaParameters); + + ParameterService.deregister(contextParameters.getDistributorParameters()); + ParameterService.deregister(contextParameters.getLockManagerParameters()); + ParameterService.deregister(contextParameters.getPersistorParameters()); + ParameterService.deregister(contextParameters); + } + + @Test + public void testContextAlbumUpdateJvmLocalVarSet() throws ApexModelException, IOException, ApexException { + logger.debug("Running testContextAlbumUpdateJVMLocalVarSet test . . ."); + + 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 ContextAlbumUpdate().testContextAlbumUpdate(); + + logger.debug("Ran testContextAlbumUpdateJVMLocalVarNotSet test"); + } +} diff --git a/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/ContextInstantiationTest.java b/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/ContextInstantiationTest.java new file mode 100644 index 000000000..d635be441 --- /dev/null +++ b/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/ContextInstantiationTest.java @@ -0,0 +1,105 @@ +/*- + * ============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.impl.schema.java.JavaSchemaHelperParameters; +import org.onap.policy.apex.context.parameters.ContextParameterConstants; +import org.onap.policy.apex.context.parameters.ContextParameters; +import org.onap.policy.apex.context.parameters.SchemaParameters; +import org.onap.policy.apex.model.basicmodel.concepts.ApexException; +import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; +import org.onap.policy.common.parameters.ParameterService; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +/** + * The Class TestContextInstantiation. + * + * @author Sergey Sachkov (sergey.sachkov@ericsson.com) + */ +public class ContextInstantiationTest { + // Logger for this class + private static final XLogger logger = XLoggerFactory.getXLogger(ContextInstantiationTest.class); + + private SchemaParameters schemaParameters; + private ContextParameters contextParameters; + + /** + * Set up context for tests. + */ + @Before + public void beforeTest() { + contextParameters = new ContextParameters(); + + contextParameters.setName(ContextParameterConstants.MAIN_GROUP_NAME); + contextParameters.getDistributorParameters().setName(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); + contextParameters.getLockManagerParameters().setName(ContextParameterConstants.LOCKING_GROUP_NAME); + contextParameters.getPersistorParameters().setName(ContextParameterConstants.PERSISTENCE_GROUP_NAME); + + ParameterService.register(contextParameters); + ParameterService.register(contextParameters.getDistributorParameters()); + ParameterService.register(contextParameters.getLockManagerParameters()); + ParameterService.register(contextParameters.getPersistorParameters()); + + schemaParameters = new SchemaParameters(); + schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME); + schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters()); + + ParameterService.register(schemaParameters); + } + + /** + * Clear down context for tests. + */ + @After + public void afterTest() { + ParameterService.deregister(schemaParameters); + + ParameterService.deregister(contextParameters.getDistributorParameters()); + ParameterService.deregister(contextParameters.getLockManagerParameters()); + ParameterService.deregister(contextParameters.getPersistorParameters()); + ParameterService.deregister(contextParameters); + } + + @Test + public void testContextInstantiationJvmLocalVarSet() throws ApexModelException, IOException, ApexException { + logger.debug("Running testContextInstantiationJVMLocalVarSet test . . ."); + + 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 ContextInstantiation().testContextInstantiation(); + + logger.debug("Ran testContextInstantiationJVMLocalVarNotSet test"); + } +} diff --git a/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/ContextUpdateTest.java b/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/ContextUpdateTest.java new file mode 100644 index 000000000..0eaf591e3 --- /dev/null +++ b/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/ContextUpdateTest.java @@ -0,0 +1,106 @@ +/*- + * ============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.impl.schema.java.JavaSchemaHelperParameters; +import org.onap.policy.apex.context.parameters.ContextParameterConstants; +import org.onap.policy.apex.context.parameters.ContextParameters; +import org.onap.policy.apex.context.parameters.SchemaParameters; +import org.onap.policy.apex.model.basicmodel.concepts.ApexException; +import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; +import org.onap.policy.common.parameters.ParameterService; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +/** + * The Class TestContextUpdate. + * + * @author Sergey Sachkov (sergey.sachkov@ericsson.com) + */ +public class ContextUpdateTest { + // Logger for this class + private static final XLogger logger = XLoggerFactory.getXLogger(ContextUpdateTest.class); + + private SchemaParameters schemaParameters; + private ContextParameters contextParameters; + + /** + * Set up context for tests. + */ + @Before + public void beforeTest() { + contextParameters = new ContextParameters(); + + contextParameters.setName(ContextParameterConstants.MAIN_GROUP_NAME); + contextParameters.getDistributorParameters().setName(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); + contextParameters.getLockManagerParameters().setName(ContextParameterConstants.LOCKING_GROUP_NAME); + contextParameters.getPersistorParameters().setName(ContextParameterConstants.PERSISTENCE_GROUP_NAME); + + ParameterService.register(contextParameters); + ParameterService.register(contextParameters.getDistributorParameters()); + ParameterService.register(contextParameters.getLockManagerParameters()); + ParameterService.register(contextParameters.getPersistorParameters()); + + schemaParameters = new SchemaParameters(); + schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME); + schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters()); + + ParameterService.register(schemaParameters); + } + + /** + * Clear down context for tests. + */ + @After + public void afterTest() { + ParameterService.deregister(schemaParameters); + + ParameterService.deregister(contextParameters.getDistributorParameters()); + ParameterService.deregister(contextParameters.getLockManagerParameters()); + ParameterService.deregister(contextParameters.getPersistorParameters()); + ParameterService.deregister(contextParameters); + } + + @Test + public void testContextUpdateJvmLocalVarSet() throws ApexModelException, IOException, ApexException { + logger.debug("Running testContextUpdateJVMLocalVarSet test . . ."); + + 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 ContextUpdate().testContextUpdate(); + + logger.debug("Ran testContextUpdateJVMLocalVarNotSet test"); + } +} diff --git a/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/SequentialContextInstantiationTest.java b/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/SequentialContextInstantiationTest.java new file mode 100644 index 000000000..21ab6ef9e --- /dev/null +++ b/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/SequentialContextInstantiationTest.java @@ -0,0 +1,109 @@ +/*- + * ============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.impl.schema.java.JavaSchemaHelperParameters; +import org.onap.policy.apex.context.parameters.ContextParameterConstants; +import org.onap.policy.apex.context.parameters.ContextParameters; +import org.onap.policy.apex.context.parameters.SchemaParameters; +import org.onap.policy.apex.model.basicmodel.concepts.ApexException; +import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; +import org.onap.policy.common.parameters.ParameterService; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +/** + * The Class TestContextInstantiation. + * + * @author Sergey Sachkov (sergey.sachkov@ericsson.com) + */ +public class SequentialContextInstantiationTest { + // Logger for this class + private static final XLogger logger = XLoggerFactory.getXLogger(SequentialContextInstantiationTest.class); + + private SchemaParameters schemaParameters; + private ContextParameters contextParameters; + + /** + * Set up context for tests. + */ + @Before + public void beforeTest() { + contextParameters = new ContextParameters(); + + contextParameters.setName(ContextParameterConstants.MAIN_GROUP_NAME); + contextParameters.getDistributorParameters().setName(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); + contextParameters.getLockManagerParameters().setName(ContextParameterConstants.LOCKING_GROUP_NAME); + contextParameters.getPersistorParameters().setName(ContextParameterConstants.PERSISTENCE_GROUP_NAME); + + ParameterService.register(contextParameters); + ParameterService.register(contextParameters.getDistributorParameters()); + ParameterService.register(contextParameters.getLockManagerParameters()); + ParameterService.register(contextParameters.getPersistorParameters()); + + schemaParameters = new SchemaParameters(); + schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME); + schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters()); + + ParameterService.register(schemaParameters); + } + + /** + * Clear down context for tests. + */ + @After + public void afterTest() { + ParameterService.deregister(schemaParameters); + + ParameterService.deregister(contextParameters.getDistributorParameters()); + ParameterService.deregister(contextParameters.getLockManagerParameters()); + ParameterService.deregister(contextParameters.getPersistorParameters()); + ParameterService.deregister(contextParameters); + } + + @Test + public void testSequentialContextInstantiationJvmLocalVarSet() + throws ApexModelException, IOException, ApexException { + logger.debug("Running testSequentialContextInstantiationJVMLocalVarSet test . . ."); + + 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/distribution/TestContextAlbumUpdate.java b/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/TestContextAlbumUpdate.java deleted file mode 100644 index 54440370c..000000000 --- a/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/TestContextAlbumUpdate.java +++ /dev/null @@ -1,100 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.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.impl.schema.java.JavaSchemaHelperParameters; -import org.onap.policy.apex.context.parameters.ContextParameterConstants; -import org.onap.policy.apex.context.parameters.ContextParameters; -import org.onap.policy.apex.context.parameters.SchemaParameters; -import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; -import org.onap.policy.common.parameters.ParameterService; -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); - - private SchemaParameters schemaParameters; - private ContextParameters contextParameters; - - /** - * Set up context data. - */ - @Before - public void beforeTest() { - contextParameters = new ContextParameters(); - - contextParameters.setName(ContextParameterConstants.MAIN_GROUP_NAME); - contextParameters.getDistributorParameters().setName(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); - contextParameters.getLockManagerParameters().setName(ContextParameterConstants.LOCKING_GROUP_NAME); - contextParameters.getPersistorParameters().setName(ContextParameterConstants.PERSISTENCE_GROUP_NAME); - - ParameterService.register(contextParameters); - ParameterService.register(contextParameters.getDistributorParameters()); - ParameterService.register(contextParameters.getLockManagerParameters()); - ParameterService.register(contextParameters.getPersistorParameters()); - - schemaParameters = new SchemaParameters(); - schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME); - schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters()); - - ParameterService.register(schemaParameters); - } - - /** - * Clear down context data. - */ - @After - public void afterTest() { - ParameterService.deregister(schemaParameters); - - ParameterService.deregister(contextParameters.getDistributorParameters()); - ParameterService.deregister(contextParameters.getLockManagerParameters()); - ParameterService.deregister(contextParameters.getPersistorParameters()); - ParameterService.deregister(contextParameters); - } - - @Test - public void testContextAlbumUpdateJvmLocalVarSet() throws ApexModelException, IOException, ApexException { - logger.debug("Running testContextAlbumUpdateJVMLocalVarSet test . . ."); - - 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 ContextAlbumUpdate().testContextAlbumUpdate(); - - logger.debug("Ran testContextAlbumUpdateJVMLocalVarNotSet test"); - } -} 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 deleted file mode 100644 index ba402da24..000000000 --- a/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/TestContextInstantiation.java +++ /dev/null @@ -1,105 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.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.impl.schema.java.JavaSchemaHelperParameters; -import org.onap.policy.apex.context.parameters.ContextParameterConstants; -import org.onap.policy.apex.context.parameters.ContextParameters; -import org.onap.policy.apex.context.parameters.SchemaParameters; -import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; -import org.onap.policy.common.parameters.ParameterService; -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); - - private SchemaParameters schemaParameters; - private ContextParameters contextParameters; - - /** - * Set up context for tests. - */ - @Before - public void beforeTest() { - contextParameters = new ContextParameters(); - - contextParameters.setName(ContextParameterConstants.MAIN_GROUP_NAME); - contextParameters.getDistributorParameters().setName(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); - contextParameters.getLockManagerParameters().setName(ContextParameterConstants.LOCKING_GROUP_NAME); - contextParameters.getPersistorParameters().setName(ContextParameterConstants.PERSISTENCE_GROUP_NAME); - - ParameterService.register(contextParameters); - ParameterService.register(contextParameters.getDistributorParameters()); - ParameterService.register(contextParameters.getLockManagerParameters()); - ParameterService.register(contextParameters.getPersistorParameters()); - - schemaParameters = new SchemaParameters(); - schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME); - schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters()); - - ParameterService.register(schemaParameters); - } - - /** - * Clear down context for tests. - */ - @After - public void afterTest() { - ParameterService.deregister(schemaParameters); - - ParameterService.deregister(contextParameters.getDistributorParameters()); - ParameterService.deregister(contextParameters.getLockManagerParameters()); - ParameterService.deregister(contextParameters.getPersistorParameters()); - ParameterService.deregister(contextParameters); - } - - @Test - public void testContextInstantiationJvmLocalVarSet() throws ApexModelException, IOException, ApexException { - logger.debug("Running testContextInstantiationJVMLocalVarSet test . . ."); - - 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 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 deleted file mode 100644 index 8ef8bf005..000000000 --- a/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/TestContextUpdate.java +++ /dev/null @@ -1,106 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.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.impl.schema.java.JavaSchemaHelperParameters; -import org.onap.policy.apex.context.parameters.ContextParameterConstants; -import org.onap.policy.apex.context.parameters.ContextParameters; -import org.onap.policy.apex.context.parameters.SchemaParameters; -import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; -import org.onap.policy.common.parameters.ParameterService; -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); - - private SchemaParameters schemaParameters; - private ContextParameters contextParameters; - - /** - * Set up context for tests. - */ - @Before - public void beforeTest() { - contextParameters = new ContextParameters(); - - contextParameters.setName(ContextParameterConstants.MAIN_GROUP_NAME); - contextParameters.getDistributorParameters().setName(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); - contextParameters.getLockManagerParameters().setName(ContextParameterConstants.LOCKING_GROUP_NAME); - contextParameters.getPersistorParameters().setName(ContextParameterConstants.PERSISTENCE_GROUP_NAME); - - ParameterService.register(contextParameters); - ParameterService.register(contextParameters.getDistributorParameters()); - ParameterService.register(contextParameters.getLockManagerParameters()); - ParameterService.register(contextParameters.getPersistorParameters()); - - schemaParameters = new SchemaParameters(); - schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME); - schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters()); - - ParameterService.register(schemaParameters); - } - - /** - * Clear down context for tests. - */ - @After - public void afterTest() { - ParameterService.deregister(schemaParameters); - - ParameterService.deregister(contextParameters.getDistributorParameters()); - ParameterService.deregister(contextParameters.getLockManagerParameters()); - ParameterService.deregister(contextParameters.getPersistorParameters()); - ParameterService.deregister(contextParameters); - } - - @Test - public void testContextUpdateJvmLocalVarSet() throws ApexModelException, IOException, ApexException { - logger.debug("Running testContextUpdateJVMLocalVarSet test . . ."); - - 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 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 deleted file mode 100644 index d1cdc6d97..000000000 --- a/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/distribution/TestSequentialContextInstantiation.java +++ /dev/null @@ -1,109 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.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.impl.schema.java.JavaSchemaHelperParameters; -import org.onap.policy.apex.context.parameters.ContextParameterConstants; -import org.onap.policy.apex.context.parameters.ContextParameters; -import org.onap.policy.apex.context.parameters.SchemaParameters; -import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; -import org.onap.policy.common.parameters.ParameterService; -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); - - private SchemaParameters schemaParameters; - private ContextParameters contextParameters; - - /** - * Set up context for tests. - */ - @Before - public void beforeTest() { - contextParameters = new ContextParameters(); - - contextParameters.setName(ContextParameterConstants.MAIN_GROUP_NAME); - contextParameters.getDistributorParameters().setName(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); - contextParameters.getLockManagerParameters().setName(ContextParameterConstants.LOCKING_GROUP_NAME); - contextParameters.getPersistorParameters().setName(ContextParameterConstants.PERSISTENCE_GROUP_NAME); - - ParameterService.register(contextParameters); - ParameterService.register(contextParameters.getDistributorParameters()); - ParameterService.register(contextParameters.getLockManagerParameters()); - ParameterService.register(contextParameters.getPersistorParameters()); - - schemaParameters = new SchemaParameters(); - schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME); - schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters()); - - ParameterService.register(schemaParameters); - } - - /** - * Clear down context for tests. - */ - @After - public void afterTest() { - ParameterService.deregister(schemaParameters); - - ParameterService.deregister(contextParameters.getDistributorParameters()); - ParameterService.deregister(contextParameters.getLockManagerParameters()); - ParameterService.deregister(contextParameters.getPersistorParameters()); - ParameterService.deregister(contextParameters); - } - - @Test - public void testSequentialContextInstantiationJvmLocalVarSet() - throws ApexModelException, IOException, ApexException { - logger.debug("Running testSequentialContextInstantiationJVMLocalVarSet test . . ."); - - 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/ConcurrentContextTest.java b/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/locking/ConcurrentContextTest.java new file mode 100644 index 000000000..7274f0d57 --- /dev/null +++ b/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/locking/ConcurrentContextTest.java @@ -0,0 +1,181 @@ +/*- + * ============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 static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.onap.policy.apex.context.test.lock.modifier.LockType.WRITE_LOCK_SINGLE_VALUE_UPDATE; +import static org.onap.policy.apex.context.test.utils.Constants.TEST_VALUE; + +import java.util.Map; + +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.impl.locking.jvmlocal.JvmLocalLockManager; +import org.onap.policy.apex.context.impl.schema.java.JavaSchemaHelperParameters; +import org.onap.policy.apex.context.parameters.ContextParameterConstants; +import org.onap.policy.apex.context.parameters.ContextParameters; +import org.onap.policy.apex.context.parameters.SchemaParameters; +import org.onap.policy.apex.context.test.concepts.TestContextLongItem; +import org.onap.policy.apex.context.test.utils.ConfigrationProvider; +import org.onap.policy.apex.context.test.utils.ConfigrationProviderImpl; +import org.onap.policy.apex.context.test.utils.Constants; +import org.onap.policy.common.parameters.ParameterService; +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 ConcurrentContextTest { + + // Logger for this class + private static final XLogger logger = XLoggerFactory.getXLogger(ConcurrentContextTest.class); + + // Test parameters + private static final int ALBUM_SIZE = 16; + 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; + + private SchemaParameters schemaParameters; + private ContextParameters contextParameters; + + /** + * Set up context for tests. + */ + @Before + public void beforeTest() { + contextParameters = new ContextParameters(); + + contextParameters.setName(ContextParameterConstants.MAIN_GROUP_NAME); + contextParameters.getDistributorParameters().setName(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); + contextParameters.getLockManagerParameters().setName(ContextParameterConstants.LOCKING_GROUP_NAME); + contextParameters.getPersistorParameters().setName(ContextParameterConstants.PERSISTENCE_GROUP_NAME); + + ParameterService.register(contextParameters); + ParameterService.register(contextParameters.getDistributorParameters()); + ParameterService.register(contextParameters.getLockManagerParameters()); + ParameterService.register(contextParameters.getPersistorParameters()); + + schemaParameters = new SchemaParameters(); + schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME); + schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters()); + + ParameterService.register(schemaParameters); + } + + /** + * Clear down context for tests. + */ + @After + public void afterTest() { + ParameterService.deregister(schemaParameters); + + ParameterService.deregister(contextParameters.getDistributorParameters()); + ParameterService.deregister(contextParameters.getLockManagerParameters()); + ParameterService.deregister(contextParameters.getPersistorParameters()); + ParameterService.deregister(contextParameters); + } + + @Test + public void testConcurrentContextJvmLocalVarSet() throws Exception { + logger.debug("Running testConcurrentContextJVMLocalVarSet test . . ."); + + contextParameters.getLockManagerParameters().setPluginClass(JvmLocalLockManager.class.getCanonicalName()); + + final ConfigrationProvider configrationProvider = getConfigrationProvider("JVMLocalVarSet", + TEST_JVM_COUNT_SINGLE_JVM, TEST_THREAD_COUNT_SINGLE_JVM, TEST_THREAD_LOOPS); + + final ConcurrentContext concurrentContext = new ConcurrentContext(configrationProvider); + final Map result = concurrentContext.testConcurrentContext(); + + assertFalse(result.isEmpty()); + final int expected = TEST_JVM_COUNT_SINGLE_JVM * TEST_THREAD_COUNT_SINGLE_JVM * TEST_THREAD_LOOPS; + final TestContextLongItem actual = result.get(TEST_VALUE); + assertNotNull(actual); + assertEquals(expected, actual.getLongValue()); + + + logger.debug("Ran testConcurrentContextJVMLocalVarSet test"); + } + + @Test + public void testConcurrentContextJvmLocalNoVarSet() throws Exception { + logger.debug("Running testConcurrentContextJVMLocalNoVarSet test . . ."); + + final ConfigrationProvider configrationProvider = getConfigrationProvider("JVMLocalNoVarSet", + TEST_JVM_COUNT_SINGLE_JVM, TEST_THREAD_COUNT_SINGLE_JVM, TEST_THREAD_LOOPS); + + final ConcurrentContext concurrentContext = new ConcurrentContext(configrationProvider); + final Map result = concurrentContext.testConcurrentContext(); + + assertFalse(result.isEmpty()); + final int expected = TEST_JVM_COUNT_SINGLE_JVM * TEST_THREAD_COUNT_SINGLE_JVM * TEST_THREAD_LOOPS; + final TestContextLongItem actual = result.get(TEST_VALUE); + assertNotNull(actual); + assertEquals(expected, actual.getLongValue()); + + logger.debug("Ran testConcurrentContextJVMLocalNoVarSet test"); + } + + @Test + public void testConcurrentContextMultiJvmNoLock() throws Exception { + logger.debug("Running testConcurrentContextMultiJVMNoLock test . . ."); + + contextParameters.getDistributorParameters().setPluginClass(JvmLocalDistributor.class.getCanonicalName()); + contextParameters.getLockManagerParameters().setPluginClass(JvmLocalLockManager.class.getCanonicalName()); + + final ConfigrationProvider configrationProvider = getConfigrationProvider("testConcurrentContextMultiJVMNoLock", + TEST_JVM_COUNT_MULTI_JVM, TEST_THREAD_COUNT_MULTI_JVM, TEST_THREAD_LOOPS); + + final ConcurrentContext concurrentContext = new ConcurrentContext(configrationProvider); + final Map result = concurrentContext.testConcurrentContext(); + + // No concurrent map so result will be zero + assertFalse(result.isEmpty()); + final TestContextLongItem actual = result.get(TEST_VALUE); + assertNotNull(actual); + assertEquals(0, actual.getLongValue()); + + logger.debug("Ran testConcurrentContextMultiJVMNoLock test"); + } + + private ConfigrationProvider getConfigrationProvider(final String testType, final int jvmCount, + final int threadCount, final int threadLoops) { + return new ConfigrationProviderImpl(testType, jvmCount, threadCount, threadLoops, ALBUM_SIZE, + WRITE_LOCK_SINGLE_VALUE_UPDATE.getValue()) { + @Override + public Map getContextAlbumInitValues() { + final Map initValues = super.getContextAlbumInitValues(); + initValues.put(Constants.TEST_VALUE, new TestContextLongItem(0L)); + return initValues; + } + }; + } +} 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 deleted file mode 100644 index ed9aff0c1..000000000 --- a/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/locking/TestConcurrentContext.java +++ /dev/null @@ -1,181 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.context.test.locking; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.onap.policy.apex.context.test.lock.modifier.LockType.WRITE_LOCK_SINGLE_VALUE_UPDATE; -import static org.onap.policy.apex.context.test.utils.Constants.TEST_VALUE; - -import java.util.Map; - -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.impl.locking.jvmlocal.JvmLocalLockManager; -import org.onap.policy.apex.context.impl.schema.java.JavaSchemaHelperParameters; -import org.onap.policy.apex.context.parameters.ContextParameterConstants; -import org.onap.policy.apex.context.parameters.ContextParameters; -import org.onap.policy.apex.context.parameters.SchemaParameters; -import org.onap.policy.apex.context.test.concepts.TestContextLongItem; -import org.onap.policy.apex.context.test.utils.ConfigrationProvider; -import org.onap.policy.apex.context.test.utils.ConfigrationProviderImpl; -import org.onap.policy.apex.context.test.utils.Constants; -import org.onap.policy.common.parameters.ParameterService; -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 ALBUM_SIZE = 16; - 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; - - private SchemaParameters schemaParameters; - private ContextParameters contextParameters; - - /** - * Set up context for tests. - */ - @Before - public void beforeTest() { - contextParameters = new ContextParameters(); - - contextParameters.setName(ContextParameterConstants.MAIN_GROUP_NAME); - contextParameters.getDistributorParameters().setName(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); - contextParameters.getLockManagerParameters().setName(ContextParameterConstants.LOCKING_GROUP_NAME); - contextParameters.getPersistorParameters().setName(ContextParameterConstants.PERSISTENCE_GROUP_NAME); - - ParameterService.register(contextParameters); - ParameterService.register(contextParameters.getDistributorParameters()); - ParameterService.register(contextParameters.getLockManagerParameters()); - ParameterService.register(contextParameters.getPersistorParameters()); - - schemaParameters = new SchemaParameters(); - schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME); - schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters()); - - ParameterService.register(schemaParameters); - } - - /** - * Clear down context for tests. - */ - @After - public void afterTest() { - ParameterService.deregister(schemaParameters); - - ParameterService.deregister(contextParameters.getDistributorParameters()); - ParameterService.deregister(contextParameters.getLockManagerParameters()); - ParameterService.deregister(contextParameters.getPersistorParameters()); - ParameterService.deregister(contextParameters); - } - - @Test - public void testConcurrentContextJvmLocalVarSet() throws Exception { - logger.debug("Running testConcurrentContextJVMLocalVarSet test . . ."); - - contextParameters.getLockManagerParameters().setPluginClass(JvmLocalLockManager.class.getCanonicalName()); - - final ConfigrationProvider configrationProvider = getConfigrationProvider("JVMLocalVarSet", - TEST_JVM_COUNT_SINGLE_JVM, TEST_THREAD_COUNT_SINGLE_JVM, TEST_THREAD_LOOPS); - - final ConcurrentContext concurrentContext = new ConcurrentContext(configrationProvider); - final Map result = concurrentContext.testConcurrentContext(); - - assertFalse(result.isEmpty()); - final int expected = TEST_JVM_COUNT_SINGLE_JVM * TEST_THREAD_COUNT_SINGLE_JVM * TEST_THREAD_LOOPS; - final TestContextLongItem actual = result.get(TEST_VALUE); - assertNotNull(actual); - assertEquals(expected, actual.getLongValue()); - - - logger.debug("Ran testConcurrentContextJVMLocalVarSet test"); - } - - @Test - public void testConcurrentContextJvmLocalNoVarSet() throws Exception { - logger.debug("Running testConcurrentContextJVMLocalNoVarSet test . . ."); - - final ConfigrationProvider configrationProvider = getConfigrationProvider("JVMLocalNoVarSet", - TEST_JVM_COUNT_SINGLE_JVM, TEST_THREAD_COUNT_SINGLE_JVM, TEST_THREAD_LOOPS); - - final ConcurrentContext concurrentContext = new ConcurrentContext(configrationProvider); - final Map result = concurrentContext.testConcurrentContext(); - - assertFalse(result.isEmpty()); - final int expected = TEST_JVM_COUNT_SINGLE_JVM * TEST_THREAD_COUNT_SINGLE_JVM * TEST_THREAD_LOOPS; - final TestContextLongItem actual = result.get(TEST_VALUE); - assertNotNull(actual); - assertEquals(expected, actual.getLongValue()); - - logger.debug("Ran testConcurrentContextJVMLocalNoVarSet test"); - } - - @Test - public void testConcurrentContextMultiJvmNoLock() throws Exception { - logger.debug("Running testConcurrentContextMultiJVMNoLock test . . ."); - - contextParameters.getDistributorParameters().setPluginClass(JvmLocalDistributor.class.getCanonicalName()); - contextParameters.getLockManagerParameters().setPluginClass(JvmLocalLockManager.class.getCanonicalName()); - - final ConfigrationProvider configrationProvider = getConfigrationProvider("testConcurrentContextMultiJVMNoLock", - TEST_JVM_COUNT_MULTI_JVM, TEST_THREAD_COUNT_MULTI_JVM, TEST_THREAD_LOOPS); - - final ConcurrentContext concurrentContext = new ConcurrentContext(configrationProvider); - final Map result = concurrentContext.testConcurrentContext(); - - // No concurrent map so result will be zero - assertFalse(result.isEmpty()); - final TestContextLongItem actual = result.get(TEST_VALUE); - assertNotNull(actual); - assertEquals(0, actual.getLongValue()); - - logger.debug("Ran testConcurrentContextMultiJVMNoLock test"); - } - - private ConfigrationProvider getConfigrationProvider(final String testType, final int jvmCount, - final int threadCount, final int threadLoops) { - return new ConfigrationProviderImpl(testType, jvmCount, threadCount, threadLoops, ALBUM_SIZE, - WRITE_LOCK_SINGLE_VALUE_UPDATE.getValue()) { - @Override - public Map getContextAlbumInitValues() { - final Map initValues = super.getContextAlbumInitValues(); - initValues.put(Constants.TEST_VALUE, new TestContextLongItem(0L)); - return initValues; - } - }; - } -} diff --git a/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/persistence/PersistentContextInstantiationTest.java b/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/persistence/PersistentContextInstantiationTest.java new file mode 100644 index 000000000..6bd4a4d41 --- /dev/null +++ b/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/persistence/PersistentContextInstantiationTest.java @@ -0,0 +1,224 @@ +/*- + * ============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.impl.schema.java.JavaSchemaHelperParameters; +import org.onap.policy.apex.context.parameters.ContextParameterConstants; +import org.onap.policy.apex.context.parameters.ContextParameters; +import org.onap.policy.apex.context.parameters.SchemaParameters; +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.TestContextLongItem; +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; +import org.onap.policy.common.parameters.ParameterService; + +/** + * The Class TestContextInstantiation. + * + * @author Sergey Sachkov (sergey.sachkov@ericsson.com) + */ +public class PersistentContextInstantiationTest { + // Logger for this class + // private static final XLogger logger = + // XLoggerFactory.getXLogger(TestPersistentContextInstantiation.class); + + private Connection connection; + private SchemaParameters schemaParameters; + private ContextParameters contextParameters; + + @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(); + } + + /** + * Set up context for tests. + */ + @Before + public void beforeTest() { + contextParameters = new ContextParameters(); + + contextParameters.setName(ContextParameterConstants.MAIN_GROUP_NAME); + contextParameters.getDistributorParameters().setName(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); + contextParameters.getLockManagerParameters().setName(ContextParameterConstants.LOCKING_GROUP_NAME); + contextParameters.getPersistorParameters().setName(ContextParameterConstants.PERSISTENCE_GROUP_NAME); + + ParameterService.register(contextParameters); + ParameterService.register(contextParameters.getDistributorParameters()); + ParameterService.register(contextParameters.getLockManagerParameters()); + ParameterService.register(contextParameters.getPersistorParameters()); + + schemaParameters = new SchemaParameters(); + schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME); + schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters()); + + ParameterService.register(schemaParameters); + } + + /** + * Clear down context for tests. + */ + @After + public void afterTest() { + ParameterService.deregister(schemaParameters); + + ParameterService.deregister(contextParameters.getDistributorParameters()); + ParameterService.deregister(contextParameters.getLockManagerParameters()); + ParameterService.deregister(contextParameters.getPersistorParameters()); + ParameterService.deregister(contextParameters); + } + + @Test + public void testContextPersistentInstantiation() throws ApexModelException, IOException, ApexException { + + 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 testMap = new HashMap(); + testMap.put("key", "This is a policy context string"); + + final Map valueMap0 = new HashMap(); + valueMap0.put("TestPolicyContextItem000", new TestContextTreeMapItem(testMap)); + + contextAlbumForMap.putAll(valueMap0); + + assertEquals("This is a policy context string", + ((TestContextTreeMapItem) contextAlbumForMap.get("TestPolicyContextItem000")).getMapValue() + .get("key")); + + 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 valueMap1 = new HashMap(); + valueMap1.put("TestPolicyContextItem00A", tci00A); + + contextAlbumForDate.putAll(valueMap1); + + assertEquals(testDate, ((TestContextDateLocaleItem) contextAlbumForDate.get("TestPolicyContextItem00A")) + .getDateValue()); + assertEquals(true, ((TestContextDateLocaleItem) contextAlbumForDate.get("TestPolicyContextItem00A")).getDst()); + + 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 valueMap2 = new HashMap(); + 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(0xFFFFFFFFFFFFFFFFL, + ((TestContextLongItem) contextAlbumForLong.get("TestPolicyContextItem0031")).getLongValue()); + assertEquals(0xFFFFFFFFFFFFFFFEL, + ((TestContextLongItem) contextAlbumForLong.get("TestPolicyContextItem0032")).getLongValue()); + assertEquals(0xFFFFFFFFFFFFFFFDL, + ((TestContextLongItem) contextAlbumForLong.get("TestPolicyContextItem0033")).getLongValue()); + assertEquals(0xFFFFFFFFFFFFFFFCL, + ((TestContextLongItem) contextAlbumForLong.get("TestPolicyContextItem0034")).getLongValue()); + assertEquals(0xFFFFFFFFFFFFFFFBL, + ((TestContextLongItem) contextAlbumForLong.get("TestPolicyContextItem0035")).getLongValue()); + + contextAlbumForLong.flush(); + contextDistributor.clear(); + } +} 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 deleted file mode 100644 index a659326a0..000000000 --- a/context/context-test-utils/src/test/java/org/onap/policy/apex/context/test/persistence/TestPersistentContextInstantiation.java +++ /dev/null @@ -1,224 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.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.impl.schema.java.JavaSchemaHelperParameters; -import org.onap.policy.apex.context.parameters.ContextParameterConstants; -import org.onap.policy.apex.context.parameters.ContextParameters; -import org.onap.policy.apex.context.parameters.SchemaParameters; -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.TestContextLongItem; -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; -import org.onap.policy.common.parameters.ParameterService; - -/** - * 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; - private SchemaParameters schemaParameters; - private ContextParameters contextParameters; - - @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(); - } - - /** - * Set up context for tests. - */ - @Before - public void beforeTest() { - contextParameters = new ContextParameters(); - - contextParameters.setName(ContextParameterConstants.MAIN_GROUP_NAME); - contextParameters.getDistributorParameters().setName(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); - contextParameters.getLockManagerParameters().setName(ContextParameterConstants.LOCKING_GROUP_NAME); - contextParameters.getPersistorParameters().setName(ContextParameterConstants.PERSISTENCE_GROUP_NAME); - - ParameterService.register(contextParameters); - ParameterService.register(contextParameters.getDistributorParameters()); - ParameterService.register(contextParameters.getLockManagerParameters()); - ParameterService.register(contextParameters.getPersistorParameters()); - - schemaParameters = new SchemaParameters(); - schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME); - schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters()); - - ParameterService.register(schemaParameters); - } - - /** - * Clear down context for tests. - */ - @After - public void afterTest() { - ParameterService.deregister(schemaParameters); - - ParameterService.deregister(contextParameters.getDistributorParameters()); - ParameterService.deregister(contextParameters.getLockManagerParameters()); - ParameterService.deregister(contextParameters.getPersistorParameters()); - ParameterService.deregister(contextParameters); - } - - @Test - public void testContextPersistentInstantiation() throws ApexModelException, IOException, ApexException { - - 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 testMap = new HashMap(); - testMap.put("key", "This is a policy context string"); - - final Map valueMap0 = new HashMap(); - valueMap0.put("TestPolicyContextItem000", new TestContextTreeMapItem(testMap)); - - contextAlbumForMap.putAll(valueMap0); - - assertEquals("This is a policy context string", - ((TestContextTreeMapItem) contextAlbumForMap.get("TestPolicyContextItem000")).getMapValue() - .get("key")); - - 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 valueMap1 = new HashMap(); - valueMap1.put("TestPolicyContextItem00A", tci00A); - - contextAlbumForDate.putAll(valueMap1); - - assertEquals(testDate, ((TestContextDateLocaleItem) contextAlbumForDate.get("TestPolicyContextItem00A")) - .getDateValue()); - assertEquals(true, ((TestContextDateLocaleItem) contextAlbumForDate.get("TestPolicyContextItem00A")).getDst()); - - 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 valueMap2 = new HashMap(); - 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(0xFFFFFFFFFFFFFFFFL, - ((TestContextLongItem) contextAlbumForLong.get("TestPolicyContextItem0031")).getLongValue()); - assertEquals(0xFFFFFFFFFFFFFFFEL, - ((TestContextLongItem) contextAlbumForLong.get("TestPolicyContextItem0032")).getLongValue()); - assertEquals(0xFFFFFFFFFFFFFFFDL, - ((TestContextLongItem) contextAlbumForLong.get("TestPolicyContextItem0033")).getLongValue()); - assertEquals(0xFFFFFFFFFFFFFFFCL, - ((TestContextLongItem) contextAlbumForLong.get("TestPolicyContextItem0034")).getLongValue()); - assertEquals(0xFFFFFFFFFFFFFFFBL, - ((TestContextLongItem) contextAlbumForLong.get("TestPolicyContextItem0035")).getLongValue()); - - contextAlbumForLong.flush(); - contextDistributor.clear(); - } -} -- cgit 1.2.3-korg