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 3, 2020
1 parent 020c4d0 commit bebf746
Show file tree
Hide file tree
Showing 21 changed files with 766 additions and 9 deletions.
5 changes: 5 additions & 0 deletions bom/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,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 @@ -409,6 +409,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
Loading

0 comments on commit bebf746

Please sign in to comment.