Search in sources :

Example 1 with I18nPerson

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();
}
Also used : I18nPerson(org.drools.compiler.I18nPerson) KieFileSystem(org.kie.api.builder.KieFileSystem) ArrayList(java.util.ArrayList) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 2 with I18nPerson

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();
}
Also used : I18nPerson(org.drools.compiler.I18nPerson) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) ArrayList(java.util.ArrayList) List(java.util.List) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with I18nPerson

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();
}
Also used : I18nPerson(org.drools.compiler.I18nPerson) ArrayList(java.util.ArrayList) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) ArrayList(java.util.ArrayList) List(java.util.List) ReleaseId(org.kie.api.builder.ReleaseId) KieModule(org.kie.api.builder.KieModule) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 4 with I18nPerson

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();
}
Also used : I18nPerson(org.drools.compiler.I18nPerson) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) ArrayList(java.util.ArrayList) List(java.util.List) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) Test(org.junit.Test)

Example 5 with I18nPerson

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();
}
Also used : I18nPerson(org.drools.compiler.I18nPerson) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) ArrayList(java.util.ArrayList) List(java.util.List) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)5 List (java.util.List)5 I18nPerson (org.drools.compiler.I18nPerson)5 Test (org.junit.Test)5 KieSession (org.kie.api.runtime.KieSession)5 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)3 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)3 KieServices (org.kie.api.KieServices)2 Ignore (org.junit.Ignore)1 KieFileSystem (org.kie.api.builder.KieFileSystem)1 KieModule (org.kie.api.builder.KieModule)1 ReleaseId (org.kie.api.builder.ReleaseId)1 KieContainer (org.kie.api.runtime.KieContainer)1