use of org.drools.compiler.I18nPerson in project drools by kiegroup.
the class I18nTest method testKieFileSystem.
@Test
public void testKieFileSystem() {
String str = "package org.drools.compiler.i18ntest;\n" + "import org.drools.compiler.I18nPerson;\n" + "\n" + "global java.util.List list;\n" + "rule \"名称 is 山田花子\"\n" + " when\n" + " p : I18nPerson( 名称 == \"山田花子\" )\n" + " then\n" + " list.add( \"名称は山田花子です\" );\n" + "end\n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", str);
ks.newKieBuilder(kfs).buildAll();
KieSession ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
List list = new ArrayList();
ksession.setGlobal("list", list);
I18nPerson i18nPerson = new I18nPerson();
i18nPerson.set名称("山田花子");
ksession.insert(i18nPerson);
ksession.fireAllRules();
assertTrue(list.contains("名称は山田花子です"));
ksession.dispose();
}
use of org.drools.compiler.I18nPerson in project drools by kiegroup.
the class I18nTest method readDrlInEncodingUtf8.
@Test
@Ignore("Fails because of JBRULES-3435. But the JBRULES-2853 part works fine. Support for i18n properties must be fixed in mvel")
public void readDrlInEncodingUtf8() throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("test_I18nPerson_utf8.drl", "UTF-8", getClass()), ResourceType.DRL);
if (kbuilder.hasErrors()) {
fail(kbuilder.getErrors().toString());
}
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
KieSession ksession = createKnowledgeSession(kbase);
List list = new ArrayList();
ksession.setGlobal("list", list);
I18nPerson i18nPerson = new I18nPerson();
i18nPerson.setGarçon("Value 1");
i18nPerson.setÉlève("Value 2");
i18nPerson.setИмя("Value 3");
i18nPerson.set名称("Value 4");
ksession.insert(i18nPerson);
ksession.fireAllRules();
assertTrue(list.contains("garçon"));
assertTrue(list.contains("élève"));
assertTrue(list.contains("имя"));
assertTrue(list.contains("名称"));
ksession.dispose();
}
use of org.drools.compiler.I18nPerson in project drools by kiegroup.
the class I18nTest method testKieModuleJar.
@Test
public void testKieModuleJar() {
String str = "package org.drools.compiler.i18ntest;\n" + "import org.drools.compiler.I18nPerson;\n" + "\n" + "global java.util.List list;\n" + "rule \"名称 is 山田花子\"\n" + " when\n" + " p : I18nPerson( 名称 == \"山田花子\" )\n" + " then\n" + " list.add( \"名称は山田花子です\" );\n" + "end\n";
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId("org.kie", "118ntest", "1.0.0");
byte[] jar = createKJar(ks, releaseId, null, str);
KieModule km = deployJar(ks, jar);
KieContainer kc = ks.newKieContainer(km.getReleaseId());
KieSession ksession = kc.newKieSession();
List list = new ArrayList();
ksession.setGlobal("list", list);
I18nPerson i18nPerson = new I18nPerson();
i18nPerson.set名称("山田花子");
ksession.insert(i18nPerson);
ksession.fireAllRules();
assertTrue(list.contains("名称は山田花子です"));
ksession.dispose();
}
use of org.drools.compiler.I18nPerson in project drools by kiegroup.
the class I18nTest method testNewClassPathResource.
@Test
public void testNewClassPathResource() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
// newClassPathResource without specifying encoding
kbuilder.add(ResourceFactory.newClassPathResource("test_I18nPerson_utf8_forTestNewClassPathResource.drl", getClass()), ResourceType.DRL);
if (kbuilder.hasErrors()) {
fail(kbuilder.getErrors().toString());
}
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
KieSession ksession = createKnowledgeSession(kbase);
List list = new ArrayList();
ksession.setGlobal("list", list);
I18nPerson i18nPerson = new I18nPerson();
i18nPerson.set名称("山田花子");
ksession.insert(i18nPerson);
ksession.fireAllRules();
assertTrue(list.contains("名称は山田花子です"));
ksession.dispose();
}
use of org.drools.compiler.I18nPerson in project drools by kiegroup.
the class I18nTest method readDrlInEncodingLatin1.
@Test
public void readDrlInEncodingLatin1() throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("test_I18nPerson_latin1.drl.latin1", "ISO-8859-1", getClass()), ResourceType.DRL);
if (kbuilder.hasErrors()) {
fail(kbuilder.getErrors().toString());
}
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
KieSession ksession = createKnowledgeSession(kbase);
List list = new ArrayList();
ksession.setGlobal("list", list);
I18nPerson i18nPerson = new I18nPerson();
i18nPerson.setGarçon("Value 1");
// i18nPerson.setÉlève("Value 2");
ksession.insert(i18nPerson);
ksession.fireAllRules();
assertTrue(list.contains("garçon"));
// assertTrue(list.contains("élève"));
ksession.dispose();
}
Aggregations