01: // Copyright © 2006-2007 ASERT. Released under the Canoo Webtest license.
02: package com.canoo.webtest.plugins.exceltest;
03:
04: import com.canoo.webtest.steps.Step;
05:
06: /**
07: * Test class for {@link ExcelSelectSheet}.<p>
08: *
09: * @author Rob Nielsen
10: */
11: public class ExcelSelectSheetTest extends BaseExcelStepTestCase {
12: protected Step createStep() {
13: return new ExcelSelectSheet();
14: }
15:
16: public void testSelectSheetByIndex() throws Exception {
17: final ExcelSelectSheet step = (ExcelSelectSheet) getStep();
18: step.setSheetIndex("2");
19: executeStep(step);
20: assertSame(step.getExcelWorkbook().getSheetAt(2), step
21: .getExcelSheet());
22: }
23:
24: public void testSelectSheetByName() throws Exception {
25: final ExcelSelectSheet step = (ExcelSelectSheet) getStep();
26: step.setSheetName("Sheet2");
27: executeStep(step);
28: assertSame(step.getExcelWorkbook().getSheetAt(1), step
29: .getExcelSheet());
30: }
31:
32: public void testInvalidParameters() {
33: checkInvalidParameters(null, null,
34: "Either sheet number or sheet name should be specified");
35: checkInvalidParameters("2", "X",
36: "One of sheet number or sheet name must be specified");
37: checkInvalidParameters("X", null,
38: "Can't parse sheetIndex parameter with value 'X' as an integer.");
39: }
40:
41: private void checkInvalidParameters(final String sheetIndex,
42: final String sheetName, final String error) {
43: final ExcelSelectSheet step = (ExcelSelectSheet) getStep();
44: step.setSheetIndex(sheetIndex);
45: step.setSheetName(sheetName);
46: assertErrorOnExecute(step, "invalid parameters", error);
47: }
48: }
|