use of org.drools.core.io.impl.UrlResource 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.drools.core.io.impl.UrlResource in project drools by kiegroup.
the class ChangeSetTest method testXmlParser.
@Test
public void testXmlParser() 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://www.domain.com/test.drl' type='DRL' />";
str += " <resource source='http://www.domain.com/test.xls' type='DTABLE' >";
str += " <decisiontable-conf worksheet-name='sheet10' input-type='XLS' />";
str += " </resource>";
str += " </add> ";
str += "</change-set>";
StringReader reader = new StringReader(str);
ChangeSet changeSet = xmlReader.read(reader);
assertEquals(2, changeSet.getResourcesAdded().size());
UrlResource resource = (UrlResource) ((List) changeSet.getResourcesAdded()).get(0);
assertEquals("http://www.domain.com/test.drl", resource.getURL().toString());
assertEquals(ResourceType.DRL, resource.getResourceType());
resource = (UrlResource) ((List) changeSet.getResourcesAdded()).get(1);
assertEquals("http://www.domain.com/test.xls", resource.getURL().toString());
assertEquals(ResourceType.DTABLE, resource.getResourceType());
DecisionTableConfiguration dtConf = (DecisionTableConfiguration) resource.getConfiguration();
assertEquals(DecisionTableInputType.XLS, dtConf.getInputType());
}
use of org.drools.core.io.impl.UrlResource in project drools by kiegroup.
the class ResourceHandler method start.
public Object start(String uri, String localName, Attributes attrs, ExtensibleXmlParser parser) throws SAXException {
parser.startElementBuilder(localName, attrs);
final Collection collection = (Collection) parser.getParent();
String src = attrs.getValue("source");
String type = attrs.getValue("type");
String basicAuthentication = attrs.getValue("basicAuthentication");
String username = attrs.getValue("username");
String password = attrs.getValue("password");
String name = attrs.getValue("name");
String description = attrs.getValue("description");
String categories = attrs.getValue("categories");
emptyAttributeCheck(localName, "source", src, parser);
emptyAttributeCheck(localName, "type", type, parser);
InternalResource resource = null;
if (src.trim().startsWith("classpath:")) {
resource = new ClassPathResource(src.substring(src.indexOf(':') + 1), parser.getClassLoader());
} else {
resource = new UrlResource(src);
((UrlResource) resource).setBasicAuthentication(basicAuthentication);
((UrlResource) resource).setUsername(username);
((UrlResource) resource).setPassword(password);
}
resource.setResourceType(ResourceType.getResourceType(type));
resource.setSourcePath(name);
resource.setDescription(description);
resource.setCategories(categories);
return resource;
}
Aggregations