/** * @return {@link Resource} corresponding to this {@link ResourceFixture}'s attributes. */ public Resource buildResource() { return new ResourceConverter().fromProperties(buildResourceProperties()); }
/** * Get a string representation of this Resource. * * @param data the Resource we are serializing * @return a string representation */ public String toPropertyString(Resource data) { Properties properties = toProperties(data); return PropertyUtils.joinOnPipe(PropertyUtils.toMap(properties)); }
/** * return a string that can be used to name this configuration or null, if jndiLocation was not * specified. * * @param jndiLocation used to construct the id * @return a string that can be used to name this configuration or null, if jndiLocation was not * specified. * @see org.codehaus.cargo.container.configuration.entry.Resource#createIdFromJndiLocation(String) */ private static String createIdFromJndiLocationIfNotNull(String jndiLocation) { String id = null; if (jndiLocation != null) { id = createIdFromJndiLocation(jndiLocation); } return id; }
/** * @return String corresponding to this {@link ResourceFixture}'s attributes. */ public String buildResourcePropertyString() { ResourceConverter converter = new ResourceConverter(); return converter.toPropertyString(buildResource()); }
/** * Test string parsing. */ public void testGetParametersAsString() { String propertyString = "user=APP;CreateDatabase=create"; String driverPropertyString = ResourcePropertySet.PARAMETERS + "=" + propertyString; Resource ds = resourceConverter.fromPropertyString(driverPropertyString); try { assertEquals(propertyString, resourceConverter .getParametersAsASemicolonDelimitedString(ds)); } catch (ComparisonFailure e) { assertEquals("CreateDatabase=create;user=APP", resourceConverter .getParametersAsASemicolonDelimitedString(ds)); } }
/** * Parse properties and add any Resources to pending configuration. Resources will be found if * their property name starts with: {@link ResourcePropertySet#RESOURCE} */ protected void addResourcesFromProperties() { getLogger().debug("Searching properties for Resource definitions", this.getClass().getName()); for (Map.Entry<String, String> property : getProperties().entrySet()) { String propertyName = property.getKey(); if (propertyName.startsWith(ResourcePropertySet.RESOURCE)) { String resourceProperty = property.getValue(); getLogger().debug("Found Resource definition: value [" + resourceProperty + "]", this.getClass().getName()); Resource resource = new ResourceConverter().fromPropertyString(resourceProperty); getResources().add(resource); } } }
/** * Test the {@link Properties} constructor. */ public void testPropertiesConstructor() { Properties props = new Properties(); props.setProperty(ResourcePropertySet.RESOURCE_NAME, "jdbc/JiraDS"); props.setProperty(ResourcePropertySet.RESOURCE_TYPE, ConfigurationEntryType.XA_DATASOURCE); props.setProperty(ResourcePropertySet.RESOURCE_CLASS, "org.hsqldb.jdbcDriver"); props.setProperty(ResourcePropertySet.RESOURCE_ID, "JiraDS"); Resource ds = resourceConverter.fromProperties(props); assertEquals(0, ds.getParameters().size()); assertEquals(props, resourceConverter.toProperties(ds)); }
/** * Test get multiple parameters delimited by a semicolon. */ public void testMultipleParametersDelimitedBySemiColon() { Properties parameters = new Properties(); parameters.setProperty("user", "APP"); parameters.setProperty("CreateDatabase", "create"); String driverPropertyString = "user=APP;CreateDatabase=create"; String propertyString = ResourcePropertySet.PARAMETERS + "=" + driverPropertyString; Resource ds = resourceConverter.fromPropertyString(propertyString); assertEquals(parameters, ds.getParameters()); }
/** * Construct a Resource from a single String. Note that parameters can be nested as long as they * are semicolon delimited Example: <code>CreateDatabase=create;DatabaseName=TEST</code>. * * @param resourceInformation A string, really a list of properties, representing a Resource * @return Resource representing the string. * @see org.codehaus.cargo.container.internal.util.PropertyUtils#splitPropertiesOnPipe(String) */ public Resource fromPropertyString(String resourceInformation) { return fromProperties(PropertyUtils.splitPropertiesOnPipe(PropertyUtils .escapeBackSlashesIfNotNull(resourceInformation))); }
/** * Creates the test resource converter. {@inheritDoc} * @throws Exception If anything goes wrong. */ @Override public void setUp() throws Exception { super.setUp(); resourceConverter = new ResourceConverter(); }
resource.setId(createIdFromJndiLocationIfNotNull(name)); resource.setParameters(PropertyUtils.toMap(getParametersFromString( PropertyUtils.escapeBackSlashesIfNotNull(parametersAsASemicolonDelimitedString)))); return resource;
/** * Get a properties object containing all of the members of this Resource object. Note that * driver properties will be nested and delimited by a semicolon. * * @param data the Resource we are serializing * @return a properties object corresponding to this Resource */ public Properties toProperties(Resource data) { Properties properties = new Properties(); PropertyUtils.setPropertyIfNotNull(properties, ResourcePropertySet.RESOURCE_NAME, data .getName()); PropertyUtils.setPropertyIfNotNull(properties, ResourcePropertySet.RESOURCE_TYPE, data .getType()); PropertyUtils.setPropertyIfNotNull(properties, ResourcePropertySet.RESOURCE_CLASS, data .getClassName()); PropertyUtils.setPropertyIfNotNull(properties, ResourcePropertySet.RESOURCE_ID, data .getId()); PropertyUtils.setPropertyIfNotNull(properties, ResourcePropertySet.PARAMETERS, getParametersAsASemicolonDelimitedString(data)); return properties; }
/** * Test string parsing when the property has backslashes. */ public void testGetParametersAsStringContainingBackslashes() { String propertyString = "user=APP;path=c:\\users\\me"; String driverPropertyString = ResourcePropertySet.PARAMETERS + "=" + propertyString; Resource ds = resourceConverter.fromPropertyString(driverPropertyString); try { assertEquals(propertyString, resourceConverter .getParametersAsASemicolonDelimitedString(ds)); } catch (ComparisonFailure e) { assertEquals("path=c:\\users\\me;user=APP", resourceConverter .getParametersAsASemicolonDelimitedString(ds)); } }
/** * Test get empty parameters. */ public void testGetEmptyParameters() { String propertyString = ""; String driverPropertyString = ResourcePropertySet.PARAMETERS + "=" + propertyString; Resource ds = resourceConverter.fromPropertyString(driverPropertyString); assertEquals(0, ds.getParameters().size()); }
/** * Test that {@link ResourcePropertySet#RESOURCE_TYPE} sets * {@link ResourcePropertySet#RESOURCE_TYPE}. */ public void testXAResourceIsXAResource() { Properties props = new Properties(); props.setProperty(ResourcePropertySet.RESOURCE_TYPE, ConfigurationEntryType.XA_DATASOURCE); Resource ds = resourceConverter.fromProperties(props); assertEquals("javax.sql.XADataSource", ds.getType()); }