Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Part I of tests for WELD-319 (parsing part)
Delegate validation to Validator Missing parser message Typo in test JIRA reference
- Loading branch information
Showing
20 changed files
with
290 additions
and
37 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
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
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
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
5 changes: 3 additions & 2 deletions
5
impl/src/main/resources/org/jboss/weld/messages/xml_en.properties
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
CONFIGURATION_ERROR=Error configuring XML parser | ||
LOAD_ERROR=Error loading {0} | ||
LOAD_ERROR=Error loading beans.xml {0} | ||
CANNOT_LOAD_CLASS=Could not load class {0} | ||
PARSING_ERROR=Error parsing {0} | ||
MULTIPLE_ALTERNATIVES=<alternatives> can only be specified once, but appears multiple times\: {0} | ||
MULTIPLE_DECORATORS=<decorator> can only be specified once, but is specified multiple times\: {0} | ||
MULTIPLE_DECORATORS=<decorators> can only be specified once, but is specified multiple times\: {0} | ||
MULTIPLE_INTERCEPTORS=<interceptor> can only be specified once, but it is specified multiple times\: {0} |
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
9 changes: 9 additions & 0 deletions
9
tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/Alt.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,9 @@ | ||
package org.jboss.weld.tests.unit.bootstrap.xml; | ||
|
||
import javax.enterprise.inject.Alternative; | ||
|
||
@Alternative | ||
public class Alt | ||
{ | ||
|
||
} |
169 changes: 169 additions & 0 deletions
169
tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/BeansXmlTest.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,169 @@ | ||
package org.jboss.weld.tests.unit.bootstrap.xml; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import org.jboss.weld.logging.messages.XmlMessage; | ||
import org.jboss.weld.mock.MockEELifecycle; | ||
import org.jboss.weld.mock.TestContainer; | ||
import org.jboss.weld.xml.WeldXmlException; | ||
import org.testng.annotations.Test; | ||
|
||
@SuppressWarnings("unchecked") | ||
public class BeansXmlTest | ||
{ | ||
private class FailedDeployment | ||
{ | ||
private List<Class<?>> beans = Collections.emptyList(); | ||
private List<URL> beansXml = Collections.emptyList(); | ||
|
||
public FailedDeployment(List<Class<?>> beans, List<URL> beansXml) | ||
{ | ||
this.beans = beans; | ||
this.beansXml = beansXml; | ||
} | ||
|
||
public void run() | ||
{ | ||
TestContainer container = null; | ||
try | ||
{ | ||
container = new TestContainer(new MockEELifecycle(), beans, beansXml).startContainer().ensureRequestActive(); | ||
} | ||
finally | ||
{ | ||
if (container != null) | ||
{ | ||
container.stopContainer(); | ||
} | ||
} | ||
} | ||
|
||
public void runAndExpect(WeldXmlException expected) | ||
{ | ||
String errorCode = expected.getMessage().substring(0, 12); | ||
try | ||
{ | ||
run(); | ||
} | ||
catch (WeldXmlException e) | ||
{ | ||
if (e.getMessage().startsWith(errorCode)) | ||
{ | ||
return; | ||
} | ||
} | ||
assert false; | ||
} | ||
|
||
} | ||
|
||
private void testWithBeansXmlAndExpectException(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)); | ||
new FailedDeployment(beans, beansXmls).runAndExpect(e); | ||
} | ||
|
||
// Multiple XML blocks | ||
|
||
@Test | ||
public void multipleAlternativeBlocksFail() | ||
{ | ||
testWithBeansXmlAndExpectException("multipleAlternativeBlocks.xml", new WeldXmlException(XmlMessage.MULTIPLE_ALTERNATIVES)); | ||
} | ||
|
||
@Test | ||
public void multipleDecoratorBlocksFail() | ||
{ | ||
testWithBeansXmlAndExpectException("multipleDecoratorBlocks.xml", new WeldXmlException(XmlMessage.MULTIPLE_DECORATORS)); | ||
} | ||
|
||
@Test | ||
public void multipleInterceptorBlocksFail() | ||
{ | ||
testWithBeansXmlAndExpectException("multipleInterceptorsBlocks.xml", new WeldXmlException(XmlMessage.MULTIPLE_INTERCEPTORS)); | ||
} | ||
|
||
@Test | ||
public void alternativesEnabled() | ||
{ | ||
List<Class<?>> beans = Arrays.asList(Alt.class, Dec.class, Int.class, IntBind.class, Plain.class); | ||
List<URL> beansXmls = Arrays.asList(getClass().getResource("alternative.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(); | ||
} | ||
|
||
@Test | ||
public void decoratorsEnabled() | ||
{ | ||
List<Class<?>> beans = Arrays.asList(Alt.class, Dec.class, Int.class, IntBind.class, Plain.class); | ||
List<URL> beansXmls = Arrays.asList(getClass().getResource("decorator.xml")); | ||
TestContainer container = new TestContainer(new MockEELifecycle(), beans, beansXmls).startContainer().ensureRequestActive(); | ||
assert container.getBeanManager().getEnabledDecoratorClasses().size() == 1; | ||
assert container.getBeanManager().getEnabledDecoratorClasses().iterator().next() == Dec.class; | ||
container.stopContainer(); | ||
} | ||
|
||
@Test | ||
public void interceptorsEnabled() | ||
{ | ||
List<Class<?>> beans = Arrays.asList(Alt.class, Dec.class, Int.class, IntBind.class, Plain.class); | ||
List<URL> beansXmls = Arrays.asList(getClass().getResource("interceptor.xml")); | ||
TestContainer container = new TestContainer(new MockEELifecycle(), beans, beansXmls).startContainer().ensureRequestActive(); | ||
assert container.getBeanManager().getEnabledInterceptorClasses().size() == 1; | ||
assert container.getBeanManager().getEnabledInterceptorClasses().iterator().next() == Int.class; | ||
container.stopContainer(); | ||
} | ||
|
||
@Test | ||
public void testMergeBeansXmls() | ||
{ | ||
List<Class<?>> beans = Arrays.asList(Alt.class, Dec.class, Int.class, IntBind.class, Plain.class); | ||
List<URL> beansXmls = Arrays.asList(getClass().getResource("alternative.xml"), getClass().getResource("decorator.xml"), getClass().getResource("interceptor.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; | ||
assert container.getBeanManager().getEnabledInterceptorClasses().size() == 1; | ||
assert container.getBeanManager().getEnabledInterceptorClasses().iterator().next() == Int.class; | ||
assert container.getBeanManager().getEnabledDecoratorClasses().size() == 1; | ||
assert container.getBeanManager().getEnabledDecoratorClasses().iterator().next() == Dec.class; | ||
container.stopContainer(); | ||
} | ||
|
||
@Test | ||
public void testBeansXmlDoesntExist() | ||
{ | ||
testWithBeansXmlAndExpectException("nope.xml", new WeldXmlException(XmlMessage.LOAD_ERROR)); | ||
} | ||
|
||
@Test(groups="stub") | ||
public void testCannotGetDocumentBuilder() | ||
{ | ||
} | ||
|
||
@Test | ||
public void testCannotLoadFile() throws MalformedURLException | ||
{ | ||
List<Class<?>> beans = Collections.emptyList(); | ||
new FailedDeployment(beans, Arrays.asList(new URL("http://foo.bar/beans.xml"))).runAndExpect(new WeldXmlException(XmlMessage.LOAD_ERROR)); | ||
} | ||
|
||
@Test | ||
public void testParsingError() | ||
{ | ||
testWithBeansXmlAndExpectException("unparseable.xml", new WeldXmlException(XmlMessage.PARSING_ERROR)); | ||
} | ||
|
||
@Test | ||
public void testCannotLoadClass() | ||
{ | ||
testWithBeansXmlAndExpectException("unloadable.xml", new WeldXmlException(XmlMessage.CANNOT_LOAD_CLASS)); | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/Dec.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,11 @@ | ||
package org.jboss.weld.tests.unit.bootstrap.xml; | ||
|
||
import javax.decorator.Decorator; | ||
import javax.decorator.Delegate; | ||
import javax.inject.Inject; | ||
|
||
@Decorator | ||
public class Dec | ||
{ | ||
@Inject @Delegate Plain plain; | ||
} |
10 changes: 10 additions & 0 deletions
10
tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/Int.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,10 @@ | ||
package org.jboss.weld.tests.unit.bootstrap.xml; | ||
|
||
import javax.interceptor.Interceptor; | ||
|
||
@Interceptor | ||
@IntBind | ||
public class Int | ||
{ | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/IntBind.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,16 @@ | ||
package org.jboss.weld.tests.unit.bootstrap.xml; | ||
|
||
import java.lang.annotation.Inherited; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
import static java.lang.annotation.ElementType.*; | ||
import static java.lang.annotation.RetentionPolicy.*; | ||
import javax.interceptor.InterceptorBinding; | ||
|
||
@InterceptorBinding | ||
@Inherited | ||
@Target( { TYPE, METHOD }) | ||
@Retention(RUNTIME) | ||
public @interface IntBind | ||
{ | ||
} |
6 changes: 6 additions & 0 deletions
6
tests/src/test/java/org/jboss/weld/tests/unit/bootstrap/xml/Plain.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,6 @@ | ||
package org.jboss.weld.tests.unit.bootstrap.xml; | ||
|
||
public class Plain | ||
{ | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
tests/src/test/resources/org/jboss/weld/tests/unit/bootstrap/xml/alternative.xml
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,5 @@ | ||
<beans> | ||
<alternatives> | ||
<class>org.jboss.weld.tests.unit.bootstrap.xml.Alt</class> | ||
</alternatives> | ||
</beans> |
Oops, something went wrong.