From 641c0b202fedd27abf20d0b5f32f00eb0c32ab38 Mon Sep 17 00:00:00 2001 From: Anuj kumar Date: Tue, 20 Nov 2012 10:06:06 +0100 Subject: [PATCH 01/11] Initial Commit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8028475..97d7280 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -EasyTest Spring: An extension of EasyTest Core module to support Data Driven Testing for Spring based projects. +EasyTest Spring : An extension of EasyTest Core module to support Data Driven Testing for Spring based projects. ------------------------------------------------------------------------------------------------------ For details on using EasyTest Spring module look at : https://github.com/EaseTech/easytest/wiki/EasyTest-:-Spring-Integration From 367b167d27f90df54c13ac912e71fad64b3c3455 Mon Sep 17 00:00:00 2001 From: Anuj kumar Date: Thu, 13 Dec 2012 15:59:57 +0100 Subject: [PATCH 02/11] Updated to depend on ResourceLoader Updated so that reports now work for Spring based test cases as well. --- pom.xml | 411 +++++++++--------- .../easytest/runner/SpringTestRunner.java | 102 ++++- src/main/resources/reports/MainReport.jrxml | 253 ----------- .../easytest/example/CustomCSVDataLoader.java | 67 +-- .../example/CustomObjectDataLoader.java | 37 -- .../TestCombinedLoadingAndWriting.java | 4 +- ...stConditionsSupportedByDataDrivenTest.java | 2 +- ...stDifferentConditionsSupportedByParam.java | 44 +- .../easytest/example/TestExcelDataLoader.java | 7 +- .../easytest/example/TestXMLDataLoader.java | 7 +- .../interceptor/CGLIBEnhancerTest.java | 2 +- 11 files changed, 344 insertions(+), 592 deletions(-) delete mode 100644 src/main/resources/reports/MainReport.jrxml delete mode 100644 src/test/java/org/easetech/easytest/example/CustomObjectDataLoader.java diff --git a/pom.xml b/pom.xml index 08afa16..bcaa4cf 100644 --- a/pom.xml +++ b/pom.xml @@ -1,220 +1,217 @@ - + - - 4.0.0 - - oss-parent - org.sonatype.oss - 7 - - - org.easetech - easytest-spring - jar - EasyTest to ease Data Driven Testing - EasyTest is a JUnit extension perform Data Driven Testing with ease and simplicity. + + 4.0.0 + + oss-parent + org.sonatype.oss + 7 + + + org.easetech + easytest-spring + jar + EasyTest to ease Data Driven Testing + EasyTest is a JUnit extension perform Data Driven Testing with ease and simplicity. It supports method parameters with Test annotation and much more. - https://github.com/EaseTech/easytest - 0.7.0-SNAPSHOT + https://github.com/EaseTech/easytest + 0.7.0-SNAPSHOT - - - anujgandharv - Anuj Kumar - anuj.gandharv@gmail.com - http://www.kumaranuj.com - - - ravi-polampelli - Ravi Polampelli - ravi.polampelli@gmail.com - - - gpcmol - Christiaan Mol - gpcmol@gmail.com - - - - - Apache 2 - http://www.apache.org/licenses/LICENSE-2.0.txt - repo - A business-friendly OSS license - - + + + anujgandharv + Anuj Kumar + anuj.gandharv@gmail.com + http://www.kumaranuj.com + + + ravi-polampelli + Ravi Polampelli + ravi.polampelli@gmail.com + + + gpcmol + Christiaan Mol + gpcmol@gmail.com + + + + + Apache 2 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + A business-friendly OSS license + + - - scm:git:https://anujgandharv@github.com/EaseTech/easytest.git - scm:git:https://anujgandharv@github.com/EaseTech/easytest.git - scm:git:https://anujgandharv@github.com/EaseTech/easytest - + + scm:git:https://anujgandharv@github.com/EaseTech/easytest.git + scm:git:https://anujgandharv@github.com/EaseTech/easytest.git + scm:git:https://anujgandharv@github.com/EaseTech/easytest + - - - - org.jvnet.jaxb2.maven2 - maven-jaxb2-plugin - 0.6.2 - - - generate-sources - - generate - - - 2.2 - true - false - - -XtoString - -XhashCode - -Xequals - - - - org.jvnet.jaxb2_commons - jaxb2-basics-annotate - 0.6.2 - - - org.jvnet.jaxb2_commons - jaxb2-basics - 0.6.2 - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 2.3.2 - - true - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.1 - - true - - - - org.apache.maven.plugins - maven-release-plugin - 2.2.2 - - anujgandharv - temp123 - forked-path - - + + + + org.jvnet.jaxb2.maven2 + maven-jaxb2-plugin + 0.6.2 + + + generate-sources + + generate + + + 2.2 + true + false + + -XtoString + -XhashCode + -Xequals + + + + org.jvnet.jaxb2_commons + jaxb2-basics-annotate + 0.6.2 + + + org.jvnet.jaxb2_commons + jaxb2-basics + 0.6.2 + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + true + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.1 + + true + + + + org.apache.maven.plugins + maven-release-plugin + 2.2.2 + + anujgandharv + temp123 + forked-path + + - - + + - - - sourceAndjavadoc - - - - org.apache.maven.plugins - maven-source-plugin - - - attach-source - - jar - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - - - attach-javadocs - - jar - - - - - - - - - release-sign-artifacts - - - performRelease - true - - - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.1 - - - sign-artifacts - verify - - sign - - - - - - - - + + + sourceAndjavadoc + + + + org.apache.maven.plugins + maven-source-plugin + + + attach-source + + jar + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + attach-javadocs + + jar + + + + + + + + + release-sign-artifacts + + + performRelease + true + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.1 + + + sign-artifacts + verify + + sign + + + + + + + + - - - org.easetech - easytest-core - 0.7.0-SNAPSHOT - - - - org.springframework - spring-test - 3.0.6.RELEASE - + + + org.easetech + easytest-core + 1.0-SNAPSHOT + - - org.springframework - spring-aop - 3.0.6.RELEASE - - - log4j - log4j + + org.springframework + spring-test + 3.0.6.RELEASE + - - - junit - junit + + org.springframework + spring-aop + 3.0.6.RELEASE + + + log4j + log4j + + + junit + junit + + + commons-logging + commons-logging + + + - - - commons-logging - commons-logging - - - - - - - + diff --git a/src/main/java/org/easetech/easytest/runner/SpringTestRunner.java b/src/main/java/org/easetech/easytest/runner/SpringTestRunner.java index dd6c7dc..86c5193 100644 --- a/src/main/java/org/easetech/easytest/runner/SpringTestRunner.java +++ b/src/main/java/org/easetech/easytest/runner/SpringTestRunner.java @@ -1,6 +1,11 @@ package org.easetech.easytest.runner; +import org.easetech.easytest.reports.data.DurationBean; + +import java.util.Date; +import org.easetech.easytest.reports.data.TestResultBean; + import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; @@ -14,6 +19,9 @@ import org.easetech.easytest.annotation.Intercept; import org.easetech.easytest.annotation.Param; import org.easetech.easytest.internal.EasyAssignments; +import org.easetech.easytest.io.Resource; +import org.easetech.easytest.io.ResourceLoader; +import org.easetech.easytest.io.ResourceLoaderStrategy; import org.easetech.easytest.loader.DataConverter; import org.easetech.easytest.loader.Loader; import org.easetech.easytest.loader.LoaderFactory; @@ -142,6 +150,8 @@ private class EasyTestRunner extends SpringJUnit4ClassRunner { * This is extremely handy in cases where we want to reflectively set instance fields on a test class. */ Object testInstance; + + TestResultBean testResult; /** * @@ -153,6 +163,7 @@ private class EasyTestRunner extends SpringJUnit4ClassRunner { public EasyTestRunner(Class klass) throws InitializationError { super(klass); try { + testReportContainer = new ReportDataContainer(getTestClass().getJavaClass()); testInstance = getTestClass().getOnlyConstructor().newInstance(); getTestContextManager().prepareTestInstance(testInstance); instrumentClass(getTestClass().getJavaClass()); @@ -495,12 +506,12 @@ protected void runWithAssignment(EasyAssignments parameterAssignment) throws Thr protected void runWithCompleteAssignment(final EasyAssignments complete) throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, Throwable { new BlockJUnit4ClassRunner(getTestClass().getJavaClass()) { - @Override + protected void collectInitializationErrors(List errors) { // do nothing } - @Override + public Statement methodBlock(FrameworkMethod method) { final Statement statement = super.methodBlock(method); //Sample Run Notifier to catch any runnable events for a test and do something. @@ -529,12 +540,12 @@ public void evaluate() throws Throwable { }; } - @Override + protected Statement methodInvoker(FrameworkMethod method, Object test) { return methodCompletesWithParameters(method, complete, test); } - @Override + public Object createTest() throws Exception { return testInstance; } @@ -560,12 +571,46 @@ public Object createTest() throws Exception { */ private Statement methodCompletesWithParameters(final FrameworkMethod method, final EasyAssignments complete, final Object freshInstance) { + + final RunNotifier testRunNotifier = new RunNotifier(); + final TestRunDurationListener testRunDurationListener = new TestRunDurationListener(); + testRunNotifier.addListener(testRunDurationListener); + final EachTestNotifier eachRunNotifier = new EachTestNotifier(testRunNotifier, null); + return new Statement() { - @Override + public void evaluate() throws Throwable { + String currentMethodName = method.getMethod().getName(); + testResult = new TestResultBean(); + testResult.setMethod(currentMethodName); + testResult.setDate(new Date()); try { final Object[] values = complete.getMethodArguments(true); + // Log Statistics about the test method as well as the actual testSubject, if required. + boolean testContainsInputParams = (values.length != 0); + Map inputData = null; + // invoke test method + eachRunNotifier.fireTestStarted(); Object returnObj = method.invokeExplosively(freshInstance, values); + eachRunNotifier.fireTestFinished(); + DurationBean testItemDurationBean = new DurationBean(currentMethodName, testRunDurationListener.getStartInNano(), testRunDurationListener.getEndInNano()); + testResult.addTestItemDurationBean(testItemDurationBean); + + testResult.setOutput((returnObj == null) ? "void" : returnObj); + testResult.setPassed(Boolean.TRUE); + if (!mapMethodName.equals(method.getMethod().getName())) { + // if mapMethodName is not same as the current executing method name + // then assign that to mapMethodName to write to writableData + mapMethodName = method.getMethod().getName(); + // initialize the row number. + rowNum = 0; + } + if (writableData.get(mapMethodName) != null) { + inputData = writableData.get(mapMethodName).get(rowNum); + testResult.setInput(inputData); + } else{ + testResult.setInput(null); + } if (returnObj != null) { LOG.debug("returnObj:" + returnObj); if (!mapMethodName.equals(method.getMethod().getName())) { @@ -576,13 +621,36 @@ public void evaluate() throws Throwable { if (writableData.get(mapMethodName) != null) { LOG.debug("writableData.get(mapMethodName)" + writableData.get(mapMethodName) + " ,rowNum:" + rowNum); - writableData.get(mapMethodName).get(rowNum++).put(Loader.ACTUAL_RESULT, returnObj); + + Map writableRow = writableData.get(mapMethodName).get(rowNum); + writableRow.put(Loader.ACTUAL_RESULT, returnObj); + if (testContainsInputParams) { + LOG.debug("writableData.get(mapMethodName)" + writableData.get(mapMethodName) + + " ,rowNum:" + rowNum); + inputData.put(Loader.ACTUAL_RESULT, returnObj); + } + Object expectedResult = writableRow.get(Loader.EXPECTED_RESULT); + // if expected result exist in user input test data, + // then compare that with actual output result + // and write the status back to writable map data. + if (expectedResult != null) { + LOG.debug("Expected result exists"); + if (expectedResult.toString().equals(returnObj.toString())) { + writableRow.put(Loader.TEST_STATUS, Loader.TEST_PASSED); + } else { + writableRow.put(Loader.TEST_STATUS, Loader.TEST_FAILED); + } + } + rowNum++; + + //writableData.get(mapMethodName).get(rowNum++).put(Loader.ACTUAL_RESULT, returnObj); } } } catch (CouldNotGenerateValueException e) { // ignore } + testReportContainer.addTestResult(testResult); } }; } @@ -764,11 +832,23 @@ protected void loadData(Class testClass, FrameworkMethod method, Class cur + "You can provide the custom Loader by choosing LoaderType.CUSTOM in TestData " + "annotation and providing your custom loader using DataLoader annotation."); } else { - Map>> data = dataLoader.loadData(testInfo.getFilePaths()); - // We also maintain the copy of the actual data for our write functionality. - writableData.putAll(data); - DataContext.setData(DataConverter.appendClassName(data, currentTestClass)); - DataContext.setConvertedData(DataConverter.convert(data, currentTestClass)); + ResourceLoader resourceLoader = new ResourceLoaderStrategy(getTestClass().getJavaClass()); + for(String filePath : testInfo.getFilePaths()){ + Resource resource = resourceLoader.getResource(filePath); + try { + if(resource.exists()){ + Map>> data = dataLoader.loadData(resource); + // We also maintain the copy of the actual data for our write functionality. + writableData.putAll(data); + DataContext.setData(DataConverter.appendClassName(data, currentTestClass)); + DataContext.setConvertedData(DataConverter.convert(data, currentTestClass)); + } + } catch (Exception e) { + PARAM_LOG.error("Error occured while trying to find the resource with path {} ", resource.getResourceName(),e); + throw new RuntimeException(e); + } + } + } } diff --git a/src/main/resources/reports/MainReport.jrxml b/src/main/resources/reports/MainReport.jrxml deleted file mode 100644 index ef03f38..0000000 --- a/src/main/resources/reports/MainReport.jrxml +++ /dev/null @@ -1,253 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - <band height="251" splitType="Stretch"> - <frame> - <reportElement mode="Opaque" x="-20" y="0" width="822" height="65" forecolor="#006699" backcolor="#006699"/> - <staticText> - <reportElement style="Title" x="231" y="0" width="578" height="65"/> - <textElement textAlignment="Right"> - <font size="54" isBold="false"/> - </textElement> - <text><![CDATA[EasyTest Reports]]></text> - </staticText> - </frame> - <textField isStretchWithOverflow="true" isBlankWhenNull="true"> - <reportElement style="SubTitle" x="180" y="65" width="609" height="29"/> - <textElement textAlignment="Right"> - <font fontName="Times New Roman" size="22" isBold="true"/> - </textElement> - <textFieldExpression><![CDATA["Test class: " + $P{TEST_CLASS_NAME}]]></textFieldExpression> - </textField> - <image> - <reportElement x="0" y="65" width="180" height="180"/> - <imageExpression><![CDATA[((org.easetech.easytest.reports.data.ReportTotalsBean)$P{REPORT_PARAMETERS_MAP}.get($P{TEST_CLASS_NAME})).getTotalsGraph()]]></imageExpression> - </image> - <textField> - <reportElement x="180" y="186" width="262" height="20"/> - <textElement textAlignment="Left"> - <font size="12" isBold="true"/> - </textElement> - <textFieldExpression><![CDATA["Passed: " + ((org.easetech.easytest.reports.data.ReportTotalsBean)$P{REPORT_PARAMETERS_MAP}.get($P{TEST_CLASS_NAME})).getPassed() + " (" + ((org.easetech.easytest.reports.data.ReportTotalsBean)$P{REPORT_PARAMETERS_MAP}.get($P{TEST_CLASS_NAME})).getPercentagePassed() + " %)"]]></textFieldExpression> - </textField> - <textField> - <reportElement x="180" y="206" width="262" height="20"/> - <textElement textAlignment="Left"> - <font size="12" isBold="true"/> - </textElement> - <textFieldExpression><![CDATA["Failed: " + ((org.easetech.easytest.reports.data.ReportTotalsBean)$P{REPORT_PARAMETERS_MAP}.get($P{TEST_CLASS_NAME})).getFailed() + " (" + ((org.easetech.easytest.reports.data.ReportTotalsBean)$P{REPORT_PARAMETERS_MAP}.get($P{TEST_CLASS_NAME})).getPercentageFailed() + " %)"]]></textFieldExpression> - </textField> - <textField> - <reportElement x="180" y="226" width="262" height="20"/> - <textElement textAlignment="Left"> - <font size="12" isBold="true"/> - </textElement> - <textFieldExpression><![CDATA["Exception: " + ((org.easetech.easytest.reports.data.ReportTotalsBean)$P{REPORT_PARAMETERS_MAP}.get($P{TEST_CLASS_NAME})).getException() + " (" + ((org.easetech.easytest.reports.data.ReportTotalsBean)$P{REPORT_PARAMETERS_MAP}.get($P{TEST_CLASS_NAME})).getPercentageException() + " %)"]]></textFieldExpression> - </textField> - </band> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/test/java/org/easetech/easytest/example/CustomCSVDataLoader.java b/src/test/java/org/easetech/easytest/example/CustomCSVDataLoader.java index afadf6a..903dd0a 100644 --- a/src/test/java/org/easetech/easytest/example/CustomCSVDataLoader.java +++ b/src/test/java/org/easetech/easytest/example/CustomCSVDataLoader.java @@ -2,17 +2,15 @@ package org.easetech.easytest.example; import com.csvreader.CsvReader; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.easetech.easytest.io.Resource; import org.easetech.easytest.loader.Loader; -import org.easetech.easytest.util.ResourceLoader; import org.junit.Assert; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -76,34 +74,7 @@ public CustomCSVDataLoader(final List csvInputStreams) throws IOExc } - /** - * Construct a new CSVDataLoader and also load the data. - * - * @param dataFiles the list of input stream string files to load the data from - * @return a Map of method name and the list of associated test data with that method name - * @throws IOException if an IO Exception occurs - */ - private Map>> LoadCSVData(final List dataFiles) throws IOException { - Map>> data = null; - Map>> finalData = new HashMap>>(); - for (String filePath : dataFiles) { - try { - ResourceLoader resource = new ResourceLoader(filePath); - data = loadFromSpreadsheet(resource.getInputStream()); - } catch (FileNotFoundException e) { - // LOG.error("The specified file was not found. The path is : {}", filePath); - // LOG.error("Continuing with the loading of next file."); - continue; - } catch (IOException e) { - LOG.error("IO Exception occured while trying to read the data from the file : {}", filePath); - LOG.error("Continuing with the loading of next file."); - continue; - } - finalData.putAll(data); - } - return finalData; - } /** * Load data from SpreadSheet @@ -148,34 +119,26 @@ private static Map>> loadFromSpreadsheet(final } - /** - * Load the data from the specified list of filePaths - * - * @param filePaths the list of File paths - * @return the data - */ - @Override - public Map>> loadData(String[] filePaths) { + + public Map>> loadData(Resource resource) { System.out.println("Using my custom Loader"); Map>> result = new HashMap>>(); - try { - result = LoadCSVData(Arrays.asList(filePaths)); - } catch (IOException e) { - Assert.fail("An I/O exception occured while reading the files from the path :" + filePaths.toString()); - } + try { + result = loadFromSpreadsheet(resource.getInputStream()); + } catch (Exception e) { + try { + Assert.fail("An I/O exception occured while reading the files from the path :" + resource.getResourceName()); + } catch (Exception e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } return result; } - /** - * Write the data to the specified File. - * - * @param filePath - * @param actualData - */ - @Override - public void writeData(String[] filePaths, String methodName, Map>> actualData) { + public void writeData(Resource resource, Map>> actualData, String... methodName) { // TODO Auto-generated method stub - + } } diff --git a/src/test/java/org/easetech/easytest/example/CustomObjectDataLoader.java b/src/test/java/org/easetech/easytest/example/CustomObjectDataLoader.java deleted file mode 100644 index 16456c0..0000000 --- a/src/test/java/org/easetech/easytest/example/CustomObjectDataLoader.java +++ /dev/null @@ -1,37 +0,0 @@ - -package org.easetech.easytest.example; - -import java.util.ArrayList; - -import java.util.HashMap; - -import java.util.List; -import java.util.Map; - -import org.easetech.easytest.loader.Loader; - -/** - * - * A Custom Data Loader that simply provides data from the class itself without reading any external files. - * - */ -public class CustomObjectDataLoader implements Loader { - - @Override - public Map>> loadData(String[] filePaths) { - Map>> result = new HashMap>>(); - List> list = new ArrayList>(); - Map map = new HashMap(); - map.put("LibraryId", new LibraryId(1L)); - list.add(map); - result.put("testGetItemsWithCustomLoader", list); - return result; - } - - @Override - public void writeData(String[] filePaths, String methodName, Map>> actualData) { - // TODO Auto-generated method stub - - } - -} diff --git a/src/test/java/org/easetech/easytest/example/TestCombinedLoadingAndWriting.java b/src/test/java/org/easetech/easytest/example/TestCombinedLoadingAndWriting.java index 8d1401d..95d5464 100644 --- a/src/test/java/org/easetech/easytest/example/TestCombinedLoadingAndWriting.java +++ b/src/test/java/org/easetech/easytest/example/TestCombinedLoadingAndWriting.java @@ -10,7 +10,7 @@ public class TestCombinedLoadingAndWriting { @Test - @DataLoader(filePaths = { "input-data-mod-again.xml" }, loaderType = LoaderType.XML) + @DataLoader(filePaths = { "classpath:input-data-mod-again.xml" }, loaderType = LoaderType.XML) public Item getItemsDataFromXMLLoaderModified(@Param(name = "libraryId") String libraryId, @Param(name = "itemId") String itemId, @Param(name = "itemType") @@ -27,7 +27,7 @@ public Item getItemsDataFromXMLLoaderModified(@Param(name = "libraryId") } @Test - @DataLoader(filePaths = { "org/easetech/data/test-combined.xls" }, loaderType = LoaderType.EXCEL) + @DataLoader(filePaths = { "classpath:org/easetech/data/test-combined.xls" }, loaderType = LoaderType.EXCEL) public Item getExcelTestDataWithReturnType(@Param(name = "libraryId") Float libraryId, @Param(name = "itemId") Float itemId) { diff --git a/src/test/java/org/easetech/easytest/example/TestConditionsSupportedByDataDrivenTest.java b/src/test/java/org/easetech/easytest/example/TestConditionsSupportedByDataDrivenTest.java index a5075c3..57404f7 100644 --- a/src/test/java/org/easetech/easytest/example/TestConditionsSupportedByDataDrivenTest.java +++ b/src/test/java/org/easetech/easytest/example/TestConditionsSupportedByDataDrivenTest.java @@ -30,7 +30,7 @@ * */ @RunWith(DataDrivenTestRunner.class) -@DataLoader(filePaths = { "getDDTData.csv" }, loaderType = LoaderType.CSV) +@DataLoader(filePaths = { "classpath:getDDTData.csv" }, loaderType = LoaderType.CSV) public class TestConditionsSupportedByDataDrivenTest { @Test diff --git a/src/test/java/org/easetech/easytest/example/TestDifferentConditionsSupportedByParam.java b/src/test/java/org/easetech/easytest/example/TestDifferentConditionsSupportedByParam.java index 65e70f0..6901d19 100644 --- a/src/test/java/org/easetech/easytest/example/TestDifferentConditionsSupportedByParam.java +++ b/src/test/java/org/easetech/easytest/example/TestDifferentConditionsSupportedByParam.java @@ -45,7 +45,7 @@ import org.springframework.util.Assert; @RunWith(DataDrivenTestRunner.class) -@DataLoader(filePaths={"paramTestConditions.csv"}) +@DataLoader(filePaths={"classpath:paramTestConditions.csv"}) public class TestDifferentConditionsSupportedByParam { @BeforeClass @@ -135,13 +135,13 @@ public void testNonGenericQueueInterface(@Param(name="items") Queue items){ } } - @Test - public void testNonGenericQueueImplementation(@Param(name="items") BlockingDeque items){ - Assert.notNull(items); - for(Object item : items){ - System.out.println("testNonGenericListImplementation : "+item); - } - } +// @Test +// public void testNonGenericQueueImplementation(@Param(name="items") BlockingDeque items){ +// Assert.notNull(items); +// for(Object item : items){ +// System.out.println("testNonGenericListImplementation : "+item); +// } +// } @Test public void testNonGenericBlockingQueueImplementation(@Param(name="items") BlockingQueue items){ @@ -151,13 +151,13 @@ public void testNonGenericBlockingQueueImplementation(@Param(name="items") Block } } - @Test - public void testNonGenericDequeImplementation(@Param(name="items") Deque items){ - Assert.notNull(items); - for(Object item : items){ - System.out.println("testNonGenericListImplementation : "+item); - } - } +// @Test +// public void testNonGenericDequeImplementation(@Param(name="items") Deque items){ +// Assert.notNull(items); +// for(Object item : items){ +// System.out.println("testNonGenericListImplementation : "+item); +// } +// } @Test public void testGenericQueueImplementation(@Param(name="items") Collection items){ @@ -279,13 +279,13 @@ public void testEnumSet(@Param(name="items") EnumSet items){ } } - @Test - public void testLinkedBlockingDeque(@Param(name="items") LinkedBlockingDeque items){ - Assert.notNull(items); - for(ItemId item : items){ - System.out.println("testNonGenericListImplementation : "+item); - } - } +// @Test +// public void testLinkedBlockingDeque(@Param(name="items") LinkedBlockingDeque items){ +// Assert.notNull(items); +// for(ItemId item : items){ +// System.out.println("testNonGenericListImplementation : "+item); +// } +// } @Test public void testLinkedBlockingQueue(@Param(name="items") LinkedBlockingQueue items){ diff --git a/src/test/java/org/easetech/easytest/example/TestExcelDataLoader.java b/src/test/java/org/easetech/easytest/example/TestExcelDataLoader.java index 56da209..d7d3ac9 100644 --- a/src/test/java/org/easetech/easytest/example/TestExcelDataLoader.java +++ b/src/test/java/org/easetech/easytest/example/TestExcelDataLoader.java @@ -15,8 +15,7 @@ @RunWith(DataDrivenTestRunner.class) -@DataLoader(filePaths = { "org/easetech/data/testExcelData.xls" }, loaderType = LoaderType.EXCEL) -@Report +@DataLoader(filePaths = { "classpath:org/easetech/data/testExcelData.xls" }, loaderType = LoaderType.EXCEL) public class TestExcelDataLoader { @Intercept @@ -43,7 +42,7 @@ public void getExcelTestData(@Param(name = "libraryId") } @Test - @DataLoader(filePaths={"overrideExcelData.csv"} , loaderType=LoaderType.CSV) + @DataLoader(filePaths={"classpath:overrideExcelData.csv"} , loaderType=LoaderType.CSV) public Item getExcelTestDataWithDouble(@Param(name = "libraryId") Double libraryId, @Param(name = "itemId") Double itemId) { @@ -74,7 +73,7 @@ public void getExcelTestDataNumberFormat() { } @Test - @DataLoader(filePaths = { "org/easetech/data/test-update.xls" }, loaderType = LoaderType.EXCEL) + @DataLoader(filePaths = { "classpath:org/easetech/data/test-update.xls" }, loaderType = LoaderType.EXCEL) public Item getExcelTestDataWithReturnType(@Param(name = "libraryId") Float libraryId, @Param(name = "itemId") Float itemId) { diff --git a/src/test/java/org/easetech/easytest/example/TestXMLDataLoader.java b/src/test/java/org/easetech/easytest/example/TestXMLDataLoader.java index 113b842..1c30362 100644 --- a/src/test/java/org/easetech/easytest/example/TestXMLDataLoader.java +++ b/src/test/java/org/easetech/easytest/example/TestXMLDataLoader.java @@ -1,6 +1,8 @@ package org.easetech.easytest.example; +import org.easetech.easytest.annotation.Report; + import org.easetech.easytest.annotation.DataLoader; import org.easetech.easytest.annotation.Param; import org.easetech.easytest.loader.LoaderType; @@ -8,7 +10,8 @@ import org.junit.runner.RunWith; @RunWith(org.easetech.easytest.runner.DataDrivenTestRunner.class) -@DataLoader(filePaths = { "input-data.xml" }, loaderType = LoaderType.XML) +@DataLoader(filePaths = { "classpath:input-data.xml" }, loaderType = LoaderType.XML) +@Report public class TestXMLDataLoader { @@ -30,7 +33,7 @@ public Item getItemsDataFromXMLLoader(@Param(name = "libraryId") } @Test - @DataLoader(filePaths = { "input-data-mod.xml" }, loaderType = LoaderType.XML) + @DataLoader(filePaths = { "classpath:input-data-mod.xml" }, loaderType = LoaderType.XML) public Item getItemsDataFromXMLLoaderModified(@Param(name = "libraryId") String libraryId, @Param(name = "itemId") String itemId, @Param(name = "itemType") diff --git a/src/test/java/org/easetech/easytest/interceptor/CGLIBEnhancerTest.java b/src/test/java/org/easetech/easytest/interceptor/CGLIBEnhancerTest.java index b2d58a7..21c7caf 100644 --- a/src/test/java/org/easetech/easytest/interceptor/CGLIBEnhancerTest.java +++ b/src/test/java/org/easetech/easytest/interceptor/CGLIBEnhancerTest.java @@ -12,7 +12,7 @@ @RunWith(DataDrivenTestRunner.class) public class CGLIBEnhancerTest { - @Intercept() public static RealItemService itemService = new RealItemService(); + @Intercept public static RealItemService itemService = new RealItemService(); @Test public void testGetItemEnh() { From 42065f6e730eb03eec36b7969a76767307357955 Mon Sep 17 00:00:00 2001 From: Anuj kumar Date: Thu, 13 Dec 2012 16:00:31 +0100 Subject: [PATCH 03/11] Updated to move to the latest report jrxml file --- src/main/resources/reports/MainReport.jrxml | 253 ++++++++++++++++++ .../example/CustomObjectDataLoader.java | 34 +++ 2 files changed, 287 insertions(+) create mode 100644 src/main/resources/reports/MainReport.jrxml create mode 100644 src/test/java/org/easetech/easytest/example/CustomObjectDataLoader.java diff --git a/src/main/resources/reports/MainReport.jrxml b/src/main/resources/reports/MainReport.jrxml new file mode 100644 index 0000000..399c79c --- /dev/null +++ b/src/main/resources/reports/MainReport.jrxml @@ -0,0 +1,253 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <band height="251" splitType="Stretch"> + <frame> + <reportElement mode="Opaque" x="-20" y="0" width="822" height="65" forecolor="#006699" backcolor="#006699"/> + <staticText> + <reportElement style="Title" x="231" y="0" width="578" height="65"/> + <textElement textAlignment="Right"> + <font size="54" isBold="false"/> + </textElement> + <text><![CDATA[EasyTest Reports]]></text> + </staticText> + </frame> + <textField isStretchWithOverflow="true" isBlankWhenNull="true"> + <reportElement style="SubTitle" x="180" y="65" width="609" height="29"/> + <textElement textAlignment="Right"> + <font fontName="Times New Roman" size="22" isBold="true"/> + </textElement> + <textFieldExpression><![CDATA["Test class: " + $P{TEST_CLASS_NAME}]]></textFieldExpression> + </textField> + <image> + <reportElement x="0" y="65" width="180" height="180"/> + <imageExpression><![CDATA[((org.easetech.easytest.reports.data.ReportTotalsBean)$P{REPORT_PARAMETERS_MAP}.get($P{TEST_CLASS_NAME})).getTotalsGraph()]]></imageExpression> + </image> + <textField> + <reportElement x="180" y="186" width="262" height="20"/> + <textElement textAlignment="Left"> + <font size="12" isBold="true"/> + </textElement> + <textFieldExpression><![CDATA["Passed: " + ((org.easetech.easytest.reports.data.ReportTotalsBean)$P{REPORT_PARAMETERS_MAP}.get($P{TEST_CLASS_NAME})).getPassed() + " (" + ((org.easetech.easytest.reports.data.ReportTotalsBean)$P{REPORT_PARAMETERS_MAP}.get($P{TEST_CLASS_NAME})).getPercentagePassed() + " %)"]]></textFieldExpression> + </textField> + <textField> + <reportElement x="180" y="206" width="262" height="20"/> + <textElement textAlignment="Left"> + <font size="12" isBold="true"/> + </textElement> + <textFieldExpression><![CDATA["Failed: " + ((org.easetech.easytest.reports.data.ReportTotalsBean)$P{REPORT_PARAMETERS_MAP}.get($P{TEST_CLASS_NAME})).getFailed() + " (" + ((org.easetech.easytest.reports.data.ReportTotalsBean)$P{REPORT_PARAMETERS_MAP}.get($P{TEST_CLASS_NAME})).getPercentageFailed() + " %)"]]></textFieldExpression> + </textField> + <textField> + <reportElement x="180" y="226" width="262" height="20"/> + <textElement textAlignment="Left"> + <font size="12" isBold="true"/> + </textElement> + <textFieldExpression><![CDATA["Exception: " + ((org.easetech.easytest.reports.data.ReportTotalsBean)$P{REPORT_PARAMETERS_MAP}.get($P{TEST_CLASS_NAME})).getException() + " (" + ((org.easetech.easytest.reports.data.ReportTotalsBean)$P{REPORT_PARAMETERS_MAP}.get($P{TEST_CLASS_NAME})).getPercentageException() + " %)"]]></textFieldExpression> + </textField> + </band> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/java/org/easetech/easytest/example/CustomObjectDataLoader.java b/src/test/java/org/easetech/easytest/example/CustomObjectDataLoader.java new file mode 100644 index 0000000..443d657 --- /dev/null +++ b/src/test/java/org/easetech/easytest/example/CustomObjectDataLoader.java @@ -0,0 +1,34 @@ + +package org.easetech.easytest.example; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.easetech.easytest.io.Resource; +import org.easetech.easytest.loader.Loader; + +/** + * + * A Custom Data Loader that simply provides data from the class itself without reading any external files. + * + */ +public class CustomObjectDataLoader implements Loader { + + + public Map>> loadData(Resource resource) { + Map>> result = new HashMap>>(); + List> list = new ArrayList>(); + Map map = new HashMap(); + map.put("LibraryId", new LibraryId(1L)); + list.add(map); + result.put("testGetItemsWithCustomLoader", list); + return result; + } + + public void writeData(Resource resource, Map>> actualData, String... methodName) { + // TODO Auto-generated method stub + + } + +} From 9691858eb8bb809786293f1e44f698f17fb7de80 Mon Sep 17 00:00:00 2001 From: Anuj kumar Date: Thu, 13 Dec 2012 16:54:42 +0100 Subject: [PATCH 04/11] Made 1.5 compliant --- pom.xml | 46 +--- .../easytest/annotation/Intercept.java | 29 -- .../EasyTestDefaultInterceptor.java | 34 --- .../easytest/runner/SpringTestRunner.java | 26 +- src/main/resources/reports/MainReport.jrxml | 253 ------------------ src/main/resources/testDataSchema.xsd | 102 ------- 6 files changed, 19 insertions(+), 471 deletions(-) delete mode 100644 src/main/java/org/easetech/easytest/annotation/Intercept.java delete mode 100644 src/main/java/org/easetech/easytest/interceptor/EasyTestDefaultInterceptor.java delete mode 100644 src/main/resources/reports/MainReport.jrxml delete mode 100644 src/main/resources/testDataSchema.xsd diff --git a/pom.xml b/pom.xml index bcaa4cf..d7294a1 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ EasyTest is a JUnit extension perform Data Driven Testing with ease and simplicity. It supports method parameters with Test annotation and much more. https://github.com/EaseTech/easytest - 0.7.0-SNAPSHOT + 1.0-SNAPSHOT @@ -47,54 +47,21 @@ - scm:git:https://anujgandharv@github.com/EaseTech/easytest.git - scm:git:https://anujgandharv@github.com/EaseTech/easytest.git - scm:git:https://anujgandharv@github.com/EaseTech/easytest + scm:git:https://anujgandharv@github.com/EaseTech/easytest-spring.git + scm:git:https://anujgandharv@github.com/EaseTech/easytest-spring.git + scm:git:https://anujgandharv@github.com/EaseTech/easytest-spring - - org.jvnet.jaxb2.maven2 - maven-jaxb2-plugin - 0.6.2 - - - generate-sources - - generate - - - 2.2 - true - false - - -XtoString - -XhashCode - -Xequals - - - - org.jvnet.jaxb2_commons - jaxb2-basics-annotate - 0.6.2 - - - org.jvnet.jaxb2_commons - jaxb2-basics - 0.6.2 - - - - - - org.apache.maven.plugins maven-compiler-plugin 2.3.2 true + 1.5 + 1.5 @@ -212,6 +179,5 @@ - diff --git a/src/main/java/org/easetech/easytest/annotation/Intercept.java b/src/main/java/org/easetech/easytest/annotation/Intercept.java deleted file mode 100644 index b7d5341..0000000 --- a/src/main/java/org/easetech/easytest/annotation/Intercept.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.easetech.easytest.annotation; - -import org.easetech.easytest.interceptor.EasyTestDefaultInterceptor; - -import org.aopalliance.intercept.MethodInterceptor; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * - * A field level annotation that can be used to intercept calls to methods within the subject under test. - * A user can specify the interceptor it wants to use to intercept the call to the test subject's method. - * The interceptor should implement {@link MethodInterceptor}. - * The default interceptor is {@link EasyTestDefaultInterceptor} that simply prints - * the time taken in nano seconds by the test method on the console. - * - */ -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.FIELD}) -public @interface Intercept { - /** - * The {@link MethodInterceptor} to use to intercept method calls. - */ - Class interceptor() default EasyTestDefaultInterceptor.class; - -} diff --git a/src/main/java/org/easetech/easytest/interceptor/EasyTestDefaultInterceptor.java b/src/main/java/org/easetech/easytest/interceptor/EasyTestDefaultInterceptor.java deleted file mode 100644 index fd31783..0000000 --- a/src/main/java/org/easetech/easytest/interceptor/EasyTestDefaultInterceptor.java +++ /dev/null @@ -1,34 +0,0 @@ - -package org.easetech.easytest.interceptor; - -import java.util.concurrent.TimeUnit; - -import org.aopalliance.intercept.MethodInterceptor; -import org.aopalliance.intercept.MethodInvocation; - -/** - * - * A default interceptor that simply prints the time taken by a method in nano seconds to the console. - * - */ -public class EasyTestDefaultInterceptor implements MethodInterceptor { - - /** - * Invoke the method with the advice - * @param invocation - * @return result of invoking the method - * @throws Throwable - */ - @Override - public Object invoke(MethodInvocation invocation) throws Throwable { - long startTime = System.nanoTime(); - Object result = invocation.getMethod().invoke(invocation.getThis(), invocation.getArguments()); - long duration = System.nanoTime() - startTime; -// long timeInMilliSeconds = TimeUnit.MILLISECONDS.convert(duration, TimeUnit.NANOSECONDS); -// System.out.println("Time taken by Method "+ invocation.getMethod().getName() + " : " + timeInMilliSeconds + " ms"); - System.out.println("Time taken by Method "+ invocation.getMethod().getName() + " : " + duration + " nanoseconds"); - return result; - - } - -} diff --git a/src/main/java/org/easetech/easytest/runner/SpringTestRunner.java b/src/main/java/org/easetech/easytest/runner/SpringTestRunner.java index 86c5193..d79ad91 100644 --- a/src/main/java/org/easetech/easytest/runner/SpringTestRunner.java +++ b/src/main/java/org/easetech/easytest/runner/SpringTestRunner.java @@ -208,7 +208,7 @@ protected void instrumentClass(Class testClass) throws IllegalArgumentExcepti * * @param errors */ - @Override + protected void collectInitializationErrors(List errors) { super.collectInitializationErrors(errors); //validateDataPointFields(errors); @@ -221,7 +221,7 @@ protected void collectInitializationErrors(List errors) { * @param method the {@link FrameworkMethod} * @return an overridden test method Name */ - @Override + protected String testName(final FrameworkMethod method) { return String.format("%s", method.getName()); } @@ -236,7 +236,7 @@ protected String testName(final FrameworkMethod method) { * * @return list of {@link FrameworkMethod} */ - @Override + protected List computeTestMethods() { if (frameworkMethods != null && !frameworkMethods.isEmpty()) { return frameworkMethods; @@ -297,7 +297,7 @@ protected List computeTestMethods() { * * @param errors list of any errors while validating the Constructor */ - @Override + protected void validateConstructor(List errors) { validateOnlyOneConstructor(errors); } @@ -307,12 +307,12 @@ protected void validateConstructor(List errors) { * * @param errors list of any errors while validating test method */ - @Override + protected void validateTestMethods(List errors) { //Do Nothing as we now support public non void arg test methods } - @Override + protected Object createTest() throws Exception { return null; @@ -325,7 +325,7 @@ protected Object createTest() throws Exception { * @return a compiled {@link Statement} object to be evaluated */ - @Override + public Statement methodBlock(final FrameworkMethod method) { return new ParamAnchor(method, getTestClass()); } @@ -340,7 +340,7 @@ public Statement methodBlock(final FrameworkMethod method) { * data from the test method. This method will make sure that the data is written to the output file once after * the Runner has completed and not for every instance of the test method. */ - @Override + protected Statement withAfterClasses(Statement statement) { List afters = getTestClass().getAnnotatedMethods(AfterClass.class); List testMethods = getTestClass().getAnnotatedMethods(Test.class); @@ -442,7 +442,7 @@ private TestClass getTestClass() { return fTestClass; } - @Override + public void evaluate() throws Throwable { runWithAssignment(EasyAssignments.allUnassigned(fTestMethod.getMethod(), getTestClass())); LOG.debug("ParamAnchor evaluate"); @@ -520,7 +520,7 @@ public Statement methodBlock(FrameworkMethod method) { final EachTestNotifier eachNotifier= new EachTestNotifier(notifier,null); eachNotifier.fireTestStarted(); return new Statement() { - @Override + public void evaluate() throws Throwable { try { statement.evaluate(); @@ -688,7 +688,7 @@ protected void handleDataPointSuccess() { * * @return a list of {@link DataDrivenTestRunner} */ - @Override + protected List getChildren() { return runners; } @@ -768,7 +768,7 @@ public SpringTestRunner(Class klass) throws InitializationError { * Returns a {@link Statement}: We override this method as it was being called twice * for the same class. Looks like a bug in JUnit. */ - @Override + protected Statement withBeforeClasses(Statement statement) { return statement; } @@ -858,7 +858,7 @@ protected void loadData(Class testClass, FrameworkMethod method, Class cur * Returns a {@link Statement}: We override this method as it was being called twice * for the same class. Looks like a bug in JUnit. */ - @Override + protected Statement withAfterClasses(Statement statement) { return statement; } diff --git a/src/main/resources/reports/MainReport.jrxml b/src/main/resources/reports/MainReport.jrxml deleted file mode 100644 index 399c79c..0000000 --- a/src/main/resources/reports/MainReport.jrxml +++ /dev/null @@ -1,253 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - <band height="251" splitType="Stretch"> - <frame> - <reportElement mode="Opaque" x="-20" y="0" width="822" height="65" forecolor="#006699" backcolor="#006699"/> - <staticText> - <reportElement style="Title" x="231" y="0" width="578" height="65"/> - <textElement textAlignment="Right"> - <font size="54" isBold="false"/> - </textElement> - <text><![CDATA[EasyTest Reports]]></text> - </staticText> - </frame> - <textField isStretchWithOverflow="true" isBlankWhenNull="true"> - <reportElement style="SubTitle" x="180" y="65" width="609" height="29"/> - <textElement textAlignment="Right"> - <font fontName="Times New Roman" size="22" isBold="true"/> - </textElement> - <textFieldExpression><![CDATA["Test class: " + $P{TEST_CLASS_NAME}]]></textFieldExpression> - </textField> - <image> - <reportElement x="0" y="65" width="180" height="180"/> - <imageExpression><![CDATA[((org.easetech.easytest.reports.data.ReportTotalsBean)$P{REPORT_PARAMETERS_MAP}.get($P{TEST_CLASS_NAME})).getTotalsGraph()]]></imageExpression> - </image> - <textField> - <reportElement x="180" y="186" width="262" height="20"/> - <textElement textAlignment="Left"> - <font size="12" isBold="true"/> - </textElement> - <textFieldExpression><![CDATA["Passed: " + ((org.easetech.easytest.reports.data.ReportTotalsBean)$P{REPORT_PARAMETERS_MAP}.get($P{TEST_CLASS_NAME})).getPassed() + " (" + ((org.easetech.easytest.reports.data.ReportTotalsBean)$P{REPORT_PARAMETERS_MAP}.get($P{TEST_CLASS_NAME})).getPercentagePassed() + " %)"]]></textFieldExpression> - </textField> - <textField> - <reportElement x="180" y="206" width="262" height="20"/> - <textElement textAlignment="Left"> - <font size="12" isBold="true"/> - </textElement> - <textFieldExpression><![CDATA["Failed: " + ((org.easetech.easytest.reports.data.ReportTotalsBean)$P{REPORT_PARAMETERS_MAP}.get($P{TEST_CLASS_NAME})).getFailed() + " (" + ((org.easetech.easytest.reports.data.ReportTotalsBean)$P{REPORT_PARAMETERS_MAP}.get($P{TEST_CLASS_NAME})).getPercentageFailed() + " %)"]]></textFieldExpression> - </textField> - <textField> - <reportElement x="180" y="226" width="262" height="20"/> - <textElement textAlignment="Left"> - <font size="12" isBold="true"/> - </textElement> - <textFieldExpression><![CDATA["Exception: " + ((org.easetech.easytest.reports.data.ReportTotalsBean)$P{REPORT_PARAMETERS_MAP}.get($P{TEST_CLASS_NAME})).getException() + " (" + ((org.easetech.easytest.reports.data.ReportTotalsBean)$P{REPORT_PARAMETERS_MAP}.get($P{TEST_CLASS_NAME})).getPercentageException() + " %)"]]></textFieldExpression> - </textField> - </band> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/resources/testDataSchema.xsd b/src/main/resources/testDataSchema.xsd deleted file mode 100644 index d4bec4b..0000000 --- a/src/main/resources/testDataSchema.xsd +++ /dev/null @@ -1,102 +0,0 @@ - - - - - - - - Base element to capture the Input Test Data. - This is the schema that the users should follow if they want - EasyTest framework to load their XML data for their test cases. - - - - - - - - - - - - - Information about a single test method. This will - contain the name of the test method - as attribute and a multiple Test Records within the test Method. Each - TestRecord signifies a single execution of the given test method. - - - - - - - - - - - - Test Record captures the test data for a single - execution of the enclosing TestMethod. - - - - - - - - - - - - - InputData element identifies the single execution record for a given test. - This means that each entry element within the InputData element will be captured in a single Map - and will be passed to the test method as its method arguments. - - - - - - - - - - OutputData element identifies the data that has been returned by the Test method. - A user never provides the value of OutputData element. It is created on the fly by the XMLDataLoader class of teh framework. - In case a user specifies the element, it will be ignored. - From a user's perspective, if a user wants to capture the output data to a file, all he/she has to do is return the data from the method. - Rest all will be taken care of by the framework. - - - - - - - - - - Each Entry identifies a single key/value pair - where key is the name of the parameter and value is its value. - - - - - - - - - - - - - From 8019296bc491212609ac9079c66ee21ecc4fce2e Mon Sep 17 00:00:00 2001 From: Anuj kumar Date: Mon, 17 Dec 2012 17:01:16 +0100 Subject: [PATCH 05/11] Added SpringIntercept annotation as an alternative to Intercept annotation. Signed-off-by: Anuj kumar --- .../interceptor/SpringDefaultInterceptor.java | 46 ++++ .../easytest/interceptor/SpringIntercept.java | 28 ++ .../easytest/runner/SpringTestRunner.java | 247 +++++++++--------- .../easytest/example/ComparableObject.java | 2 +- .../example/ComparableObjectConverter.java | 2 +- .../easytest/example/DelayedObject.java | 6 +- .../example/DelayedObjectConverter.java | 2 +- .../easytest/example/EnumConverter.java | 2 +- .../easytest/example/ItemConverter.java | 2 +- .../easytest/example/RealItemService.java | 4 +- .../easytest/example/TestExcelDataLoader.java | 10 +- 11 files changed, 210 insertions(+), 141 deletions(-) create mode 100644 src/main/java/org/easetech/easytest/interceptor/SpringDefaultInterceptor.java create mode 100644 src/main/java/org/easetech/easytest/interceptor/SpringIntercept.java diff --git a/src/main/java/org/easetech/easytest/interceptor/SpringDefaultInterceptor.java b/src/main/java/org/easetech/easytest/interceptor/SpringDefaultInterceptor.java new file mode 100644 index 0000000..64f1b86 --- /dev/null +++ b/src/main/java/org/easetech/easytest/interceptor/SpringDefaultInterceptor.java @@ -0,0 +1,46 @@ + +package org.easetech.easytest.interceptor; + +import org.aopalliance.intercept.MethodInvocation; + +import java.lang.reflect.Method; +import net.sf.cglib.proxy.MethodProxy; +import org.aopalliance.intercept.MethodInterceptor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * A default interceptor that simply Logs the time taken by a method in nano seconds to the attached logger. + * + * @author Anuj Kumar + * + */ +public class SpringDefaultInterceptor implements MethodInterceptor { + + /** + * An instance of logger associated with the test framework. + */ + protected static final Logger LOG = LoggerFactory.getLogger(SpringDefaultInterceptor.class); + + /** + * Intercept the method with the advice + * @param invocation + * @return returned value + * @throws Throwable + */ + + public Object invoke(MethodInvocation invocation) throws Throwable { + long startTime = System.nanoTime(); + Object result = invocation.getMethod().invoke(invocation.getThis(), invocation.getArguments()); + long duration = System.nanoTime() - startTime; + LOG.debug("Method {} took {} nanoseconds", invocation.getMethod().getName(), duration); + return result; + } + + + + + + +} diff --git a/src/main/java/org/easetech/easytest/interceptor/SpringIntercept.java b/src/main/java/org/easetech/easytest/interceptor/SpringIntercept.java new file mode 100644 index 0000000..81e0773 --- /dev/null +++ b/src/main/java/org/easetech/easytest/interceptor/SpringIntercept.java @@ -0,0 +1,28 @@ +package org.easetech.easytest.interceptor; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import org.aopalliance.intercept.MethodInterceptor; + +/** + * + * A field level annotation that can be used to intercept calls to methods within the subject under test. + * A user can specify the interceptor it wants to use to intercept the call to the test subject's method. + * The interceptor should implement {@link MethodInterceptor}. + * The default interceptor is {@link SpringDefaultInterceptor} that simply prints + * the time taken in nano seconds by the test method on the console. + * + * @author Anuj Kumar + * + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.FIELD}) +public @interface SpringIntercept { + /** + * The {@link MethodInterceptor} to use to intercept method calls. + */ + Class interceptor() default SpringDefaultInterceptor.class; + +} diff --git a/src/main/java/org/easetech/easytest/runner/SpringTestRunner.java b/src/main/java/org/easetech/easytest/runner/SpringTestRunner.java index d79ad91..de1755d 100644 --- a/src/main/java/org/easetech/easytest/runner/SpringTestRunner.java +++ b/src/main/java/org/easetech/easytest/runner/SpringTestRunner.java @@ -1,15 +1,13 @@ package org.easetech.easytest.runner; -import org.easetech.easytest.reports.data.DurationBean; - -import java.util.Date; -import org.easetech.easytest.reports.data.TestResultBean; +import org.easetech.easytest.interceptor.SpringIntercept; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Collections; +import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -26,7 +24,9 @@ import org.easetech.easytest.loader.Loader; import org.easetech.easytest.loader.LoaderFactory; import org.easetech.easytest.loader.LoaderType; +import org.easetech.easytest.reports.data.DurationBean; import org.easetech.easytest.reports.data.ReportDataContainer; +import org.easetech.easytest.reports.data.TestResultBean; import org.easetech.easytest.util.DataContext; import org.easetech.easytest.util.RunAftersWithOutputData; import org.easetech.easytest.util.TestInfo; @@ -53,9 +53,9 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** - * A Spring based implementation of {@link Suite} that encapsulates the {@link EasyTestRunner} in order to provide users with clear - * indication of which test method is run and what is the input test data that the method is run with. For example, when - * a user runs the test method with name : getTestData with the following test data: + * A Spring based implementation of {@link Suite} that encapsulates the {@link EasyTestRunner} in order to provide users + * with clear indication of which test method is run and what is the input test data that the method is run with. For + * example, when a user runs the test method with name : getTestData with the following test data: *
    *
  • "libraryId=1 and itemId=2"
  • *
  • "libraryId=2456 and itemId=789"

  • @@ -78,17 +78,16 @@ */ public class SpringTestRunner extends Suite { - /** * An instance of {@link Map} that contains the data to be written to the File */ private static Map>> writableData = new HashMap>>(); - + /** * The default rowNum within the {@link #writableData}'s particular method data. */ private static int rowNum = 0; - + /** * The name of the method currently being executed. Used for populating the {@link #writableData} map. */ @@ -98,7 +97,7 @@ public class SpringTestRunner extends Suite { * The report container which holds all the reporting data */ private ReportDataContainer testReportContainer = null; - + /** * An instance of logger associated with the test framework. */ @@ -144,13 +143,13 @@ private class EasyTestRunner extends SpringJUnit4ClassRunner { * Convenient class member to get the list of {@link FrameworkMethod} that this runner will execute. */ List frameworkMethods; - + /** - * The actual instance of the test class. - * This is extremely handy in cases where we want to reflectively set instance fields on a test class. + * The actual instance of the test class. This is extremely handy in cases where we want to reflectively set + * instance fields on a test class. */ Object testInstance; - + TestResultBean testResult; /** @@ -167,51 +166,55 @@ public EasyTestRunner(Class klass) throws InitializationError { testInstance = getTestClass().getOnlyConstructor().newInstance(); getTestContextManager().prepareTestInstance(testInstance); instrumentClass(getTestClass().getJavaClass()); - + } catch (Exception e) { - Assert.fail("Test failed while trying to instrument fileds in the class : " + getTestClass().getJavaClass()); + Assert.fail("Test failed while trying to instrument fileds in the class : " + + getTestClass().getJavaClass() + " Exception is : " + e); } } - + /** * Instrument the class's field that are marked with {@link Intercept} annotation + * * @param testClass the class under test * @throws IllegalArgumentException if an exception occurred * @throws IllegalAccessException if an exception occurred * @throws AopConfigException if an exception occurred * @throws InstantiationException if an exception occurred */ - protected void instrumentClass(Class testClass) throws IllegalArgumentException, IllegalAccessException, AopConfigException, InstantiationException{ - Field[] fields = testClass.getFields(); - for(Field field : fields){ - Intercept interceptor = field.getAnnotation(Intercept.class); - if(interceptor != null){ - Class interceptorClass = interceptor.interceptor(); - //This is the field we want to enhance - Object fieldInstance = field.get(testInstance); - ProxyFactory factory = new ProxyFactory(); - factory.setTarget(fieldInstance); - factory.addAdvice(interceptorClass.newInstance()); - Object proxy = factory.getProxy(); - try{ - field.set(testInstance,proxy); - }catch(Exception e){ - Assert.fail("Failed while trying to instrument the class for Intercept annotation with exception : " + e.getStackTrace()); + protected void instrumentClass(Class testClass) throws IllegalArgumentException, IllegalAccessException, + AopConfigException, InstantiationException { + Field[] fields = testClass.getDeclaredFields(); + try { + for (Field field : fields) { + SpringIntercept interceptor = field.getAnnotation(SpringIntercept.class); + if (interceptor != null) { + Class interceptorClass = interceptor.interceptor(); + // This is the field we want to enhance + Object fieldInstance = field.get(testInstance); + ProxyFactory factory = new ProxyFactory(); + factory.setTarget(fieldInstance); + factory.addAdvice(interceptorClass.newInstance()); + Object proxy = factory.getProxy(); + field.set(testInstance, proxy); } } + + } catch (Exception e) { + throw new RuntimeException(e); } - } + } /** * Try to collect any initialization errors, if any. * * @param errors */ - + protected void collectInitializationErrors(List errors) { super.collectInitializationErrors(errors); - //validateDataPointFields(errors); + // validateDataPointFields(errors); } /** @@ -221,7 +224,7 @@ protected void collectInitializationErrors(List errors) { * @param method the {@link FrameworkMethod} * @return an overridden test method Name */ - + protected String testName(final FrameworkMethod method) { return String.format("%s", method.getName()); } @@ -236,17 +239,17 @@ protected String testName(final FrameworkMethod method) { * * @return list of {@link FrameworkMethod} */ - + protected List computeTestMethods() { if (frameworkMethods != null && !frameworkMethods.isEmpty()) { return frameworkMethods; } List finalList = new ArrayList(); - //Iterator testMethodsItr = super.computeTestMethods().iterator(); + // Iterator testMethodsItr = super.computeTestMethods().iterator(); Class testClass = getTestClass().getJavaClass(); for (FrameworkMethod methodWithData : methodsWithData) { String superMethodName = DataConverter.getFullyQualifiedTestName(methodWithData.getName(), testClass); - for(FrameworkMethod method : super.computeTestMethods()) { + for (FrameworkMethod method : super.computeTestMethods()) { if (superMethodName.equals(DataConverter.getFullyQualifiedTestName(method.getName(), testClass))) { // Load the data,if any, at the method level @@ -284,20 +287,20 @@ protected List computeTestMethods() { * * @param errors list of any errors while validating the {@link DataPoint} field. */ -// private void validateDataPointFields(List errors) { -// Field[] fields = getTestClass().getJavaClass().getDeclaredFields(); -// -// for (Field each : fields) -// if (each.getAnnotation(DataPoint.class) != null && !Modifier.isStatic(each.getModifiers())) -// errors.add(new Error("DataPoint field " + each.getName() + " must be static")); -// } + // private void validateDataPointFields(List errors) { + // Field[] fields = getTestClass().getJavaClass().getDeclaredFields(); + // + // for (Field each : fields) + // if (each.getAnnotation(DataPoint.class) != null && !Modifier.isStatic(each.getModifiers())) + // errors.add(new Error("DataPoint field " + each.getName() + " must be static")); + // } /** * Validate that there could ever be only one constructor. * * @param errors list of any errors while validating the Constructor */ - + protected void validateConstructor(List errors) { validateOnlyOneConstructor(errors); } @@ -307,15 +310,14 @@ protected void validateConstructor(List errors) { * * @param errors list of any errors while validating test method */ - + protected void validateTestMethods(List errors) { - //Do Nothing as we now support public non void arg test methods + // Do Nothing as we now support public non void arg test methods } - - + protected Object createTest() throws Exception { return null; - + } /** @@ -324,8 +326,7 @@ protected Object createTest() throws Exception { * @param method the Framework Method * @return a compiled {@link Statement} object to be evaluated */ - - + public Statement methodBlock(final FrameworkMethod method) { return new ParamAnchor(method, getTestClass()); } @@ -340,35 +341,35 @@ public Statement methodBlock(final FrameworkMethod method) { * data from the test method. This method will make sure that the data is written to the output file once after * the Runner has completed and not for every instance of the test method. */ - + protected Statement withAfterClasses(Statement statement) { List afters = getTestClass().getAnnotatedMethods(AfterClass.class); List testMethods = getTestClass().getAnnotatedMethods(Test.class); List testInfoList = new ArrayList(); TestInfo testInfo = null; - //populateTestInfo(testInfo); + // populateTestInfo(testInfo); // THere would always be atleast one method associated with the Runner, else validation would fail. - for(FrameworkMethod method : testMethods){ - - // Only if the return type of the Method is not VOID, we try to determine the right loader and data files. + for (FrameworkMethod method : testMethods) { + + // Only if the return type of the Method is not VOID, we try to determine the right loader and data + // files. DataLoader loaderAnnotation = method.getAnnotation(DataLoader.class); if (loaderAnnotation != null) { - testInfo = determineLoader(loaderAnnotation , getTestClass()); + testInfo = determineLoader(loaderAnnotation, getTestClass()); } else { loaderAnnotation = getTestClass().getJavaClass().getAnnotation(DataLoader.class); if (loaderAnnotation != null) { - testInfo = determineLoader(loaderAnnotation , getTestClass()); + testInfo = determineLoader(loaderAnnotation, getTestClass()); } } - if(testInfo != null){ + if (testInfo != null) { testInfo.setMethodName(method.getName()); testInfoList.add(testInfo); } - - + } - return new RunAftersWithOutputData(statement, afters, null, testInfoList, writableData, testReportContainer); + return new RunAftersWithOutputData(statement, afters, null, testInfoList, writableData, testReportContainer); } /** @@ -442,7 +443,6 @@ private TestClass getTestClass() { return fTestClass; } - public void evaluate() throws Throwable { runWithAssignment(EasyAssignments.allUnassigned(fTestMethod.getMethod(), getTestClass())); LOG.debug("ParamAnchor evaluate"); @@ -458,8 +458,8 @@ public void evaluate() throws Throwable { * {@link #runWithCompleteAssignment(EasyAssignments)} for each {@link EasyAssignments} element in the * {@link #listOfAssignments} * - * @param parameterAssignment an instance of {@link EasyAssignments} identifying the parameters that needs to be - * supplied test data + * @param parameterAssignment an instance of {@link EasyAssignments} identifying the parameters that needs + * to be supplied test data * @throws Throwable if any exception occurs. */ protected void runWithAssignment(EasyAssignments parameterAssignment) throws Throwable { @@ -468,8 +468,8 @@ protected void runWithAssignment(EasyAssignments parameterAssignment) throws Thr boolean isFirstSetOfArguments = listOfAssignments.isEmpty(); for (int i = 0; i < potentialAssignments.size(); i++) { if (isFirstSetOfArguments) { - EasyAssignments assignments = EasyAssignments - .allUnassigned(fTestMethod.getMethod(), getTestClass()); + EasyAssignments assignments = EasyAssignments.allUnassigned(fTestMethod.getMethod(), + getTestClass()); listOfAssignments.add(assignments.assignNext(potentialAssignments.get(i))); } else { EasyAssignments assignments = listOfAssignments.get(i); @@ -506,21 +506,20 @@ protected void runWithAssignment(EasyAssignments parameterAssignment) throws Thr protected void runWithCompleteAssignment(final EasyAssignments complete) throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, Throwable { new BlockJUnit4ClassRunner(getTestClass().getJavaClass()) { - + protected void collectInitializationErrors(List errors) { // do nothing } - public Statement methodBlock(FrameworkMethod method) { final Statement statement = super.methodBlock(method); - //Sample Run Notifier to catch any runnable events for a test and do something. + // Sample Run Notifier to catch any runnable events for a test and do something. final RunNotifier notifier = new RunNotifier(); notifier.addListener(new EasyTestRunListener()); - final EachTestNotifier eachNotifier= new EachTestNotifier(notifier,null); + final EachTestNotifier eachNotifier = new EachTestNotifier(notifier, null); eachNotifier.fireTestStarted(); return new Statement() { - + public void evaluate() throws Throwable { try { statement.evaluate(); @@ -531,8 +530,8 @@ public void evaluate() throws Throwable { } catch (Throwable e) { eachNotifier.addFailure(e); throw e; - - }finally { + + } finally { eachNotifier.fireTestFinished(); } } @@ -540,12 +539,10 @@ public void evaluate() throws Throwable { }; } - protected Statement methodInvoker(FrameworkMethod method, Object test) { return methodCompletesWithParameters(method, complete, test); } - public Object createTest() throws Exception { return testInstance; } @@ -569,16 +566,16 @@ public Object createTest() throws Exception { * @param freshInstance a fresh instance of the class for which the method needs to be invoked. * @return an instance of {@link Statement} */ - private Statement methodCompletesWithParameters(final FrameworkMethod method, final EasyAssignments complete, - final Object freshInstance) { - + private Statement methodCompletesWithParameters(final FrameworkMethod method, + final EasyAssignments complete, final Object freshInstance) { + final RunNotifier testRunNotifier = new RunNotifier(); final TestRunDurationListener testRunDurationListener = new TestRunDurationListener(); testRunNotifier.addListener(testRunDurationListener); final EachTestNotifier eachRunNotifier = new EachTestNotifier(testRunNotifier, null); - + return new Statement() { - + public void evaluate() throws Throwable { String currentMethodName = method.getMethod().getName(); testResult = new TestResultBean(); @@ -586,16 +583,17 @@ public void evaluate() throws Throwable { testResult.setDate(new Date()); try { final Object[] values = complete.getMethodArguments(true); - // Log Statistics about the test method as well as the actual testSubject, if required. + // Log Statistics about the test method as well as the actual testSubject, if required. boolean testContainsInputParams = (values.length != 0); Map inputData = null; - // invoke test method + // invoke test method eachRunNotifier.fireTestStarted(); Object returnObj = method.invokeExplosively(freshInstance, values); eachRunNotifier.fireTestFinished(); - DurationBean testItemDurationBean = new DurationBean(currentMethodName, testRunDurationListener.getStartInNano(), testRunDurationListener.getEndInNano()); + DurationBean testItemDurationBean = new DurationBean(currentMethodName, + testRunDurationListener.getStartInNano(), testRunDurationListener.getEndInNano()); testResult.addTestItemDurationBean(testItemDurationBean); - + testResult.setOutput((returnObj == null) ? "void" : returnObj); testResult.setPassed(Boolean.TRUE); if (!mapMethodName.equals(method.getMethod().getName())) { @@ -608,7 +606,7 @@ public void evaluate() throws Throwable { if (writableData.get(mapMethodName) != null) { inputData = writableData.get(mapMethodName).get(rowNum); testResult.setInput(inputData); - } else{ + } else { testResult.setInput(null); } if (returnObj != null) { @@ -621,13 +619,13 @@ public void evaluate() throws Throwable { if (writableData.get(mapMethodName) != null) { LOG.debug("writableData.get(mapMethodName)" + writableData.get(mapMethodName) + " ,rowNum:" + rowNum); - + Map writableRow = writableData.get(mapMethodName).get(rowNum); writableRow.put(Loader.ACTUAL_RESULT, returnObj); if (testContainsInputParams) { - LOG.debug("writableData.get(mapMethodName)" + writableData.get(mapMethodName) - + " ,rowNum:" + rowNum); - inputData.put(Loader.ACTUAL_RESULT, returnObj); + LOG.debug("writableData.get(mapMethodName)" + writableData.get(mapMethodName) + + " ,rowNum:" + rowNum); + inputData.put(Loader.ACTUAL_RESULT, returnObj); } Object expectedResult = writableRow.get(Loader.EXPECTED_RESULT); // if expected result exist in user input test data, @@ -642,8 +640,9 @@ public void evaluate() throws Throwable { } } rowNum++; - - //writableData.get(mapMethodName).get(rowNum++).put(Loader.ACTUAL_RESULT, returnObj); + + // writableData.get(mapMethodName).get(rowNum++).put(Loader.ACTUAL_RESULT, + // returnObj); } } @@ -666,13 +665,11 @@ protected void handleDataPointSuccess() { } - - /** - * A List of {@link EasyTestRunner}s + * A List of {@link EasyTestRunner}s */ private final ArrayList runners = new ArrayList(); - + /** * List of {@link FrameworkMethod} that does not have any external test data associated with them. */ @@ -688,16 +685,16 @@ protected void handleDataPointSuccess() { * * @return a list of {@link DataDrivenTestRunner} */ - + protected List getChildren() { return runners; } /** * - * Construct a new {@link SpringTestRunner}. During construction, we will load the test data, and then we will create a list - * of {@link EasyTestRunner}. each instance of {@link DataDrivenTestRunner} in the list will correspond to a single method - * in the Test Class under test.
    + * Construct a new {@link SpringTestRunner}. During construction, we will load the test data, and then we will + * create a list of {@link EasyTestRunner}. each instance of {@link DataDrivenTestRunner} in the list will + * correspond to a single method in the Test Class under test.
    * The algorithm is as follows:
    *
      *
    • STEP 1: Load the test data. This will also do the check whether there exists a {@link DataLoader} annotation @@ -718,10 +715,11 @@ protected List getChildren() { * * Iteration over each method ends.
      * - * Finally create an instance of {@link EasyTestRunner} and make it use all the different types of methods we identified.
      - * We need to identify methods with data and methods with no data primarily to group the test methods together - * as well as to efficiently create new test methods for each method that has test data associated with it. - * This whole process will happen for each of the test class that is part of the Suite. + * Finally create an instance of {@link EasyTestRunner} and make it use all the different types of methods we + * identified.
      + * We need to identify methods with data and methods with no data primarily to group the test methods together as + * well as to efficiently create new test methods for each method that has test data associated with it. This whole + * process will happen for each of the test class that is part of the Suite. * * @param klass the test class * @throws InitializationError if an initializationError occurs @@ -763,12 +761,12 @@ public SpringTestRunner(Class klass) throws InitializationError { } runners.add(new EasyTestRunner(klass)); } - + /** - * Returns a {@link Statement}: We override this method as it was being called twice - * for the same class. Looks like a bug in JUnit. + * Returns a {@link Statement}: We override this method as it was being called twice for the same class. Looks like + * a bug in JUnit. */ - + protected Statement withBeforeClasses(Statement statement) { return statement; } @@ -825,7 +823,7 @@ protected void loadData(Class testClass, FrameworkMethod method, Class cur testData = method.getAnnotation(DataLoader.class); } if (testData != null) { - TestInfo testInfo = determineLoader(testData , getTestClass()); + TestInfo testInfo = determineLoader(testData, getTestClass()); Loader dataLoader = testInfo.getDataLoader(); if (testInfo.getDataLoader() == null) { Assert.fail("The framework currently does not support the specified Loader type. " @@ -833,10 +831,10 @@ protected void loadData(Class testClass, FrameworkMethod method, Class cur + "annotation and providing your custom loader using DataLoader annotation."); } else { ResourceLoader resourceLoader = new ResourceLoaderStrategy(getTestClass().getJavaClass()); - for(String filePath : testInfo.getFilePaths()){ + for (String filePath : testInfo.getFilePaths()) { Resource resource = resourceLoader.getResource(filePath); try { - if(resource.exists()){ + if (resource.exists()) { Map>> data = dataLoader.loadData(resource); // We also maintain the copy of the actual data for our write functionality. writableData.putAll(data); @@ -844,21 +842,21 @@ protected void loadData(Class testClass, FrameworkMethod method, Class cur DataContext.setConvertedData(DataConverter.convert(data, currentTestClass)); } } catch (Exception e) { - PARAM_LOG.error("Error occured while trying to find the resource with path {} ", resource.getResourceName(),e); + PARAM_LOG.error("Error occured while trying to find the resource with path {} ", + resource.getResourceName(), e); throw new RuntimeException(e); } } - } } } - + /** - * Returns a {@link Statement}: We override this method as it was being called twice - * for the same class. Looks like a bug in JUnit. + * Returns a {@link Statement}: We override this method as it was being called twice for the same class. Looks like + * a bug in JUnit. */ - + protected Statement withAfterClasses(Statement statement) { return statement; } @@ -871,9 +869,10 @@ protected Statement withAfterClasses(Statement statement) { * data back to the file. * @param testClass the class that the {@link TestInfo} object will be associated with * - * @return {@link TestInfo} an instance of {@link TestInfo} containing information about the currently executing test. + * @return {@link TestInfo} an instance of {@link TestInfo} containing information about the currently executing + * test. */ - private TestInfo determineLoader(DataLoader testData , TestClass testClass) { + private TestInfo determineLoader(DataLoader testData, TestClass testClass) { TestInfo result = new TestInfo(testClass); String[] dataFiles = testData.filePaths(); LoaderType loaderType = testData.loaderType(); diff --git a/src/test/java/org/easetech/easytest/example/ComparableObject.java b/src/test/java/org/easetech/easytest/example/ComparableObject.java index 2a4c236..ea82c55 100644 --- a/src/test/java/org/easetech/easytest/example/ComparableObject.java +++ b/src/test/java/org/easetech/easytest/example/ComparableObject.java @@ -40,7 +40,7 @@ public void setItem(Long item) { * @param o * @return */ - @Override + public int compareTo(ComparableObject o) { return 1; } diff --git a/src/test/java/org/easetech/easytest/example/ComparableObjectConverter.java b/src/test/java/org/easetech/easytest/example/ComparableObjectConverter.java index ac4ef78..c1a800c 100644 --- a/src/test/java/org/easetech/easytest/example/ComparableObjectConverter.java +++ b/src/test/java/org/easetech/easytest/example/ComparableObjectConverter.java @@ -10,7 +10,7 @@ public class ComparableObjectConverter extends AbstractConverter convertFrom) { String items = (String)convertFrom.get("items"); return new ComparableObject(Long.valueOf(items)); diff --git a/src/test/java/org/easetech/easytest/example/DelayedObject.java b/src/test/java/org/easetech/easytest/example/DelayedObject.java index 38119bb..f7c10bc 100644 --- a/src/test/java/org/easetech/easytest/example/DelayedObject.java +++ b/src/test/java/org/easetech/easytest/example/DelayedObject.java @@ -9,7 +9,7 @@ public class DelayedObject implements Delayed { private Long value; - @Override + public String toString() { return "DelayedObject [value=" + value + "]"; } @@ -31,13 +31,13 @@ public DelayedObject(Long value) { this.value = value; } - @Override + public int compareTo(Delayed o) { return 1; } - @Override + public long getDelay(TimeUnit unit) { return 0; diff --git a/src/test/java/org/easetech/easytest/example/DelayedObjectConverter.java b/src/test/java/org/easetech/easytest/example/DelayedObjectConverter.java index bbfff7c..c51282c 100644 --- a/src/test/java/org/easetech/easytest/example/DelayedObjectConverter.java +++ b/src/test/java/org/easetech/easytest/example/DelayedObjectConverter.java @@ -10,7 +10,7 @@ public class DelayedObjectConverter extends AbstractConverter{ * @param convertFrom * @return */ - @Override + public DelayedObject convert(Map convertFrom) { return new DelayedObject(Long.valueOf((String)convertFrom.get("items"))); diff --git a/src/test/java/org/easetech/easytest/example/EnumConverter.java b/src/test/java/org/easetech/easytest/example/EnumConverter.java index 14fa2fd..461e6e2 100644 --- a/src/test/java/org/easetech/easytest/example/EnumConverter.java +++ b/src/test/java/org/easetech/easytest/example/EnumConverter.java @@ -12,7 +12,7 @@ public class EnumConverter extends AbstractConverter { * @param convertFrom * @return */ - @Override + public Workingday convert(Map convertFrom) { return Workingday.valueOf((String)convertFrom.get("items")); diff --git a/src/test/java/org/easetech/easytest/example/ItemConverter.java b/src/test/java/org/easetech/easytest/example/ItemConverter.java index 169d9bf..c8a6b0c 100644 --- a/src/test/java/org/easetech/easytest/example/ItemConverter.java +++ b/src/test/java/org/easetech/easytest/example/ItemConverter.java @@ -7,7 +7,7 @@ public class ItemConverter extends AbstractConverter { - @Override + public Item convert(Map convertFrom) { Item item = null; diff --git a/src/test/java/org/easetech/easytest/example/RealItemService.java b/src/test/java/org/easetech/easytest/example/RealItemService.java index 483c2aa..bd213bb 100644 --- a/src/test/java/org/easetech/easytest/example/RealItemService.java +++ b/src/test/java/org/easetech/easytest/example/RealItemService.java @@ -11,13 +11,13 @@ public class RealItemService implements ItemService { public String testString; @SuppressWarnings("unchecked") - @Override + public List getItems(LibraryId libraryId, String searchText, String itemType) { System.out.println("getItems Called"); return Collections.EMPTY_LIST; } - @Override + public Item findItem(LibraryId libraryId, ItemId itemId) { System.out.println("findItems Called"); Item item = new Item(); diff --git a/src/test/java/org/easetech/easytest/example/TestExcelDataLoader.java b/src/test/java/org/easetech/easytest/example/TestExcelDataLoader.java index d7d3ac9..2c818f3 100644 --- a/src/test/java/org/easetech/easytest/example/TestExcelDataLoader.java +++ b/src/test/java/org/easetech/easytest/example/TestExcelDataLoader.java @@ -1,10 +1,11 @@ package org.easetech.easytest.example; +import org.easetech.easytest.interceptor.SpringIntercept; + import org.easetech.easytest.annotation.DataLoader; import org.easetech.easytest.annotation.Intercept; import org.easetech.easytest.annotation.Param; -import org.easetech.easytest.annotation.Report; import org.easetech.easytest.loader.LoaderType; import org.easetech.easytest.runner.DataDrivenTestRunner; import org.junit.BeforeClass; @@ -20,12 +21,7 @@ public class TestExcelDataLoader { @Intercept public static RealItemService itemService = new RealItemService(); - - @BeforeClass - public static void setUpGone() { - - System.out.println("Should be printed only once"); - } + /** * An instance of logger associated with the test framework. */ From 74b27bbbf75dcc3d68273d8c9309273df4f49ff4 Mon Sep 17 00:00:00 2001 From: Anuj kumar Date: Mon, 24 Dec 2012 11:38:03 +0100 Subject: [PATCH 06/11] Updated to use the same @Intercept annotation in the spring module as being used in the core module, thus hiding the implementation details from the user. Removed @SpringIntercept annotation. Signed-off-by: Anuj kumar --- .../InternalSpringInterceptor.java | 71 +++++++++++++++++++ .../interceptor/SpringDefaultInterceptor.java | 46 ------------ .../easytest/interceptor/SpringIntercept.java | 28 -------- .../easytest/runner/SpringTestRunner.java | 15 ++-- .../easytest/example/TestExcelDataLoader.java | 5 +- 5 files changed, 82 insertions(+), 83 deletions(-) create mode 100644 src/main/java/org/easetech/easytest/interceptor/InternalSpringInterceptor.java delete mode 100644 src/main/java/org/easetech/easytest/interceptor/SpringDefaultInterceptor.java delete mode 100644 src/main/java/org/easetech/easytest/interceptor/SpringIntercept.java diff --git a/src/main/java/org/easetech/easytest/interceptor/InternalSpringInterceptor.java b/src/main/java/org/easetech/easytest/interceptor/InternalSpringInterceptor.java new file mode 100644 index 0000000..801c73d --- /dev/null +++ b/src/main/java/org/easetech/easytest/interceptor/InternalSpringInterceptor.java @@ -0,0 +1,71 @@ + +package org.easetech.easytest.interceptor; + +import org.easetech.easytest.annotation.Intercept; + +import java.lang.reflect.Method; +import org.aopalliance.intercept.MethodInterceptor; +import org.aopalliance.intercept.MethodInvocation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * A internal implementation of the {@link MethodInterceptor} implementation that hides the implementation logic + * of intercepting the method call from the user. + * It always has an instance of {@link MethodIntercepter} whose + * {@link MethodIntercepter#intercept(Method, Object, Object[])} method is called internally. + * The actual implementation of the {@link MethodIntercepter} is provided by the user as an attribute to the {@link Intercept} annotation. + * If none is provided, then {@link DefaultMethodIntercepter} implementation is used. + * + * @author Anuj Kumar + * + */ +public class InternalSpringInterceptor implements MethodInterceptor { + + /** + * An instance of the {@link MethodIntercepter} + */ + private MethodIntercepter userIntercepter; + + /** + * An instance of logger associated with the test framework. + */ + protected static final Logger LOG = LoggerFactory.getLogger(InternalSpringInterceptor.class); + + /** + * Intercept the method with the advice + * @param invocation + * @return returned value + * @throws Throwable + */ + + public Object invoke(MethodInvocation invocation) throws Throwable { + return userIntercepter.intercept(invocation.getMethod(), invocation.getThis(), invocation.getArguments()); + + } + + /** + * Return an instance of {@link MethodIntercepter}. See the class javadocs for details. + * @return the userIntercepter + */ + public MethodIntercepter getUserIntercepter() { + return userIntercepter; + } + + /** + * Set the user interceptor + * @param userIntercepter the userIntercepter to set + */ + public void setUserIntercepter(MethodIntercepter userIntercepter) { + this.userIntercepter = userIntercepter; + } + + + + + + + + +} diff --git a/src/main/java/org/easetech/easytest/interceptor/SpringDefaultInterceptor.java b/src/main/java/org/easetech/easytest/interceptor/SpringDefaultInterceptor.java deleted file mode 100644 index 64f1b86..0000000 --- a/src/main/java/org/easetech/easytest/interceptor/SpringDefaultInterceptor.java +++ /dev/null @@ -1,46 +0,0 @@ - -package org.easetech.easytest.interceptor; - -import org.aopalliance.intercept.MethodInvocation; - -import java.lang.reflect.Method; -import net.sf.cglib.proxy.MethodProxy; -import org.aopalliance.intercept.MethodInterceptor; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * - * A default interceptor that simply Logs the time taken by a method in nano seconds to the attached logger. - * - * @author Anuj Kumar - * - */ -public class SpringDefaultInterceptor implements MethodInterceptor { - - /** - * An instance of logger associated with the test framework. - */ - protected static final Logger LOG = LoggerFactory.getLogger(SpringDefaultInterceptor.class); - - /** - * Intercept the method with the advice - * @param invocation - * @return returned value - * @throws Throwable - */ - - public Object invoke(MethodInvocation invocation) throws Throwable { - long startTime = System.nanoTime(); - Object result = invocation.getMethod().invoke(invocation.getThis(), invocation.getArguments()); - long duration = System.nanoTime() - startTime; - LOG.debug("Method {} took {} nanoseconds", invocation.getMethod().getName(), duration); - return result; - } - - - - - - -} diff --git a/src/main/java/org/easetech/easytest/interceptor/SpringIntercept.java b/src/main/java/org/easetech/easytest/interceptor/SpringIntercept.java deleted file mode 100644 index 81e0773..0000000 --- a/src/main/java/org/easetech/easytest/interceptor/SpringIntercept.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.easetech.easytest.interceptor; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import org.aopalliance.intercept.MethodInterceptor; - -/** - * - * A field level annotation that can be used to intercept calls to methods within the subject under test. - * A user can specify the interceptor it wants to use to intercept the call to the test subject's method. - * The interceptor should implement {@link MethodInterceptor}. - * The default interceptor is {@link SpringDefaultInterceptor} that simply prints - * the time taken in nano seconds by the test method on the console. - * - * @author Anuj Kumar - * - */ -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.FIELD}) -public @interface SpringIntercept { - /** - * The {@link MethodInterceptor} to use to intercept method calls. - */ - Class interceptor() default SpringDefaultInterceptor.class; - -} diff --git a/src/main/java/org/easetech/easytest/runner/SpringTestRunner.java b/src/main/java/org/easetech/easytest/runner/SpringTestRunner.java index de1755d..5edb791 100644 --- a/src/main/java/org/easetech/easytest/runner/SpringTestRunner.java +++ b/src/main/java/org/easetech/easytest/runner/SpringTestRunner.java @@ -1,7 +1,7 @@ package org.easetech.easytest.runner; -import org.easetech.easytest.interceptor.SpringIntercept; +import org.easetech.easytest.config.ConfigLoader; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; @@ -12,10 +12,11 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -import org.aopalliance.intercept.MethodInterceptor; import org.easetech.easytest.annotation.DataLoader; import org.easetech.easytest.annotation.Intercept; import org.easetech.easytest.annotation.Param; +import org.easetech.easytest.interceptor.InternalSpringInterceptor; +import org.easetech.easytest.interceptor.MethodIntercepter; import org.easetech.easytest.internal.EasyAssignments; import org.easetech.easytest.io.Resource; import org.easetech.easytest.io.ResourceLoader; @@ -165,6 +166,7 @@ public EasyTestRunner(Class klass) throws InitializationError { testReportContainer = new ReportDataContainer(getTestClass().getJavaClass()); testInstance = getTestClass().getOnlyConstructor().newInstance(); getTestContextManager().prepareTestInstance(testInstance); + ConfigLoader.loadTestConfigurations(getTestClass().getJavaClass(), testInstance); instrumentClass(getTestClass().getJavaClass()); } catch (Exception e) { @@ -187,14 +189,17 @@ protected void instrumentClass(Class testClass) throws IllegalArgumentExcepti Field[] fields = testClass.getDeclaredFields(); try { for (Field field : fields) { - SpringIntercept interceptor = field.getAnnotation(SpringIntercept.class); + field.setAccessible(true); + Intercept interceptor = field.getAnnotation(Intercept.class); if (interceptor != null) { - Class interceptorClass = interceptor.interceptor(); + Class interceptorClass = interceptor.interceptor(); // This is the field we want to enhance Object fieldInstance = field.get(testInstance); ProxyFactory factory = new ProxyFactory(); factory.setTarget(fieldInstance); - factory.addAdvice(interceptorClass.newInstance()); + InternalSpringInterceptor internalIntercepter = new InternalSpringInterceptor(); + internalIntercepter.setUserIntercepter(interceptorClass.newInstance()); + factory.addAdvice(internalIntercepter); Object proxy = factory.getProxy(); field.set(testInstance, proxy); } diff --git a/src/test/java/org/easetech/easytest/example/TestExcelDataLoader.java b/src/test/java/org/easetech/easytest/example/TestExcelDataLoader.java index 2c818f3..46350b7 100644 --- a/src/test/java/org/easetech/easytest/example/TestExcelDataLoader.java +++ b/src/test/java/org/easetech/easytest/example/TestExcelDataLoader.java @@ -1,14 +1,11 @@ package org.easetech.easytest.example; -import org.easetech.easytest.interceptor.SpringIntercept; - import org.easetech.easytest.annotation.DataLoader; import org.easetech.easytest.annotation.Intercept; import org.easetech.easytest.annotation.Param; import org.easetech.easytest.loader.LoaderType; import org.easetech.easytest.runner.DataDrivenTestRunner; -import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.slf4j.Logger; @@ -20,7 +17,7 @@ public class TestExcelDataLoader { @Intercept - public static RealItemService itemService = new RealItemService(); + static RealItemService itemService = new RealItemService(); /** * An instance of logger associated with the test framework. From cbeaa0a9df864ef7e0389fe0b9c1d01b502755ba Mon Sep 17 00:00:00 2001 From: Christiaan Mol Date: Wed, 26 Dec 2012 14:22:24 +0100 Subject: [PATCH 07/11] removed not used class --- .../easytest/reports/TestReports.java | 99 ------------------- 1 file changed, 99 deletions(-) delete mode 100644 src/test/java/org/easetech/easytest/reports/TestReports.java diff --git a/src/test/java/org/easetech/easytest/reports/TestReports.java b/src/test/java/org/easetech/easytest/reports/TestReports.java deleted file mode 100644 index 9dbf588..0000000 --- a/src/test/java/org/easetech/easytest/reports/TestReports.java +++ /dev/null @@ -1,99 +0,0 @@ -package org.easetech.easytest.reports; - -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.IOException; -import java.util.Calendar; -import java.util.Date; -import org.easetech.easytest.reports.data.ReportTotalsBean; -import org.easetech.easytest.reports.utils.ChartUtils; -import org.jfree.chart.ChartUtilities; -import org.jfree.chart.JFreeChart; -import org.jfree.data.general.DefaultPieDataset; -import org.junit.Test; - -public class TestReports { - -// @Test -// public void testReports() { -// -// String className = "TestRouteCalculationBusiness"; - -// ReportDataContainer testReportContainer = new ReportDataContainer(className); -// Map input1 = new HashMap(); -// input1.put("name", "molly"); -// input1.put("cars", 0); -// input1.put("object", new Object()); -// Object output1 = new HashMap(); -// String output2 = "OUTPUT string"; -// -// testReportContainer.addTestResult("method1", input1, output1, true, null, null, null, new Date(), getDymmyDate()); -// testReportContainer.addTestResult("method1", new HashMap(), null, true, null, null, null, new Date(), getDymmyDate()); -// testReportContainer.addTestResult("method1", new HashMap(), null, false, "string not blank", null, null, new Date(), getDymmyDate()); -// testReportContainer.addTestResult("method1", new HashMap(), null, false, "int too high", false, null, new Date(), getDymmyDate()); -// testReportContainer.addTestResult("method1", new HashMap(), null, null, null, true, "NoDataAccessException", new Date(), getDymmyDate()); -// testReportContainer.addTestResult("method1", new HashMap(), null, null, null, true, "RuntimeException", new Date(), getDymmyDate()); -// testReportContainer.addTestResult("method1", new HashMap(), null, true, null, null, null, new Date(), getDymmyDate()); -// testReportContainer.addTestResult("method1", new HashMap(), null, true, null, null, null, new Date(), getDymmyDate()); -// testReportContainer.addTestResult("method1", new HashMap(), output2, true, null, null, null, new Date(), getDymmyDate()); -// testReportContainer.addTestResult("method1", new HashMap(), null, true, null, null, null, new Date(), getDymmyDate()); -// -// testReportContainer.addTestResult("method2", new HashMap(), null, true, "", null, "", new Date(), getDymmyDate()); -// testReportContainer.addTestResult("method2", new HashMap(), null, true, "", null, "", new Date(), getDymmyDate()); -// testReportContainer.addTestResult("method2", new HashMap(), null, false, "", null, "", new Date(), getDymmyDate()); -// testReportContainer.addTestResult("method2", new HashMap(), null, false, "", null, "", new Date(), getDymmyDate()); -// testReportContainer.addTestResult("method2", new HashMap(), null, null, "", true, "", new Date(), getDymmyDate()); -// testReportContainer.addTestResult("method2", new HashMap(), null, null, "", true, "", new Date(), getDymmyDate()); -// testReportContainer.addTestResult("method2", new HashMap(), null, true, "", null, "", new Date(), getDymmyDate()); -// testReportContainer.addTestResult("method2", new HashMap(), null, true, "", null, "", new Date(), getDymmyDate()); -// testReportContainer.addTestResult("method2", new HashMap(), null, true, "", null, "", new Date(), getDymmyDate()); -// testReportContainer.addTestResult("method2", new HashMap(), null, true, "", null, "", new Date(), getDymmyDate()); -// -// ReportRunner testReportHelper = new ReportRunner(); -// testReportHelper.createReports(testReportContainer); -// -// } - - private Date getDymmyDate() { - Calendar calendar = Calendar.getInstance(); - calendar.setTime(new Date()); - calendar.add(Calendar.MILLISECOND, 0 + (int) (Math.random() * 2000)); - return calendar.getTime(); - } - - @Test - public void testPieChart() { - String locationToSaveFile = "c:/temp"; - JFreeChart chart = getDummyChart(); - - int width = 300; - int height = 300; - try { - File file = new File(locationToSaveFile + "/dummychart.png"); - ChartUtilities.saveChartAsPNG(file, chart, width, height); - BufferedImage createBufferedImage = chart.createBufferedImage(width, height); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - private JFreeChart getDummyChart() { - ReportTotalsBean testReportTotals = new ReportTotalsBean(); - testReportTotals.setPassed(12L); - testReportTotals.setFailed(3L); - testReportTotals.setException(2L); - - // create a dataset... - DefaultPieDataset dataset = new DefaultPieDataset(); - dataset.setValue("Passed ("+testReportTotals.getPercentagePassed()+"%)", testReportTotals.getPercentagePassed()); - dataset.setValue("Failed ("+testReportTotals.getPercentageFailed()+"%)", testReportTotals.getPercentageFailed()); - dataset.setValue("Exception ("+testReportTotals.getPercentageException()+"%)", testReportTotals.getPercentageException()); - - JFreeChart pieChart = ChartUtils.getPieChart("TotalsReport", dataset); - BufferedImage bufferedImageChartImage = ChartUtils.getBufferedImageChartImage(pieChart, 400, 400); - - return pieChart; - } - -} From 7f66e449443a8ae56b737ef49c4583ab8c27f632 Mon Sep 17 00:00:00 2001 From: Anuj kumar Date: Tue, 1 Jan 2013 18:34:47 +0100 Subject: [PATCH 08/11] Refactored the SpringTestRunner to depend on common base classes. This has resulted in simple Runner implementation for Spring based test cases. Signed-off-by: Anuj kumar --- .../easytest/runner/SpringTestRunner.java | 646 ++---------------- .../easytest/example/TestExcelDataLoader.java | 2 +- 2 files changed, 59 insertions(+), 589 deletions(-) diff --git a/src/main/java/org/easetech/easytest/runner/SpringTestRunner.java b/src/main/java/org/easetech/easytest/runner/SpringTestRunner.java index 5edb791..14945f8 100644 --- a/src/main/java/org/easetech/easytest/runner/SpringTestRunner.java +++ b/src/main/java/org/easetech/easytest/runner/SpringTestRunner.java @@ -1,31 +1,20 @@ package org.easetech.easytest.runner; -import org.easetech.easytest.config.ConfigLoader; - import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Collections; -import java.util.Date; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import org.easetech.easytest.annotation.DataLoader; import org.easetech.easytest.annotation.Intercept; import org.easetech.easytest.annotation.Param; +import org.easetech.easytest.config.ConfigLoader; import org.easetech.easytest.interceptor.InternalSpringInterceptor; import org.easetech.easytest.interceptor.MethodIntercepter; -import org.easetech.easytest.internal.EasyAssignments; -import org.easetech.easytest.io.Resource; -import org.easetech.easytest.io.ResourceLoader; -import org.easetech.easytest.io.ResourceLoaderStrategy; import org.easetech.easytest.loader.DataConverter; -import org.easetech.easytest.loader.Loader; -import org.easetech.easytest.loader.LoaderFactory; -import org.easetech.easytest.loader.LoaderType; -import org.easetech.easytest.reports.data.DurationBean; +import org.easetech.easytest.loader.DataLoaderUtil; import org.easetech.easytest.reports.data.ReportDataContainer; import org.easetech.easytest.reports.data.TestResultBean; import org.easetech.easytest.util.DataContext; @@ -34,19 +23,13 @@ import org.junit.AfterClass; import org.junit.Assert; import org.junit.Test; -import org.junit.experimental.theories.PotentialAssignment; -import org.junit.experimental.theories.PotentialAssignment.CouldNotGenerateValueException; -import org.junit.internal.AssumptionViolatedException; -import org.junit.internal.runners.model.EachTestNotifier; import org.junit.runner.Runner; -import org.junit.runner.notification.RunNotifier; import org.junit.runners.BlockJUnit4ClassRunner; import org.junit.runners.Suite; import org.junit.runners.model.FrameworkMethod; import org.junit.runners.model.InitializationError; import org.junit.runners.model.MultipleFailureException; import org.junit.runners.model.Statement; -import org.junit.runners.model.TestClass; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.aop.framework.AopConfigException; @@ -77,32 +60,55 @@ * * */ -public class SpringTestRunner extends Suite { +public class SpringTestRunner extends BaseSuite { - /** - * An instance of {@link Map} that contains the data to be written to the File - */ - private static Map>> writableData = new HashMap>>(); /** - * The default rowNum within the {@link #writableData}'s particular method data. - */ - private static int rowNum = 0; - - /** - * The name of the method currently being executed. Used for populating the {@link #writableData} map. + * An instance of logger associated with the test framework. */ - private String mapMethodName = ""; + protected static final Logger PARAM_LOG = LoggerFactory.getLogger(SpringTestRunner.class); + /** - * The report container which holds all the reporting data + * + * Construct a new {@link SpringTestRunner}. During construction, we will load the test data, and then we will + * create a list of {@link EasyTestRunner}. each instance of {@link DataDrivenTestRunner} in the list will + * correspond to a single method in the Test Class under test.
      + * The algorithm is as follows:
      + *
        + *
      • STEP 1: Load the test data. This will also do the check whether there exists a {@link DataLoader} annotation + * at the class level
      • + *
      • Iterate over each method.
        + * For each method: + *
          + *
        1. If method has {@link DataLoader} annotation, it means that there is test data associated with the test + * method.
          + * In such a case add the method to the methodsWithData List. + *
        2. If method does not have a {@link DataLoader} annotation, then: + *
            + *
          1. Check if there already exists data for the method. This is possible as the data could have been loaded at the + * class level.
            + *
          2. If the data for the given method exists, add the method to the methodsWithData List. + *
          3. If the data does not exists for the given test method, put it aside in a list of unused methods, + *
          + *
        + * Iteration over each method ends.
        + * + * Finally create an instance of {@link EasyTestRunner} and make it use all the different types of methods we + * identified.
        + * We need to identify methods with data and methods with no data primarily to group the test methods together as + * well as to efficiently create new test methods for each method that has test data associated with it. This whole + * process will happen for each of the test class that is part of the Suite. + * + * @param klass the test class + * @throws InitializationError if an initializationError occurs */ - private ReportDataContainer testReportContainer = null; + @SuppressWarnings("unchecked") + public SpringTestRunner(Class klass) throws InitializationError { + super(klass); + runners.add(new EasyTestRunner(klass)); + } - /** - * An instance of logger associated with the test framework. - */ - protected static final Logger PARAM_LOG = LoggerFactory.getLogger(SpringTestRunner.class); /** * A {@link BlockJUnit4ClassRunner} Runner implementation that adds support of input parameters as part of the @@ -144,13 +150,22 @@ private class EasyTestRunner extends SpringJUnit4ClassRunner { * Convenient class member to get the list of {@link FrameworkMethod} that this runner will execute. */ List frameworkMethods; + + + /** + * The report container which holds all the reporting data + */ + private ReportDataContainer testReportContainer = null; /** * The actual instance of the test class. This is extremely handy in cases where we want to reflectively set * instance fields on a test class. */ Object testInstance; - + + /** + * An instance that contains the result for a single test execution + */ TestResultBean testResult; /** @@ -197,7 +212,7 @@ protected void instrumentClass(Class testClass) throws IllegalArgumentExcepti Object fieldInstance = field.get(testInstance); ProxyFactory factory = new ProxyFactory(); factory.setTarget(fieldInstance); - InternalSpringInterceptor internalIntercepter = new InternalSpringInterceptor(); + InternalSpringInterceptor internalIntercepter = new InternalSpringInterceptor(); internalIntercepter.setUserIntercepter(interceptorClass.newInstance()); factory.addAdvice(internalIntercepter); Object proxy = factory.getProxy(); @@ -258,7 +273,7 @@ protected List computeTestMethods() { if (superMethodName.equals(DataConverter.getFullyQualifiedTestName(method.getName(), testClass))) { // Load the data,if any, at the method level - loadData(null, method, getTestClass().getJavaClass()); + DataLoaderUtil.loadData(null, method, getTestClass(), writableData); List> methodData = DataContext.getData().get(superMethodName); if (methodData == null) { Assert.fail("Method with name : " + superMethodName @@ -333,7 +348,7 @@ protected Object createTest() throws Exception { */ public Statement methodBlock(final FrameworkMethod method) { - return new ParamAnchor(method, getTestClass()); + return new InternalParameterizedStatement(method, testResult, testReportContainer, writableData, getTestClass(), testInstance); } /** @@ -360,12 +375,12 @@ protected Statement withAfterClasses(Statement statement) { // files. DataLoader loaderAnnotation = method.getAnnotation(DataLoader.class); if (loaderAnnotation != null) { - testInfo = determineLoader(loaderAnnotation, getTestClass()); + testInfo = DataLoaderUtil.determineLoader(loaderAnnotation, getTestClass()); } else { loaderAnnotation = getTestClass().getJavaClass().getAnnotation(DataLoader.class); if (loaderAnnotation != null) { - testInfo = determineLoader(loaderAnnotation, getTestClass()); + testInfo = DataLoaderUtil.determineLoader(loaderAnnotation, getTestClass()); } } if (testInfo != null) { @@ -377,551 +392,6 @@ protected Statement withAfterClasses(Statement statement) { return new RunAftersWithOutputData(statement, afters, null, testInfoList, writableData, testReportContainer); } - /** - * - * Static inner class to support Statement evaluation. - * - */ - public class ParamAnchor extends Statement { - - /** - * An instance of logger associated with the test framework. - */ - protected final Logger LOG = LoggerFactory.getLogger(EasyTestRunner.ParamAnchor.class); - - private int successes = 0; - - /** - * an instance of {@link FrameworkMethod} identifying the method to be tested. - */ - private FrameworkMethod fTestMethod; - - /** - * An instance of {@link TestClass} identifying the class under test - */ - private TestClass fTestClass; - - /** - * A List of {@link EasyAssignments}. Each member in the list corresponds to a single set of test data to be - * passed to the test method. For eg. If the user has specified the test data in the CSV file as:
        - *
        - * testGetItems,LibraryId,itemType,searchText
        - * ,4,journal,batman
        - * ,1,ebook,potter
        - * where:
      • testGetItems is the name of the method
      • - * LibraryId,itemType,searchText are the names of the parameters that the test method expects
      • and
      • - * ,4,journal,batman
      • ,1,ebook,potter
      • are the actual test data
        - * then this list will consists of TWO {@link EasyAssignments} instances with values:
      • [[{LibraryId=4, - * itemType=journal, searchText=batman}]]
      • AND
      • [[{LibraryId=1, itemType=ebook, searchText=potter}]] - * - */ - private List listOfAssignments; - - /** - * List of Invalid parameters - */ - private List fInvalidParameters = new ArrayList(); - - /** - * - * Construct a new ParamAnchor. The constructor performs the following operations:
        - *
      • It sets the class variables method , testClass and initializes the instance of - * {@link #listOfAssignments}
      • - * It searches for {@link DataLoader} annotation and if it finds one, it tries to get the right - * {@link Loader} from the {@link LoaderFactory}. If the {@link Loader} is not found, the test fails. If the - * Loader is found, it loads the data and makes it available to the entire test Thread using - * {@link DataContext} - * - * - * @param method the method to run the test on - * @param testClass an instance of {@link TestClass} - */ - public ParamAnchor(FrameworkMethod method, TestClass testClass) { - fTestMethod = method; - fTestClass = testClass; - listOfAssignments = new ArrayList(); - DataContext.setMethodName(DataConverter.getFullyQualifiedTestName(method.getName(), - testClass.getJavaClass())); - } - - private TestClass getTestClass() { - return fTestClass; - } - - public void evaluate() throws Throwable { - runWithAssignment(EasyAssignments.allUnassigned(fTestMethod.getMethod(), getTestClass())); - LOG.debug("ParamAnchor evaluate"); - if (successes == 0) - Assert.fail("Never found parameters that satisfied method assumptions. Violated assumptions: " - + fInvalidParameters); - } - - /** - * This method encapsulates the actual change in behavior from the traditional JUnit Theories way of - * populating and supplying the test data to the test method. This method creates a list of - * {@link EasyAssignments} identified by {@link #listOfAssignments} and then calls - * {@link #runWithCompleteAssignment(EasyAssignments)} for each {@link EasyAssignments} element in the - * {@link #listOfAssignments} - * - * @param parameterAssignment an instance of {@link EasyAssignments} identifying the parameters that needs - * to be supplied test data - * @throws Throwable if any exception occurs. - */ - protected void runWithAssignment(EasyAssignments parameterAssignment) throws Throwable { - while (!parameterAssignment.isComplete()) { - List potentialAssignments = parameterAssignment.potentialsForNextUnassigned(); - boolean isFirstSetOfArguments = listOfAssignments.isEmpty(); - for (int i = 0; i < potentialAssignments.size(); i++) { - if (isFirstSetOfArguments) { - EasyAssignments assignments = EasyAssignments.allUnassigned(fTestMethod.getMethod(), - getTestClass()); - listOfAssignments.add(assignments.assignNext(potentialAssignments.get(i))); - } else { - EasyAssignments assignments = listOfAssignments.get(i); - try { - listOfAssignments.set(i, assignments.assignNext(potentialAssignments.get(i))); - } catch (IndexOutOfBoundsException e) { - listOfAssignments.add(assignments.assignNext(potentialAssignments.get(i))); - } - } - - } - parameterAssignment = parameterAssignment.assignNext(null); - } - if (listOfAssignments.isEmpty()) { - LOG.debug("The list of Assignments is null. It normally happens when the user has not supplied any parameters to the test."); - LOG.debug(" Creating an instance of Assignments object with all its value unassigned."); - listOfAssignments.add(EasyAssignments.allUnassigned(fTestMethod.getMethod(), getTestClass())); - } - for (EasyAssignments assignments : listOfAssignments) { - runWithCompleteAssignment(assignments); - } - } - - /** - * Run the test data with complete Assignments - * - * @param complete the {@link EasyAssignments} - * @throws InstantiationException if an error occurs while instantiating the method - * @throws IllegalAccessException if an error occurs due to illegal access to the test method - * @throws InvocationTargetException if an error occurs because the method is not invokable - * @throws NoSuchMethodException if an error occurs because no such method with the given name exists. - * @throws Throwable any other error - */ - protected void runWithCompleteAssignment(final EasyAssignments complete) throws InstantiationException, - IllegalAccessException, InvocationTargetException, NoSuchMethodException, Throwable { - new BlockJUnit4ClassRunner(getTestClass().getJavaClass()) { - - protected void collectInitializationErrors(List errors) { - // do nothing - } - - public Statement methodBlock(FrameworkMethod method) { - final Statement statement = super.methodBlock(method); - // Sample Run Notifier to catch any runnable events for a test and do something. - final RunNotifier notifier = new RunNotifier(); - notifier.addListener(new EasyTestRunListener()); - final EachTestNotifier eachNotifier = new EachTestNotifier(notifier, null); - eachNotifier.fireTestStarted(); - return new Statement() { - - public void evaluate() throws Throwable { - try { - statement.evaluate(); - handleDataPointSuccess(); - } catch (AssumptionViolatedException e) { - eachNotifier.addFailedAssumption(e); - handleAssumptionViolation(e); - } catch (Throwable e) { - eachNotifier.addFailure(e); - throw e; - - } finally { - eachNotifier.fireTestFinished(); - } - } - - }; - } - - protected Statement methodInvoker(FrameworkMethod method, Object test) { - return methodCompletesWithParameters(method, complete, test); - } - - public Object createTest() throws Exception { - return testInstance; - } - }.methodBlock(fTestMethod).evaluate(); - } - - /** - * This method is responsible for actually executing the test method as well as capturing the test data - * returned by the test method. The algorithm to capture the output data is as follows: - *
          - * After the method has been invoked explosively, the returned value is checked. If there is a return value: - *
        1. We get the name of the method that is currently executing, - *
        2. We find teh exact place in the test input data for which this method was executed, - *
        3. We put the returned result in the map of input test data. The entry in the map has the key : - * {@link Loader#ACTUAL_RESULT} and the value is the returned value by the test method. - * - * We finally write the test data to the file. - * - * @param method an instance of {@link FrameworkMethod} that needs to be executed - * @param complete an instance of {@link EasyAssignments} that contains the input test data values - * @param freshInstance a fresh instance of the class for which the method needs to be invoked. - * @return an instance of {@link Statement} - */ - private Statement methodCompletesWithParameters(final FrameworkMethod method, - final EasyAssignments complete, final Object freshInstance) { - - final RunNotifier testRunNotifier = new RunNotifier(); - final TestRunDurationListener testRunDurationListener = new TestRunDurationListener(); - testRunNotifier.addListener(testRunDurationListener); - final EachTestNotifier eachRunNotifier = new EachTestNotifier(testRunNotifier, null); - - return new Statement() { - - public void evaluate() throws Throwable { - String currentMethodName = method.getMethod().getName(); - testResult = new TestResultBean(); - testResult.setMethod(currentMethodName); - testResult.setDate(new Date()); - try { - final Object[] values = complete.getMethodArguments(true); - // Log Statistics about the test method as well as the actual testSubject, if required. - boolean testContainsInputParams = (values.length != 0); - Map inputData = null; - // invoke test method - eachRunNotifier.fireTestStarted(); - Object returnObj = method.invokeExplosively(freshInstance, values); - eachRunNotifier.fireTestFinished(); - DurationBean testItemDurationBean = new DurationBean(currentMethodName, - testRunDurationListener.getStartInNano(), testRunDurationListener.getEndInNano()); - testResult.addTestItemDurationBean(testItemDurationBean); - - testResult.setOutput((returnObj == null) ? "void" : returnObj); - testResult.setPassed(Boolean.TRUE); - if (!mapMethodName.equals(method.getMethod().getName())) { - // if mapMethodName is not same as the current executing method name - // then assign that to mapMethodName to write to writableData - mapMethodName = method.getMethod().getName(); - // initialize the row number. - rowNum = 0; - } - if (writableData.get(mapMethodName) != null) { - inputData = writableData.get(mapMethodName).get(rowNum); - testResult.setInput(inputData); - } else { - testResult.setInput(null); - } - if (returnObj != null) { - LOG.debug("returnObj:" + returnObj); - if (!mapMethodName.equals(method.getMethod().getName())) { - mapMethodName = method.getMethod().getName(); - rowNum = 0; - } - LOG.debug("mapMethodName:" + mapMethodName + " ,rowNum:" + rowNum); - if (writableData.get(mapMethodName) != null) { - LOG.debug("writableData.get(mapMethodName)" + writableData.get(mapMethodName) - + " ,rowNum:" + rowNum); - - Map writableRow = writableData.get(mapMethodName).get(rowNum); - writableRow.put(Loader.ACTUAL_RESULT, returnObj); - if (testContainsInputParams) { - LOG.debug("writableData.get(mapMethodName)" + writableData.get(mapMethodName) - + " ,rowNum:" + rowNum); - inputData.put(Loader.ACTUAL_RESULT, returnObj); - } - Object expectedResult = writableRow.get(Loader.EXPECTED_RESULT); - // if expected result exist in user input test data, - // then compare that with actual output result - // and write the status back to writable map data. - if (expectedResult != null) { - LOG.debug("Expected result exists"); - if (expectedResult.toString().equals(returnObj.toString())) { - writableRow.put(Loader.TEST_STATUS, Loader.TEST_PASSED); - } else { - writableRow.put(Loader.TEST_STATUS, Loader.TEST_FAILED); - } - } - rowNum++; - - // writableData.get(mapMethodName).get(rowNum++).put(Loader.ACTUAL_RESULT, - // returnObj); - } - - } - } catch (CouldNotGenerateValueException e) { - // ignore - } - testReportContainer.addTestResult(testResult); - } - }; - } - - protected void handleAssumptionViolation(AssumptionViolatedException e) { - fInvalidParameters.add(e); - } - - protected void handleDataPointSuccess() { - successes++; - } - } - - } - - /** - * A List of {@link EasyTestRunner}s - */ - private final ArrayList runners = new ArrayList(); - - /** - * List of {@link FrameworkMethod} that does not have any external test data associated with them. - */ - private List methodsWithNoData = new ArrayList(); - - /** - * List of {@link FrameworkMethod} that does have any external test data associated with them. - */ - private List methodsWithData = new ArrayList(); - - /** - * Get the children Runners - * - * @return a list of {@link DataDrivenTestRunner} - */ - - protected List getChildren() { - return runners; - } - - /** - * - * Construct a new {@link SpringTestRunner}. During construction, we will load the test data, and then we will - * create a list of {@link EasyTestRunner}. each instance of {@link DataDrivenTestRunner} in the list will - * correspond to a single method in the Test Class under test.
          - * The algorithm is as follows:
          - *
            - *
          • STEP 1: Load the test data. This will also do the check whether there exists a {@link DataLoader} annotation - * at the class level
          • - *
          • Iterate over each method.
            - * For each method: - *
              - *
            1. If method has {@link DataLoader} annotation, it means that there is test data associated with the test - * method.
              - * In such a case add the method to the methodsWithData List. - *
            2. If method does not have a {@link DataLoader} annotation, then: - *
                - *
              1. Check if there already exists data for the method. This is possible as the data could have been loaded at the - * class level.
                - *
              2. If the data for the given method exists, add the method to the methodsWithData List. - *
              3. If the data does not exists for the given test method, put it aside in a list of unused methods, - *
              - *
            - * Iteration over each method ends.
            - * - * Finally create an instance of {@link EasyTestRunner} and make it use all the different types of methods we - * identified.
            - * We need to identify methods with data and methods with no data primarily to group the test methods together as - * well as to efficiently create new test methods for each method that has test data associated with it. This whole - * process will happen for each of the test class that is part of the Suite. - * - * @param klass the test class - * @throws InitializationError if an initializationError occurs - */ - @SuppressWarnings("unchecked") - public SpringTestRunner(Class klass) throws InitializationError { - super(klass, Collections.EMPTY_LIST); - Class testClass = getTestClass().getJavaClass(); - // Load the data at the class level, if any. - loadData(klass, null, testClass); - List availableMethods = getTestClass().getAnnotatedMethods(Test.class); - List methodsWithNoData = new ArrayList(); - List methodsWithData = new ArrayList(); - for (FrameworkMethod method : availableMethods) { - // Try loading the data if any at the method level - if (method.getAnnotation(DataLoader.class) != null) { - methodsWithData.add(method); - } else { - // Method does not have its own dataloader annotation - // Does method have data already loaded at the class level? - boolean methodDataLoaded = isMethodDataLoaded(DataConverter.getFullyQualifiedTestName(method.getName(), - testClass)); - if (methodDataLoaded) { - methodsWithData.add(method); - } else { - methodsWithNoData.add(method); - } - } - - } - // Finally create a runner for methods that do not have Data specified with them. - // These are potentially the methods with no method parameters and with @Test annotation. - if (!methodsWithNoData.isEmpty()) { - this.methodsWithNoData = methodsWithNoData; - - } - if (!methodsWithData.isEmpty()) { - this.methodsWithData = methodsWithData; - } - runners.add(new EasyTestRunner(klass)); - } - - /** - * Returns a {@link Statement}: We override this method as it was being called twice for the same class. Looks like - * a bug in JUnit. - */ - - protected Statement withBeforeClasses(Statement statement) { - return statement; - } - - /** - * Check if the data for the given method is loaded or not. - * - * @param methodName the name of the method whose data needs to be checked. - * @return true if there exists data for the given method, else false. - */ - protected boolean isMethodDataLoaded(String methodName) { - - boolean result = false; - if (DataContext.getData() == null || DataContext.getData().keySet() == null - || DataContext.getData().keySet().isEmpty()) { - result = false; - } else { - Iterator keyIterator = DataContext.getData().keySet().iterator(); - while (keyIterator.hasNext()) { - result = methodName.equals(keyIterator.next()) ? true : false; - if (result) { - break; - } - } - } - - return result; - } - - /** - * Load the Data for the given class or method. This method will try to find {@link DataLoader} on either the class - * level or the method level. In case the annotation is found, this method will load the data using the specified - * loader class and then save it in the DataContext for further use by the system. We also create another copy of - * the input test data that we store in the {@link SpringTestRunner#writableData} field. This is done in order to - * facilitate the writing of the data that might be returned by the test method. - * - * @param testClass the class object, if any. - * @param method current executing method, if any. - * @param currentTestClass the currently executing test class. this is used to append in front of the method name to - * get unique method names as there could be methods in different classes with the same name and thus we - * want to avoid conflicts. - */ - - protected void loadData(Class testClass, FrameworkMethod method, Class currentTestClass) { - if (testClass == null && method == null) { - Assert - .fail("The framework should provide either the testClass parameter or the method parameter in order to load the test data."); - } - // We give priority to Class Loading and then to method loading - DataLoader testData = null; - if (testClass != null) { - testData = testClass.getAnnotation(DataLoader.class); - } else { - testData = method.getAnnotation(DataLoader.class); - } - if (testData != null) { - TestInfo testInfo = determineLoader(testData, getTestClass()); - Loader dataLoader = testInfo.getDataLoader(); - if (testInfo.getDataLoader() == null) { - Assert.fail("The framework currently does not support the specified Loader type. " - + "You can provide the custom Loader by choosing LoaderType.CUSTOM in TestData " - + "annotation and providing your custom loader using DataLoader annotation."); - } else { - ResourceLoader resourceLoader = new ResourceLoaderStrategy(getTestClass().getJavaClass()); - for (String filePath : testInfo.getFilePaths()) { - Resource resource = resourceLoader.getResource(filePath); - try { - if (resource.exists()) { - Map>> data = dataLoader.loadData(resource); - // We also maintain the copy of the actual data for our write functionality. - writableData.putAll(data); - DataContext.setData(DataConverter.appendClassName(data, currentTestClass)); - DataContext.setConvertedData(DataConverter.convert(data, currentTestClass)); - } - } catch (Exception e) { - PARAM_LOG.error("Error occured while trying to find the resource with path {} ", - resource.getResourceName(), e); - throw new RuntimeException(e); - } - } - - } - } - } - - /** - * Returns a {@link Statement}: We override this method as it was being called twice for the same class. Looks like - * a bug in JUnit. - */ - - protected Statement withAfterClasses(Statement statement) { - return statement; - } - - /** - * Method that determines the right Loader and the right Data Files for the "write output data" functionality - * supported by the EasyTest Framework. - * - * @param testData an instance of {@link DataLoader} that helps in identifying the right {@link Loader} to write the - * data back to the file. - * @param testClass the class that the {@link TestInfo} object will be associated with - * - * @return {@link TestInfo} an instance of {@link TestInfo} containing information about the currently executing - * test. - */ - private TestInfo determineLoader(DataLoader testData, TestClass testClass) { - TestInfo result = new TestInfo(testClass); - String[] dataFiles = testData.filePaths(); - LoaderType loaderType = testData.loaderType(); - // Loader - Loader dataLoader = null; - if (LoaderType.CUSTOM.equals(loaderType)) { - PARAM_LOG.info("User specified to use custom Loader. Trying to get the custom loader."); - if (testData.loader() == null) { - Assert.fail("Specified the LoaderType as CUSTOM but did not specify loader" - + " attribute. A loaderType of CUSTOM requires the loader " + "attribute specifying " - + "the Custom Loader Class which implements Loader interface."); - } else { - try { - Class loaderClass = testData.loader(); - dataLoader = loaderClass.newInstance(); - } catch (Exception e) { - throw new RuntimeException("Exception occured while trying to instantiate a class of type :" - + testData.loader(), e); - } - } - } else if (dataFiles.length == 0) { - // No files specified, implies user wants to load data with - // custom loader - if (testData.loader() == null) { - Assert.fail("Specified the LoaderType as CUSTOM but did not specify loader" - + " attribute. A loaderType of CUSTOM requires the loader " + "attribute specifying " - + "the Custom Loader Class which implements Loader interface."); - } else { - try { - Class loaderClass = testData.loader(); - dataLoader = loaderClass.newInstance(); - } catch (Exception e) { - throw new RuntimeException("Exception occured while trying to instantiate a class of type :" - + testData.loader(), e); - } - } - } else { - // user has specified data files and the data fileType is also - // not custom. - dataLoader = LoaderFactory.getLoader(loaderType); - } - result.setDataLoader(dataLoader); - result.setFilePaths(dataFiles); - return result; } } diff --git a/src/test/java/org/easetech/easytest/example/TestExcelDataLoader.java b/src/test/java/org/easetech/easytest/example/TestExcelDataLoader.java index 46350b7..c33ceec 100644 --- a/src/test/java/org/easetech/easytest/example/TestExcelDataLoader.java +++ b/src/test/java/org/easetech/easytest/example/TestExcelDataLoader.java @@ -17,7 +17,7 @@ public class TestExcelDataLoader { @Intercept - static RealItemService itemService = new RealItemService(); + static ItemService itemService = new RealItemService(); /** * An instance of logger associated with the test framework. From 1ad1aa6c8f85dbbb4935b7b230f0561b9584903e Mon Sep 17 00:00:00 2001 From: Anuj kumar Date: Thu, 10 Jan 2013 11:23:17 +0100 Subject: [PATCH 09/11] Simplified DataLoader annotation. Its no longer required to provide the loaderType attribute to the DataLoader annotation Signed-off-by: Anuj kumar --- .../easytest/example/TestCombinedLoadingAndWriting.java | 4 ++-- .../example/TestConditionsSupportedByDataDrivenTest.java | 2 +- .../easetech/easytest/example/TestExcelDataLoader.java | 4 ++-- .../org/easetech/easytest/example/TestXMLDataLoader.java | 8 +++----- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/test/java/org/easetech/easytest/example/TestCombinedLoadingAndWriting.java b/src/test/java/org/easetech/easytest/example/TestCombinedLoadingAndWriting.java index 95d5464..18ddb01 100644 --- a/src/test/java/org/easetech/easytest/example/TestCombinedLoadingAndWriting.java +++ b/src/test/java/org/easetech/easytest/example/TestCombinedLoadingAndWriting.java @@ -10,7 +10,7 @@ public class TestCombinedLoadingAndWriting { @Test - @DataLoader(filePaths = { "classpath:input-data-mod-again.xml" }, loaderType = LoaderType.XML) + @DataLoader(filePaths = { "classpath:input-data-mod-again.xml" }) public Item getItemsDataFromXMLLoaderModified(@Param(name = "libraryId") String libraryId, @Param(name = "itemId") String itemId, @Param(name = "itemType") @@ -27,7 +27,7 @@ public Item getItemsDataFromXMLLoaderModified(@Param(name = "libraryId") } @Test - @DataLoader(filePaths = { "classpath:org/easetech/data/test-combined.xls" }, loaderType = LoaderType.EXCEL) + @DataLoader(filePaths = { "classpath:org/easetech/data/test-combined.xls" }) public Item getExcelTestDataWithReturnType(@Param(name = "libraryId") Float libraryId, @Param(name = "itemId") Float itemId) { diff --git a/src/test/java/org/easetech/easytest/example/TestConditionsSupportedByDataDrivenTest.java b/src/test/java/org/easetech/easytest/example/TestConditionsSupportedByDataDrivenTest.java index 57404f7..25f5d12 100644 --- a/src/test/java/org/easetech/easytest/example/TestConditionsSupportedByDataDrivenTest.java +++ b/src/test/java/org/easetech/easytest/example/TestConditionsSupportedByDataDrivenTest.java @@ -30,7 +30,7 @@ * */ @RunWith(DataDrivenTestRunner.class) -@DataLoader(filePaths = { "classpath:getDDTData.csv" }, loaderType = LoaderType.CSV) +@DataLoader(filePaths = { "classpath:getDDTData.csv" }) public class TestConditionsSupportedByDataDrivenTest { @Test diff --git a/src/test/java/org/easetech/easytest/example/TestExcelDataLoader.java b/src/test/java/org/easetech/easytest/example/TestExcelDataLoader.java index c33ceec..267175d 100644 --- a/src/test/java/org/easetech/easytest/example/TestExcelDataLoader.java +++ b/src/test/java/org/easetech/easytest/example/TestExcelDataLoader.java @@ -13,7 +13,7 @@ @RunWith(DataDrivenTestRunner.class) -@DataLoader(filePaths = { "classpath:org/easetech/data/testExcelData.xls" }, loaderType = LoaderType.EXCEL) +@DataLoader(filePaths = { "classpath:org/easetech/data/testExcelData.xls" }) public class TestExcelDataLoader { @Intercept @@ -66,7 +66,7 @@ public void getExcelTestDataNumberFormat() { } @Test - @DataLoader(filePaths = { "classpath:org/easetech/data/test-update.xls" }, loaderType = LoaderType.EXCEL) + @DataLoader(filePaths = { "classpath:org/easetech/data/test-update.xls" }) public Item getExcelTestDataWithReturnType(@Param(name = "libraryId") Float libraryId, @Param(name = "itemId") Float itemId) { diff --git a/src/test/java/org/easetech/easytest/example/TestXMLDataLoader.java b/src/test/java/org/easetech/easytest/example/TestXMLDataLoader.java index 1c30362..1f68a4b 100644 --- a/src/test/java/org/easetech/easytest/example/TestXMLDataLoader.java +++ b/src/test/java/org/easetech/easytest/example/TestXMLDataLoader.java @@ -1,16 +1,14 @@ package org.easetech.easytest.example; -import org.easetech.easytest.annotation.Report; - import org.easetech.easytest.annotation.DataLoader; import org.easetech.easytest.annotation.Param; -import org.easetech.easytest.loader.LoaderType; +import org.easetech.easytest.annotation.Report; import org.junit.Test; import org.junit.runner.RunWith; @RunWith(org.easetech.easytest.runner.DataDrivenTestRunner.class) -@DataLoader(filePaths = { "classpath:input-data.xml" }, loaderType = LoaderType.XML) +@DataLoader(filePaths = { "input-data.xml" }) @Report public class TestXMLDataLoader { @@ -33,7 +31,7 @@ public Item getItemsDataFromXMLLoader(@Param(name = "libraryId") } @Test - @DataLoader(filePaths = { "classpath:input-data-mod.xml" }, loaderType = LoaderType.XML) + @DataLoader(filePaths = { "classpath:input-data-mod.xml" }) public Item getItemsDataFromXMLLoaderModified(@Param(name = "libraryId") String libraryId, @Param(name = "itemId") String itemId, @Param(name = "itemType") From 1e057f6fcc66ec852cbd77f0dcf0959f4de83265 Mon Sep 17 00:00:00 2001 From: Anuj kumar Date: Thu, 10 Jan 2013 13:41:40 +0100 Subject: [PATCH 10/11] Minor update due to refactoring. --- .../java/org/easetech/easytest/runner/SpringTestRunner.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main/java/org/easetech/easytest/runner/SpringTestRunner.java b/src/main/java/org/easetech/easytest/runner/SpringTestRunner.java index 14945f8..b055e32 100644 --- a/src/main/java/org/easetech/easytest/runner/SpringTestRunner.java +++ b/src/main/java/org/easetech/easytest/runner/SpringTestRunner.java @@ -3,14 +3,11 @@ import java.lang.reflect.Field; import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.Map; import org.easetech.easytest.annotation.DataLoader; import org.easetech.easytest.annotation.Intercept; import org.easetech.easytest.annotation.Param; -import org.easetech.easytest.config.ConfigLoader; import org.easetech.easytest.interceptor.InternalSpringInterceptor; import org.easetech.easytest.interceptor.MethodIntercepter; import org.easetech.easytest.loader.DataConverter; @@ -23,7 +20,6 @@ import org.junit.AfterClass; import org.junit.Assert; import org.junit.Test; -import org.junit.runner.Runner; import org.junit.runners.BlockJUnit4ClassRunner; import org.junit.runners.Suite; import org.junit.runners.model.FrameworkMethod; @@ -181,7 +177,7 @@ public EasyTestRunner(Class klass) throws InitializationError { testReportContainer = new ReportDataContainer(getTestClass().getJavaClass()); testInstance = getTestClass().getOnlyConstructor().newInstance(); getTestContextManager().prepareTestInstance(testInstance); - ConfigLoader.loadTestConfigurations(getTestClass().getJavaClass(), testInstance); + TestConfigUtil.loadTestConfigurations(getTestClass().getJavaClass(), testInstance); instrumentClass(getTestClass().getJavaClass()); } catch (Exception e) { From 66135bff7e4512539c198e8ccccedd3b266d0b37 Mon Sep 17 00:00:00 2001 From: Anuj kumar Date: Fri, 11 Jan 2013 12:12:34 +0100 Subject: [PATCH 11/11] removed name attribute from Param annotation --- .../TestCombinedLoadingAndWriting.java | 12 +-- ...stConditionsSupportedByDataDrivenTest.java | 12 +-- ...stDifferentConditionsSupportedByParam.java | 74 +++++++++---------- .../easytest/example/TestExcelDataLoader.java | 16 ++-- .../easytest/example/TestXMLDataLoader.java | 16 ++-- 5 files changed, 65 insertions(+), 65 deletions(-) diff --git a/src/test/java/org/easetech/easytest/example/TestCombinedLoadingAndWriting.java b/src/test/java/org/easetech/easytest/example/TestCombinedLoadingAndWriting.java index 18ddb01..0a47750 100644 --- a/src/test/java/org/easetech/easytest/example/TestCombinedLoadingAndWriting.java +++ b/src/test/java/org/easetech/easytest/example/TestCombinedLoadingAndWriting.java @@ -11,10 +11,10 @@ public class TestCombinedLoadingAndWriting { @Test @DataLoader(filePaths = { "classpath:input-data-mod-again.xml" }) - public Item getItemsDataFromXMLLoaderModified(@Param(name = "libraryId") - String libraryId, @Param(name = "itemId") - String itemId, @Param(name = "itemType") - String itemType, @Param(name = "expectedItems") + public Item getItemsDataFromXMLLoaderModified(@Param("libraryId") + String libraryId, @Param("itemId") + String itemId, @Param("itemType") + String itemType, @Param("expectedItems") String expectedItems) { System.out.print("Executing TestCombinedLoadingAndWriting#getItemsDataFromXMLLoaderModified :"); System.out.println("LibraryId :" + libraryId + " itemId : " + itemId + " itemType :" + itemType @@ -28,8 +28,8 @@ public Item getItemsDataFromXMLLoaderModified(@Param(name = "libraryId") @Test @DataLoader(filePaths = { "classpath:org/easetech/data/test-combined.xls" }) - public Item getExcelTestDataWithReturnType(@Param(name = "libraryId") - Float libraryId, @Param(name = "itemId") + public Item getExcelTestDataWithReturnType(@Param("libraryId") + Float libraryId, @Param("itemId") Float itemId) { System.out.print("Executing TestCombinedLoadingAndWriting#getExcelTestDataWithReturnType : "); ItemService itemService = new RealItemService(); diff --git a/src/test/java/org/easetech/easytest/example/TestConditionsSupportedByDataDrivenTest.java b/src/test/java/org/easetech/easytest/example/TestConditionsSupportedByDataDrivenTest.java index 25f5d12..1e864e8 100644 --- a/src/test/java/org/easetech/easytest/example/TestConditionsSupportedByDataDrivenTest.java +++ b/src/test/java/org/easetech/easytest/example/TestConditionsSupportedByDataDrivenTest.java @@ -34,7 +34,7 @@ public class TestConditionsSupportedByDataDrivenTest { @Test - public void testBug(@Param(name="className") String name, @Param(name="dateDebut")Date dateDebut , @Param(name="dateFin")Date dateFin){ + public void testBug(@Param("className") String name, @Param("dateDebut")Date dateDebut , @Param("dateFin")Date dateFin){ System.out.println("Class Name :" + name + " DateDebut : " + dateDebut + " dateFin :" + dateFin); } @@ -107,7 +107,7 @@ public void testDDTGetItemsWithCustomLoader( * @param item an instance of Item object that is automatically converted from a map to an Item instance. */ @Test - public void testDDTConverter(@Param(name="items")LinkedList items) { + public void testDDTConverter(@Param("items")LinkedList items) { System.out.print("Executing testDDTConverter :"); for(ItemId itemId : items){ System.out.println("Item Id is:" + itemId); @@ -118,7 +118,7 @@ public void testDDTConverter(@Param(name="items")LinkedList items) { } // @Test -// public void testDDTConverter(@Param(name="items")HashSet items) { +// public void testDDTConverter(@Param("items")HashSet items) { // System.out.print("Executing testDDTConverter :"); // for(ItemId itemId : items){ // System.out.println("Item Id is:" + itemId); @@ -129,7 +129,7 @@ public void testDDTConverter(@Param(name="items")LinkedList items) { // } // // @Test -// public void testDDTConverter(@Param(name="items")Queue items) { +// public void testDDTConverter(@Param("items")Queue items) { // System.out.print("Executing testDDTConverter :"); // for(ItemId itemId : items){ // System.out.println("Item Id is:" + itemId); @@ -140,7 +140,7 @@ public void testDDTConverter(@Param(name="items")LinkedList items) { // } // // @Test -// public void testDDTConverter(@Param(name="items")Set items) { +// public void testDDTConverter(@Param("items")Set items) { // System.out.print("Executing testDDTConverter :"); // for(ItemId itemId : items){ // System.out.println("Item Id is:" + itemId); @@ -151,7 +151,7 @@ public void testDDTConverter(@Param(name="items")LinkedList items) { // } // @Test -// public void testDDTConverter(@Param(name="items")List items) { +// public void testDDTConverter(@Param("items")List items) { // System.out.print("Executing testDDTConverter :"); // for(ItemId itemId : items){ // System.out.println("Item Id is:" + itemId); diff --git a/src/test/java/org/easetech/easytest/example/TestDifferentConditionsSupportedByParam.java b/src/test/java/org/easetech/easytest/example/TestDifferentConditionsSupportedByParam.java index 6901d19..2b5b016 100644 --- a/src/test/java/org/easetech/easytest/example/TestDifferentConditionsSupportedByParam.java +++ b/src/test/java/org/easetech/easytest/example/TestDifferentConditionsSupportedByParam.java @@ -56,7 +56,7 @@ public static void before(){ } @Test - public void testNonGenericListInterface(@Param(name="items") List items){ + public void testNonGenericListInterface(@Param("items") List items){ Assert.notNull(items); for(Object item : items){ System.out.println("testNonGenericListInterface : "+item); @@ -64,7 +64,7 @@ public void testNonGenericListInterface(@Param(name="items") List items){ } @Test - public void testGenericListInterface(@Param(name="items") List items){ + public void testGenericListInterface(@Param("items") List items){ Assert.notNull(items); for(ItemId item : items){ System.out.println("testGenericListInterface : "+item); @@ -72,7 +72,7 @@ public void testGenericListInterface(@Param(name="items") List items){ } @Test - public void testGenericListImplementation(@Param(name="items") LinkedList items){ + public void testGenericListImplementation(@Param("items") LinkedList items){ Assert.notNull(items); for(ItemId item : items){ System.out.println("testGenericListImplementation : "+item); @@ -80,7 +80,7 @@ public void testGenericListImplementation(@Param(name="items") LinkedList items){ + public void testGenericSetInterface(@Param("dates") Set items){ Assert.notNull(items); for(Date date : items){ System.out.println("testNonGenericListImplementation : "+date); @@ -96,7 +96,7 @@ public void testGenericSetInterface(@Param(name="dates") Set items){ } @Test - public void testNonGenericSetInterface(@Param(name="items") Set items){ + public void testNonGenericSetInterface(@Param("items") Set items){ Assert.notNull(items); for(Object item : items){ System.out.println("testNonGenericListImplementation : "+item); @@ -104,7 +104,7 @@ public void testNonGenericSetInterface(@Param(name="items") Set items){ } @Test - public void testNonGenericSetImplementation(@Param(name="items") TreeSet items){ + public void testNonGenericSetImplementation(@Param("items") TreeSet items){ Assert.notNull(items); for(Object item : items){ System.out.println("testNonGenericListImplementation : "+item); @@ -112,7 +112,7 @@ public void testNonGenericSetImplementation(@Param(name="items") TreeSet items){ } @Test - public void testGenericSetImplementation(@Param(name="items") SortedSet items){ + public void testGenericSetImplementation(@Param("items") SortedSet items){ Assert.notNull(items); for(Long item : items){ System.out.println("testNonGenericListImplementation : "+item); @@ -120,7 +120,7 @@ public void testGenericSetImplementation(@Param(name="items") SortedSet it } @Test - public void testGenericQueueInterface(@Param(name="items") Queue items){ + public void testGenericQueueInterface(@Param("items") Queue items){ Assert.notNull(items); for(ItemId item : items){ System.out.println("testNonGenericListImplementation : "+item); @@ -128,7 +128,7 @@ public void testGenericQueueInterface(@Param(name="items") Queue items){ } @Test - public void testNonGenericQueueInterface(@Param(name="items") Queue items){ + public void testNonGenericQueueInterface(@Param("items") Queue items){ Assert.notNull(items); for(Object item : items){ System.out.println("testNonGenericListImplementation : "+item); @@ -136,7 +136,7 @@ public void testNonGenericQueueInterface(@Param(name="items") Queue items){ } // @Test -// public void testNonGenericQueueImplementation(@Param(name="items") BlockingDeque items){ +// public void testNonGenericQueueImplementation(@Param("items") BlockingDeque items){ // Assert.notNull(items); // for(Object item : items){ // System.out.println("testNonGenericListImplementation : "+item); @@ -144,7 +144,7 @@ public void testNonGenericQueueInterface(@Param(name="items") Queue items){ // } @Test - public void testNonGenericBlockingQueueImplementation(@Param(name="items") BlockingQueue items){ + public void testNonGenericBlockingQueueImplementation(@Param("items") BlockingQueue items){ Assert.notNull(items); for(Object item : items){ System.out.println("testNonGenericListImplementation : "+item); @@ -152,7 +152,7 @@ public void testNonGenericBlockingQueueImplementation(@Param(name="items") Block } // @Test -// public void testNonGenericDequeImplementation(@Param(name="items") Deque items){ +// public void testNonGenericDequeImplementation(@Param("items") Deque items){ // Assert.notNull(items); // for(Object item : items){ // System.out.println("testNonGenericListImplementation : "+item); @@ -160,7 +160,7 @@ public void testNonGenericBlockingQueueImplementation(@Param(name="items") Block // } @Test - public void testGenericQueueImplementation(@Param(name="items") Collection items){ + public void testGenericQueueImplementation(@Param("items") Collection items){ Assert.notNull(items); for(ItemId item : items){ System.out.println("testNonGenericListImplementation : "+item); @@ -168,7 +168,7 @@ public void testGenericQueueImplementation(@Param(name="items") Collection items){ + public void testAbstractCollection(@Param("items") AbstractCollection items){ Assert.notNull(items); for(ItemId item : items){ System.out.println("testNonGenericListImplementation : "+item); @@ -176,7 +176,7 @@ public void testAbstractCollection(@Param(name="items") AbstractCollection items){ + public void testAbstractList(@Param("items") AbstractList items){ Assert.notNull(items); for(ItemId item : items){ System.out.println("testNonGenericListImplementation : "+item); @@ -184,7 +184,7 @@ public void testAbstractList(@Param(name="items") AbstractList items){ } @Test - public void testAbstractQueue(@Param(name="items") AbstractQueue items){ + public void testAbstractQueue(@Param("items") AbstractQueue items){ Assert.notNull(items); for(ItemId item : items){ System.out.println("testNonGenericListImplementation : "+item); @@ -192,7 +192,7 @@ public void testAbstractQueue(@Param(name="items") AbstractQueue items){ } @Test - public void testAbstractSequentialList(@Param(name="items") AbstractSequentialList items){ + public void testAbstractSequentialList(@Param("items") AbstractSequentialList items){ Assert.notNull(items); for(ItemId item : items){ System.out.println("testNonGenericListImplementation : "+item); @@ -200,7 +200,7 @@ public void testAbstractSequentialList(@Param(name="items") AbstractSequentialLi } @Test - public void testAbstractSet(@Param(name="items") AbstractSet items){ + public void testAbstractSet(@Param("items") AbstractSet items){ Assert.notNull(items); for(ComparableObject item : items){ System.out.println("testNonGenericListImplementation : "+item); @@ -208,7 +208,7 @@ public void testAbstractSet(@Param(name="items") AbstractSet i } @Test - public void testArrayBlockingQueue(@Param(name="items") ArrayBlockingQueue items){ + public void testArrayBlockingQueue(@Param("items") ArrayBlockingQueue items){ Assert.notNull(items); for(Float item : items){ System.out.println("testNonGenericListImplementation : "+item); @@ -216,7 +216,7 @@ public void testArrayBlockingQueue(@Param(name="items") ArrayBlockingQueue items){ + public void testArrayDeque(@Param("items") ArrayDeque items){ Assert.notNull(items); for(ItemId item : items){ System.out.println("testNonGenericListImplementation : "+item); @@ -224,7 +224,7 @@ public void testArrayDeque(@Param(name="items") ArrayDeque items){ } @Test - public void testArrayList(@Param(name="items") ArrayList items){ + public void testArrayList(@Param("items") ArrayList items){ Assert.notNull(items); for(ItemId item : items){ System.out.println("testNonGenericListImplementation : "+item); @@ -232,7 +232,7 @@ public void testArrayList(@Param(name="items") ArrayList items){ } @Test - public void testAttributeList(@Param(name="items") AttributeList items){ + public void testAttributeList(@Param("items") AttributeList items){ Assert.notNull(items); for(Object item : items){ System.out.println("testNonGenericListImplementation : "+item); @@ -240,7 +240,7 @@ public void testAttributeList(@Param(name="items") AttributeList items){ } @Test - public void testConcurrentLinkedQueue(@Param(name="items") ConcurrentLinkedQueue items){ + public void testConcurrentLinkedQueue(@Param("items") ConcurrentLinkedQueue items){ Assert.notNull(items); for(ItemId item : items){ System.out.println("testNonGenericListImplementation : "+item); @@ -248,7 +248,7 @@ public void testConcurrentLinkedQueue(@Param(name="items") ConcurrentLinkedQueue } @Test - public void testConcurrentSkipListSet(@Param(name="items") ConcurrentSkipListSet items){ + public void testConcurrentSkipListSet(@Param("items") ConcurrentSkipListSet items){ Assert.notNull(items); for(ComparableObject item : items){ System.out.println("testNonGenericListImplementation : "+item); @@ -256,7 +256,7 @@ public void testConcurrentSkipListSet(@Param(name="items") ConcurrentSkipListSet } @Test - public void testCopyOnWriteArrayList(@Param(name="items") CopyOnWriteArrayList items){ + public void testCopyOnWriteArrayList(@Param("items") CopyOnWriteArrayList items){ Assert.notNull(items); for(ItemId item : items){ System.out.println("testNonGenericListImplementation : "+item); @@ -264,14 +264,14 @@ public void testCopyOnWriteArrayList(@Param(name="items") CopyOnWriteArrayList items){ + public void testCopyOnWriteArraySet(@Param("items") CopyOnWriteArraySet items){ Assert.notNull(items); for(ItemId item : items){ System.out.println("testNonGenericListImplementation : "+item); } } @Test - public void testEnumSet(@Param(name="items") EnumSet items){ + public void testEnumSet(@Param("items") EnumSet items){ Assert.notNull(items); for(Object item : items){ @@ -280,7 +280,7 @@ public void testEnumSet(@Param(name="items") EnumSet items){ } // @Test -// public void testLinkedBlockingDeque(@Param(name="items") LinkedBlockingDeque items){ +// public void testLinkedBlockingDeque(@Param("items") LinkedBlockingDeque items){ // Assert.notNull(items); // for(ItemId item : items){ // System.out.println("testNonGenericListImplementation : "+item); @@ -288,7 +288,7 @@ public void testEnumSet(@Param(name="items") EnumSet items){ // } @Test - public void testLinkedBlockingQueue(@Param(name="items") LinkedBlockingQueue items){ + public void testLinkedBlockingQueue(@Param("items") LinkedBlockingQueue items){ Assert.notNull(items); for(ItemId item : items){ System.out.println("testNonGenericListImplementation : "+item); @@ -296,7 +296,7 @@ public void testLinkedBlockingQueue(@Param(name="items") LinkedBlockingQueue items){ + public void testLinkedHashSet(@Param("items") LinkedHashSet items){ Assert.notNull(items); for(ItemId item : items){ System.out.println("testNonGenericListImplementation : "+item); @@ -304,7 +304,7 @@ public void testLinkedHashSet(@Param(name="items") LinkedHashSet items){ } @Test - public void testPriorityBlockingQueue(@Param(name="items") PriorityBlockingQueue items){ + public void testPriorityBlockingQueue(@Param("items") PriorityBlockingQueue items){ Assert.notNull(items); for(ComparableObject item : items){ System.out.println("testNonGenericListImplementation : "+item); @@ -312,7 +312,7 @@ public void testPriorityBlockingQueue(@Param(name="items") PriorityBlockingQueue } @Test - public void testPriorityQueue(@Param(name="items") PriorityQueue items){ + public void testPriorityQueue(@Param("items") PriorityQueue items){ Assert.notNull(items); for(ComparableObject item : items){ System.out.println("testNonGenericListImplementation : "+item); @@ -320,7 +320,7 @@ public void testPriorityQueue(@Param(name="items") PriorityQueue items){ + public void testStack(@Param("items") Stack items){ Assert.notNull(items); for(ItemId item : items){ System.out.println("testNonGenericListImplementation : "+item); @@ -345,7 +345,7 @@ public void testStack(@Param(name="items") Stack items){ @Test - public void testVector(@Param(name="items") Vector items){ + public void testVector(@Param("items") Vector items){ Assert.notNull(items); for(ItemId item : items){ System.out.println("testNonGenericListImplementation : "+item); diff --git a/src/test/java/org/easetech/easytest/example/TestExcelDataLoader.java b/src/test/java/org/easetech/easytest/example/TestExcelDataLoader.java index 267175d..dad4785 100644 --- a/src/test/java/org/easetech/easytest/example/TestExcelDataLoader.java +++ b/src/test/java/org/easetech/easytest/example/TestExcelDataLoader.java @@ -27,8 +27,8 @@ public class TestExcelDataLoader { @Test - public void getExcelTestData(@Param(name = "libraryId") - Float libraryId, @Param(name = "itemId") + public void getExcelTestData(@Param( "libraryId") + Float libraryId, @Param( "itemId") Float itemId) { System.out.print("Executing getExcelTestData :"); System.out.println("LibraryId is :" + libraryId + " and Item Id is :" + itemId); @@ -36,8 +36,8 @@ public void getExcelTestData(@Param(name = "libraryId") @Test @DataLoader(filePaths={"classpath:overrideExcelData.csv"} , loaderType=LoaderType.CSV) - public Item getExcelTestDataWithDouble(@Param(name = "libraryId") - Double libraryId, @Param(name = "itemId") + public Item getExcelTestDataWithDouble(@Param( "libraryId") + Double libraryId, @Param( "itemId") Double itemId) { System.out.print("Executing getExcelTestDataWithDouble :"); // if(itemId.equals(11568.0D)){ @@ -51,8 +51,8 @@ public Item getExcelTestDataWithDouble(@Param(name = "libraryId") } @Test - public void getExcelTestDataWithString(@Param(name = "libraryId") - String libraryId, @Param(name = "itemId") + public void getExcelTestDataWithString(@Param( "libraryId") + String libraryId, @Param( "itemId") String itemId) { System.out.print("Executing getExcelTestDataWithString :"); System.out.println("LibraryId is :" + libraryId + " and Item Id is :" + itemId); @@ -67,8 +67,8 @@ public void getExcelTestDataNumberFormat() { @Test @DataLoader(filePaths = { "classpath:org/easetech/data/test-update.xls" }) - public Item getExcelTestDataWithReturnType(@Param(name = "libraryId") - Float libraryId, @Param(name = "itemId") + public Item getExcelTestDataWithReturnType(@Param( "libraryId") + Float libraryId, @Param( "itemId") Float itemId) { System.out.println("Executing getExcelTestDataWithReturnType : "); LOG.debug("LibraryId is :" + libraryId + " and Item Id is :" + itemId); diff --git a/src/test/java/org/easetech/easytest/example/TestXMLDataLoader.java b/src/test/java/org/easetech/easytest/example/TestXMLDataLoader.java index 1f68a4b..966c90a 100644 --- a/src/test/java/org/easetech/easytest/example/TestXMLDataLoader.java +++ b/src/test/java/org/easetech/easytest/example/TestXMLDataLoader.java @@ -15,10 +15,10 @@ public class TestXMLDataLoader { @Test - public Item getItemsDataFromXMLLoader(@Param(name = "libraryId") - String libraryId, @Param(name = "itemId") - String itemId, @Param(name = "itemType") - String itemType, @Param(name = "expectedItems") + public Item getItemsDataFromXMLLoader(@Param( "libraryId") + String libraryId, @Param( "itemId") + String itemId, @Param( "itemType") + String itemType, @Param( "expectedItems") String expectedItems) { System.out.print("Executing getItemsDataFromXMLLoader :"); System.out.println("LibraryId :" + libraryId + " itemId : " + itemId + " itemType :" + itemType @@ -32,10 +32,10 @@ public Item getItemsDataFromXMLLoader(@Param(name = "libraryId") @Test @DataLoader(filePaths = { "classpath:input-data-mod.xml" }) - public Item getItemsDataFromXMLLoaderModified(@Param(name = "libraryId") - String libraryId, @Param(name = "itemId") - String itemId, @Param(name = "itemType") - String itemType, @Param(name = "expectedItems") + public Item getItemsDataFromXMLLoaderModified(@Param( "libraryId") + String libraryId, @Param( "itemId") + String itemId, @Param( "itemType") + String itemType, @Param( "expectedItems") String expectedItems) { System.out.print("Executing getItemsDataFromXMLLoaderModified :"); System.out.println("LibraryId :" + libraryId + " itemId : " + itemId + " itemType :" + itemType