Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add suitable config for running tests incontainer from an IDE
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@1688 1c488680-804c-0410-94cd-c6b725194a0e
- Loading branch information
Showing
8 changed files
with
475 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
233 changes: 233 additions & 0 deletions
233
...r/src/main/java/org/jboss/webbeans/tck/integration/jbossas/util/DeploymentProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,233 @@ | ||
package org.jboss.webbeans.tck.integration.jbossas.util; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.URL; | ||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Properties; | ||
import java.util.Set; | ||
|
||
import org.apache.log4j.Logger; | ||
|
||
/** | ||
* Utility class to load deployment properties | ||
* | ||
* @author Pete Muir | ||
*/ | ||
public class DeploymentProperties | ||
{ | ||
// The resource bundle used to control Web Beans RI deployment | ||
public static final String RESOURCE_BUNDLE = "META-INF/web-beans-tck.properties"; | ||
|
||
private static final Logger log = Logger.getLogger(DeploymentProperties.class); | ||
|
||
// The class to work from | ||
private SimpleResourceLoader resourceLoader; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param classLoader The classloader to work on | ||
*/ | ||
public DeploymentProperties() | ||
{ | ||
this.resourceLoader = new SimpleResourceLoader(); | ||
} | ||
|
||
/** | ||
* Get a list of possible values for a given key. | ||
* | ||
* First, System properties are tried, followed by the specified resource | ||
* bundle (first in classpath only). | ||
* | ||
* @param key The key to search for | ||
* @return A list of possible values. An empty list is returned if there are | ||
* no matches. | ||
*/ | ||
public List<String> getPropertyValues(String key) | ||
{ | ||
List<String> values = new ArrayList<String>(); | ||
addPropertiesFromSystem(key, values); | ||
addPropertiesFromResourceBundle(key, values); | ||
return values; | ||
} | ||
|
||
/** | ||
* Adds matches from system properties | ||
* | ||
* @param key The key to match | ||
* @param values The currently found values | ||
*/ | ||
private void addPropertiesFromSystem(String key, List<String> values) | ||
{ | ||
addProperty(key, System.getProperty(key), values); | ||
} | ||
|
||
/** | ||
* Adds matches from detected resource bundles | ||
* | ||
* @param key The key to match | ||
* @param values The currently found values | ||
*/ | ||
private void addPropertiesFromResourceBundle(String key, List<String> values) | ||
{ | ||
try | ||
{ | ||
for (URL url : resourceLoader.getResources(RESOURCE_BUNDLE)) | ||
{ | ||
Properties properties = new Properties(); | ||
InputStream propertyStream = url.openStream(); | ||
try | ||
{ | ||
properties.load(propertyStream); | ||
addProperty(key, properties.getProperty(key), values); | ||
} | ||
finally | ||
{ | ||
if (propertyStream != null) | ||
{ | ||
propertyStream.close(); | ||
} | ||
} | ||
} | ||
} | ||
catch (IOException e) | ||
{ | ||
// No - op, file is optional | ||
} | ||
} | ||
|
||
/** | ||
* Add the property to the set of properties only if it hasn't already been | ||
* added | ||
* | ||
* @param key The key searched for | ||
* @param value The value of the property | ||
* @param values The currently found values | ||
*/ | ||
private void addProperty(String key, String value, List<String> values) | ||
{ | ||
if (value != null) | ||
{ | ||
values.add(value); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* Gets the possible implementation class for a given property for which the | ||
* values are classanames | ||
* | ||
* @param deploymentProperties The deployment properties object to use | ||
* @param resourceLoader The resource laoder to use to attempt | ||
* @param propertyName The name of the property to load | ||
* @return A set of classes specified | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
public <T> Set<Class<T>> getClasses(String propertyName, Class<T> expectedType) | ||
{ | ||
Set<Class<T>> classes = new HashSet<Class<T>>(); | ||
for (String className : getPropertyValues(propertyName)) | ||
{ | ||
try | ||
{ | ||
classes.add((Class<T>) resourceLoader.classForName(className)); | ||
} | ||
catch (ResourceLoadingException e) | ||
{ | ||
//log.debug("Unable to load class " + className + " for property " + propertyName, e); | ||
} | ||
} | ||
return classes; | ||
} | ||
|
||
public <T> Class<T> getClassValue(String propertyName, Class<T> expectedType, boolean required) | ||
{ | ||
Set<Class<T>> classes = getClasses(propertyName, expectedType); | ||
if (classes.size() == 0) | ||
{ | ||
if (required) | ||
{ | ||
throw new IllegalArgumentException("Cannot find any implementations of " + expectedType.getSimpleName() + ", check that " + propertyName + " is specified"); | ||
} | ||
else | ||
{ | ||
return null; | ||
} | ||
} | ||
else if (classes.size() > 1) | ||
{ | ||
throw new IllegalArgumentException("More than one implementation of " + expectedType.getSimpleName() + " specified by " + propertyName + ", not sure which one to use!"); | ||
} | ||
else | ||
{ | ||
return classes.iterator().next(); | ||
} | ||
} | ||
|
||
public <T> T getInstanceValue(String propertyName, Class<T> expectedType, boolean required) | ||
{ | ||
Class<T> clazz = getClassValue(propertyName, expectedType, required); | ||
if (clazz != null) | ||
{ | ||
try | ||
{ | ||
return clazz.newInstance(); | ||
} | ||
catch (InstantiationException e) | ||
{ | ||
throw new IllegalStateException("Error instantiating " + clazz + " specified by " + propertyName, e); | ||
} | ||
catch (IllegalAccessException e) | ||
{ | ||
throw new IllegalStateException("Error instantiating " + clazz + " specified by " + propertyName, e); | ||
} | ||
} | ||
else | ||
{ | ||
return null; | ||
} | ||
} | ||
|
||
public boolean getBooleanValue(String propertyName, boolean _default, boolean required) | ||
{ | ||
return Boolean.valueOf(getStringValue(propertyName, _default ? "true" : "false", required)); | ||
} | ||
|
||
public int getIntValue(String propertyName, int _default, boolean required) | ||
{ | ||
return Integer.valueOf(getStringValue(propertyName, Integer.toString(_default), required)).intValue(); | ||
} | ||
|
||
public long getLongValue(String propertyName, long _default, boolean required) | ||
{ | ||
return Long.valueOf(getStringValue(propertyName, Long.toString(_default), required)).longValue(); | ||
} | ||
|
||
public String getStringValue(String propertyName, String _default, boolean required) | ||
{ | ||
List<String> values = getPropertyValues(propertyName); | ||
if (values.size() == 0) | ||
{ | ||
if (required) | ||
{ | ||
throw new IllegalArgumentException("Cannot find required property " + propertyName + ", check that it is specified"); | ||
} | ||
else | ||
{ | ||
return _default; | ||
} | ||
} | ||
else if (values.size() > 1) | ||
{ | ||
throw new IllegalArgumentException("More than one value given for " + propertyName + ", not sure which one to use!"); | ||
} | ||
else | ||
{ | ||
return values.iterator().next(); | ||
} | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
...er/src/main/java/org/jboss/webbeans/tck/integration/jbossas/util/EnumerationIterable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.jboss.webbeans.tck.integration.jbossas.util; | ||
|
||
import java.util.Enumeration; | ||
import java.util.Iterator; | ||
|
||
/** | ||
* An Enumeration -> Iteratble adaptor | ||
* | ||
* @author Pete Muir | ||
* @see org.jboss.webbeans.util.EnumerationIterator | ||
*/ | ||
class EnumerationIterable<T> implements Iterable<T> | ||
{ | ||
// The enumeration-iteartor | ||
private EnumerationIterator<T> iterator; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param enumeration The enumeration | ||
*/ | ||
public EnumerationIterable(Enumeration<T> enumeration) | ||
{ | ||
this.iterator = new EnumerationIterator<T>(enumeration); | ||
} | ||
|
||
/** | ||
* Gets an iterator | ||
* | ||
* @return The iterator | ||
*/ | ||
public Iterator<T> iterator() | ||
{ | ||
return iterator; | ||
} | ||
|
||
} |
Oops, something went wrong.