Author: vpakan(a)redhat.com
Date: 2011-07-29 04:56:15 -0400 (Fri, 29 Jul 2011)
New Revision: 33346
Added:
trunk/jsf/tests/org.jboss.tools.jsf.ui.bot.test/src/org/jboss/tools/jsf/ui/bot/test/smoke/MarkersTest.java
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/MarkerHelper.java
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.ui.bot.test/src/org/jboss/tools/jsf/ui/bot/test/JSFAllBotTests.java
Log:
Added test for Markers
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.ui.bot.test/src/org/jboss/tools/jsf/ui/bot/test/JSFAllBotTests.java
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.ui.bot.test/src/org/jboss/tools/jsf/ui/bot/test/JSFAllBotTests.java 2011-07-29
08:08:01 UTC (rev 33345)
+++
trunk/jsf/tests/org.jboss.tools.jsf.ui.bot.test/src/org/jboss/tools/jsf/ui/bot/test/JSFAllBotTests.java 2011-07-29
08:56:15 UTC (rev 33346)
@@ -16,6 +16,7 @@
import org.jboss.tools.jsf.ui.bot.test.smoke.CodeCompletionTest;
import org.jboss.tools.jsf.ui.bot.test.smoke.CreateNewJSFProjectTest;
import org.jboss.tools.jsf.ui.bot.test.smoke.FacesConfigCodeCompletionTest;
+import org.jboss.tools.jsf.ui.bot.test.smoke.MarkersTest;
import org.jboss.tools.jsf.ui.bot.test.smoke.OpenOnTest;
import org.jboss.tools.jsf.ui.bot.test.templates.SetTemplateForUnknownTagTest;
import org.jboss.tools.jsf.ui.bot.test.templates.UnknownTemplateTest;
@@ -44,6 +45,7 @@
suite.addTestSuite(OpenOnTest.class);
suite.addTestSuite(CodeCompletionTest.class);
suite.addTestSuite(FacesConfigCodeCompletionTest.class);
+ suite.addTestSuite(MarkersTest.class);
return suite;
}
}
\ No newline at end of file
Added:
trunk/jsf/tests/org.jboss.tools.jsf.ui.bot.test/src/org/jboss/tools/jsf/ui/bot/test/smoke/MarkersTest.java
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.ui.bot.test/src/org/jboss/tools/jsf/ui/bot/test/smoke/MarkersTest.java
(rev 0)
+++
trunk/jsf/tests/org.jboss.tools.jsf.ui.bot.test/src/org/jboss/tools/jsf/ui/bot/test/smoke/MarkersTest.java 2011-07-29
08:56:15 UTC (rev 33346)
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jsf.ui.bot.test.smoke;
+
+import org.jboss.tools.jsf.ui.bot.test.JSFAutoTestCase;
+import org.jboss.tools.ui.bot.ext.SWTJBTExt;
+import org.jboss.tools.ui.bot.ext.SWTTestExt;
+import org.jboss.tools.ui.bot.ext.Timing;
+import org.jboss.tools.ui.bot.ext.helper.MarkerHelper;
+import org.jboss.tools.ui.bot.ext.parts.SWTBotEditorExt;
+import org.jboss.tools.vpe.ui.bot.test.VPEAutoTestCase;
+/**
+ * Test Markers position and attributes regarding to JSF components within jsp page
+ * @author Vladimir Pakan
+ *
+ */
+public class MarkersTest extends JSFAutoTestCase{
+ private SWTBotEditorExt editor;
+ private String originalEditorText;
+ /**
+ * Test open on functionality of JSF components within jsp page
+ */
+ public void testMarkers(){
+ MarkerHelper markerHelper = new MarkerHelper(TEST_PAGE,
+ VPEAutoTestCase.JBT_TEST_PROJECT_NAME,"WebContent","pages");
+ String textToSelect = "<h:outputText value=\"#{Message.header";
+ String insertText = "yyaddedxx";
+ int[] expectedMarkerLines = new int[3];
+ String[] expectedMarkerDesc = new String[3];
+ SWTJBTExt.selectTextInSourcePane(SWTTestExt.bot,
+ TEST_PAGE,
+ textToSelect,
+ textToSelect.length(),
+ 0,
+ 0);
+ editor.insertText(insertText);
+ expectedMarkerLines[0] = editor.cursorPosition().line;
+ expectedMarkerDesc[0] = "^\"header" + insertText + "\"
cannot be resolved";
+ textToSelect = "<h:outputText value=\"#{Message.prompt_message";
+ SWTJBTExt.selectTextInSourcePane(SWTTestExt.bot,
+ TEST_PAGE,
+ textToSelect,
+ textToSelect.length(),
+ 0,
+ 0);
+ editor.insertText(insertText);
+ expectedMarkerLines[1] = editor.cursorPosition().line;
+ expectedMarkerDesc[1] = "^\"prompt_message" + insertText +
"\" cannot be resolved";
+ textToSelect = "<h:inputText value=\"#{user.name";
+ SWTJBTExt.selectTextInSourcePane(SWTTestExt.bot,
+ TEST_PAGE,
+ textToSelect,
+ textToSelect.length(),
+ 0,
+ 0);
+ editor.insertText(insertText);
+ expectedMarkerLines[2] = editor.cursorPosition().line;
+ expectedMarkerDesc[2] = "^\"name" + insertText + "\" cannot
be resolved";
+ editor.save();
+ bot.sleep(Timing.time2S());
+ // Check markers
+ for (int index = 0 ; index < expectedMarkerLines.length ; index++){
+ markerHelper.checkForMarker(String.valueOf(expectedMarkerLines[index] + 1),
+ expectedMarkerDesc[index]);
+ }
+ }
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ openPage(TEST_PAGE);
+ editor = SWTTestExt.bot.swtBotEditorExtByTitle(TEST_PAGE);
+ originalEditorText = editor.getText();
+ }
+ @Override
+ protected void tearDown() throws Exception {
+ if (editor != null){
+ editor.setText(originalEditorText);
+ editor.saveAndClose();
+ }
+ super.tearDown();
+ }
+}
\ No newline at end of file
Property changes on:
trunk/jsf/tests/org.jboss.tools.jsf.ui.bot.test/src/org/jboss/tools/jsf/ui/bot/test/smoke/MarkersTest.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/MarkerHelper.java
===================================================================
---
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/MarkerHelper.java
(rev 0)
+++
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/MarkerHelper.java 2011-07-29
08:56:15 UTC (rev 33346)
@@ -0,0 +1,272 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.ui.bot.ext.helper;
+
+import static org.junit.Assert.assertFalse;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+
+/**
+ * Helper for Marker related tests
+ * @author Vladimir Pakan
+ *
+ */
+public class MarkerHelper {
+ private IResource resource;
+
+ public MarkerHelper (String resourceName, String... pathToResource){
+ this.resource = ResourcesPlugin
+ .getWorkspace()
+ .getRoot()
+ .findMember(MarkerHelper.getPathToResource(resourceName, pathToResource));
+ }
+ /**
+ * Returns Markers for specified resource recursively
+ * @param resourceName
+ * @param pathToResource
+ * @return
+ */
+ public static IMarker[] getResourceMarkers(String resourceName, String...
pathToResource){
+ return MarkerHelper.getResourceMarkers(null, resourceName, pathToResource);
+ }
+ /**
+ * Returns Markers of specified type for specified resource recursively
+ * @param type
+ * @param resourceName
+ * @param pathToResource
+ * @return
+ */
+ public static IMarker[] getResourceMarkers(String type , String resourceName, String...
pathToResource){
+ try {
+ return ResourcesPlugin
+ .getWorkspace()
+ .getRoot()
+ .findMember(MarkerHelper.getPathToResource(resourceName, pathToResource))
+ .findMarkers(type, true, IResource.DEPTH_INFINITE);
+ } catch (CoreException ce) {
+ throw new RuntimeException(ce);
+ }
+ }
+ /**
+ * Returns Markers of specified type for resource specified within constructor
recursively
+ * @param type
+ * @return
+ */
+ public IMarker[] getMarkers(String type){
+ try {
+ return resource.findMarkers(type, true, IResource.DEPTH_INFINITE);
+ } catch (CoreException ce) {
+ throw new RuntimeException(ce);
+ }
+ }
+ /**
+ * Returns Markers for resource specified within constructor recursively
+ * @return
+ */
+ public IMarker[] getMarkers(){
+ return getMarkers(null);
+ }
+ /**
+ * Returns path to specified resource
+ * @param resourceName
+ * @param pathToResource
+ * @return
+ */
+ private static IPath getPathToResource (String resourceName, String...
pathToResource){
+ IPath path = new Path("/");
+
+ if (pathToResource != null){
+ for (String pathElement : pathToResource){
+ path = path.append(pathElement);
+ }
+ }
+ return path.append(resourceName);
+
+ }
+ /**
+ * Returns Marker Line Number
+ * @param marker
+ * @return
+ */
+ public static String getMarkerLineNumber (IMarker marker){
+ try {
+ return marker.getAttribute(IMarker.LINE_NUMBER).toString();
+ } catch (CoreException ce) {
+ return "";
+ }
+ }
+ /**
+ * Returns Marker Message
+ * @param marker
+ * @return
+ */
+ public static String getMarkerMessage (IMarker marker){
+ return marker.getAttribute(IMarker.MESSAGE, "");
+ }
+ /**
+ * Returns Marker Resource Name
+ * @param marker
+ * @return
+ */
+ public static String getMarkerResourceName (IMarker marker){
+ return marker.getResource().getName();
+ }
+ /**
+ * Returns Marker Resource Location i.e. path to resource without resource name
+ * @param marker
+ * @return
+ */
+ public static String getMarkerResourceLocation (IMarker marker){
+ return marker.getResource().getParent().getFullPath().toString();
+ }
+ /**
+ * Display all markers of type for resource specified within constructor
+ * @param type
+ */
+ public void displayAllMarkers(String type){
+ displayMarkers(getMarkers(type));
+ }
+ /**
+ * Display all markers for resource specified within constructor
+ */
+ public void displayAllMarkers(){
+ displayAllMarkers(null);
+ }
+ /**
+ * Display all Markers of specified type for specified resource recursively
+ * @param resourceName
+ * @param pathToResource
+ * @param type
+ */
+ public static void displayAllMarkers(String type, String resourceName, String...
pathToResource){
+ MarkerHelper.displayMarkers(
+ MarkerHelper.getResourceMarkers(type , resourceName, pathToResource));
+ }
+ /**
+ * Display all Markers for specified resource recursively
+ * @param resourceName
+ * @param pathToResource
+ */
+ public static void displayAllMarkers(String resourceName, String... pathToResource){
+ MarkerHelper.displayAllMarkers(null, resourceName, pathToResource);
+ }
+ /**
+ * Display markers nicely formatted
+ */
+ private static void displayMarkers (IMarker[] markers) {
+ for (IMarker marker : markers){
+ StringBuffer sb = new StringBuffer("");
+ sb.append("Line Number: ");
+ sb.append(MarkerHelper.getMarkerLineNumber(marker));
+ sb.append(" Location: ");
+ sb.append(MarkerHelper.getMarkerResourceLocation(marker));
+ sb.append(" Resource Name: ");
+ sb.append(MarkerHelper.getMarkerResourceName(marker));
+ sb.append(" Message: ");
+ sb.append(MarkerHelper.getMarkerMessage(marker));
+ System.out.println(sb);
+ try {
+ sb = new StringBuffer(" - attributes:");
+ for (Object key : marker.getAttributes().keySet()){
+ sb.append(" ");
+ sb.append(key);
+ sb.append("=");
+ sb.append(marker.getAttribute(key.toString()));
+ }
+ System.out.println(sb);
+ } catch (CoreException ce) {
+ throw new RuntimeException(ce);
+ }
+ }
+ }
+ /**
+ * Check if resource specified within constructor has marker
+ * on specified line of specified type and with message matching decritpionRegex
+ * @param lineNumber
+ * @param descriptionRegex
+ * @param type
+ */
+ public void checkForMarker (String lineNumber , String descriptionRegex , String
type){
+ MarkerHelper.checkMarkersForMarker(getMarkers(type),
+ lineNumber,
+ descriptionRegex,
+ resource.getName());
+ }
+ /**
+ * Check if resource specified within constructor has marker
+ * on specified line and with message matching decritpionRegex
+ * @param lineNumber
+ * @param descriptionRegex
+ */
+ public void checkForMarker (String lineNumber , String descriptionRegex ){
+ checkForMarker(lineNumber, descriptionRegex, null);
+ }
+ /**
+ * Check if specified resource has marker
+ * on specified line and with message matching decritpionRegex
+ * @param lineNumber
+ * @param descriptionRegex
+ * @param resourceName
+ * @param pathToResource
+ */
+ public static void checkResourceForMarker (String lineNumber , String descriptionRegex,
String resourceName, String... pathToResource){
+ MarkerHelper.checkResourceForMarker(null,
+ lineNumber,
+ descriptionRegex,
+ resourceName,
+ pathToResource);
+ }
+ /**
+ * Check if specified resource has marker
+ * on specified line of specified type and with message matching decritpionRegex
+ * @param type
+ * @param lineNumber
+ * @param descriptionRegex
+ * @param resourceName
+ * @param pathToResource
+ */
+ public static void checkResourceForMarker (String type , String lineNumber , String
descriptionRegex, String resourceName, String... pathToResource){
+ MarkerHelper.checkMarkersForMarker(MarkerHelper.getResourceMarkers(type ,
resourceName, pathToResource),
+ lineNumber,
+ descriptionRegex,
+ resourceName);
+ }
+ /**
+ * Check if markers contains marker
+ * on specified line and with message matching decritpionRegex
+ * @param markers
+ * @param lineNumber
+ * @param descriptionRegex
+ * @param resourceName
+ */
+ private static void checkMarkersForMarker (IMarker[] markers , String lineNumber ,
String descriptionRegex , String resourceName){
+ boolean notFound = true;
+ int index = 0;
+ while (notFound && index < markers.length){
+ if (MarkerHelper.getMarkerLineNumber(markers[index]).equals(lineNumber)){
+ if (MarkerHelper.getMarkerMessage(markers[index]).matches(descriptionRegex)){
+ notFound = false;
+ }
+ }
+ index++;
+ }
+ assertFalse("Resource: " + resourceName +
+ "doesn't have marker on line " + lineNumber +
+ " with descritpion matching regular expression '" +
descriptionRegex + "'",
+ notFound);
+ }
+
+}
Property changes on:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/helper/MarkerHelper.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain