001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.test.sanity;
043:
044: import com.meterware.httpunit.HttpUnitOptions;
045: import com.meterware.httpunit.SubmitButton;
046: import com.meterware.httpunit.WebConversation;
047: import com.meterware.httpunit.WebForm;
048: import com.meterware.httpunit.WebResponse;
049: import java.awt.Component;
050: import javax.swing.JComponent;
051: import junit.framework.Test;
052: import junit.framework.TestSuite;
053: import org.netbeans.jemmy.ComponentChooser;
054: import org.netbeans.jemmy.TimeoutExpiredException;
055: import org.netbeans.junit.NbTestSuite;
056:
057: import java.io.File;
058: import java.awt.*;
059:
060: import org.netbeans.modules.visualweb.gravy.*;
061: import org.netbeans.modules.visualweb.gravy.ProjectNavigatorOperator;
062: import org.netbeans.modules.visualweb.gravy.dataconnectivity.ServerNavigatorOperator;
063: import org.netbeans.modules.visualweb.gravy.plugins.PluginsOperator;
064: import org.netbeans.modules.visualweb.gravy.toolbox.PaletteContainerOperator;
065: import org.netbeans.modules.visualweb.gravy.designer.DesignerPaneOperator;
066: import org.netbeans.modules.visualweb.gravy.model.IDE;
067: import org.netbeans.modules.visualweb.gravy.model.deployment.*;
068: import org.netbeans.modules.visualweb.gravy.navigation.NavigatorOperator;
069: import org.netbeans.modules.visualweb.gravy.properties.SheetTableOperator;
070: import java.awt.event.KeyEvent;
071: import java.io.IOException;
072: import java.io.IOException;
073: import java.util.regex.Matcher;
074: import java.util.regex.Pattern;
075: import org.netbeans.jellytools.OutputTabOperator;
076: import org.netbeans.jemmy.operators.*;
077:
078: /**
079: * @author Alexey Butenko (alexey.butenko@sun.com)
080: */
081: public class SanityTests extends RaveTestCase {
082:
083: public static String _projectName = "SanityProject";
084: public static String _projectPath = System
085: .getProperty("xtest.workdir")
086: + File.separator
087: + "projects"
088: + File.separator
089: + _projectName;
090: public static String bundle = "org.netbeans.test.sanity.Bundle";
091: public static String ravePaletteBundle = Bundle.getStringTrimmed(
092: bundle, "RavePaletteBundle");
093: public static String _projectType = Bundle.getStringTrimmed(bundle,
094: "ProjectType");
095: /*
096: public static String _projectCategory = Bundle.getStringTrimmed(
097: Bundle.getStringTrimmed(bundle,"ProjectWizardBundle"),
098: Bundle.getStringTrimmed(bundle, "ProjectCategory"));
099: */
100: public static String _projectCategory = Bundle.getStringTrimmed(
101: bundle, "ProjectCategory");
102: public static String _requestPrefix;
103: public static String _pluginName = "Visual Web JSF Backwards Compatibility Kit";
104: public static DesignerPaneOperator designer;
105: public static String paletteGroup = null;
106: public static int xButtonLoc;
107: public static int yButtonLoc;
108:
109: public SanityTests(String testName) {
110: super (testName);
111: doFullThreadDump = true;
112: }
113:
114: public static Test suite() {
115: TestSuite suite = new NbTestSuite();
116: suite.addTest(new SanityTests("testAddPlugin"));
117: suite.addTest(new SanityTests("testAddApplicationServer"));
118: suite.addTest(new SanityTests("testCreateProject"));
119: suite.addTest(new SanityTests("testAddButton"));
120: // Comment out as PageNavigation is not supposed to work for M7
121: //suite.addTest(new SanityTests("testPageNavigation"));
122: //TODO: commented because creating of component's Event Habdler method not implemented yet
123: suite.addTest(new SanityTests("testBackingFile"));
124: suite.addTest(new SanityTests("testCloseProject"));
125: suite.addTest(new SanityTests("testCreateJavaEE5Project"));
126: //suite.addTest(new SanityTests("testAddComponents"));
127: suite.addTest(new SanityTests("testAddStandardComponents"));
128: suite.addTest(new SanityTests("testExecution"));
129: suite.addTest(new SanityTests("testCheckIDELog"));
130: return suite;
131: }
132:
133: /** method called before each testcase
134: */
135: protected void setUp() {
136: Util.saveAllAPICall();
137: System.out.println("######## " + getName() + " #######");
138: }
139:
140: /** method called after each testcase
141: */
142: protected void tearDown() {
143: //Util.saveAllAPICall();
144: System.out.println("######## " + getName()
145: + " Finished #######");
146: }
147:
148: public void testAddPlugin() {
149: startTest();
150: PluginsOperator.getInstance().installAvailablePlugins(
151: _pluginName);
152: endTest();
153: }
154:
155: public void testAddApplicationServer() {
156: startTest();
157: // JemmyProperties.setCurrentDispatchingModel(JemmyProperties.ROBOT_MODEL_MASK);
158: IDE.getIDE();
159: endTest();
160: }
161:
162: /*
163: * Create new project
164: * And add property val to SessionBean1.java
165: */
166: public void testCreateProject() {
167: startTest();
168: // Create Project
169: try {
170: log("project type = " + _projectType
171: + ", project category = " + _projectCategory);
172: TestUtils.createNewProjectLoc(_projectPath, _projectName,
173: true, _projectType, _projectCategory);
174: } catch (Exception e) {
175: e.printStackTrace();
176: log("Exception during project creation occured " + e);
177: fail();
178: }
179: endTest();
180: }
181:
182: public void testAddButton() {
183: startTest();
184: new org.netbeans.jellytools.TopComponentOperator(
185: RaveWindowOperator.getDefaultRave(), Bundle
186: .getStringTrimmed(bundle, "Page1"));
187: TestUtils.wait(50000);
188: designer = new DesignerPaneOperator(RaveWindowOperator
189: .getDefaultRave());
190:
191: //Bring up palette. Workaround for issue http://www.netbeans.org/issues/show_bug.cgi?id=105200
192: PaletteContainerOperator.showPalette();
193: TestUtils.wait(1000);
194:
195: // Add Button component
196: paletteGroup = Bundle.getStringTrimmed(ravePaletteBundle,
197: Bundle.getStringTrimmed(bundle, "PaletteGroup"));
198: log("Palette Group = " + paletteGroup);
199: PaletteContainerOperator palette = new PaletteContainerOperator(
200: paletteGroup);
201:
202: // Wait for the Portfolio to appear
203: try {
204: Thread.sleep(5000);
205: } catch (Exception e) {
206: }
207: log("Rave Palette Bundle = " + ravePaletteBundle);
208: //log("Button text = "+ Bundle.getStringTrimmed(ravePaletteBundle,Bundle.getStringTrimmed(bundle,"ButtonComponent")));
209: // TODO :Need to fine appropriate bundle
210: //palette.addComponent(Bundle.getStringTrimmed(ravePaletteBundle,Bundle.getStringTrimmed(bundle,"ButtonComponent")), designer, new Point(168, 168));
211: palette.addComponent(Bundle.getStringTrimmed(bundle,
212: "ButtonComponent"), designer, new Point(168, 168));
213: TestUtils.wait(7000);
214: try {
215: //Waiting until button's Properties window appeared, otherwise will fail.
216: new org.netbeans.jellytools.TopComponentOperator("button1:");
217: } catch (Exception e) {
218: e.printStackTrace();
219: fail("Probably button wasn't aded on designer: " + e);
220: }
221: SheetTableOperator sheet = new SheetTableOperator();
222: TestUtils.wait(2000);
223: String componentValue = //Bundle.getStringTrimmed(
224: //Bundle.getStringTrimmed(bundle,"PropertiesBundle"),
225: Bundle.getStringTrimmed(bundle, "ComponentValue");//);
226: log("componentValue = " + componentValue);
227: sheet.clickForEdit(sheet.findCell(componentValue, 2).y, 1);
228: TestUtils.wait(2000);
229: new JTextComponentOperator(sheet).enterText(Bundle
230: .getStringTrimmed(bundle, "TCButtonValue"));
231: TestUtils.wait(1000);
232:
233: try {
234: Point btnLoc = designer.getComponentCenter("button1");
235: } catch (Exception e) {
236: e.printStackTrace();
237: fail("Button disappeared: " + e);
238: }
239: //Util.saveAllAPICall();
240: designer.switchToJSPSource();
241: //This string should present in JSP editor
242: String verStr = "text=\""
243: + Bundle.getStringTrimmed(bundle, "TCButtonValue")
244: + "\"";
245: String Page1 = Bundle.getStringTrimmed(bundle, "Page1");
246: assertFalse("There is no \"" + verStr
247: + "\" string in jsp editor",
248: new org.netbeans.jellytools.EditorOperator(Page1)
249: .getText().indexOf(verStr) == -1);
250: endTest();
251: }
252:
253: public void testPageNavigation() {
254: startTest();
255: ProjectNavigatorOperator prjNav = new ProjectNavigatorOperator();
256: prjNav.requestFocus();
257:
258: TestUtils.wait(1000);
259: String bundleName = Bundle.getStringTrimmed(bundle,
260: "ProjectsBundle");
261: String pageNavigation = Bundle.getStringTrimmed(bundleName,
262: Bundle.getStringTrimmed(bundle, "PageNavigation"));
263: log("pageNavigation = " + pageNavigation);
264: prjNav.pressPopupItemOnNode(
265: _projectName + "|" + pageNavigation, Bundle
266: .getStringTrimmed(bundle, "OpenPopupItem"));
267: NavigatorOperator no = new NavigatorOperator();
268: TestUtils.wait(1500);
269: String addPage = Bundle.getStringTrimmed(Bundle
270: .getStringTrimmed(bundle, "RaveNavigationGraphBundle"),
271: Bundle.getStringTrimmed(bundle, "AddPagePopupItem"));
272: log("Add Page Popup Item = " + addPage);
273: no.pushPopup(addPage);
274: TestUtils.wait(5000);
275: bundleName = Bundle.getStringTrimmed(bundle,
276: "RaveNavigationBundle");
277: String newFormTitle = Bundle.getStringTrimmed(bundleName,
278: Bundle.getStringTrimmed(bundle, "NewFormTitle"));
279: log("newFormTitle = " + newFormTitle);
280: new JButtonOperator(new JDialogOperator(newFormTitle), "OK")
281: .pushNoBlock();
282:
283: // Create link between page1 to page2, named 'go'
284: no
285: .link(
286: Bundle.getStringTrimmed(bundle, "Page1")
287: + ".jsp", Bundle.getStringTrimmed(
288: bundle, "Page2")
289: + ".jsp", "go");
290: TestUtils.wait(500);
291: endTest();
292: }
293:
294: /*
295: * Test for java file editing
296: */
297: public void testBackingFile() {
298: startTest();
299: designer = new DesignerPaneOperator(RaveWindowOperator
300: .getDefaultRave());
301: designer.makeComponentVisible();
302: TestUtils.wait(2000);
303: // Double click at button to open Jave Editor
304: try {
305: Point btnLoc = designer.getComponentCenter("button1");
306: xButtonLoc = (int) btnLoc.getX();
307: yButtonLoc = (int) btnLoc.getY();
308: } catch (Exception e) {
309: e.printStackTrace();
310: fail("There is no button1 was found on designer: " + e);
311: }
312:
313: TestUtils.wait(2000);
314: log("(x,y)=(" + xButtonLoc + "," + yButtonLoc + ")");
315:
316: designer.clickMouse(xButtonLoc, yButtonLoc, 2);
317: org.netbeans.jellytools.TopComponentOperator tc = new org.netbeans.jellytools.TopComponentOperator(
318: Bundle.getStringTrimmed(bundle, "Page1"));
319: org.netbeans.jellytools.EditorOperator editor = new org.netbeans.jellytools.EditorOperator(
320: (JComponent) tc
321: .waitSubComponent(new ComponentChooser() {
322: public boolean checkComponent(Component comp) {
323: return comp
324: .getClass()
325: .getName()
326: .endsWith(
327: "JavaEditorTopComponent");
328: }
329:
330: public String getDescription() {
331: return "JavaEditorTopComponent";
332: }
333: }));
334: editor.replace("return null;", "return \"go\";\n");
335: new Action(null, "Format").perform(editor);
336: // Switch to design panel
337: designer.makeComponentVisible();
338: endTest();
339: }
340:
341: public void testCloseProject() {
342: startTest();
343: Util.saveAllAPICall();
344: String closeProjectPopupItem = //Bundle.getStringTrimmed(
345: // Bundle.getStringTrimmed(bundle,"ProjectsCustomizerBundle"),
346: Bundle.getStringTrimmed(bundle, "CloseProjectPopupItem");//);
347: log("closeProjectPopupItem = " + closeProjectPopupItem);
348: new ProjectNavigatorOperator().pressPopupItemOnNode(
349: _projectName, closeProjectPopupItem);
350: //TestUtils.closeCurrentProject();
351: TestUtils.wait(5000);
352: endTest();
353: }
354:
355: public void testCreateJavaEE5Project() {
356: _projectName = "SanityJavaEE5Project";
357: startTest();
358: try {
359: TestUtils.createJavaEE5ProjectLoc(_projectPath,
360: _projectName, true, _projectType, _projectCategory);
361: } catch (Exception e) {
362: e.printStackTrace();
363: log("Exception during project creation occured " + e);
364: fail("Exception during project creation: ");
365: }
366: endTest();
367: }
368:
369: public void testAddComponents() {
370: startTest();
371: new org.netbeans.jellytools.TopComponentOperator(
372: RaveWindowOperator.getDefaultRave(), Bundle
373: .getStringTrimmed(bundle, "Page1"));
374: //TestUtils.wait(20000);
375: org.netbeans.jemmy.QueueTool theTool = new org.netbeans.jemmy.QueueTool();
376: theTool.getTimeouts().setTimeout(
377: "QueueTool.WaitQueueEmptyTimeout", 60000);
378: theTool.waitEmpty(100);
379: designer = new DesignerPaneOperator(Util.getMainWindow());
380:
381: //Bring up palette. Workaround for issue http://www.netbeans.org/issues/show_bug.cgi?id=105200
382: PaletteContainerOperator.showPalette();
383: TestUtils.wait(1000);
384:
385: paletteGroup = Bundle.getStringTrimmed(ravePaletteBundle,
386: Bundle.getStringTrimmed(bundle, "PaletteGroup"));
387: PaletteContainerOperator palette = new PaletteContainerOperator(
388: paletteGroup);
389: TestUtils.wait(2000);
390: //TODO: Find appropriate Rave bundle
391: //String label = Bundle.getStringTrimmed(ravePaletteBundle,Bundle.getStringTrimmed(bundle,"LabelComponent"));
392: String label = Bundle
393: .getStringTrimmed(bundle, "LabelComponent");
394: palette.addComponent(label, designer, new Point(5, 5));
395: TestUtils.wait(10000);
396: String componentValue = //Bundle.getStringTrimmed(
397: //Bundle.getStringTrimmed(bundle,"PropertiesBundle"),
398: Bundle.getStringTrimmed(bundle, "ComponentValue");//);
399: log("componentValue = " + componentValue);
400: new SheetTableOperator().setTextValue(componentValue,
401: "Java EE 5 Project");
402: TestUtils.wait(2000);
403: //Getting button name from Rave bundle
404: //by getting its bundle name and bundle location from local byndle
405: //TODO Find appropriate Rave Bundle
406: //String button = Bundle.getStringTrimmed(ravePaletteBundle,Bundle.getStringTrimmed(bundle,"ButtonComponent"));
407: String button = Bundle.getStringTrimmed(bundle,
408: "ButtonComponent");
409: palette.addComponent(button, designer, new Point(100, 80));
410: TestUtils.wait(5000);
411: try {
412: //Waiting until button's Properties window appeared, otherwise will fail.
413: new org.netbeans.jellytools.TopComponentOperator("button1:");
414: } catch (Exception e) {
415: e.printStackTrace();
416: fail("Probably button wasn't aded on designer: " + e);
417: }
418:
419: new SheetTableOperator().setButtonValue("text", "Push me");
420: TestUtils.wait(2000);
421: Util.saveAllAPICall();
422: designer.clickMouse("button1", 2);
423: EditorOperator editor = new EditorOperator(
424: Util.getMainWindow(), Bundle.getStringTrimmed(bundle,
425: "Page1"));
426: //Because of #123536, it will be necessary to add binding explicitly, therefore requires an additional
427: //step in sanity. Commenting out the following to avoid sanity failures
428: // TestUtils.wait(2000);
429: // editor.txtEditorPane().typeText("label1.setValue(\"Clicked on button\"); \n");
430: TestUtils.wait(2000);
431: designer.switchToDesignerPane();
432: TestUtils.wait(2000);
433: Util.getMainWindow().saveAll();
434: endTest();
435: }
436:
437: public void testAddStandardComponents() {
438: startTest();
439: new org.netbeans.jellytools.TopComponentOperator(
440: RaveWindowOperator.getDefaultRave(), Bundle
441: .getStringTrimmed(bundle, "Page1"));
442: TestUtils.wait(20000);
443: designer = new DesignerPaneOperator(Util.getMainWindow());
444:
445: paletteGroup = Bundle.getStringTrimmed(bundle,
446: "StandardPalette");
447: PaletteContainerOperator palette = new PaletteContainerOperator(
448: paletteGroup);
449: TestUtils.wait(2000);
450: //TODO: Find appropriate Rave bundle
451: //String label = Bundle.getStringTrimmed(ravePaletteBundle,Bundle.getStringTrimmed(bundle,"LabelComponent"));
452: String label = Bundle.getStringTrimmed(bundle,
453: "StandardOutputTextComponent");
454: palette.addComponent(label, designer, new Point(5, 5));
455: TestUtils.wait(5000);
456: String componentValue = //Bundle.getStringTrimmed(
457: //Bundle.getStringTrimmed(bundle,"PropertiesBundle"),
458: Bundle.getStringTrimmed(bundle, "ComponentValue");//);
459: log("componentValue = " + componentValue);
460: new SheetTableOperator().setTextValue("value",
461: "Java EE 5 Project");
462: TestUtils.wait(2000);
463: //Getting button name from Rave bundle
464: //by getting its bundle name and bundle location from local byndle
465: //TODO Find appropriate Rave Bundle
466: //String button = Bundle.getStringTrimmed(ravePaletteBundle,Bundle.getStringTrimmed(bundle,"ButtonComponent"));
467: String button = Bundle.getStringTrimmed(bundle,
468: "StandardButtonComponent");
469: palette.addComponent(button, designer, new Point(100, 80));
470: TestUtils.wait(5000);
471: try {
472: //Waiting until button's Properties window appeared, otherwise will fail.
473: new org.netbeans.jellytools.TopComponentOperator("button1:");
474: } catch (Exception e) {
475: e.printStackTrace();
476: fail("Probably button wasn't aded on designer: " + e);
477: }
478:
479: new SheetTableOperator().setTextValue("value", "Push me");
480: TestUtils.wait(2000);
481: Util.saveAllAPICall();
482: designer.clickMouse("button1", 2);
483: EditorOperator editor = new EditorOperator(
484: Util.getMainWindow(), Bundle.getStringTrimmed(bundle,
485: "Page1"));
486: TestUtils.wait(2000);
487: //Because of #123536, it will be necessary to add binding explicitly, therefore requires an additional
488: //step in sanity. Commenting out the following to avoid sanity failures
489: // editor.txtEditorPane().typeText("outputText1.setValue(\"Clicked on button\"); \n");
490: // TestUtils.wait(2000);
491: designer.switchToDesignerPane();
492: TestUtils.wait(2000);
493: Util.getMainWindow().saveAll();
494: endTest();
495: }
496:
497: public void testExecution() {
498: startTest();
499: String runProjectPopupItem = Bundle.getStringTrimmed(Bundle
500: .getStringTrimmed(bundle, "ProjectsBundle"), Bundle
501: .getStringTrimmed(bundle, "RunProjectPopupItem"));
502: log("runProjectPopupItem = " + runProjectPopupItem);
503: ProjectNavigatorOperator.pressPopupItemOnNode(_projectName,
504: runProjectPopupItem);
505: TestUtils.wait(2000);
506: OutputTabOperator oto = new OutputTabOperator(_projectName);
507: oto.getTimeouts().setTimeout(
508: "ComponentOperator.WaitStateTimeout", 240000);
509: try {
510: oto.waitText("BUILD SUCCESSFUL");
511: } catch (TimeoutExpiredException e) {
512: log(oto.getText());
513: try {
514: // log glassfish message
515: log("glassfish.txt", new OutputTabOperator("GlassFish")
516: .getText());
517: } catch (Exception ex) {
518: // ignore
519: }
520: e.printStackTrace();
521: fail("Deployment error: " + e);
522: }
523:
524: try {
525: WebConversation conversation = new WebConversation();
526: WebResponse response = null;
527: //HttpUnitOptions.setExceptionsThrownOnScriptError(false);
528: HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);
529: HttpUnitOptions.setScriptingEnabled(false);
530:
531: // Get deployment target prefix from test/data/DefaultDepploymentTargets.propertes.
532: // By default, it is http://localhost:8080
533: ApplicationServer as = (ApplicationServer) IDE.getIDE()
534: .getDeploymentTargets().get(0);
535: _requestPrefix = as.requestPrefix;
536: log("prefix=" + as.requestPrefix);
537:
538: response = conversation.getResponse(_requestPrefix
539: + _projectName);
540: TestUtils.wait(5000);
541: log("Response text before form1 submit: "
542: + response.getText());
543: WebForm addContainer = response.getForms()[0];
544: SubmitButton btn = addContainer.getSubmitButtons()[0];
545: response = addContainer.submit(btn);
546: TestUtils.wait(5000);
547: log("Response text after form1 submit: "
548: + response.getText());
549: //TODO action handler commented in testAddComponents()
550: //Because of #123536, it will be necessary to add binding explicitly, therefore requires an additional
551: //step in sanity. Commenting out the following to avoid sanity failures. Should uncomment once additional
552: //step is added
553: // assertFalse("Wrong response after form submit", response.getText().indexOf("Clicked on button")==-1);
554: // //assertFalse("Wrong response after form submit", response.getText().indexOf("Push me")==-1);
555: TestUtils.wait(2000);
556: ServerNavigatorOperator.showNavigatorOperator().pushPopup(
557: ServerNavigatorOperator.STR_SERVERS_PATH
558: + as.web_applications_path + "|"
559: + as.app_pref + _projectName,
560: as.APPLICATION_UNDEPLOY);
561: TestUtils.wait(1000);
562: } catch (Exception e) {
563: e.printStackTrace();
564: fail("Exception during run : " + e);
565: }
566: endTest();
567: }
568:
569: public void testCheckIDELog() {
570: startTest();
571: try {
572: assertTrue("Unexpected exceptions found in message.log",
573: !hasUnexpectedException());
574: } catch (IOException ioe) {
575: ioe.printStackTrace();
576: fail("Failed to open message.log : " + ioe);
577: }
578: endTest();
579: }
580:
581: public boolean hasUnexpectedException() throws IOException {
582: String[] knownException = {
583: "import javax.faces.FacesException",
584: "java.lang.IllegalStateException",
585: "java.lang.IllegalArgumentException: Expected scheme-specific part at index",
586: "java.lang.IllegalArgumentException: Cannot get BASE revision,",
587: "java.net.UnknownHostException: www.netbeans.org",
588: "java.io.IOException" };
589:
590: String logFile = System.getProperty("xtest.workdir")
591: + File.separator
592: + Bundle.getStringTrimmed(bundle, "LogFile");
593: String lineSep = System.getProperty("line.separator");
594: StringBuffer sb = new StringBuffer();
595: String nextLine = "";
596: boolean isUnexpectedException;
597:
598: //Get lines that has word "Exceptions" from message.log
599: String exceptions = TestUtils.parseLogs(logFile, "Exception");
600: if (exceptions.equals("")) {
601: log("There are no any execptions found");
602: return false;
603: } else {
604: log("Exceptions found in message.log:\n" + exceptions);
605: // Compile the pattern
606: String patternStr = "^(.*)$";
607: Pattern pattern = Pattern.compile(patternStr,
608: Pattern.MULTILINE);
609: Matcher matcher = pattern.matcher(exceptions);
610:
611: // Read exceptions line by line to determine if it is unexpected
612: while (matcher.find()) {
613: isUnexpectedException = true;
614: nextLine = matcher.group(1);
615: for (int i = 0; i < knownException.length; i++) {
616: if (nextLine.indexOf(knownException[i]) != -1)
617: isUnexpectedException = false;
618: }
619: if (isUnexpectedException) {
620: sb.append(nextLine);
621: sb.append(lineSep);
622: }
623: }
624: if (!sb.toString().equals("")) {
625: log("Unexpected exceptions: \n" + sb.toString());
626: return true;
627: } else
628: return false;
629: }
630: }
631: }
|