Author: scabanovich
Date: 2012-01-23 20:34:14 -0500 (Mon, 23 Jan 2012)
New Revision: 38059
Added:
trunk/jst/tests/org.jboss.tools.jst.web.test/projects/testWebProject/WebContent/WEB-INF/webJAXFX.xml
trunk/jst/tests/org.jboss.tools.jst.web.test/projects/testWebProject/src/test/
trunk/jst/tests/org.jboss.tools.jst.web.test/projects/testWebProject/src/test/MyApplication.java
Modified:
trunk/jst/tests/org.jboss.tools.jst.web.test/src/org/jboss/tools/jst/web/test/WebXMLValidationTest.java
Log:
JBIDE-10645
https://issues.joss.org/browse/JBIDE-10645
Tests for support of JAX-RS in validation of servlet-mapping/servlet-name.
Added:
trunk/jst/tests/org.jboss.tools.jst.web.test/projects/testWebProject/WebContent/WEB-INF/webJAXFX.xml
===================================================================
---
trunk/jst/tests/org.jboss.tools.jst.web.test/projects/testWebProject/WebContent/WEB-INF/webJAXFX.xml
(rev 0)
+++
trunk/jst/tests/org.jboss.tools.jst.web.test/projects/testWebProject/WebContent/WEB-INF/webJAXFX.xml 2012-01-24
01:34:14 UTC (rev 38059)
@@ -0,0 +1,27 @@
+<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
+ <!-- One of the way of activating REST Servises is adding these lines, the server
is responsible for adding the corresponding servlet automatically. If the src folder,
org.jboss.as.quickstarts.poh5helloworld.HelloWorld class has the Annotations to receive
REST invocation-->
+ <servlet-mapping>
+ <servlet-name>javax.ws.rs.core.Application</servlet-name>
+ <url-pattern>/hello/*</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>test.MyApplication</servlet-name>
+ <url-pattern>/hello/*</url-pattern>
+ </servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>notaservlet</servlet-name>
+ <url-pattern>/hello/*</url-pattern>
+ </servlet-mapping>
+
+ <servlet>
+ <servlet-name>myServlet</servlet-name>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>myServlet</servlet-name>
+ <url-pattern>/hello/*</url-pattern>
+ </servlet-mapping>
+</web-app>
Property changes on:
trunk/jst/tests/org.jboss.tools.jst.web.test/projects/testWebProject/WebContent/WEB-INF/webJAXFX.xml
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/jst/tests/org.jboss.tools.jst.web.test/projects/testWebProject/src/test/MyApplication.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.jst.web.test/projects/testWebProject/src/test/MyApplication.java
(rev 0)
+++
trunk/jst/tests/org.jboss.tools.jst.web.test/projects/testWebProject/src/test/MyApplication.java 2012-01-24
01:34:14 UTC (rev 38059)
@@ -0,0 +1,5 @@
+package test;
+
+public class MyApplication {
+
+}
Property changes on:
trunk/jst/tests/org.jboss.tools.jst.web.test/projects/testWebProject/src/test/MyApplication.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/jst/tests/org.jboss.tools.jst.web.test/src/org/jboss/tools/jst/web/test/WebXMLValidationTest.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.jst.web.test/src/org/jboss/tools/jst/web/test/WebXMLValidationTest.java 2012-01-24
01:31:18 UTC (rev 38058)
+++
trunk/jst/tests/org.jboss.tools.jst.web.test/src/org/jboss/tools/jst/web/test/WebXMLValidationTest.java 2012-01-24
01:34:14 UTC (rev 38059)
@@ -24,6 +24,7 @@
import org.jboss.tools.common.validation.ValidatorManager;
import org.jboss.tools.jst.web.validation.WebXMLCoreValidator;
import org.jboss.tools.jst.web.validation.WebXMLValidatorMessages;
+import org.jboss.tools.jst.web.webapp.model.WebAppConstants;
import org.jboss.tools.test.util.JobUtils;
import org.jboss.tools.test.util.ProjectImportTestSetup;
import org.jboss.tools.test.util.ResourcesUtils;
@@ -110,15 +111,41 @@
}
static boolean hasMarkerOnLine(IMarker[] ms, int line) {
+ return getMarkerOnLine(ms, line) != null;
+ }
+
+ static IMarker getMarkerOnLine(IMarker[] ms, int line) {
for (IMarker m: ms) {
int l = m.getAttribute(IMarker.LINE_NUMBER, -1);
if(line == l) {
- return true;
+ return m;
}
}
- return false;
+ return null;
}
+ public void testServletMapping() throws CoreException {
+ IFile webxml = project.getFile("WebContent/WEB-INF/webJAXFX.xml");
+ IMarker[] markers = webxml.findMarkers(WebXMLCoreValidator.PROBLEM_TYPE, false,
IResource.DEPTH_ZERO);
+
+ //1. If servlet-mapping/servlet-name=javax.ws.rs.core.Application, it is ok.
+ assertFalse(hasMarkerOnLine(markers, 6));
+
+ //2. If servlet-mapping/servlet-name is a class it should extend
javax.ws.rs.core.Application.
+ assertTrue(hasMarkerOnLine(markers, 11));
+ IMarker m = getMarkerOnLine(markers, 11);
+ String expected = NLS.bind(WebXMLValidatorMessages.CLASS_NOT_EXTENDS, new
Object[]{WebAppConstants.SERVLET_NAME, "test.MyApplication",
"javax.ws.rs.core.Application"});
+ assertEquals(expected, m.getAttribute(IMarker.MESSAGE, ""));
+
+ //3. If servlet-mapping/servlet-name is not a class, it should reference
servlet/servlet-name
+ assertTrue(hasMarkerOnLine(markers, 16));
+ m = getMarkerOnLine(markers, 16);
+ expected = NLS.bind(WebXMLValidatorMessages.SERVLET_NOT_EXISTS, new
Object[]{WebAppConstants.SERVLET_NAME, "notaservlet"});
+ assertEquals(expected, m.getAttribute(IMarker.MESSAGE, ""));
+
+ assertFalse(hasMarkerOnLine(markers, 24));
+ }
+
public static void replaceFile(IProject project, String sourcePath, String targetPath)
throws CoreException {
boolean saveAutoBuild = ResourcesUtils.setBuildAutomatically(false);
try {