/jboss-as-7.1.1.Final/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/weld/ejb/SessionObjectReferenceTestCase.java
Java | 123 lines | 82 code | 11 blank | 30 comment | 0 complexity | ff4341e69224c47277cf2f2bd02e3875 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
1/*
2 * JBoss, Home of Professional Open Source.
3 * Copyright (c) 2011, Red Hat, Inc., and individual contributors
4 * as indicated by the @author tags. See the copyright.txt file in the
5 * distribution for a full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */
22package org.jboss.as.test.integration.weld.ejb;
23
24import java.beans.XMLDecoder;
25import java.io.ByteArrayInputStream;
26import java.io.IOException;
27import java.net.MalformedURLException;
28import java.net.URL;
29import java.util.List;
30import java.util.concurrent.ExecutionException;
31import java.util.concurrent.TimeoutException;
32
33import javax.ejb.ConcurrentAccessException;
34
35import org.jboss.arquillian.container.test.api.Deployment;
36import org.jboss.arquillian.container.test.api.RunAsClient;
37import org.jboss.arquillian.junit.Arquillian;
38import org.jboss.arquillian.test.api.ArquillianResource;
39import org.jboss.as.test.integration.common.HttpRequest;
40import org.jboss.shrinkwrap.api.ShrinkWrap;
41import org.jboss.shrinkwrap.api.asset.EmptyAsset;
42import org.jboss.shrinkwrap.api.asset.StringAsset;
43import org.jboss.shrinkwrap.api.spec.WebArchive;
44import org.jboss.stdio.WriterOutputStream;
45import org.junit.Test;
46import org.junit.runner.RunWith;
47
48import static java.util.concurrent.TimeUnit.SECONDS;
49import static org.junit.Assert.assertEquals;
50import static org.junit.Assert.assertTrue;
51
52/**
53 * Test two things:
54 * 1. EJBTHREE-697: First concurrent call doesn't throw exception
55 * 2. make sure the SFSB is instantiated in the same thread as the Servlet, so propagation works
56 * <p/>
57 * Make sure a concurrent call to a SFSB proxy over Weld gets a ConcurrentAccessException.
58 *
59 * @author <a href="mailto:cdewolf@redhat.com">Carlo de Wolf</a>
60 */
61@RunWith(Arquillian.class)
62@RunAsClient
63public class SessionObjectReferenceTestCase {
64
65 @ArquillianResource
66 private URL url;
67
68 @Deployment
69 public static WebArchive deployment() {
70 WebArchive war = ShrinkWrap.create(WebArchive.class, "war-example.war")
71 .addClasses(HttpRequest.class, SimpleServlet.class, SimpleStatefulSessionBean.class, WriterOutputStream.class)
72 .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
73 .addAsWebInfResource(new StringAsset(WEB_XML), "web.xml");
74 return war;
75 }
76
77 private String performCall(String urlPattern, String param) {
78 String spec = url.toExternalForm() + urlPattern + "?input=" + param;
79 try {
80 return HttpRequest.get(spec, 30, SECONDS);
81 } catch (ExecutionException e) {
82 throw new RuntimeException(e.getCause());
83 } catch (MalformedURLException e) {
84 throw new RuntimeException(e);
85 } catch (TimeoutException e) {
86 throw new RuntimeException(e);
87 } catch (IOException e) {
88 throw new RuntimeException(e);
89 }
90 }
91
92 @Test
93 public void testEcho() throws Exception {
94 String result = performCall("simple", "Hello+world");
95 XMLDecoder decoder = new XMLDecoder(new ByteArrayInputStream(result.getBytes()));
96 List<String> results = (List<String>) decoder.readObject();
97 List<Exception> exceptions = (List<Exception>) decoder.readObject();
98 String sharedContext = (String) decoder.readObject();
99 decoder.close();
100
101 assertEquals(1, results.size());
102 assertEquals("Echo Hello world", results.get(0));
103 assertEquals(1, exceptions.size());
104 assertTrue(exceptions.get(0) instanceof ConcurrentAccessException);
105 assertEquals("Shared context", sharedContext);
106 }
107
108 private static final String WEB_XML = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" +
109 "<!--org.jboss.as.weld.deployment.processors.WebIntegrationProcessor checks for the existence of WebMetaData -->\n" +
110 "<web-app version=\"3.0\" xmlns=\"http://java.sun.com/xml/ns/j2ee\"\n" +
111 " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
112 " xsi:schemaLocation=\"http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_3_0.xsd\">\n" +
113 " <!-- if I have a web.xml, annotations won't work anymore -->\n" +
114 " <servlet>\n" +
115 " <servlet-name>SimpleServlet</servlet-name>\n" +
116 " <servlet-class>org.jboss.as.test.integration.weld.ejb.SimpleServlet</servlet-class>\n" +
117 " </servlet>\n" +
118 " <servlet-mapping>\n" +
119 " <servlet-name>SimpleServlet</servlet-name>\n" +
120 " <url-pattern>/simple</url-pattern>\n" +
121 " </servlet-mapping>\n" +
122 "</web-app>";
123}