PageRenderTime 25ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/jaxrs/cfg/ResteasyScanResourcesTestCase.java

https://bitbucket.org/cprenzberg/wildfly
Java | 177 lines | 130 code | 21 blank | 26 comment | 0 complexity | f32344d7d1d0791d22b13bc838b8ea2b MD5 | raw file
  1. /*
  2. * JBoss, Home of Professional Open Source
  3. * Copyright 2010, Red Hat Inc., and individual contributors as indicated
  4. * by the @authors tag. See the copyright.txt in the distribution for a
  5. * 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.jaxrs.cfg;
  23. import java.net.URL;
  24. import java.util.concurrent.TimeUnit;
  25. import org.junit.Assert;
  26. import org.jboss.arquillian.container.test.api.Deployer;
  27. import org.jboss.arquillian.container.test.api.Deployment;
  28. import org.jboss.arquillian.container.test.api.OperateOnDeployment;
  29. import org.jboss.arquillian.container.test.api.RunAsClient;
  30. import org.jboss.arquillian.junit.Arquillian;
  31. import org.jboss.arquillian.test.api.ArquillianResource;
  32. import org.jboss.as.test.integration.common.HttpRequest;
  33. import org.jboss.as.test.integration.jaxrs.cfg.applicationclasses.HelloWorldApplication;
  34. import org.jboss.as.test.integration.jaxrs.packaging.war.WebXml;
  35. import org.jboss.shrinkwrap.api.Archive;
  36. import org.jboss.shrinkwrap.api.ShrinkWrap;
  37. import org.jboss.shrinkwrap.api.asset.StringAsset;
  38. import org.jboss.shrinkwrap.api.spec.WebArchive;
  39. import org.junit.Test;
  40. import org.junit.runner.RunWith;
  41. import static org.junit.Assert.assertEquals;
  42. /**
  43. * Tests for RESTEasy configuration parameter 'resteasy.scan.resources'
  44. *
  45. * @author Pavel Janousek
  46. */
  47. @RunWith(Arquillian.class)
  48. @RunAsClient
  49. public class ResteasyScanResourcesTestCase {
  50. private static final String depNameTrue = "dep_true";
  51. private static final String depNameFalse = "dep_false";
  52. private static final String depNameInvalid = "dep_invalid";
  53. private static final String depNameTrueApp = "dep_true_app";
  54. private static final String depNameFalseApp = "dep_false_app";
  55. private static final String depNameInvalidApp = "dep_invalid_app";
  56. @Deployment(name = depNameTrue, managed = true)
  57. public static Archive<?> deploy_true() {
  58. return ShrinkWrap.create(WebArchive.class, depNameTrue + ".war")
  59. .addClasses(ResteasyScanResourcesTestCase.class, HelloWorldResource.class)
  60. .setWebXML(webXmlWithMapping("resteasy.scan.resources", "true"));
  61. }
  62. @Deployment(name = depNameFalse, managed = true)
  63. public static Archive<?> deploy_false() {
  64. return ShrinkWrap.create(WebArchive.class, depNameFalse + ".war")
  65. .addClasses(ResteasyScanResourcesTestCase.class, HelloWorldResource.class)
  66. .setWebXML(webXmlWithMapping("resteasy.scan.resources", "false"));
  67. }
  68. @Deployment(name = depNameInvalid, managed = false)
  69. public static Archive<?> deploy_invalid() {
  70. return ShrinkWrap.create(WebArchive.class, depNameInvalid + ".war")
  71. .addClasses(ResteasyScanResourcesTestCase.class, HelloWorldResource.class)
  72. .setWebXML(webXmlWithMapping("resteasy.scan.resources", "blah"));
  73. }
  74. @Deployment(name = depNameTrueApp, managed = true)
  75. public static Archive<?> deploy_true_app() {
  76. return ShrinkWrap.create(WebArchive.class, depNameTrueApp + ".war")
  77. .addClasses(ResteasyScanResourcesTestCase.class, HelloWorldResource.class, HelloWorldApplication.class)
  78. .setWebXML(webXml("resteasy.scan.resources", "true"));
  79. }
  80. @Deployment(name = depNameFalseApp, managed = true)
  81. public static Archive<?> deploy_false_app() {
  82. return ShrinkWrap.create(WebArchive.class, depNameFalseApp + ".war")
  83. .addClasses(ResteasyScanResourcesTestCase.class, HelloWorldResource.class, HelloWorldApplication.class)
  84. .setWebXML(webXml("resteasy.scan.resources", "false"));
  85. }
  86. @Deployment(name = depNameInvalidApp, managed = false)
  87. public static Archive<?> deploy_invalid_app() {
  88. return ShrinkWrap.create(WebArchive.class, depNameInvalidApp + ".war")
  89. .addClasses(ResteasyScanResourcesTestCase.class, HelloWorldResource.class, HelloWorldApplication.class)
  90. .setWebXML(webXml("resteasy.scan.resources", "blah"));
  91. }
  92. private static StringAsset webXml(final String paramName, final String paramValue) {
  93. return WebXml.get(getCfgString(paramName, paramValue));
  94. }
  95. private static StringAsset webXmlWithMapping(final String paramName, final String paramValue) {
  96. return WebXml.get("<servlet-mapping>\n" + " <servlet-name>javax.ws.rs.core.Application</servlet-name>\n"
  97. + " <url-pattern>/myjaxrs/*</url-pattern>\n" + "</servlet-mapping>\n"
  98. + getCfgString(paramName, paramValue));
  99. }
  100. private static String getCfgString(final String paramName, final String paramValue) {
  101. return "<context-param>\n" + " <param-name>" + paramName + "</param-name>\n" + " <param-value>"
  102. + paramValue + "</param-value>\n" + "</context-param>\n" + "\n";
  103. }
  104. @ArquillianResource
  105. private Deployer deployer;
  106. @Test
  107. @OperateOnDeployment(depNameTrue)
  108. public void testDeployTrue(@ArquillianResource URL url) throws Exception {
  109. String result = HttpRequest.get(url.toExternalForm() + "myjaxrs/helloworld", 10, TimeUnit.SECONDS);
  110. assertEquals("Hello World!", result);
  111. }
  112. @Test
  113. @OperateOnDeployment(depNameFalse)
  114. public void testDeployFalse(@ArquillianResource URL url) throws Exception {
  115. try {
  116. @SuppressWarnings("unused")
  117. String result = HttpRequest.get(url.toExternalForm() + "myjaxrs/helloworld", 10, TimeUnit.SECONDS);
  118. Assert.fail("Scan of Resources is disabled so we should not pass to there - HTTP 404 must occur!");
  119. } catch (Exception e) {
  120. Assert.assertTrue(e.toString().contains("HTTP Status 404"));
  121. }
  122. }
  123. @Test
  124. public void testDeployInvalid() throws Exception {
  125. try {
  126. deployer.deploy(depNameInvalid);
  127. Assert.fail("Test should not go here - invalid deployment (invalid value of resteasy.scan.resources)!");
  128. } catch (Exception e) {
  129. }
  130. }
  131. @Test
  132. @OperateOnDeployment(depNameTrueApp)
  133. public void testDeployTrueApp(@ArquillianResource URL url) throws Exception {
  134. String result = HttpRequest.get(url.toExternalForm() + "app1/helloworld", 10, TimeUnit.SECONDS);
  135. assertEquals("Hello World!", result);
  136. }
  137. @Test
  138. @OperateOnDeployment(depNameFalseApp)
  139. public void testDeployFalseApp(@ArquillianResource URL url) throws Exception {
  140. try {
  141. @SuppressWarnings("unused")
  142. String result = HttpRequest.get(url.toExternalForm() + "app1/helloworld", 10, TimeUnit.SECONDS);
  143. Assert.fail("Scan of Resources is disabled so we should not pass to there - HTTP 404 must occur!");
  144. } catch (Exception e) {
  145. Assert.assertTrue(e.toString().contains("HTTP Status 404"));
  146. }
  147. }
  148. @Test
  149. public void testDeployInvalidApp() throws Exception {
  150. try {
  151. deployer.deploy(depNameInvalidApp);
  152. Assert.fail("Test should not go here - invalid deployment (invalid value of resteasy.scan.resources)!");
  153. } catch (Exception e) {
  154. }
  155. }
  156. }