Skip to content

Commit

Permalink
Add CDI Extension tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleAure committed Oct 11, 2023
1 parent 6150102 commit a65da04
Show file tree
Hide file tree
Showing 13 changed files with 136 additions and 20 deletions.
14 changes: 14 additions & 0 deletions tck-dist/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

<properties>
<jakarta.data.tck.version>${project.version}</jakarta.data.tck.version>
<jakarta.data.api.version>${project.version}</jakarta.data.api.version>

<maven.site.skip>true</maven.site.skip>
<asciidoctor.maven.plugin.version>2.2.4</asciidoctor.maven.plugin.version>
Expand All @@ -49,10 +50,23 @@
</properties>

<dependencies>
<!-- The TCK, used to auto generate docs -->
<dependency>
<groupId>jakarta.data</groupId>
<artifactId>jakarta-data-tck</artifactId>
<version>${jakarta.data.tck.version}</version>
</dependency>
<!-- Provided dependencies for the TCK -->
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>${jakarta.servlet.version}</version>
</dependency>

<dependency>
<groupId>jakarta.data</groupId>
<artifactId>jakarta-data-api</artifactId>
<version>${jakarta.data.api.version}</version>
</dependency>
</dependencies>

Expand Down
7 changes: 7 additions & 0 deletions tck/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
<version>${jakarta.enterprise.cdi.version}</version>
<scope>provided</scope>
</dependency>

<!-- Provided Entity APIs -->
<dependency>
<groupId>jakarta.nosql</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package ee.jakarta.tck.data.full.cdi;
package ee.jakarta.tck.data.core.cdi;

import java.util.List;

import ee.jakarta.tck.data.core.cdi.provider.PersonExtension;
import jakarta.data.repository.DataRepository;
import jakarta.data.repository.Repository;

import ee.jakarta.tck.data.full.cdi.provider.PersonExtension;

/**
* A Directory repository for testing.
*
* @see ee.jakarta.tck.data.full.cdi.provider.DirectoryRepository
* @see ee.jakarta.tck.data.core.cdi.provider.DirectoryRepository
*/
@Repository(provider = PersonExtension.PERSON_PROVIDER)
public interface Directory extends DataRepository<Person, Long> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package ee.jakarta.tck.data.full.cdi;
package ee.jakarta.tck.data.core.cdi;

import static org.junit.jupiter.api.Assertions.assertEquals;

Expand All @@ -24,15 +24,15 @@
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.api.spec.WebArchive;

import ee.jakarta.tck.data.core.cdi.provider.PersonExtension;
import ee.jakarta.tck.data.framework.junit.anno.AnyEntity;
import ee.jakarta.tck.data.framework.junit.anno.Assertion;
import ee.jakarta.tck.data.framework.junit.anno.CDI;
import ee.jakarta.tck.data.framework.junit.anno.Full;
import ee.jakarta.tck.data.full.cdi.provider.PersonExtension;
import ee.jakarta.tck.data.framework.junit.anno.Core;
import jakarta.enterprise.inject.spi.Extension;
import jakarta.inject.Inject;

@Full
@Core
@AnyEntity
@CDI
public class ExtensionTests {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package ee.jakarta.tck.data.full.cdi;
package ee.jakarta.tck.data.core.cdi;

import ee.jakarta.tck.data.full.cdi.provider.PersonEntity;
import ee.jakarta.tck.data.core.cdi.provider.PersonEntity;

/**
* A test entity that will be persisted to a repository.
* Uses the custom {@literal @}PersonEntity annotation.
*
* @see ee.jakarta.tck.data.full.cdi.provider.PersonEntity
* @see ee.jakarta.tck.data.core.cdi.provider.PersonEntity
*/
@PersonEntity
public class Person {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package ee.jakarta.tck.data.full.cdi.provider;
package ee.jakarta.tck.data.core.cdi.provider;

import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import ee.jakarta.tck.data.full.cdi.Directory;
import ee.jakarta.tck.data.full.cdi.Person;
import ee.jakarta.tck.data.core.cdi.Directory;
import ee.jakarta.tck.data.core.cdi.Person;

/**
* An implementation of the Directory repository interface.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package ee.jakarta.tck.data.full.cdi.provider;
package ee.jakarta.tck.data.core.cdi.provider;

import java.util.Collections;
import java.util.Set;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package ee.jakarta.tck.data.full.cdi.provider;
package ee.jakarta.tck.data.core.cdi.provider;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package ee.jakarta.tck.data.full.cdi.provider;
package ee.jakarta.tck.data.core.cdi.provider;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2023 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
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package ee.jakarta.tck.data.framework.junit.anno;

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

import org.junit.jupiter.api.extension.ExtendWith;

import ee.jakarta.tck.data.framework.junit.extensions.CDIConditionExtension;

/**
* These are tests that require CDI for testing.
* This annotation will verify that CDI is available.
* If CDI is not available, tests are skipped, otherwise, tests are run.
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@ExtendWith(CDIConditionExtension.class)
public @interface CDI {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2023 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
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package ee.jakarta.tck.data.framework.junit.extensions;

import java.util.logging.Logger;

import org.jboss.arquillian.junit5.ArquillianExtension;
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
import org.junit.jupiter.api.extension.ExecutionCondition;
import org.junit.jupiter.api.extension.ExtensionContext;

import jakarta.enterprise.inject.spi.CDI;

/**
* Evaluates the availability of CDI to determine if a test class/method is enabled/disabled.
*
* @see ee.jakarta.tck.data.framework.junit.anno.CDI
*/
public class CDIConditionExtension implements ExecutionCondition {

private static final Logger log = Logger.getLogger(CDIConditionExtension.class.getCanonicalName());

@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {

//We are only verifying CDI when running on a platform so first verify that this condition is running on a platform
if(Boolean.parseBoolean(context.getConfigurationParameter(ArquillianExtension.RUNNING_INSIDE_ARQUILLIAN).orElse("false"))) {
log.info("Inside Jakarta EE Platform, testing CDI provider.");
} else {
log.info("Outside Jakarta EE Platform, waiting to test CDI provider until inside.");
return ConditionEvaluationResult.enabled("Deploying test to container.");
}

try {
CDI.current();
return ConditionEvaluationResult.enabled("CDI provider is available");
} catch (IllegalStateException e) {
return ConditionEvaluationResult.disabled("CDI provider is not available");
} catch (Throwable t) {
return ConditionEvaluationResult.disabled("CDI provider available state unknown", t.getLocalizedMessage());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@
@Standalone
@AnyEntity
@ReadOnlyTest
public class EntityTest {
public class EntityTests {

public static final Logger log = Logger.getLogger(EntityTest.class.getCanonicalName());
public static final Logger log = Logger.getLogger(EntityTests.class.getCanonicalName());

@Deployment
public static JavaArchive createDeployment() {
return ShrinkWrap.create(JavaArchive.class).addClasses(EntityTest.class);
return ShrinkWrap.create(JavaArchive.class).addClasses(EntityTests.class);
}

@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@

jakarta.data
jakarta.data.exceptions
jakarta.data.model
jakarta.data.page
jakarta.data.repository

0 comments on commit a65da04

Please sign in to comment.