From 19257102e06ecea46c0c3a6ba2063a42e6c4231a Mon Sep 17 00:00:00 2001 From: Jorge Hernandez Date: Thu, 8 Feb 2018 13:35:44 -0600 Subject: programatic install of rules artifacts for junits instead of relying on pom.xml, build settings. since jenkins jobs that generate sonars don't seem to go through a build phase anymore, therefore the preceding artifacts are not available in the local repository, which is required by the tests. Change-Id: Icfd14b2f8a6c6e1ac7d986bd6eb977b2a83b044d Issue-ID: POLICY-621 Signed-off-by: Jorge Hernandez --- .../policy/drools/core/DroolsContainerTest.java | 27 +++++++++++++++++-- .../src/test/resources/drools-artifact-1.1/pom.xml | 31 ++++++++++++++++++++++ .../src/main/resources/META-INF/kmodule.xml | 6 +++++ .../src/main/resources/rules.drl | 30 +++++++++++++++++++++ .../src/test/resources/drools-artifact-1.2/pom.xml | 31 ++++++++++++++++++++++ .../src/main/resources/META-INF/kmodule.xml | 6 +++++ .../src/main/resources/rules.drl | 29 ++++++++++++++++++++ 7 files changed, 158 insertions(+), 2 deletions(-) create mode 100644 policy-core/src/test/resources/drools-artifact-1.1/pom.xml create mode 100644 policy-core/src/test/resources/drools-artifact-1.1/src/main/resources/META-INF/kmodule.xml create mode 100644 policy-core/src/test/resources/drools-artifact-1.1/src/main/resources/rules.drl create mode 100644 policy-core/src/test/resources/drools-artifact-1.2/pom.xml create mode 100644 policy-core/src/test/resources/drools-artifact-1.2/src/main/resources/META-INF/kmodule.xml create mode 100644 policy-core/src/test/resources/drools-artifact-1.2/src/main/resources/rules.drl (limited to 'policy-core/src/test') diff --git a/policy-core/src/test/java/org/onap/policy/drools/core/DroolsContainerTest.java b/policy-core/src/test/java/org/onap/policy/drools/core/DroolsContainerTest.java index a956075e..1da6e011 100644 --- a/policy-core/src/test/java/org/onap/policy/drools/core/DroolsContainerTest.java +++ b/policy-core/src/test/java/org/onap/policy/drools/core/DroolsContainerTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-core * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. 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. @@ -25,10 +25,12 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collection; - +import org.junit.BeforeClass; import org.junit.Test; +import org.onap.policy.drools.util.KieUtils; /** * These tests focus on the following classes: @@ -38,6 +40,27 @@ import org.junit.Test; */ public class DroolsContainerTest { + /** + * This test is centered around the creation of a 'PolicyContainer' + * and 'PolicySession', and the updating of that container to a new + * version. + */ + @BeforeClass + public static void setUp() throws Exception + { + KieUtils.installArtifact + (Paths.get("src/test/resources/drools-artifact-1.1/src/main/resources/META-INF/kmodule.xml").toFile(), + Paths.get("src/test/resources/drools-artifact-1.1/pom.xml").toFile(), + "src/main/resources/rules/org/onap/policy/drools/core/test/rules.drl", + Paths.get("src/test/resources/drools-artifact-1.1/src/main/resources/rules.drl").toFile()); + + KieUtils.installArtifact + (Paths.get("src/test/resources/drools-artifact-1.2/src/main/resources/META-INF/kmodule.xml").toFile(), + Paths.get("src/test/resources/drools-artifact-1.2/pom.xml").toFile(), + "src/main/resources/rules/org/onap/policy/drools/core/test/rules.drl", + Paths.get("src/test/resources/drools-artifact-1.2/src/main/resources/rules.drl").toFile()); + } + /** * This test is centered around the creation of a 'PolicyContainer' * and 'PolicySession', and the updating of that container to a new diff --git a/policy-core/src/test/resources/drools-artifact-1.1/pom.xml b/policy-core/src/test/resources/drools-artifact-1.1/pom.xml new file mode 100644 index 00000000..15e8ac28 --- /dev/null +++ b/policy-core/src/test/resources/drools-artifact-1.1/pom.xml @@ -0,0 +1,31 @@ + + + + + 4.0.0 + + org.onap.policy.drools-pdp + drools-artifact1 + 17.1.0-SNAPSHOT + supports Junit tests in policy-core + + diff --git a/policy-core/src/test/resources/drools-artifact-1.1/src/main/resources/META-INF/kmodule.xml b/policy-core/src/test/resources/drools-artifact-1.1/src/main/resources/META-INF/kmodule.xml new file mode 100644 index 00000000..22319689 --- /dev/null +++ b/policy-core/src/test/resources/drools-artifact-1.1/src/main/resources/META-INF/kmodule.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/policy-core/src/test/resources/drools-artifact-1.1/src/main/resources/rules.drl b/policy-core/src/test/resources/drools-artifact-1.1/src/main/resources/rules.drl new file mode 100644 index 00000000..9dac208b --- /dev/null +++ b/policy-core/src/test/resources/drools-artifact-1.1/src/main/resources/rules.drl @@ -0,0 +1,30 @@ +package org.onap.policy.drools.core.test; + +rule "Initialization" + when + then + { + System.out.println("Initialization rule running"); + } +end + +rule "Add elements of an int array" + when + $object : Object() + then + { + if ($object instanceof int[]) + { + int[] array = (int[])($object); + + System.out.println("Received array of length " + array.length); + int sum = 0; + for (int i = 1 ; i < array.length ; i += 1) + { + sum += array[i]; + } + array[0] = sum; + retract($object); + } + } +end diff --git a/policy-core/src/test/resources/drools-artifact-1.2/pom.xml b/policy-core/src/test/resources/drools-artifact-1.2/pom.xml new file mode 100644 index 00000000..0b78f847 --- /dev/null +++ b/policy-core/src/test/resources/drools-artifact-1.2/pom.xml @@ -0,0 +1,31 @@ + + + + + 4.0.0 + + org.onap.policy.drools-pdp + drools-artifact1 + 17.2.0-SNAPSHOT + supports Junit tests in policy-core + + diff --git a/policy-core/src/test/resources/drools-artifact-1.2/src/main/resources/META-INF/kmodule.xml b/policy-core/src/test/resources/drools-artifact-1.2/src/main/resources/META-INF/kmodule.xml new file mode 100644 index 00000000..22319689 --- /dev/null +++ b/policy-core/src/test/resources/drools-artifact-1.2/src/main/resources/META-INF/kmodule.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/policy-core/src/test/resources/drools-artifact-1.2/src/main/resources/rules.drl b/policy-core/src/test/resources/drools-artifact-1.2/src/main/resources/rules.drl new file mode 100644 index 00000000..e69b6597 --- /dev/null +++ b/policy-core/src/test/resources/drools-artifact-1.2/src/main/resources/rules.drl @@ -0,0 +1,29 @@ +package org.onap.policy.drools.core.test; + +rule "Initialization" + when + then + { + System.out.println("Initialization rule running"); + } +end + +rule "Multiply elements of an int array" + when + $object : Object() + then + { + if ($object instanceof int[]) + { + int[] array = (int[])($object); + + System.out.println("Received array of length " + array.length); + int product = 1; + for (int i = 1 ; i < array.length ; i += 1) + { + product *= array[i]; + } + array[0] = product; + } + } +end -- cgit 1.2.3-korg