use of org.kie.api.builder.ReleaseId in project drools by kiegroup.
the class SecurityPolicyTest method testCustomAccumulate.
@Test
public void testCustomAccumulate() throws Exception {
String drl = "package org.foo.bar\n" + "rule testRule\n" + " when\n" + " Number() from accumulate(Object(), " + " init(System.exit(-1);), " + " action(System.exit(-1);), " + " reverse(System.exit(-1);), " + " result(0))\n" + " then\n" + "end";
try {
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write(ResourceFactory.newByteArrayResource(drl.getBytes()).setSourcePath("org/foo/bar/r1.drl"));
ks.newKieBuilder(kfs).buildAll();
ReleaseId releaseId = ks.getRepository().getDefaultReleaseId();
KieContainer kc = ks.newKieContainer(releaseId);
KieSession ksession = kc.newKieSession();
ksession.fireAllRules();
Assert.fail("The security policy for the rule should have prevented this from executing...");
} catch (ShouldHavePrevented e) {
Assert.fail("The security policy for the rule should have prevented this from executing...");
} catch (Exception e) {
// test succeeded. the policy in place prevented the rule from executing the System.exit().
}
}
use of org.kie.api.builder.ReleaseId in project drools by kiegroup.
the class DslExpansionTest method testDSLExpansion_MessageImplNPE.
@Test
public void testDSLExpansion_MessageImplNPE() throws Exception {
final KieServices ks = KieServices.Factory.get();
final ReleaseId releaseId = ks.newReleaseId("org.kie", "dsl-test", "1.0-SNAPSHOT");
final KieModuleModel kproj = ks.newKieModuleModel();
final KieFileSystem kfs = ks.newKieFileSystem();
kfs.writeKModuleXML(kproj.toXML()).writePomXML(generatePomXml(releaseId)).write("src/main/resources/KBase1/test-dsl.dsl", createDSL()).write("src/main/resources/KBase1/test-rule.dslr", createDRL());
final KieBuilder kieBuilder = ks.newKieBuilder(kfs);
final List<Message> messages = kieBuilder.buildAll().getResults().getMessages();
if (!messages.isEmpty()) {
for (final Message m : messages) {
System.out.println(m.getText());
}
}
assertTrue(messages.isEmpty());
}
use of org.kie.api.builder.ReleaseId in project drools by kiegroup.
the class WireChannelTest method testWireChannel.
@Test
public void testWireChannel() throws Exception {
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId("org.kie", "listener-test", "1.0-SNAPSHOT");
build(ks, releaseId);
KieContainer kieContainer = ks.newKieContainer(releaseId);
KieSession ksession = kieContainer.newKieSession();
ksession.fireAllRules();
assertEquals(1, channelMessages.size());
assertEquals("Test Message", channelMessages.get(0));
}
use of org.kie.api.builder.ReleaseId in project drools by kiegroup.
the class KieModuleRepoTest method newerVersionDeployOverwritesTest.
// 2. simultaneous deploy requests
// - multitenant UI
// - duplicate REST requests
@Test(timeout = 5000)
public void newerVersionDeployOverwritesTest() throws Exception {
// setup
final ReleaseIdImpl releaseId = new ReleaseIdImpl("org", "deployTwiceAfterUpdateDependency", "1.0-SNAPSHOT");
final InternalKieModule originalOldKieModule = new InternalKieModuleStub();
final ReleaseId dependentReleaseid = new ReleaseIdImpl("org", "deployTwiceAfterUpdate", "1.0-SNAPSHOT");
final KieContainerImpl kieContainer = createMockKieContainer(dependentReleaseid, kieModuleRepo);
// 1. deploy
kieModuleRepo.store(originalOldKieModule);
// 2. another project is dependent on this project
kieContainer.updateDependencyToVersion(releaseId, releaseId);
final InternalKieModule newKieModule = mock(InternalKieModule.class);
when(newKieModule.getReleaseId()).thenReturn(releaseId);
when(newKieModule.getCreationTimestamp()).thenReturn(10l);
final CyclicBarrier storeOperationBarrier = new CyclicBarrier(2);
final CyclicBarrier storeSerializationBarrier = new CyclicBarrier(2);
final CyclicBarrier threadsFinishedBarrier = new CyclicBarrier(3);
final Runnable deployRunnable = () -> {
waitFor(storeOperationBarrier);
// Second thread waits with store until the first one finishes with it.
if (Thread.currentThread().getName().equals("two")) {
waitFor(storeSerializationBarrier);
}
kieModuleRepo.store(newKieModule);
if (Thread.currentThread().getName().equals("one")) {
waitFor(storeSerializationBarrier);
}
waitFor(threadsFinishedBarrier);
};
final ExecutorService executor = Executors.newFixedThreadPool(2);
// 2. remove and redploy
final Thread deployThread = new Thread(deployRunnable);
deployThread.setName("one");
executor.submit(deployThread);
final Thread secondDeployThread = new Thread(deployRunnable);
secondDeployThread.setName("two");
executor.submit(secondDeployThread);
try {
waitFor(threadsFinishedBarrier);
} finally {
executor.shutdownNow();
}
// never gets this far, but this is a good check
final KieModule oldKieModule = kieModuleRepo.oldKieModules.get(releaseId);
final long oldKieModuleTimeStamp = ((InternalKieModule) oldKieModule).getCreationTimestamp();
final long originalKieModuleTimestamp = originalOldKieModule.getCreationTimestamp();
assertEquals("The old kie module in the repo is not the originally deployed module!", originalKieModuleTimestamp, oldKieModuleTimeStamp);
}
use of org.kie.api.builder.ReleaseId in project drools by kiegroup.
the class ReleaseIdTest method testDecendingSort.
@Test
public void testDecendingSort() {
List<ReleaseId> list = newUnsortedList();
list.sort(new ReleaseIdComparator(DESCENDING));
assertSame(gav7, list.get(0));
assertSame(gav6, list.get(1));
assertSame(gav5, list.get(2));
assertSame(gav4, list.get(3));
assertSame(gav3, list.get(4));
assertSame(gav2, list.get(5));
assertSame(gav1, list.get(6));
assertSame(gav0, list.get(7));
}
Aggregations