Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,21 @@ public boolean isEmpty() {

/**
* Return true if this class is a query bean using naming conventions for query beans.
* <p>
* When no entity packages are configured (e.g. ebean.mf was not accessible to the
* classloader — a known Gradle Kotlin KAPT scenario), fall back to naming-convention
* detection only, consistent with {@code FilterQueryBean.detectOnAll} behaviour.
* </p>
*/
public boolean isQueryBean(String owner) {
int subPackagePos = owner.lastIndexOf("/query/");
if (subPackagePos > -1) {
String suffix = owner.substring(subPackagePos);
if (isQueryBeanSuffix(suffix)) {
if (entityPackages.isEmpty()) {
// No entity packages loaded (manifest not found) — trust naming convention.
return true;
}
String domainPackage = owner.substring(0, subPackagePos + 1);
return isEntityBeanPackage(domainPackage);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package io.ebean.enhance.querybean;

import org.junit.jupiter.api.Test;

import java.util.Set;

import static org.assertj.core.api.Assertions.assertThat;

public class DetectQueryBeanTest {

@Test
void isQueryBean_withPackages_matches() {
DetectQueryBean detect = new DetectQueryBean();
detect.addAll(Set.of("de.worldinsight.wision"));

assertThat(detect.isQueryBean("de/worldinsight/wision/auth/roles/query/QRoleEntity")).isTrue();
assertThat(detect.isQueryBean("de/worldinsight/wision/domain/query/QCustomer")).isTrue();
assertThat(detect.isQueryBean("de/worldinsight/wision/auth/roles/query/RoleEntity")).isFalse(); // no Q prefix
assertThat(detect.isQueryBean("com/other/query/QFoo")).isFalse(); // wrong package
}

@Test
void isQueryBean_withPackages_noMatch_returnsFalse() {
DetectQueryBean detect = new DetectQueryBean();
detect.addAll(Set.of("de.worldinsight.wision"));

assertThat(detect.isQueryBean("com/other/query/QFoo")).isFalse();
assertThat(detect.isQueryBean("de/worldinsight/wision/RoleEntity")).isFalse(); // not in query sub-package
}

@Test
void isQueryBean_emptyPackages_namingConventionFallback() {
// When no packages loaded (ebean.mf not found — Gradle Kotlin KAPT scenario),
// trust naming convention: .../query/Q... classes are treated as query beans.
DetectQueryBean detect = new DetectQueryBean();
assertThat(detect.isEmpty()).isTrue();

assertThat(detect.isQueryBean("de/worldinsight/wision/auth/roles/query/QRoleEntity")).isTrue();
assertThat(detect.isQueryBean("com/example/domain/query/QCustomer")).isTrue();
assertThat(detect.isQueryBean("com/example/domain/query/assoc/QAssocAddress")).isTrue();
}

@Test
void isQueryBean_emptyPackages_nonQueryClass_returnsFalse() {
DetectQueryBean detect = new DetectQueryBean();
assertThat(detect.isEmpty()).isTrue();

assertThat(detect.isQueryBean("de/worldinsight/wision/auth/roles/RoleEntity")).isFalse();
assertThat(detect.isQueryBean("de/worldinsight/wision/auth/roles/query/RoleRepository")).isFalse(); // no Q prefix
assertThat(detect.isQueryBean("com/example/SomeClass")).isFalse();
}
}

Loading