Search in sources :

Example 1 with ChangeSet

use of org.kie.internal.ChangeSet in project drools by kiegroup.

the class ChangeSetTest method testBasicAuthentication.

@Test
public void testBasicAuthentication() throws SAXException, IOException {
    KnowledgeBuilderConfigurationImpl conf = new KnowledgeBuilderConfigurationImpl();
    XmlChangeSetReader xmlReader = new XmlChangeSetReader(conf.getSemanticModules());
    xmlReader.setClassLoader(ChangeSetTest.class.getClassLoader(), ChangeSetTest.class);
    String str = "";
    str += "<change-set ";
    str += "xmlns='http://drools.org/drools-5.0/change-set' ";
    str += "xmlns:xs='http://www.w3.org/2001/XMLSchema-instance' ";
    str += "xs:schemaLocation='http://drools.org/drools-5.0/change-set http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-api/src/main/resources/change-set-1.0.0.xsd' >";
    str += "    <add> ";
    str += "        <resource source='http://localhost:8081/jboss-brms/org.kie.guvnor.Guvnor/package/defaultPackage/LATEST' type='PKG' basicAuthentication='enabled' username='admin' password='pwd'/>";
    str += "    </add> ";
    str += "</change-set>";
    StringReader reader = new StringReader(str);
    ChangeSet changeSet = xmlReader.read(reader);
    assertEquals(1, changeSet.getResourcesAdded().size());
    UrlResource resource = (UrlResource) ((List) changeSet.getResourcesAdded()).get(0);
    assertEquals("http://localhost:8081/jboss-brms/org.kie.guvnor.Guvnor/package/defaultPackage/LATEST", resource.getURL().toString());
    assertEquals("enabled", resource.getBasicAuthentication());
    assertEquals("admin", resource.getUsername());
    assertEquals("pwd", resource.getPassword());
    assertEquals(ResourceType.PKG, resource.getResourceType());
}
Also used : KnowledgeBuilderConfigurationImpl(org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl) UrlResource(org.drools.core.io.impl.UrlResource) StringReader(java.io.StringReader) XmlChangeSetReader(org.drools.core.xml.XmlChangeSetReader) ChangeSet(org.kie.internal.ChangeSet) Test(org.junit.Test)

Example 2 with ChangeSet

use of org.kie.internal.ChangeSet in project drools by kiegroup.

the class XmlChangeSetReaderTest method testResourceAttributes.

@Test
public void testResourceAttributes() throws Exception {
    SemanticModules semanticModules = new SemanticModules();
    semanticModules.addSemanticModule(new ChangeSetSemanticModule());
    XmlChangeSetReader changeSetReader = new XmlChangeSetReader(semanticModules);
    changeSetReader.setClassLoader(XmlChangeSetReaderTest.class.getClassLoader(), null);
    ChangeSet changeSet = changeSetReader.read(XmlChangeSetReaderTest.class.getClassLoader().getResourceAsStream("org/drools/core/xml/test-change-set.xml"));
    Assert.assertNotNull(changeSet);
    Collection<Resource> resourcesAdded = changeSet.getResourcesAdded();
    Assert.assertNotNull(resourcesAdded);
    Assert.assertEquals(4, resourcesAdded.size());
    InternalResource resource1 = null;
    InternalResource resource2 = null;
    InternalResource resource3 = null;
    InternalResource secureResource = null;
    for (Resource r : resourcesAdded) {
        InternalResource resource = (InternalResource) r;
        if (resource.getSourcePath() != null && resource.getSourcePath().equals("resource1")) {
            resource1 = resource;
        } else if (resource.getSourcePath() != null && resource.getSourcePath().equals("secureResource")) {
            secureResource = resource;
        } else if (resource.getSourcePath() == null && resource.getDescription() == null) {
            resource3 = resource;
        } else if (resource.getSourcePath() == null) {
            resource2 = resource;
        }
    }
    Assert.assertNotNull(resource1);
    Assert.assertNotNull(resource2);
    Assert.assertNotNull(resource3);
    Assert.assertNotNull(secureResource);
    Assert.assertNull(resource1.getDescription());
    Assert.assertEquals("another description", resource2.getDescription());
    Assert.assertEquals("some useful description", secureResource.getDescription());
    Assert.assertEquals(2, changeSetReader.getParser().getAttrs().getLength());
    Assert.assertEquals("DRL", changeSetReader.getParser().getAttrs().getValue("type"));
}
Also used : InternalResource(org.drools.core.io.internal.InternalResource) Resource(org.kie.api.io.Resource) InternalResource(org.drools.core.io.internal.InternalResource) ChangeSet(org.kie.internal.ChangeSet) Test(org.junit.Test)

