mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-13 21:01:01 +08:00
added more tests for annotations
This commit is contained in:
parent
5520112542
commit
2b61829dee
@ -3,6 +3,8 @@ package com.mysema.query.apt;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.processing.AbstractProcessor;
|
||||
@ -48,6 +50,7 @@ public abstract class AbstractProcessorTest {
|
||||
options.add(processorClass.getName());
|
||||
options.add("-sourcepath");
|
||||
options.add("src/test/java");
|
||||
options.addAll(getAPTOptions());
|
||||
options.addAll(classes);
|
||||
int compilationResult = compiler.run(null, null, null, options.toArray(new String[options.size()]));
|
||||
if(compilationResult == 0){
|
||||
@ -57,4 +60,8 @@ public abstract class AbstractProcessorTest {
|
||||
}
|
||||
}
|
||||
|
||||
protected Collection<String> getAPTOptions() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,17 @@
|
||||
package com.mysema.query.apt;
|
||||
|
||||
import java.sql.Date;
|
||||
|
||||
import com.mysema.query.annotations.QueryDelegate;
|
||||
import com.mysema.query.types.Predicate;
|
||||
import com.mysema.query.types.expr.DateExpression;
|
||||
import com.mysema.query.types.path.BooleanPath;
|
||||
|
||||
public class DateExtensions {
|
||||
|
||||
@QueryDelegate(Date.class)
|
||||
public static Predicate extension(DateExpression<Date> date){
|
||||
return new BooleanPath("b");
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,55 @@
|
||||
package com.mysema.query.apt;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DateExtensionsTest extends AbstractProcessorTest{
|
||||
|
||||
private static final String packagePath = "src/test/java/com/mysema/query/apt/";
|
||||
|
||||
@Test
|
||||
public void Handles_Date_Extensions_Correctly() throws IOException, InterruptedException{
|
||||
File source = new File(packagePath, "EntityWithExtensions.java");
|
||||
File source2 = new File(packagePath, "DateExtensions.java");
|
||||
List<String> sources = Arrays.asList(source.getPath(), source2.getPath());
|
||||
File qType = new File("target/overwrite3/com/mysema/query/apt/QEntityWithExtensions.java");
|
||||
|
||||
// QEntityWithExtensions is generated
|
||||
process(QuerydslAnnotationProcessor.class, sources, "overwrite3");
|
||||
assertTrue(qType.exists());
|
||||
long modified = qType.lastModified();
|
||||
Thread.sleep(1000);
|
||||
System.out.println(FileUtils.readFileToString(qType).contains("QDate"));
|
||||
|
||||
// EntityWithExtensions has not changed, QEntityWithExtensions is not overwritten
|
||||
compile(QuerydslAnnotationProcessor.class, sources, "overwrite3");
|
||||
assertEquals(modified, qType.lastModified());
|
||||
|
||||
// EntityWithExtensions is updated, QEntityWithExtensions is overwritten
|
||||
FileUtils.touch(source);
|
||||
compile(QuerydslAnnotationProcessor.class, sources, "overwrite3");
|
||||
assertTrue("" + modified + " >= " + qType.lastModified(), modified < qType.lastModified());
|
||||
assertTrue(FileUtils.readFileToString(qType).contains("QDate"));
|
||||
|
||||
// QEntityWithExtensions is deleted and regenerated
|
||||
assertTrue(qType.delete());
|
||||
compile(QuerydslAnnotationProcessor.class, sources, "overwrite3");
|
||||
assertTrue(qType.exists());
|
||||
assertTrue(FileUtils.readFileToString(qType).contains("QDate"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<String> getAPTOptions() {
|
||||
return Arrays.asList("-AdefaultOverwrite=true");
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package com.mysema.query.apt;
|
||||
|
||||
import com.mysema.query.annotations.QueryDelegate;
|
||||
import com.mysema.query.domain.QEntityWithExtensions;
|
||||
import com.mysema.query.types.Predicate;
|
||||
import com.mysema.query.types.path.BooleanPath;
|
||||
|
||||
public class EntityExtensions {
|
||||
|
||||
@QueryDelegate(EntityWithExtensions.class)
|
||||
public static Predicate extension(QEntityWithExtensions entity){
|
||||
return new BooleanPath("b");
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,55 @@
|
||||
package com.mysema.query.apt;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
public class EntityExtensionsTest extends AbstractProcessorTest{
|
||||
|
||||
private static final String packagePath = "src/test/java/com/mysema/query/apt/";
|
||||
|
||||
@Test
|
||||
public void Handles_Entity_Extensions_Correctly() throws IOException, InterruptedException{
|
||||
File source = new File(packagePath, "EntityWithExtensions.java");
|
||||
File source2 = new File(packagePath, "EntityExtensions.java");
|
||||
List<String> sources = Arrays.asList(source.getPath(), source2.getPath());
|
||||
File qType = new File("target/overwrite2/com/mysema/query/apt/QEntityWithExtensions.java");
|
||||
|
||||
// QEntityWithExtensions is generated
|
||||
process(QuerydslAnnotationProcessor.class, sources, "overwrite2");
|
||||
assertTrue(qType.exists());
|
||||
long modified = qType.lastModified();
|
||||
Thread.sleep(1000);
|
||||
System.out.println(FileUtils.readFileToString(qType).contains("extension()"));
|
||||
|
||||
// EntityWithExtensions has not changed, QEntityWithExtensions is not overwritten
|
||||
compile(QuerydslAnnotationProcessor.class, sources, "overwrite2");
|
||||
assertEquals(modified, qType.lastModified());
|
||||
|
||||
// EntityWithExtensions is updated, QEntityWithExtensions is overwritten
|
||||
FileUtils.touch(source);
|
||||
compile(QuerydslAnnotationProcessor.class, sources, "overwrite2");
|
||||
assertTrue("" + modified + " >= " + qType.lastModified(), modified < qType.lastModified());
|
||||
assertTrue(FileUtils.readFileToString(qType).contains("extension()"));
|
||||
|
||||
// QEntityWithExtensions is deleted and regenerated
|
||||
assertTrue(qType.delete());
|
||||
compile(QuerydslAnnotationProcessor.class, sources, "overwrite2");
|
||||
assertTrue(qType.exists());
|
||||
assertTrue(FileUtils.readFileToString(qType).contains("extension()"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<String> getAPTOptions() {
|
||||
return Arrays.asList("-AdefaultOverwrite=true");
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
package com.mysema.query.apt;
|
||||
|
||||
import java.sql.Date;
|
||||
|
||||
import com.mysema.query.annotations.QueryEntity;
|
||||
|
||||
@QueryEntity
|
||||
public class EntityWithExtensions {
|
||||
|
||||
String id;
|
||||
|
||||
Date date;
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user