use of org.drools.compiler.kie.builder.impl.InternalKieModule in project drools by kiegroup.
the class ChangeSetBuilderTest method testModified2.
@Test
public void testModified2() {
String drl1 = "package org.drools\n" + "rule \"Rule 1\" when\n" + " $m : Message( message == \"Hello World\" )\n" + "then\n" + "end\n" + "rule \"An updated rule\" when\n" + " $m : Message( message == \"Hello World\" )\n" + "then\n" + "end\n" + "rule \"A removed rule\" when\n" + " $m : Message( message == \"Hello World\" )\n" + "then\n" + "end\n";
String drl1_5 = "package org.drools\n" + "rule \"Rule 1\" when\n" + " $m : Message( message == \"Hello World\" )\n" + "then\n" + "end\n" + "rule \"An updated rule\" when\n" + " $m : Message( message == \"Good Bye World\" )\n" + "then\n" + "end\n" + "rule \"An added rule\" when\n" + " $m : Message( message == \"Good Bye World\" )\n" + "then\n" + "end\n";
String drl2 = "package org.drools\n" + "rule \"This is the name of rule 3\" when\n" + " $m : Message( message == \"Hello World\" )\n" + "then\n" + "end\n";
String drl3 = "package org.drools\n" + "rule \"Another dumb rule\" when\n" + " $m : Message( message == \"Good bye World\" )\n" + "then\n" + "end\n";
InternalKieModule kieJar1 = createKieJar(drl1, drl2);
InternalKieModule kieJar2 = createKieJar(drl1_5, null, drl3);
KieJarChangeSet changes = ChangeSetBuilder.build(kieJar1, kieJar2);
// System.out.println( builder.toProperties( changes ) );
String modifiedFile = (String) kieJar2.getFileNames().toArray()[0];
String addedFile = (String) kieJar2.getFileNames().toArray()[1];
String removedFile = (String) kieJar1.getFileNames().toArray()[1];
assertThat(changes.getChanges().size(), is(3));
ResourceChangeSet cs = changes.getChanges().get(removedFile);
assertThat(cs, not(nullValue()));
assertThat(cs.getChangeType(), is(ChangeType.REMOVED));
assertThat(cs.getChanges().size(), is(0));
cs = changes.getChanges().get(addedFile);
assertThat(cs, not(nullValue()));
assertThat(cs.getChangeType(), is(ChangeType.ADDED));
assertThat(cs.getChanges().size(), is(0));
cs = changes.getChanges().get(modifiedFile);
assertThat(cs, not(nullValue()));
assertThat(cs.getChangeType(), is(ChangeType.UPDATED));
// assertThat( cs.getChanges().size(), is(3) );
// assertThat( cs.getChanges().get( 0 ), is( new ResourceChange(ChangeType.ADDED, Type.RULE, "An added rule") ) );
// assertThat( cs.getChanges().get( 1 ), is( new ResourceChange(ChangeType.REMOVED, Type.RULE, "A removed rule") ) );
// assertThat( cs.getChanges().get( 2 ), is( new ResourceChange(ChangeType.UPDATED, Type.RULE, "An updated rule") ) );
}
use of org.drools.compiler.kie.builder.impl.InternalKieModule in project drools by kiegroup.
the class ChangeSetBuilderTest method createKieJar.
private InternalKieModule createKieJar(String... drls) {
InternalKieModule kieJar = mock(InternalKieModule.class);
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId("org.kie", "hello-world", "1.0-SNAPSHOT");
List<String> drlFs = new ArrayList<String>();
for (int i = 0; i < drls.length; i++) {
if (drls[i] != null) {
String fileName = "src/main/resources/org/pkg1/drlFile" + i + ".drl";
drlFs.add(fileName);
when(kieJar.getBytes(fileName)).thenReturn(drls[i].getBytes());
}
}
when(kieJar.getBytes(KieModuleModelImpl.KMODULE_JAR_PATH)).thenReturn(createKieProjectWithPackages(ks, releaseId).toXML().getBytes());
when(kieJar.getFileNames()).thenReturn(drlFs);
return (InternalKieModule) kieJar;
}
use of org.drools.compiler.kie.builder.impl.InternalKieModule in project drools by kiegroup.
the class ChangeSetBuilderTest method testModified.
@Test
public void testModified() {
String drl1 = "package org.drools\n" + "rule R1 when\n" + " $m : Message( message == \"Hello World\" )\n" + "then\n" + "end\n";
String drl2 = "package org.drools\n" + "rule R2 when\n" + " $m : Message( message == \"Hello World\" )\n" + "then\n" + "end\n";
String drl3 = "package org.drools\n" + "rule R3 when\n" + " $m : Message( message == \"Good bye World\" )\n" + "then\n" + "end\n";
InternalKieModule kieJar1 = createKieJar(drl1, drl2);
InternalKieModule kieJar2 = createKieJar(drl1, drl3);
KieJarChangeSet changes = ChangeSetBuilder.build(kieJar1, kieJar2);
String modifiedFile = (String) kieJar2.getFileNames().toArray()[1];
assertThat(changes.getChanges().size(), is(1));
ResourceChangeSet cs = changes.getChanges().get(modifiedFile);
assertThat(cs, not(nullValue()));
assertThat(cs.getChangeType(), is(ChangeType.UPDATED));
assertThat(cs.getChanges().size(), is(2));
assertThat(cs.getChanges().get(1), is(new ResourceChange(ChangeType.ADDED, Type.RULE, "R3")));
assertThat(cs.getChanges().get(0), is(new ResourceChange(ChangeType.REMOVED, Type.RULE, "R2")));
// ChangeSetBuilder builder = new ChangeSetBuilder();
// System.out.println( builder.toProperties( changes ) );
}
use of org.drools.compiler.kie.builder.impl.InternalKieModule in project drools by kiegroup.
the class KieHelper method createJar.
public static byte[] createJar(KieServices ks, ReleaseId releaseId, Resource... resources) {
KieFileSystem kfs = ks.newKieFileSystem().generateAndWritePomXML(releaseId);
for (int i = 0; i < resources.length; i++) {
if (resources[i] != null) {
kfs.write(resources[i]);
}
}
KieBuilder kieBuilder = ks.newKieBuilder(kfs);
((InternalKieBuilder) kieBuilder).buildAll(o -> true);
Results results = kieBuilder.getResults();
if (results.hasMessages(Message.Level.ERROR)) {
throw new IllegalStateException(results.getMessages(Message.Level.ERROR).toString());
}
InternalKieModule kieModule = (InternalKieModule) ks.getRepository().getKieModule(releaseId);
byte[] jar = kieModule.getBytes();
return jar;
}
use of org.drools.compiler.kie.builder.impl.InternalKieModule in project drools by kiegroup.
the class AbstractKieCiTest method createKieJar.
protected InternalKieModule createKieJar(KieServices ks, ReleaseId releaseId, String pomXml, boolean isdefault, String... rules) throws IOException {
KieFileSystem kfs = createKieFileSystemWithKProject(ks, isdefault);
kfs.writePomXML(pomXml);
for (String rule : rules) {
String file = "org/test/" + rule + ".drl";
kfs.write("src/main/resources/KBase1/" + file, createDRL(rule));
}
KieBuilder kieBuilder = ks.newKieBuilder(kfs);
assertTrue(kieBuilder.buildAll().getResults().getMessages().isEmpty());
return (InternalKieModule) kieBuilder.getKieModule();
}
Aggregations