Version20ModelBuilder extends AbstractModelBuilder { public static File getControllerDefinitionFile(ControllerConfiguration config) throws ConfigurationException { if (config.getResourcePath().isEmpty()) { throw new ConfigurationException("Empty resource path configuration."); } try { URI uri = new URI(config.getResourcePath()); log.trace( "Converted controller definition file location from URI ''{0}''", uri.resolve(CONTROLLER_XML) ); return new File(uri.resolve(CONTROLLER_XML)); } catch (Throwable t) { String xmlPath = PathUtil.addSlashSuffix(config.getResourcePath()) + CONTROLLER_XML; log.trace("Applied legacy resource path conversion to non-compatible URI ''{0}''", xmlPath); return new File(xmlPath); } } Version20ModelBuilder(StatusCache cache, ControllerConfiguration config,
                               SensorBuilder<Version20ModelBuilder> sensorBuilder,
                               DeviceProtocolBuilder deviceProtocolBuilder,
                               CommandFactory commandFactory); static boolean checkControllerDefinitionExists(ControllerConfiguration config); static File getControllerDefinitionFile(ControllerConfiguration config); Map<String, String> getConfigurationProperties(); StatusCache getDeviceStateCache(); void setCommandListeners(List<DeployerCommandListener> listeners); void setSensorListeners(List<DeployerSensorListener> listeners); @Override boolean hasControllerDefinitionChanged(); final static String CONTROLLER_XML; }
@Test (expected = ConfigurationException.class) public void testGetControllerDefinitionFileEmptyString() throws Exception { ControllerConfiguration cc = new ControllerConfiguration(); cc.setResourcePath(""); File f = Version20ModelBuilder.getControllerDefinitionFile(cc); }
@Test (expected = IllegalArgumentException.class) public void testGetControllerDefinitionFileNull() throws Exception { ControllerConfiguration cc = new ControllerConfiguration(); cc.setResourcePath(null); Assert.fail("Setting null as resource path didn't throw exception"); File f = Version20ModelBuilder.getControllerDefinitionFile(cc); }
@Test public void testGetControllerDefinitionFileWhiteSpace() throws Exception { ControllerConfiguration cc = new ControllerConfiguration(); cc.setResourcePath("/My Path"); File f = Version20ModelBuilder.getControllerDefinitionFile(cc); Assert.assertTrue( "Expected '/My Path/" + Version20ModelBuilder.CONTROLLER_XML + "', got : '" + f.toString() + "'", f.toString().equals("/My Path/" + Version20ModelBuilder.CONTROLLER_XML) ); }
@Test public void testGetControllerDefinitionFileURIEncoding() throws Exception { ControllerConfiguration cc = new ControllerConfiguration(); cc.setResourcePath("/Test%20Path"); File f = Version20ModelBuilder.getControllerDefinitionFile(cc); Assert.assertTrue( "Expected '/Test%20Path/" + Version20ModelBuilder.CONTROLLER_XML + "', got : '" + f.toString() + "'", f.toString().equals("/Test%20Path/" + Version20ModelBuilder.CONTROLLER_XML) ); }
@Test public void testGetControllerDefinitionFileURLEncoding() throws Exception { ControllerConfiguration cc = new ControllerConfiguration(); cc.setResourcePath("/Test+Path"); File f = Version20ModelBuilder.getControllerDefinitionFile(cc); Assert.assertTrue( "Expected '/Test+Path/" + Version20ModelBuilder.CONTROLLER_XML + "', got : '" + f.toString() + "'", f.toString().equals("/Test+Path/" + Version20ModelBuilder.CONTROLLER_XML) ); }