@Test public void addAssetXLSDtableWithOwnConfigTest() { Resource resource = ResourceFactory.newClassPathResource("/data/resource.xls", getClass()); DecisionTableConfigurationImpl config = new DecisionTableConfigurationImpl(); config.setInputType(DecisionTableInputType.XLS); String worksheetName = "test-worksheet-name"; config.setWorksheetName(worksheetName); resource.setConfiguration(config); environment.addAsset(resource, ResourceType.DTABLE); verify(this.kbuilder).add(any(Resource.class), any(ResourceType.class)); } }
public DecisionTableConfigurationAdapter( org.drools.builder.DecisionTableConfiguration delegate ) { super.setResourceType(ResourceType.DTABLE); this.delegate = delegate; }
public ResourceConfiguration fromProperties(Properties prop) { super.fromProperties(prop); ((JaxbConfigurationImpl)delegate).setSystemId( prop.getProperty( "drools.jaxb.conf.systemId", null ) ); String classesStr = prop.getProperty( "drools.jaxb.conf.classes", "[]" ); classesStr = classesStr.substring( 1, classesStr.length()-1 ).trim(); List<String> classes = new ArrayList<String>(); if( classesStr != null && classesStr.length() > 1 ) { // can't use Arrays.asList() because have to trim() each element for( String clz : classesStr.split( "," ) ) { classes.add( clz.trim() ); } } ((JaxbConfigurationImpl)delegate).setClasses(classes); // how to deserialize Options from a properties file? String optsClass = prop.getProperty( "drools.jaxb.conf.opts.class", null ); if (optsClass != null) { try { Options xjcOpts = (Options) Class.forName( optsClass ).newInstance(); String optsLang = prop.getProperty( "drools.jaxb.conf.opts.lang", null ); if (optsLang != null) { xjcOpts.setSchemaLanguage( Language.valueOf(optsLang) ); } ((JaxbConfigurationImpl)delegate).setXjcOpts(xjcOpts); } catch (Exception e) { throw new RuntimeException(e); } } return this; }
public Properties toProperties() { Properties prop = super.toProperties(); prop.setProperty( DecisionTableConfigurationImpl.DROOLS_DT_TYPE, getInputType().toString() ); if( getWorksheetName() != null ) { prop.setProperty( DecisionTableConfigurationImpl.DROOLS_DT_WORKSHEET, getWorksheetName() ); } return prop; }
public ResourceConfiguration fromProperties(Properties prop) { super.fromProperties(prop); setInputType( DecisionTableInputType.valueOf( prop.getProperty( DecisionTableConfigurationImpl.DROOLS_DT_TYPE, DecisionTableInputType.XLS.toString() ) ) ); setWorksheetName( prop.getProperty( DecisionTableConfigurationImpl.DROOLS_DT_WORKSHEET, null ) ); return this; }
xsdResource.setConfiguration(new JaxbConfigurationImpl(xjcOptions, "test-system-id")); kh.addResource( xsdResource, ResourceType.XSD );
kbaseImpl.jaxbClasses = new ArrayList<List<String>>(); for ( JaxbConfigurationImpl conf : xsds ) { kbaseImpl.jaxbClasses.add( conf.getClasses() );
@Test public void addAssetCsvXlsReplaceConfigTest() { // config preserved ArgumentCaptor<ResourceConfiguration> resourceConfigCaptor = ArgumentCaptor.forClass(ResourceConfiguration.class); doThrow(new IllegalStateException("XLS resource not handled correctly!")).when(this.kbuilder).add(any(Resource.class), any(ResourceType.class)); Resource resource = ResourceFactory.newClassPathResource("/data/resource.xls", getClass()); DecisionTableConfigurationImpl config = new DecisionTableConfigurationImpl(); config.setInputType(DecisionTableInputType.CSV); String worksheetName = "test-worksheet-name"; config.setWorksheetName(worksheetName); resource.setConfiguration(config); // do method environment.addAsset(resource, ResourceType.DTABLE); verify(this.kbuilder).add(any(Resource.class), any(ResourceType.class), resourceConfigCaptor.capture()); ResourceConfiguration replacedConfig = resourceConfigCaptor.getValue(); assertTrue("Not a DecisionTableConfiguration, but a " + replacedConfig.getClass().getSimpleName(), replacedConfig instanceof DecisionTableConfiguration); assertEquals("Incorrect file type", DecisionTableInputType.XLS, ((DecisionTableConfiguration) replacedConfig).getInputType()); assertEquals("Worksheet name not preserved", worksheetName, ((DecisionTableConfiguration) replacedConfig).getWorksheetName()); }
public Properties toProperties() { Properties prop = super.toProperties(); prop.setProperty( "drools.jaxb.conf.systemId", getSystemId() ); prop.setProperty( "drools.jaxb.conf.classes", getClass().toString() ); Options xjcOpts = getXjcOpts(); if (xjcOpts != null) { // how to serialize Options to a property file??? prop.setProperty( "drools.jaxb.conf.opts.class", xjcOpts.getClass().getName() ); if (xjcOpts.getSchemaLanguage() != null) { prop.setProperty( "drools.jaxb.conf.opts.lang", xjcOpts.getSchemaLanguage().toString() ); } } return prop; }
if ( !childElements.isEmpty() ) { Element conf = childElements.get( 0 ); DecisionTableConfigurationImpl dtableConf = new DecisionTableConfigurationImpl(); INPUT_TYPE_ATTRIBUTE, inputType ); dtableConf.setInputType( DecisionTableInputType.valueOf(inputType) ); WORKSHEET_NAME_ATTRIBUTE, worksheetName ); dtableConf.setWorksheetName( worksheetName );