JUnit for evaluation test model generator 73/68873/1
authorliamfallon <liam.fallon@ericsson.com>
Tue, 25 Sep 2018 13:34:08 +0000 (14:34 +0100)
committerliamfallon <liam.fallon@ericsson.com>
Tue, 25 Sep 2018 13:36:11 +0000 (14:36 +0100)
Issue-ID: POLICY-1034
Change-Id: Ic8f9971d612dd5500c73f95e5cbbb786c5ad51f3
Signed-off-by: liamfallon <liam.fallon@ericsson.com>
testsuites/integration/integration-common/src/main/java/org/onap/policy/apex/testsuites/integration/common/model/EvalDomainModelFactory.java
testsuites/integration/integration-common/src/test/java/org/onap/policy/apex/testsuites/integration/common/model/EvalDomainModelFactoryTest.java [new file with mode: 0644]
testsuites/integration/integration-common/src/test/java/org/onap/policy/apex/testsuites/integration/common/model/SampleDomainModelFactoryTest.java [new file with mode: 0644]
testsuites/integration/integration-common/src/test/java/org/onap/policy/apex/testsuites/integration/common/model/SampleDomainModelSaverTest.java [new file with mode: 0644]

index 70d7235..db21463 100644 (file)
@@ -215,7 +215,7 @@ public class EvalDomainModelFactory {
         final AxTasks tasks = new AxTasks(new AxArtifactKey("Tasks", DEFAULT_VERSION));
 
         final AxLogicReader logicReader = new PolicyLogicReader().setLogicPackage(PACKAGE)
-                        .setDefaultLogic("EvalTask_Logic");
+                        .setDefaultLogic("EvalTaskLogic");
 
         final AxTask obTask = new AxTask(new AxArtifactKey("Task_Observe_0", DEFAULT_VERSION));
         obTask.duplicateInputFields(event0000.getParameterMap());
@@ -382,7 +382,7 @@ public class EvalDomainModelFactory {
                     final List<String> axLogicExecutorTypeList, final List<AxArtifactKey> defaultTaskList,
                     final List<Set<AxArtifactKey>> taskKeySetList) {
         final AxLogicReader logicReader = new PolicyLogicReader().setLogicPackage(PACKAGE)
-                        .setDefaultLogic("EvalState_Logic");
+                        .setDefaultLogic("EvalStateLogic");
 
         final AxState actState = new AxState(new AxReferenceKey(policyKey, "Act"));
         actState.setTrigger(inEventKeyList.get(THIRD_MEMBER));
@@ -459,7 +459,7 @@ public class EvalDomainModelFactory {
         final AxTasks tasks = new AxTasks(new AxArtifactKey("Tasks", DEFAULT_VERSION));
 
         final AxLogicReader logicReader = new PolicyLogicReader().setLogicPackage(PACKAGE)
-                        .setDefaultLogic("EvalTask_Logic");
+                        .setDefaultLogic("EvalTaskLogic");
 
         final AxTask eTask = new AxTask(new AxArtifactKey("Task_Event_0", DEFAULT_VERSION));
         eTask.duplicateInputFields(event0000.getParameterMap());
@@ -584,7 +584,7 @@ public class EvalDomainModelFactory {
                     final List<AxArtifactKey> outEventKeyList, final List<String> axLogicExecutorTypeList,
                     final List<AxArtifactKey> defaultTaskList, final List<Set<AxArtifactKey>> taskKeySetList) {
         final AxLogicReader logicReader = new PolicyLogicReader().setLogicPackage(PACKAGE)
-                        .setDefaultLogic("EvalState_Logic");
+                        .setDefaultLogic("EvalStateLogic");
 
         final AxState actionState = new AxState(new AxReferenceKey(policyKey, ACTION));
         actionState.setTrigger(inEventKeyList.get(2));
diff --git a/testsuites/integration/integration-common/src/test/java/org/onap/policy/apex/testsuites/integration/common/model/EvalDomainModelFactoryTest.java b/testsuites/integration/integration-common/src/test/java/org/onap/policy/apex/testsuites/integration/common/model/EvalDomainModelFactoryTest.java
new file mode 100644 (file)
index 0000000..5149c86
--- /dev/null
@@ -0,0 +1,45 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 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.testsuites.integration.common.model;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
+
+/**
+ * Test the evaluation domain model factory.
+ */
+public class EvalDomainModelFactoryTest {
+
+    @Test
+    public void testEvalDomainModelFactory() {
+        EvalDomainModelFactory edmf = new EvalDomainModelFactory();
+        assertNotNull(edmf);
+        
+        AxPolicyModel ecaPolicyModel = edmf.getEcaPolicyModel();
+        assertEquals("EvaluationPolicyModel_ECA:0.0.1", ecaPolicyModel.getId());
+        
+        AxPolicyModel oodaPolicyModel = edmf.getOodaPolicyModel();
+        assertEquals("EvaluationPolicyModel_OODA:0.0.1", oodaPolicyModel.getId());
+    }
+}
diff --git a/testsuites/integration/integration-common/src/test/java/org/onap/policy/apex/testsuites/integration/common/model/SampleDomainModelFactoryTest.java b/testsuites/integration/integration-common/src/test/java/org/onap/policy/apex/testsuites/integration/common/model/SampleDomainModelFactoryTest.java
new file mode 100644 (file)
index 0000000..406bec1
--- /dev/null
@@ -0,0 +1,54 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 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.testsuites.integration.common.model;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
+
+/**
+ * Test the evaluation domain model factory.
+ */
+public class SampleDomainModelFactoryTest {
+
+    @Test
+    public void testSampleDomainModelFactory() {
+        SampleDomainModelFactory sdmf = new SampleDomainModelFactory();
+        assertNotNull(sdmf);
+        
+        AxPolicyModel samplePolicyModel = sdmf.getSamplePolicyModel("JAVASCRIPT");
+        assertEquals("SamplePolicyModelJAVASCRIPT:0.0.1", samplePolicyModel.getId());
+        
+        samplePolicyModel = sdmf.getSamplePolicyModel("JAVA");
+        assertEquals("SamplePolicyModelJAVA:0.0.1", samplePolicyModel.getId());
+        
+        samplePolicyModel = sdmf.getSamplePolicyModel("JYTHON");
+        assertEquals("SamplePolicyModelJYTHON:0.0.1", samplePolicyModel.getId());
+        
+        samplePolicyModel = sdmf.getSamplePolicyModel("JRUBY");
+        assertEquals("SamplePolicyModelJRUBY:0.0.1", samplePolicyModel.getId());
+        
+        samplePolicyModel = sdmf.getSamplePolicyModel("MVEL");
+        assertEquals("SamplePolicyModelMVEL:0.0.1", samplePolicyModel.getId());
+    }
+}
diff --git a/testsuites/integration/integration-common/src/test/java/org/onap/policy/apex/testsuites/integration/common/model/SampleDomainModelSaverTest.java b/testsuites/integration/integration-common/src/test/java/org/onap/policy/apex/testsuites/integration/common/model/SampleDomainModelSaverTest.java
new file mode 100644 (file)
index 0000000..744f47d
--- /dev/null
@@ -0,0 +1,74 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 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.testsuites.integration.common.model;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Comparator;
+
+import org.junit.Test;
+
+/**
+ * Test the sample domain model saver.
+ */
+public class SampleDomainModelSaverTest {
+
+    @Test
+    public void testSampleDomainModelSaver() throws IOException {
+        try {
+            SampleDomainModelSaver.main(null);
+            fail("test should throw an exception");
+        } catch (Exception exc) {
+            assertEquals("java.lang.NullPointerException", exc.getClass().getCanonicalName());
+        }
+
+        String[] args0 =
+            { "two", "arguments" };
+
+        try {
+            SampleDomainModelSaver.main(args0);
+        } catch (Exception exc) {
+            fail("test should not throw an exception");
+        }
+
+        Path tempDirectory = Files.createTempDirectory("ApexModelTempDir");
+        String[] args1 =
+            { tempDirectory.toString() };
+
+        try {
+            SampleDomainModelSaver.main(args1);
+        } catch (Exception exc) {
+            fail("test should not throw an exception");
+        }
+
+        File tempDir = new File(tempDirectory.toString());
+        assertTrue(tempDir.isDirectory());
+        assertEquals(10, tempDir.listFiles().length);
+
+        Files.walk(tempDirectory).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
+    }
+}