-
Notifications
You must be signed in to change notification settings - Fork 44
/
InterceptorEnvironmentJNDITest.java
143 lines (117 loc) · 6.71 KB
/
InterceptorEnvironmentJNDITest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
* JBoss, Home of Professional Open Source
* Copyright 2012, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.cdi.tck.interceptors.tests.contract.interceptorLifeCycle.environment.jndi;
import static org.jboss.cdi.tck.TestGroups.JAVAEE_FULL;
import static org.jboss.cdi.tck.interceptors.InterceptorsSections.INTERCEPTOR_ENVIRONMENT;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.cdi.tck.AbstractTest;
import org.jboss.cdi.tck.shrinkwrap.EnterpriseArchiveBuilder;
import org.jboss.cdi.tck.shrinkwrap.WebArchiveBuilder;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.shrinkwrap.descriptor.api.Descriptors;
import org.jboss.shrinkwrap.descriptor.api.application6.ApplicationDescriptor;
import org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor;
import org.jboss.test.audit.annotations.SpecAssertion;
import org.jboss.test.audit.annotations.SpecVersion;
import org.testng.annotations.Test;
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.WebClient;
/**
* @author Matus Abaffy
*/
@RunAsClient
@SpecVersion(spec = "interceptors", version = "1.2")
public class InterceptorEnvironmentJNDITest extends AbstractTest {
private static final String GREETING = "greeting";
private static final String JAVA_LANG_STRING = "java.lang.String";
private static final String HELLO = "Hello";
private static final String BYE = "Bye";
private static final String FOO_GET = "foo?get=";
private static final String BAR_GET = "bar?get=";
@Deployment(testable = false)
public static EnterpriseArchive createTestArchive() {
EnterpriseArchive enterpriseArchive = new EnterpriseArchiveBuilder()
.notTestArchive()
.withClasses(MyBinding.class, MyInterceptor.class, Animal.class)
.noDefaultWebModule().build();
StringAsset applicationXml = new StringAsset(Descriptors.create(ApplicationDescriptor.class)
.version(EnterpriseArchiveBuilder.DEFAULT_APP_VERSION).applicationName("Test").createModule()
.ejb(EnterpriseArchiveBuilder.DEFAULT_EJB_MODULE_NAME).up().createModule().getOrCreateWeb().webUri("test1.war")
.contextRoot("/test1").up().up().createModule().getOrCreateWeb().webUri("test2.war").contextRoot("/test2").up()
.up().exportAsString());
enterpriseArchive.setApplicationXML(applicationXml);
WebArchive fooArchive = new WebArchiveBuilder().notTestArchive().withName("test1.war")
.withClasses(FooServlet.class, Foo.class, Dog.class)
.withWebXml(
Descriptors.create(WebAppDescriptor.class).createEnvEntry().envEntryName(GREETING)
.envEntryType(JAVA_LANG_STRING).envEntryValue(BYE).up())
.withDefaultEjbModuleDependency()
.build();
enterpriseArchive.addAsModule(fooArchive);
WebArchive barArchive = new WebArchiveBuilder().notTestArchive().withName("test2.war")
.withClasses(BarServlet.class, Bar.class, Cat.class)
.withWebXml(
Descriptors.create(WebAppDescriptor.class).createEnvEntry().envEntryName(GREETING)
.envEntryType(JAVA_LANG_STRING).envEntryValue(HELLO).up())
.withDefaultEjbModuleDependency()
.build();
enterpriseArchive.addAsModule(barArchive);
return enterpriseArchive;
}
@ArquillianResource(FooServlet.class)
URL fooContextPath;
@ArquillianResource(BarServlet.class)
URL barContextPath;
@Test(groups = JAVAEE_FULL)
@SpecAssertion(section = INTERCEPTOR_ENVIRONMENT, id = "a")
public void testInterceptorEnvironment() throws FailingHttpStatusCodeException, MalformedURLException, IOException {
WebClient webClient = new WebClient();
webClient.setThrowExceptionOnFailingStatusCode(true);
// create an instance of Foo and fail if interceptor was not called
webClient.getPage(fooContextPath + FOO_GET + "init");
String fooAnimalName = webClient.getPage(fooContextPath + FOO_GET + "name").getWebResponse().getContentAsString();
String fooGreeting = webClient.getPage(fooContextPath + FOO_GET + "greeting").getWebResponse().getContentAsString();
String fooInterceptorAnimalName = webClient.getPage(fooContextPath + FOO_GET + "intName").getWebResponse()
.getContentAsString();
String fooInterceptorGreeting = webClient.getPage(fooContextPath + FOO_GET + "intGreeting").getWebResponse()
.getContentAsString();
assertEquals(fooInterceptorGreeting, fooGreeting);
assertEquals(fooInterceptorAnimalName, fooAnimalName);
assertEquals(fooGreeting, BYE);
assertEquals(fooAnimalName, "Dog");
// create an instance of Bar and fail if interceptor was not called
webClient.getPage(barContextPath + BAR_GET + "init");
String barAnimalName = webClient.getPage(barContextPath + BAR_GET + "name").getWebResponse().getContentAsString();
String barGreeting = webClient.getPage(barContextPath + BAR_GET + "greeting").getWebResponse().getContentAsString();
String barInterceptorAnimalName = webClient.getPage(barContextPath + BAR_GET + "intName").getWebResponse()
.getContentAsString();
String barInterceptorGreeting = webClient.getPage(barContextPath + BAR_GET + "intGreeting").getWebResponse()
.getContentAsString();
assertEquals(barInterceptorGreeting, barGreeting);
assertEquals(barInterceptorAnimalName, barAnimalName);
assertEquals(barGreeting, HELLO);
assertEquals(barAnimalName, "Cat");
}
}