Skip to content

Commit

Permalink
New panache-mock module for mocking Panache static methods
Browse files Browse the repository at this point in the history
  • Loading branch information
FroMage committed Apr 6, 2020
1 parent 7c646af commit e67615a
Show file tree
Hide file tree
Showing 26 changed files with 832 additions and 23 deletions.
5 changes: 5 additions & 0 deletions bom/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,11 @@
<artifactId>quarkus-panache-common-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-panache-mock-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-mongodb-panache-deployment</artifactId>
Expand Down
5 changes: 5 additions & 0 deletions bom/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,11 @@
<artifactId>quarkus-panache-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-panache-mock</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-panacheql</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public final class FeatureBuildItem extends MultiBuildItem {
public static final String OIDC = "oidc";
public static final String OPTAPLANNER = "optaplanner";
public static final String OPTAPLANNER_JACKSON = "optaplanner-jackson";
public static final String PANACHE_MOCK = "panache-mock";
public static final String QUTE = "qute";
public static final String RESTEASY = "resteasy";
public static final String RESTEASY_JACKSON = "resteasy-jackson";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.quarkus.hibernate.orm.panache.deployment;

import java.lang.reflect.Modifier;
import java.util.List;

import javax.persistence.Transient;

Expand All @@ -22,6 +23,7 @@
import io.quarkus.panache.common.deployment.EntityModel;
import io.quarkus.panache.common.deployment.MetamodelInfo;
import io.quarkus.panache.common.deployment.PanacheEntityEnhancer;
import io.quarkus.panache.common.deployment.PanacheMethodCustomizer;

public class PanacheJpaEntityEnhancer extends PanacheEntityEnhancer<MetamodelInfo<EntityModel<EntityField>>> {

Expand All @@ -38,24 +40,25 @@ public class PanacheJpaEntityEnhancer extends PanacheEntityEnhancer<MetamodelInf

private static final DotName DOTNAME_TRANSIENT = DotName.createSimple(Transient.class.getName());

public PanacheJpaEntityEnhancer(IndexView index) {
super(index, PanacheResourceProcessor.DOTNAME_PANACHE_ENTITY_BASE);
public PanacheJpaEntityEnhancer(IndexView index, List<PanacheMethodCustomizer> methodCustomizers) {
super(index, PanacheResourceProcessor.DOTNAME_PANACHE_ENTITY_BASE, methodCustomizers);
modelInfo = new MetamodelInfo<>();
}

@Override
public ClassVisitor apply(String className, ClassVisitor outputClassVisitor) {
return new PanacheJpaEntityClassVisitor(className, outputClassVisitor, modelInfo, panacheEntityBaseClassInfo,
indexView.getClassByName(DotName.createSimple(className)));
indexView.getClassByName(DotName.createSimple(className)), methodCustomizers);
}

static class PanacheJpaEntityClassVisitor extends PanacheEntityClassVisitor<EntityField> {

public PanacheJpaEntityClassVisitor(String className, ClassVisitor outputClassVisitor,
MetamodelInfo<EntityModel<EntityField>> modelInfo,
ClassInfo panacheEntityBaseClassInfo,
ClassInfo entityInfo) {
super(className, outputClassVisitor, modelInfo, panacheEntityBaseClassInfo, entityInfo);
ClassInfo entityInfo,
List<PanacheMethodCustomizer> methodCustomizers) {
super(className, outputClassVisitor, modelInfo, panacheEntityBaseClassInfo, entityInfo, methodCustomizers);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import javax.persistence.EntityManager;

Expand All @@ -27,6 +28,8 @@
import io.quarkus.panache.common.deployment.MetamodelInfo;
import io.quarkus.panache.common.deployment.PanacheEntityClassesBuildItem;
import io.quarkus.panache.common.deployment.PanacheFieldAccessEnhancer;
import io.quarkus.panache.common.deployment.PanacheMethodCustomizer;
import io.quarkus.panache.common.deployment.PanacheMethodCustomizerBuildItem;
import io.quarkus.panache.common.deployment.PanacheRepositoryEnhancer;

public final class PanacheResourceProcessor {
Expand Down Expand Up @@ -60,7 +63,11 @@ UnremovableBeanBuildItem ensureBeanLookupAvailable() {
void build(CombinedIndexBuildItem index,
BuildProducer<BytecodeTransformerBuildItem> transformers,
HibernateEnhancersRegisteredBuildItem hibernateMarker,
BuildProducer<PanacheEntityClassesBuildItem> entityClasses) throws Exception {
BuildProducer<PanacheEntityClassesBuildItem> entityClasses,
List<PanacheMethodCustomizerBuildItem> methodCustomizersBuildItems) throws Exception {

List<PanacheMethodCustomizer> methodCustomizers = methodCustomizersBuildItems.stream()
.map(bi -> bi.getMethodCustomizer()).collect(Collectors.toList());

PanacheJpaRepositoryEnhancer daoEnhancer = new PanacheJpaRepositoryEnhancer(index.getIndex());
Set<String> daoClasses = new HashSet<>();
Expand All @@ -81,7 +88,7 @@ void build(CombinedIndexBuildItem index,
transformers.produce(new BytecodeTransformerBuildItem(daoClass, daoEnhancer));
}

PanacheJpaEntityEnhancer modelEnhancer = new PanacheJpaEntityEnhancer(index.getIndex());
PanacheJpaEntityEnhancer modelEnhancer = new PanacheJpaEntityEnhancer(index.getIndex(), methodCustomizers);
Set<String> modelClasses = new HashSet<>();
// Note that we do this in two passes because for some reason Jandex does not give us subtypes
// of PanacheEntity if we ask for subtypes of PanacheEntityBase
Expand Down
10 changes: 10 additions & 0 deletions extensions/panache/hibernate-orm-panache/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@
<artifactId>quarkus-jackson</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.lang.reflect.Modifier;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.bson.codecs.pojo.annotations.BsonIgnore;
Expand All @@ -19,6 +20,7 @@
import io.quarkus.panache.common.deployment.EntityModel;
import io.quarkus.panache.common.deployment.MetamodelInfo;
import io.quarkus.panache.common.deployment.PanacheEntityEnhancer;
import io.quarkus.panache.common.deployment.PanacheMethodCustomizer;

public class PanacheMongoEntityEnhancer extends PanacheEntityEnhancer<MetamodelInfo<EntityModel<EntityField>>> {
public final static String MONGO_OPERATIONS_NAME = MongoOperations.class.getName();
Expand All @@ -28,23 +30,23 @@ public class PanacheMongoEntityEnhancer extends PanacheEntityEnhancer<MetamodelI

final Map<String, EntityModel> entities = new HashMap<>();

public PanacheMongoEntityEnhancer(IndexView index) {
super(index, PanacheResourceProcessor.DOTNAME_PANACHE_ENTITY_BASE);
public PanacheMongoEntityEnhancer(IndexView index, List<PanacheMethodCustomizer> methodCustomizers) {
super(index, PanacheResourceProcessor.DOTNAME_PANACHE_ENTITY_BASE, methodCustomizers);
modelInfo = new MetamodelInfo<>();
}

@Override
public ClassVisitor apply(String className, ClassVisitor outputClassVisitor) {
return new PanacheMongoEntityClassVisitor(className, outputClassVisitor, modelInfo, panacheEntityBaseClassInfo,
indexView.getClassByName(DotName.createSimple(className)));
indexView.getClassByName(DotName.createSimple(className)), methodCustomizers);
}

static class PanacheMongoEntityClassVisitor extends PanacheEntityClassVisitor<EntityField> {

public PanacheMongoEntityClassVisitor(String className, ClassVisitor outputClassVisitor,
MetamodelInfo<EntityModel<EntityField>> modelInfo, ClassInfo panacheEntityBaseClassInfo,
ClassInfo entityInfo) {
super(className, outputClassVisitor, modelInfo, panacheEntityBaseClassInfo, entityInfo);
ClassInfo entityInfo, List<PanacheMethodCustomizer> methodCustomizers) {
super(className, outputClassVisitor, modelInfo, panacheEntityBaseClassInfo, entityInfo, methodCustomizers);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import org.bson.codecs.pojo.annotations.BsonProperty;
import org.bson.types.ObjectId;
Expand Down Expand Up @@ -51,6 +52,8 @@
import io.quarkus.mongodb.panache.reactive.ReactivePanacheMongoRepositoryBase;
import io.quarkus.panache.common.deployment.PanacheEntityClassesBuildItem;
import io.quarkus.panache.common.deployment.PanacheFieldAccessEnhancer;
import io.quarkus.panache.common.deployment.PanacheMethodCustomizer;
import io.quarkus.panache.common.deployment.PanacheMethodCustomizerBuildItem;
import io.quarkus.panache.common.deployment.PanacheRepositoryEnhancer;

public class PanacheResourceProcessor {
Expand Down Expand Up @@ -133,7 +136,11 @@ void buildImperative(CombinedIndexBuildItem index,
BuildProducer<BytecodeTransformerBuildItem> transformers,
BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
BuildProducer<PropertyMappingClassBuildStep> propertyMappingClass,
BuildProducer<PanacheEntityClassesBuildItem> entityClasses) {
BuildProducer<PanacheEntityClassesBuildItem> entityClasses,
List<PanacheMethodCustomizerBuildItem> methodCustomizersBuildItems) {

List<PanacheMethodCustomizer> methodCustomizers = methodCustomizersBuildItems.stream()
.map(bi -> bi.getMethodCustomizer()).collect(Collectors.toList());

PanacheMongoRepositoryEnhancer daoEnhancer = new PanacheMongoRepositoryEnhancer(index.getIndex());
Set<String> daoClasses = new HashSet<>();
Expand Down Expand Up @@ -167,7 +174,7 @@ void buildImperative(CombinedIndexBuildItem index,
propertyMappingClass.produce(new PropertyMappingClassBuildStep(parameterType.name().toString()));
}

PanacheMongoEntityEnhancer modelEnhancer = new PanacheMongoEntityEnhancer(index.getIndex());
PanacheMongoEntityEnhancer modelEnhancer = new PanacheMongoEntityEnhancer(index.getIndex(), methodCustomizers);
Set<String> modelClasses = new HashSet<>();
// Note that we do this in two passes because for some reason Jandex does not give us subtypes
// of PanacheMongoEntity if we ask for subtypes of PanacheMongoEntityBase
Expand Down Expand Up @@ -214,7 +221,11 @@ void buildMutiny(CombinedIndexBuildItem index,
ApplicationIndexBuildItem applicationIndex,
BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
BuildProducer<PropertyMappingClassBuildStep> propertyMappingClass,
BuildProducer<BytecodeTransformerBuildItem> transformers) {
BuildProducer<BytecodeTransformerBuildItem> transformers,
List<PanacheMethodCustomizerBuildItem> methodCustomizersBuildItems) {

List<PanacheMethodCustomizer> methodCustomizers = methodCustomizersBuildItems.stream()
.map(bi -> bi.getMethodCustomizer()).collect(Collectors.toList());

ReactivePanacheMongoRepositoryEnhancer daoEnhancer = new ReactivePanacheMongoRepositoryEnhancer(index.getIndex());
Set<String> daoClasses = new HashSet<>();
Expand Down Expand Up @@ -249,7 +260,8 @@ void buildMutiny(CombinedIndexBuildItem index,
propertyMappingClass.produce(new PropertyMappingClassBuildStep(parameterType.name().toString()));
}

ReactivePanacheMongoEntityEnhancer modelEnhancer = new ReactivePanacheMongoEntityEnhancer(index.getIndex());
ReactivePanacheMongoEntityEnhancer modelEnhancer = new ReactivePanacheMongoEntityEnhancer(index.getIndex(),
methodCustomizers);
Set<String> modelClasses = new HashSet<>();
// Note that we do this in two passes because for some reason Jandex does not give us subtypes
// of PanacheMongoEntity if we ask for subtypes of PanacheMongoEntityBase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.lang.reflect.Modifier;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.bson.codecs.pojo.annotations.BsonIgnore;
Expand All @@ -19,6 +20,7 @@
import io.quarkus.panache.common.deployment.EntityModel;
import io.quarkus.panache.common.deployment.MetamodelInfo;
import io.quarkus.panache.common.deployment.PanacheEntityEnhancer;
import io.quarkus.panache.common.deployment.PanacheMethodCustomizer;

public class ReactivePanacheMongoEntityEnhancer extends PanacheEntityEnhancer<MetamodelInfo<EntityModel<EntityField>>> {
public final static String MONGO_OPERATIONS_NAME = ReactiveMongoOperations.class.getName();
Expand All @@ -28,23 +30,23 @@ public class ReactivePanacheMongoEntityEnhancer extends PanacheEntityEnhancer<Me

final Map<String, EntityModel> entities = new HashMap<>();

public ReactivePanacheMongoEntityEnhancer(IndexView index) {
super(index, PanacheResourceProcessor.DOTNAME_MUTINY_PANACHE_ENTITY_BASE);
public ReactivePanacheMongoEntityEnhancer(IndexView index, List<PanacheMethodCustomizer> methodCustomizers) {
super(index, PanacheResourceProcessor.DOTNAME_MUTINY_PANACHE_ENTITY_BASE, methodCustomizers);
modelInfo = new MetamodelInfo<>();
}

@Override
public ClassVisitor apply(String className, ClassVisitor outputClassVisitor) {
return new PanacheMongoEntityClassVisitor(className, outputClassVisitor, modelInfo, panacheEntityBaseClassInfo,
indexView.getClassByName(DotName.createSimple(className)));
indexView.getClassByName(DotName.createSimple(className)), methodCustomizers);
}

static class PanacheMongoEntityClassVisitor extends PanacheEntityClassVisitor<EntityField> {

public PanacheMongoEntityClassVisitor(String className, ClassVisitor outputClassVisitor,
MetamodelInfo<EntityModel<EntityField>> modelInfo, ClassInfo panacheEntityBaseClassInfo,
ClassInfo entityInfo) {
super(className, outputClassVisitor, modelInfo, panacheEntityBaseClassInfo, entityInfo);
ClassInfo entityInfo, List<PanacheMethodCustomizer> methodCustomizers) {
super(className, outputClassVisitor, modelInfo, panacheEntityBaseClassInfo, entityInfo, methodCustomizers);
}

@Override
Expand Down
Loading

0 comments on commit e67615a

Please sign in to comment.