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 diff --git a/pom.xml b/pom.xml index 08afa16..d7294a1 100644 --- a/pom.xml +++ b/pom.xml @@ -1,220 +1,183 @@ - + - - 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 + 1.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-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 - - - - 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.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + true + 1.5 + 1.5 + + + + 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 - - - - commons-logging - commons-logging - - - - - - - + + org.springframework + spring-aop + 3.0.6.RELEASE + + + log4j + log4j + + + junit + junit + + + commons-logging + commons-logging + + + + 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/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/runner/SpringTestRunner.java b/src/main/java/org/easetech/easytest/runner/SpringTestRunner.java index dd6c7dc..b055e32 100644 --- a/src/main/java/org/easetech/easytest/runner/SpringTestRunner.java +++ b/src/main/java/org/easetech/easytest/runner/SpringTestRunner.java @@ -2,42 +2,30 @@ package org.easetech.easytest.runner; import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -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.internal.EasyAssignments; +import org.easetech.easytest.interceptor.InternalSpringInterceptor; +import org.easetech.easytest.interceptor.MethodIntercepter; 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.loader.DataLoaderUtil; 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; 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; @@ -45,9 +33,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: *