PageRenderTime 56ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/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. package org.jboss.as.test.integration.jpa.webtxem;
  23. import static java.util.concurrent.TimeUnit.SECONDS;
  24. import static org.junit.Assert.assertEquals;
  25. import java.net.URL;
  26. import org.jboss.arquillian.container.test.api.Deployment;
  27. import org.jboss.arquillian.container.test.api.RunAsClient;
  28. import org.jboss.arquillian.junit.Arquillian;
  29. import org.jboss.arquillian.test.api.ArquillianResource;
  30. import org.jboss.as.test.integration.common.HttpRequest;
  31. import org.jboss.as.test.integration.jpa.hibernate.entity.Company;
  32. import org.jboss.as.test.integration.jpa.hibernate.entity.Customer;
  33. import org.jboss.as.test.integration.jpa.hibernate.entity.Flight;
  34. import org.jboss.as.test.integration.jpa.hibernate.entity.Ticket;
  35. import org.jboss.shrinkwrap.api.ShrinkWrap;
  36. import org.jboss.shrinkwrap.api.asset.StringAsset;
  37. import org.jboss.shrinkwrap.api.spec.WebArchive;
  38. import org.junit.Test;
  39. import org.junit.runner.RunWith;
  40. /**
  41. *
  42. * This test writes and reads entity in the {@link TestServlet}. (based on the
  43. * EAP 5 testsuite).
  44. *
  45. * @author ZbynÄ›k Roubal?­k
  46. */
  47. @RunWith(Arquillian.class)
  48. @RunAsClient
  49. public class WebJPATestCase {
  50. private static final String ARCHIVE_NAME = "web_jpa";
  51. @ArquillianResource
  52. static URL baseUrl;
  53. private static final String persistence_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> "
  54. + "<persistence xmlns=\"http://java.sun.com/xml/ns/persistence\" version=\"1.0\">"
  55. + " <persistence-unit name=\"web_jpa_pc\">"
  56. + " <description>Persistence Unit.</description>"
  57. + " <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>"
  58. + " <properties> "
  59. + " <property name=\"hibernate.hbm2ddl.auto\" value=\"create-drop\"/>"
  60. + " </properties>" + " </persistence-unit>" + "</persistence>";
  61. @Deployment
  62. public static WebArchive deployment() {
  63. WebArchive war = ShrinkWrap.create(WebArchive.class, ARCHIVE_NAME + ".war");
  64. war.addClasses(WebJPATestCase.class, TestServlet.class,
  65. HttpRequest.class, Flight.class, Company.class, Customer.class,
  66. Ticket.class);
  67. war.addAsResource(new StringAsset(persistence_xml), "META-INF/persistence.xml");
  68. return war;
  69. }
  70. private static String performCall(String urlPattern, String param)
  71. throws Exception {
  72. return HttpRequest.get(baseUrl.toString() + urlPattern + "?mode=" + param, 20, SECONDS);
  73. }
  74. @Test
  75. public void testReadWrite() throws Exception {
  76. performCall("test", "write");
  77. String result = performCall("test", "read");
  78. assertEquals("Flight number one", result);
  79. }
  80. }