Skip to content

Commit

Permalink
HV-418: Simplified AP tests, they can now be started without any syst…
Browse files Browse the repository at this point in the history
…em properties.
  • Loading branch information
gunnarmorling authored and hferentschik committed Jan 25, 2011
1 parent aa033ac commit aae68e5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 74 deletions.
46 changes: 0 additions & 46 deletions hibernate-validator-annotation-processor/pom.xml
Expand Up @@ -19,52 +19,6 @@
<compilerArgument>-proc:none</compilerArgument>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>generate-test-sources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<stripVersion>true</stripVersion>
<artifactItems>
<artifactItem>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemProperties>
<property>
<name>testSourceBaseDir</name>
<value>${basedir}/src/test/java</value>
</property>
<!--
Used to specify the class path for the JavaCompiler in tests. For some reason
this is not required within eclipse. The JavaCompiler there has access to all dependencies
of the program by default.
TODO GM: find a better way to solve this issue
-->
<property>
<name>pathToBeanValidationApiJar</name>
<value>${project.build.directory}/lib/validation-api.jar</value>
</property>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
Expand Down
Expand Up @@ -20,12 +20,10 @@
import javax.tools.JavaFileObject;
import javax.tools.ToolProvider;

import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;

import org.hibernate.validator.ap.testutil.CompilerTestHelper;

import static org.testng.Assert.assertNotNull;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;

/**
* Base class providing common functionality for all tests for the constraint validation processor using the Java compiler
Expand All @@ -42,22 +40,8 @@ public abstract class ConstraintValidationProcessorTestBase {
@BeforeClass
public static void setUpCompilerHelper() {

String testSourceBaseDir = System.getProperty( "testSourceBaseDir" );
String pathToBeanValidationApiJar = System.getProperty( "pathToBeanValidationApiJar" );

assertNotNull(
testSourceBaseDir,
"The system property testSourceBaseDir has to be set and point to the base directory of the test java sources."
);
assertNotNull(
pathToBeanValidationApiJar,
"The system property pathToBeanValidationApiJar has to be set and point to the BV API Jars."
);

compilerHelper =
new CompilerTestHelper(
ToolProvider.getSystemJavaCompiler(), testSourceBaseDir, pathToBeanValidationApiJar
);
new CompilerTestHelper( ToolProvider.getSystemJavaCompiler() );
}

@BeforeMethod
Expand Down
Expand Up @@ -16,10 +16,15 @@
*/
package org.hibernate.validator.ap.testutil;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.annotation.processing.Processor;
import javax.tools.Diagnostic;
import javax.tools.Diagnostic.Kind;
Expand All @@ -31,9 +36,6 @@

import org.hibernate.validator.ap.util.DiagnosticExpectation;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;

/**
* Infrastructure for unit tests based on the Java Compiler API.
*
Expand All @@ -45,13 +47,20 @@ public class CompilerTestHelper {

private final String sourceBaseDir;

private final String pathToBeanValidationApiJar;

public CompilerTestHelper(JavaCompiler compiler, String sourceBaseDir, String pathToBeanValidationApiJar) {
public CompilerTestHelper(JavaCompiler compiler) {

this.compiler = compiler;
this.sourceBaseDir = sourceBaseDir;
this.pathToBeanValidationApiJar = pathToBeanValidationApiJar;

String basePath;

try {
basePath = new File( "." ).getCanonicalPath();
}
catch ( IOException e ) {
throw new RuntimeException( e );
}

this.sourceBaseDir = basePath + "/src/test/java";
}

/**
Expand Down Expand Up @@ -119,7 +128,7 @@ public boolean compile(

List<String> options = new ArrayList<String>();

options.addAll( Arrays.asList( "-classpath", pathToBeanValidationApiJar, "-d", "target" ) );
options.addAll( Arrays.asList( "-classpath", System.getProperty( "java.class.path" ), "-d", "target" ) );

if ( diagnosticKind != null ) {
options.add( "-AdiagnosticKind=" + diagnosticKind );
Expand Down

0 comments on commit aae68e5

Please sign in to comment.