use of org.drools.testcoverage.common.model.Primitives in project drools by kiegroup.
the class ArrayTest method testNotContainsLongArray.
@Test
public void testNotContainsLongArray() {
final KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("array-test", kieBaseTestConfiguration, getDrl("Long", true, "10"));
final KieSession kieSession = kbase.newKieSession();
try {
final List list = new ArrayList();
addGlobalsToSession(kieSession, list, 10L, new Long[] { 40L, 50L, 60L });
final Primitives p1 = new Primitives();
p1.setPrimitiveLongArray(new long[] { 40, 50, 60 });
p1.setLongPrimitive(5);
final Primitives p2 = new Primitives();
p2.setLongPrimitive(10);
p2.setPrimitiveLongArray(new long[] { 40, 50, 60 });
testArrayContains(kieSession, p1, p2, list);
} finally {
kieSession.dispose();
}
}
use of org.drools.testcoverage.common.model.Primitives in project drools by kiegroup.
the class ArrayTest method testNotContainsDoubleArray.
@Test
public void testNotContainsDoubleArray() {
final KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("array-test", kieBaseTestConfiguration, getDrl("Double", true, "10"));
final KieSession kieSession = kbase.newKieSession();
try {
final List list = new ArrayList();
addGlobalsToSession(kieSession, list, 10.0d, new Double[] { 40d, 50d, 60d });
final Primitives p1 = new Primitives();
p1.setPrimitiveDoubleArray(new double[] { 40, 50, 60 });
p1.setDoublePrimitive(5);
final Primitives p2 = new Primitives();
p2.setDoublePrimitive(10);
p2.setPrimitiveDoubleArray(new double[] { 40, 50, 60 });
testArrayContains(kieSession, p1, p2, list);
} finally {
kieSession.dispose();
}
}
use of org.drools.testcoverage.common.model.Primitives in project drools by kiegroup.
the class ArrayTest method testContainsFloatArray.
@Test
public void testContainsFloatArray() {
final KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("array-test", kieBaseTestConfiguration, getDrl("Float", false, "10f"));
final KieSession kieSession = kbase.newKieSession();
try {
final List list = new ArrayList();
addGlobalsToSession(kieSession, list, 10.0f, new Float[] { 5f, 10f, 20f });
final Primitives p1 = new Primitives();
p1.setFloatPrimitive(5);
p1.setPrimitiveFloatArray(new float[] { 5, 10, 20 });
final Primitives p2 = new Primitives();
p2.setFloatPrimitive(10);
p2.setPrimitiveFloatArray(new float[] { 5, 10, 20 });
testArrayContains(kieSession, p1, p2, list);
} finally {
kieSession.dispose();
}
}
use of org.drools.testcoverage.common.model.Primitives in project drools by kiegroup.
the class ArrayTest method testPrimitiveArray.
@Test
public void testPrimitiveArray() {
final String drl = "package org.drools.compiler\n" + "import " + Primitives.class.getCanonicalName() + "\n" + "global java.util.List result;\n" + "\n" + "function boolean testNonEmptyArray(int[] elements) {\n" + " return elements != null && elements.length > 0;\n" + "}\n" + "\n" + "function boolean isNonEmptyObjectArray(Object[] elements) {\n" + " return elements != null && elements.length > 0;\n" + "}\n" + "\n" + "rule \"Primitive elements in function\" salience 20\n" + " when\n" + " Primitives( $elements : primitiveIntArray )\n" + " eval( testNonEmptyArray($elements) )\n" + " then\n" + " result.add( new Integer( $elements.length ) );\n" + "end\n" + "\n" + "rule \"Primitive Array with Object in function\" salience 10\n" + " when\n" + " Primitives( $sArray : arrayAttribute )\n" + " eval( isNonEmptyObjectArray($sArray) )\n" + " then\n" + " result.add( new Integer( $sArray.length ) );\n" + "end\n" + "\n" + "rule \"Test Array\" salience 0\n" + " when\n" + " Primitives( $elements : primitiveIntArray, eval(($elements != null) && ($elements.length > 0)))\n" + " then\n" + " result.add( new Integer( $elements.length ) );\n" + "end";
final KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("array-test", kieBaseTestConfiguration, drl);
final KieSession session = kbase.newKieSession();
try {
final List result = new ArrayList();
session.setGlobal("result", result);
final Primitives p1 = new Primitives();
p1.setPrimitiveIntArray(new int[] { 1, 2, 3 });
p1.setArrayAttribute(new String[] { "a", "b" });
session.insert(p1);
session.fireAllRules();
assertEquals(3, result.size());
assertEquals(3, ((Integer) result.get(0)).intValue());
assertEquals(2, ((Integer) result.get(1)).intValue());
assertEquals(3, ((Integer) result.get(2)).intValue());
} finally {
session.dispose();
}
}
use of org.drools.testcoverage.common.model.Primitives in project drools by kiegroup.
the class ArrayTest method testContainsByteArray.
@Test
public void testContainsByteArray() {
final KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("array-test", kieBaseTestConfiguration, getDrl("Byte", false, "1"));
final KieSession kieSession = kbase.newKieSession();
try {
final List list = new ArrayList();
addGlobalsToSession(kieSession, list, (byte) 1, new Byte[] { 1, 2, 3 });
final Primitives p1 = new Primitives();
p1.setPrimitiveByteArray(new byte[] { 1, 2, 3 });
p1.setBytePrimitive((byte) 2);
final Primitives p2 = new Primitives();
p2.setPrimitiveByteArray(new byte[] { 1, 2, 3 });
p2.setBytePrimitive((byte) 1);
testArrayContains(kieSession, p1, p2, list);
} finally {
kieSession.dispose();
}
}
Aggregations