Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix QBN issue in CDI tests #649

Merged
merged 5 commits into from
Apr 5, 2024
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
7 changes: 5 additions & 2 deletions tck/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,16 @@
</executions>
<configuration>
<classes>${project.build.directory}/jakarta.data-api</classes>
<classes>${project.build.directory}/jimage/java.base</classes><classes>${project.build.directory}/jimage/java.base</classes>
<classes>${project.build.directory}/jimage/java.base</classes>
<packages>
jakarta.data,
jakarta.data.exceptions,
jakarta.data.metamodel,
jakarta.data.metamodel.impl,
jakarta.data.page,
jakarta.data.repository
jakarta.data.page.impl,
jakarta.data.repository,
jakarta.data.spi
</packages>
<attach>false</attach>
<sigfile>${project.build.directory}/jakarta.data.sig_${java.version}</sigfile>
Expand Down
15 changes: 13 additions & 2 deletions tck/src/main/java/ee/jakarta/tck/data/common/cdi/Directory.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -15,9 +15,13 @@
*/
package ee.jakarta.tck.data.common.cdi;

import static jakarta.data.repository.By.ID;

import java.util.List;

import jakarta.data.repository.By;
import jakarta.data.repository.DataRepository;
import jakarta.data.repository.Delete;
import jakarta.data.repository.Repository;

/**
Expand All @@ -31,5 +35,12 @@ public interface Directory extends DataRepository<Person, Long> {
//Self referencing provider so that this repository can be used for both WEB and CORE tests
public static final String PERSON_PROVIDER = "PERSON_PROVIDER";

List<String> findFirstNameByIdInOrderByAgeDesc(List<Long> ids);
List<Person> findByIdInOrderByAgeDesc(List<Long> ids);

@Delete
void deleteById(@By(ID) Long id);

@PutTCKLifecyleMethod
Person putPerson(Person person);

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -43,14 +43,22 @@ public DirectoryRepository() {
}

@Override
public List<String> findFirstNameByIdInOrderByAgeDesc(List<Long> ids) {
public List<Person> findByIdInOrderByAgeDesc(List<Long> ids) {
return data.values()
.stream()
.filter(p -> ids.contains(p.id))
.sorted(Comparator.comparing((Person p) -> p.age).reversed())
.map(p -> p.firstName)
.collect(Collectors.toList());
}

}
@Override
public Person putPerson(Person person) {
return data.put(person.id, person);
}

@Override
public void deleteById(Long id) {
data.remove(id);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package ee.jakarta.tck.data.common.cdi;

import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

/**
* This is a custom lifecycle annotation only supported by the Jakarta Data provider present
* in this TCK and is used to verify the <code>@Repository</code> provider attribute is honored by
* any other Jakarta Data providers present on the tests classpath.
*
* This lifecycle annotation is named in such a way that it should not conflict with any other
* custom lifecycle annotations from other Jakarta Data providers.
*/
@Retention(RUNTIME)
@Target(METHOD)
public @interface PutTCKLifecyleMethod {

}
24 changes: 21 additions & 3 deletions tck/src/main/java/ee/jakarta/tck/data/core/cdi/ExtensionTests.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -18,6 +18,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.List;
import java.util.stream.Collectors;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.shrinkwrap.api.ShrinkWrap;
Expand Down Expand Up @@ -55,9 +56,26 @@ public static WebArchive createDeployment() {
@Inject
Directory directory;

@Assertion(id = "133", strategy="Verifies ability for a CDI BuildCompatibleExtension to handle custom entity annotations")
@Assertion(id = "133", strategy = "Verifies ability for a CDI BuildCompatibleExtension to handle custom entity annotations")
public void testDataProviderWithBuildCompatibleExtension() {
assertEquals(List.of("Olivia", "Lauren", "Victor"), directory.findFirstNameByIdInOrderByAgeDesc(List.of(04L, 05L, 011L)));
List<Person> result = directory.findByIdInOrderByAgeDesc(List.of(04L, 05L, 011L));
List<String> firstNames = result.stream().map(p -> p.firstName).collect(Collectors.toList());
List<String> lastNames = result.stream().map(p -> p.lastName).collect(Collectors.toList());
assertEquals(List.of("Olivia", "Lauren", "Victor"), firstNames);
assertEquals(List.of("Skinner", "Powell", "Gibson"), lastNames);
}

@Assertion(id = "640", strategy = "Verifies that another Jakarta Data Provider does not attempt to implement the Dictonary repository")
public void testDataRepositoryHonorsProviderAttribute() {
long id = 013L;
Person original = new Person(id, "Mark", "Pearson", 46);
Person updated = new Person(id, "Mark", "Pearson", 45);

try {
assertEquals(null, directory.putPerson(original));
assertEquals(original, directory.putPerson(updated));
} finally {
directory.deleteById(id);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,24 @@ public DataSignatureTestRunner() {
* Returns a list of strings where each string represents a package name. Each
* package name will have it's signature tested by the signature test framework.
*
* TODO is there a way to construct this list at runtime?
* Unlikely due to lazy classloading Package.getPackages() will not contain anything
* that hasn't been loaded.
*
* @return String[] The names of the packages whose signatures should be
* verified.
*/
@Override
protected String[] getPackages(String vehicleName) {
return new String[] {
"jakarta.data",
"jakarta.data.exceptions",
"jakarta.data.page",
"jakarta.data.repository"
"jakarta.data",
"jakarta.data.exceptions",
"jakarta.data.metamodel",
"jakarta.data.metamodel.impl",
"jakarta.data.page",
"jakarta.data.page.impl",
"jakarta.data.repository",
"jakarta.data.spi"
};
}

Expand Down
22 changes: 20 additions & 2 deletions tck/src/main/java/ee/jakarta/tck/data/web/cdi/ExtensionTests.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -18,6 +18,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.List;
import java.util.stream.Collectors;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.shrinkwrap.api.ShrinkWrap;
Expand Down Expand Up @@ -57,7 +58,24 @@ public static WebArchive createDeployment() {

@Assertion(id = "133", strategy="Verifies ability for a CDI Extension to handle custom entity annotations")
public void testDataProviderWithExtension() {
assertEquals(List.of("Olivia", "Lauren", "Victor"), directory.findFirstNameByIdInOrderByAgeDesc(List.of(04L, 05L, 011L)));
List<Person> result = directory.findByIdInOrderByAgeDesc(List.of(04L, 05L, 011L));
List<String> firstNames = result.stream().map(p -> p.firstName).collect(Collectors.toList());
List<String> lastNames = result.stream().map(p -> p.lastName).collect(Collectors.toList());
assertEquals(List.of("Olivia", "Lauren", "Victor"), firstNames);
assertEquals(List.of("Skinner", "Powell", "Gibson"), lastNames);
}

@Assertion(id = "640", strategy = "Verifies that another Jakarta Data Provider does not attempt to implement the Dictonary repository")
public void testDataRepositoryHonorsProviderAttribute() {
long id = 013L;
Person original = new Person(id, "Mark", "Pearson", 46);
Person updated = new Person(id, "Mark", "Pearson", 45);

try {
assertEquals(null, directory.putPerson(original));
assertEquals(original, directory.putPerson(updated));
} finally {
directory.deleteById(id);
}
}
}
Loading