Skip to content

Commit

Permalink
WELD-467
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuir committed Jun 5, 2010
1 parent 38967b5 commit b342ad0
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 19 deletions.
Expand Up @@ -31,7 +31,7 @@
@SuppressWarnings("unchecked")
public class BeansXmlTest
{
private class FailedDeployment
private static class FailedDeployment
{
private List<Class<?>> beans = Collections.emptyList();
private List<URL> beansXml = Collections.emptyList();
Expand Down Expand Up @@ -60,7 +60,7 @@ public void run()

public void runAndExpect(WeldXmlException expected)
{
String errorCode = expected.getMessage().substring(0, 12);
String errorCode = expected.getMessage().substring(0, 11);
try
{
run();
Expand All @@ -77,35 +77,35 @@ public void runAndExpect(WeldXmlException expected)

}

private void testWithBeansXmlAndExpectException(String beansXml, WeldXmlException e)
private static void checkWithBeansXmlAndExpectException(String beansXml, WeldXmlException e)
{
List<Class<?>> beans = Arrays.asList(Alt.class, Dec.class, Int.class, Plain.class, IntBind.class);
List<URL> beansXmls = Arrays.asList(getClass().getResource(beansXml));
List<URL> beansXmls = Arrays.asList(BeansXmlTest.class.getResource(beansXml));
new FailedDeployment(beans, beansXmls).runAndExpect(e);
}

// Multiple XML blocks

@Test
public void multipleAlternativeBlocksFail()
public void testMultipleAlternativeBlocksFail()
{
testWithBeansXmlAndExpectException("multipleAlternativeBlocks.xml", new WeldXmlException(XmlMessage.MULTIPLE_ALTERNATIVES));
checkWithBeansXmlAndExpectException("multipleAlternativeBlocks.xml", new WeldXmlException(XmlMessage.MULTIPLE_ALTERNATIVES));
}

@Test
public void multipleDecoratorBlocksFail()
public void testMultipleDecoratorBlocksFail()
{
testWithBeansXmlAndExpectException("multipleDecoratorBlocks.xml", new WeldXmlException(XmlMessage.MULTIPLE_DECORATORS));
checkWithBeansXmlAndExpectException("multipleDecoratorBlocks.xml", new WeldXmlException(XmlMessage.MULTIPLE_DECORATORS));
}

@Test
public void multipleInterceptorBlocksFail()
public void testMultipleInterceptorBlocksFail()
{
testWithBeansXmlAndExpectException("multipleInterceptorsBlocks.xml", new WeldXmlException(XmlMessage.MULTIPLE_INTERCEPTORS));
checkWithBeansXmlAndExpectException("multipleInterceptorsBlocks.xml", new WeldXmlException(XmlMessage.MULTIPLE_INTERCEPTORS));
}

@Test
public void alternativesEnabled()
public void testAlternativesEnabled()
{
List<Class<?>> beans = Arrays.asList(Alt.class, Dec.class, Int.class, IntBind.class, Plain.class);
List<URL> beansXmls = Arrays.asList(getClass().getResource("alternative.xml"));
Expand All @@ -116,7 +116,7 @@ public void alternativesEnabled()
}

@Test
public void decoratorsEnabled()
public void testDecoratorsEnabled()
{
List<Class<?>> beans = Arrays.asList(Alt.class, Dec.class, Int.class, IntBind.class, Plain.class);
List<URL> beansXmls = Arrays.asList(getClass().getResource("decorator.xml"));
Expand All @@ -127,7 +127,7 @@ public void decoratorsEnabled()
}

@Test
public void interceptorsEnabled()
public void testInterceptorsEnabled()
{
List<Class<?>> beans = Arrays.asList(Alt.class, Dec.class, Int.class, IntBind.class, Plain.class);
List<URL> beansXmls = Arrays.asList(getClass().getResource("interceptor.xml"));
Expand Down Expand Up @@ -155,13 +155,33 @@ public void testMergeBeansXmls()
@Test
public void testBeansXmlDoesntExist()
{
testWithBeansXmlAndExpectException("nope.xml", new WeldXmlException(XmlMessage.LOAD_ERROR));
checkWithBeansXmlAndExpectException("nope.xml", new WeldXmlException(XmlMessage.LOAD_ERROR));
}

@Test(groups="stub")
public void testCannotGetDocumentBuilder()

// WELD-467
@Test
public void testNamespacedBeansXml()
{
List<Class<?>> beans = Arrays.asList(Alt.class, Dec.class, Int.class, IntBind.class, Plain.class);
List<URL> beansXmls = Arrays.asList(getClass().getResource("namespaced.xml"));
TestContainer container = new TestContainer(new MockEELifecycle(), beans, beansXmls).startContainer().ensureRequestActive();
assert container.getBeanManager().getEnabledAlternativeClasses().size() == 1;
assert container.getBeanManager().getEnabledAlternativeClasses().iterator().next() == Alt.class;
container.stopContainer();
}

// WELD-467
@Test
public void testNotDefaultNamespacedBeansXml()
{
List<Class<?>> beans = Arrays.asList(Alt.class, Dec.class, Int.class, IntBind.class, Plain.class);
List<URL> beansXmls = Arrays.asList(getClass().getResource("nonDefaultNamespaced.xml"));
TestContainer container = new TestContainer(new MockEELifecycle(), beans, beansXmls).startContainer().ensureRequestActive();
assert container.getBeanManager().getEnabledAlternativeClasses().size() == 1;
assert container.getBeanManager().getEnabledAlternativeClasses().iterator().next() == Alt.class;
container.stopContainer();
}

/*
* https://jira.jboss.org/jira/browse/WELD-362
*/
Expand All @@ -186,13 +206,13 @@ public void testCannotLoadFile() throws MalformedURLException
@Test
public void testParsingError()
{
testWithBeansXmlAndExpectException("unparseable.xml", new WeldXmlException(XmlMessage.PARSING_ERROR));
checkWithBeansXmlAndExpectException("unparseable.xml", new WeldXmlException(XmlMessage.PARSING_ERROR));
}

@Test
public void testCannotLoadClass()
{
testWithBeansXmlAndExpectException("unloadable.xml", new WeldXmlException(XmlMessage.CANNOT_LOAD_CLASS));
checkWithBeansXmlAndExpectException("unloadable.xml", new WeldXmlException(XmlMessage.CANNOT_LOAD_CLASS));
}

}
@@ -0,0 +1,11 @@
<beans xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:s="urn:java:seam:core"
xmlns:p="org.jboss.seam.xml.examples.princess"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://docs.jboss.org/cdi/beans_1_0.xsd">
<alternatives>
<class>org.jboss.weld.tests.unit.bootstrap.xml.Alt</class>
</alternatives>
</beans>
@@ -0,0 +1,12 @@
<ee:beans xmlns:ee="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:java:seam:core"
xmlns:p="org.jboss.seam.xml.examples.princess"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://docs.jboss.org/cdi/beans_1_0.xsd">
<ee:alternatives>
<ee:class>org.jboss.weld.tests.unit.bootstrap.xml.Alt</ee:class>
</ee:alternatives>
<foo />
</ee:beans>

0 comments on commit b342ad0

Please sign in to comment.