/jboss-as-7.1.1.Final/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jpa/webtxem/WebJPATestCase.java
Java | 95 lines | 52 code | 15 blank | 28 comment | 0 complexity | 91ac09f5e548eec8fc1e8509e870327a MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
1/*
2 * JBoss, Home of Professional Open Source.
3 * Copyright 2012, 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 */
22
23package org.jboss.as.test.integration.jpa.webtxem;
24
25import static java.util.concurrent.TimeUnit.SECONDS;
26import static org.junit.Assert.assertEquals;
27
28import java.net.URL;
29
30import org.jboss.arquillian.container.test.api.Deployment;
31import org.jboss.arquillian.container.test.api.RunAsClient;
32import org.jboss.arquillian.junit.Arquillian;
33import org.jboss.arquillian.test.api.ArquillianResource;
34import org.jboss.as.test.integration.common.HttpRequest;
35import org.jboss.as.test.integration.jpa.hibernate.entity.Company;
36import org.jboss.as.test.integration.jpa.hibernate.entity.Customer;
37import org.jboss.as.test.integration.jpa.hibernate.entity.Flight;
38import org.jboss.as.test.integration.jpa.hibernate.entity.Ticket;
39import org.jboss.shrinkwrap.api.ShrinkWrap;
40import org.jboss.shrinkwrap.api.asset.StringAsset;
41import org.jboss.shrinkwrap.api.spec.WebArchive;
42import org.junit.Test;
43import org.junit.runner.RunWith;
44
45/**
46 *
47 * This test writes and reads entity in the {@link TestServlet}. (based on the
48 * EAP 5 testsuite).
49 *
50 * @author Zbyněk Roubal?k
51 */
52@RunWith(Arquillian.class)
53@RunAsClient
54public class WebJPATestCase {
55
56 private static final String ARCHIVE_NAME = "web_jpa";
57
58 @ArquillianResource
59 static URL baseUrl;
60
61 private static final String persistence_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> "
62 + "<persistence xmlns=\"http://java.sun.com/xml/ns/persistence\" version=\"1.0\">"
63 + " <persistence-unit name=\"web_jpa_pc\">"
64 + " <description>Persistence Unit.</description>"
65 + " <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>"
66 + " <properties> "
67 + " <property name=\"hibernate.hbm2ddl.auto\" value=\"create-drop\"/>"
68 + " </properties>" + " </persistence-unit>" + "</persistence>";
69
70 @Deployment
71 public static WebArchive deployment() {
72 WebArchive war = ShrinkWrap.create(WebArchive.class, ARCHIVE_NAME + ".war");
73 war.addClasses(WebJPATestCase.class, TestServlet.class,
74 HttpRequest.class, Flight.class, Company.class, Customer.class,
75 Ticket.class);
76
77 war.addAsResource(new StringAsset(persistence_xml), "META-INF/persistence.xml");
78
79 return war;
80 }
81
82 private static String performCall(String urlPattern, String param)
83 throws Exception {
84 return HttpRequest.get(baseUrl.toString() + urlPattern + "?mode=" + param, 20, SECONDS);
85 }
86
87 @Test
88 public void testReadWrite() throws Exception {
89 performCall("test", "write");
90
91 String result = performCall("test", "read");
92 assertEquals("Flight number one", result);
93 }
94
95}