Example 3 with ChangeSet

use of org.kie.internal.ChangeSet in project drools by kiegroup.

the class RemoveHandler method start.

public Object start(String uri, String localName, Attributes attrs, ExtensibleXmlParser parser) throws SAXException {
    parser.startElementBuilder(localName, attrs);
    final ChangeSet changeSet = (ChangeSet) parser.getParent();
    return new ArrayList();
}
Also used : ArrayList(java.util.ArrayList) ChangeSet(org.kie.internal.ChangeSet)

Example 4 with ChangeSet

use of org.kie.internal.ChangeSet in project drools by kiegroup.

the class ModifyHandler method start.

public Object start(String uri, String localName, Attributes attrs, ExtensibleXmlParser parser) throws SAXException {
    parser.startElementBuilder(localName, attrs);
    final ChangeSet changeSet = (ChangeSet) parser.getParent();
    return new ArrayList();
}
Also used : ArrayList(java.util.ArrayList) ChangeSet(org.kie.internal.ChangeSet)

Example 5 with ChangeSet

use of org.kie.internal.ChangeSet in project drools by kiegroup.

the class KnowledgeBuilderImpl method registerBuildResource.

public void registerBuildResource(final Resource resource, ResourceType type) {
    InternalResource ires = (InternalResource) resource;
    if (ires.getResourceType() == null) {
        ires.setResourceType(type);
    } else if (ires.getResourceType() != type) {
        addBuilderResult(new ResourceTypeDeclarationWarning(resource, ires.getResourceType(), type));
    }
    if (ResourceType.CHANGE_SET == type) {
        try {
            ChangeSet changeSet = parseChangeSet(resource);
            List<Resource> resources = new ArrayList<Resource>();
            resources.add(resource);
            for (Resource addedRes : changeSet.getResourcesAdded()) {
                resources.add(addedRes);
            }
            for (Resource modifiedRes : changeSet.getResourcesModified()) {
                resources.add(modifiedRes);
            }
            for (Resource removedRes : changeSet.getResourcesRemoved()) {
                resources.add(removedRes);
            }
            buildResources.push(resources);
        } catch (Exception e) {
            results.add(new DroolsError() {

                public String getMessage() {
                    return "Unable to register changeset resource " + resource;
                }

                public int[] getLines() {
                    return new int[0];
                }
            });
        }
    } else {
        buildResources.push(Collections.singletonList(resource));
    }
}
Also used : InternalResource(org.drools.core.io.internal.InternalResource) DroolsError(org.drools.compiler.compiler.DroolsError) BaseResource(org.drools.core.io.impl.BaseResource) DescrResource(org.drools.core.io.impl.DescrResource) ClassPathResource(org.drools.core.io.impl.ClassPathResource) Resource(org.kie.api.io.Resource) ReaderResource(org.drools.core.io.impl.ReaderResource) PMMLResource(org.drools.compiler.compiler.PMMLResource) InternalResource(org.drools.core.io.internal.InternalResource) ArrayList(java.util.ArrayList) ResourceTypeDeclarationWarning(org.drools.compiler.compiler.ResourceTypeDeclarationWarning) ChangeSet(org.kie.internal.ChangeSet) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ExpanderException(org.drools.compiler.lang.ExpanderException) DroolsParserException(org.drools.compiler.compiler.DroolsParserException) SAXException(org.xml.sax.SAXException)

Aggregations

ChangeSet (org.kie.internal.ChangeSet)8 ArrayList (java.util.ArrayList)5 StringReader (java.io.StringReader)3 InternalResource (org.drools.core.io.internal.InternalResource)3 XmlChangeSetReader (org.drools.core.xml.XmlChangeSetReader)3 Test (org.junit.Test)3 Resource (org.kie.api.io.Resource)3 KnowledgeBuilderConfigurationImpl (org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl)2 PMMLResource (org.drools.compiler.compiler.PMMLResource)2 BaseResource (org.drools.core.io.impl.BaseResource)2 ClassPathResource (org.drools.core.io.impl.ClassPathResource)2 DescrResource (org.drools.core.io.impl.DescrResource)2 ReaderResource (org.drools.core.io.impl.ReaderResource)2 UrlResource (org.drools.core.io.impl.UrlResource)2 IOException (java.io.IOException)1 Reader (java.io.Reader)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1 DroolsError (org.drools.compiler.compiler.DroolsError)1 DroolsParserException (org.drools.compiler.compiler.DroolsParserException)1