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());
}
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"));
}
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();
}
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();
}
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));
}
}
Aggregations