Skip to content

Commit

Permalink
add the CreationalContexts SPI
Browse files Browse the repository at this point in the history
This commit also removes a few outdated references to Web Beans.
  • Loading branch information
Ladicek authored and manovotn committed Sep 21, 2023
1 parent a9e9540 commit 770c00e
Show file tree
Hide file tree
Showing 13 changed files with 160 additions and 9 deletions.
18 changes: 13 additions & 5 deletions api/src/main/java/org/jboss/cdi/tck/api/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.jboss.cdi.tck.spi.Beans;
import org.jboss.cdi.tck.spi.Contexts;
import org.jboss.cdi.tck.spi.CreationalContexts;
import org.jboss.cdi.tck.spi.EL;

/**
Expand Down Expand Up @@ -79,17 +80,24 @@ public interface Configuration {
*/
public <T extends Context> Contexts<T> getContexts();

public void setBeans(Beans beans);

public <T extends Context> void setContexts(Contexts<T> contexts);

public void setEl(EL el);
/**
* The implementation of {@link CreationalContexts} in use.
*/
public CreationalContexts getCreationalContexts();

/**
* The implementation of {@link EL} in use.
*/
public EL getEl();

public void setBeans(Beans beans);

public <T extends Context> void setContexts(Contexts<T> contexts);

public void setCreationalContexts(CreationalContexts creationalContexts);

public void setEl(EL el);

/**
* The TCK allows additional libraries to be put in the deployed test artifacts (for example the porting package for the implementation). Any jars in this
* directory will be added to the deployed artifact.
Expand Down
2 changes: 1 addition & 1 deletion api/src/main/java/org/jboss/cdi/tck/spi/Contexts.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public interface Contexts<T extends Context> {
public T getDependentContext();

/**
* Destroy the context. This operation is defined by the Web Beans specification but has no API.
* Destroy the context. This operation is defined by the CDI specification but has no API.
*
* @param context the context to destroy
*/
Expand Down
70 changes: 70 additions & 0 deletions api/src/main/java/org/jboss/cdi/tck/spi/CreationalContexts.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright 2023, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.cdi.tck.spi;

import jakarta.enterprise.context.spi.Contextual;
import jakarta.enterprise.context.spi.CreationalContext;

/**
* Provides CreationalContext related operations.
*
* The TCK porting package must provide an implementation of this interface which is suitable for the target implementation.
*/
public interface CreationalContexts {

public static final String PROPERTY_NAME = CreationalContexts.class.getName();

/**
* Creates an {@linkplain Inspectable inspectable} CreationalContext for given Contextual.
* This operation is identical to {@link jakarta.enterprise.inject.spi.BeanContainer#createCreationalContext(Contextual)},
* except it returns a specialized variant of CreationalContext that can be inspected.
*
* @param contextual a Contextual for which a CreationalContext should be created
* @return a CreationalContext that can be inspected
* @param <T> type of the instance
*/
public <T> Inspectable<T> create(Contextual<T> contextual);

/**
* A CreationalContext that can be inspected.
*
* @param <T> type of the instances
*/
public static interface Inspectable<T> extends CreationalContext<T> {
/**
* Returns whether {@link #push(Object)} was called on this CreationalContext.
*
* @return whether {@link #push(Object)} was called on this CreationalContext.
*/
public boolean isPushCalled();

/**
* If {@code push} {@linkplain #isPushCalled() was called} on this CreationalContext, returns the pushed object.
* Returns {@code null} otherwise.
*
* @return the pushed object if {@code push} was called, otherwise {@code null}
*/
public Object getLastBeanPushed();

/**
* Returns whether {@link #release()} was called on this CreationalContext.
*
* @return whether {@link #release()} was called on this CreationalContext.
*/
public boolean isReleaseCalled();
}

}
3 changes: 1 addition & 2 deletions api/src/main/java/org/jboss/cdi/tck/spi/EL.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
*
* For the purpose of TCK, EL function and variable mapping is not required and therefore may be disabled.
*
* The TCK porting package must provide an implementation of this interface which is suitable for the target Web Beans
* implementation.
* The TCK porting package must provide an implementation of this interface which is suitable for the target implementation.
*
* @author Pete Muir
*/
Expand Down
1 change: 1 addition & 0 deletions doc/reference/src/main/asciidoc/configuration.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ The SPI classes in the CDI TCK are as follows:

* +org.jboss.cdi.tck.spi.Beans+
* +org.jboss.cdi.tck.spi.Contexts+
* +org.jboss.cdi.tck.spi.CreationalContexts+
* +org.jboss.cdi.tck.spi.EL+

Please consult the JavaDoc for these interfaces for the implementation requirements.
Expand Down
1 change: 1 addition & 0 deletions impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
<!-- Dummy porting package impls -->
<org.jboss.cdi.tck.spi.Beans>org.jboss.cdi.tck.test.porting.DummyBeans</org.jboss.cdi.tck.spi.Beans>
<org.jboss.cdi.tck.spi.Contexts>org.jboss.cdi.tck.test.porting.DummyContexts</org.jboss.cdi.tck.spi.Contexts>
<org.jboss.cdi.tck.spi.CreationalContexts>org.jboss.cdi.tck.test.porting.DummyCreationalContexts</org.jboss.cdi.tck.spi.CreationalContexts>
<org.jboss.cdi.tck.spi.EL>org.jboss.cdi.tck.test.porting.DummyEL</org.jboss.cdi.tck.spi.EL>
</systemPropertyVariables>
</configuration>
Expand Down
6 changes: 6 additions & 0 deletions impl/src/main/java/org/jboss/cdi/tck/AbstractTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.Set;

import jakarta.enterprise.context.spi.Context;
import jakarta.enterprise.context.spi.Contextual;
import jakarta.enterprise.inject.AmbiguousResolutionException;
import jakarta.enterprise.inject.UnsatisfiedResolutionException;
import jakarta.enterprise.inject.spi.Bean;
Expand All @@ -39,6 +40,7 @@
import org.jboss.arquillian.testng.Arquillian;
import org.jboss.cdi.tck.api.Configuration;
import org.jboss.cdi.tck.impl.ConfigurationFactory;
import org.jboss.cdi.tck.spi.CreationalContexts;
import org.jboss.cdi.tck.util.BeanLookupUtils;
import org.jboss.cdi.tck.util.DependentInstance;

Expand Down Expand Up @@ -94,6 +96,10 @@ protected void destroyContext(Context context) {
getCurrentConfiguration().getContexts().destroyContext(context);
}

protected <T> CreationalContexts.Inspectable<T> createInspectableCreationalContext(Contextual<T> contextual) {
return getCurrentConfiguration().getCreationalContexts().create(contextual);
}

protected Configuration getCurrentConfiguration() {
return ConfigurationFactory.get();
}
Expand Down
11 changes: 11 additions & 0 deletions impl/src/main/java/org/jboss/cdi/tck/impl/ConfigurationImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.jboss.cdi.tck.api.Configuration;
import org.jboss.cdi.tck.spi.Beans;
import org.jboss.cdi.tck.spi.Contexts;
import org.jboss.cdi.tck.spi.CreationalContexts;
import org.jboss.cdi.tck.spi.EL;

/**
Expand All @@ -35,6 +36,7 @@ public class ConfigurationImpl implements Configuration {

private Beans beans;
private Contexts<? extends Context> contexts;
private CreationalContexts creationalContexts;
private EL el;

private String libraryDirectory;
Expand Down Expand Up @@ -74,6 +76,14 @@ public <T extends Context> void setContexts(Contexts<T> contexts) {
this.contexts = contexts;
}

public CreationalContexts getCreationalContexts() {
return creationalContexts;
}

public void setCreationalContexts(CreationalContexts creationalContexts) {
this.creationalContexts = creationalContexts;
}

public EL getEl() {
return el;
}
Expand Down Expand Up @@ -149,6 +159,7 @@ public String toString() {
configuration.append("\tCDI Lite mode: ").append(getCdiLiteMode()).append("\n");
configuration.append("\tBeans: ").append(getBeans()).append("\n");
configuration.append("\tContexts: ").append(getContexts()).append("\n");
configuration.append("\tCreationalContexts: ").append(getCreationalContexts()).append("\n");
configuration.append("\tEL: ").append(getEl()).append("\n");
configuration.append("\tLibrary dir: ").append(getLibraryDirectory()).append("\n");
configuration.append("\tTest DS: ").append(getTestDataSource()).append("\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.jboss.cdi.tck.api.Configuration;
import org.jboss.cdi.tck.spi.Beans;
import org.jboss.cdi.tck.spi.Contexts;
import org.jboss.cdi.tck.spi.CreationalContexts;
import org.jboss.cdi.tck.spi.EL;

import java.io.IOException;
Expand Down Expand Up @@ -66,6 +67,7 @@ public PropertiesBasedConfigurationBuilder init(boolean deploymentPhase) {
configuration.setBeans(getInstanceValue(Beans.PROPERTY_NAME, Beans.class, !deploymentPhase));
configuration.setEl(getInstanceValue(EL.PROPERTY_NAME, EL.class, !deploymentPhase));
configuration.setContexts((Contexts<?>)getInstanceValue(Contexts.PROPERTY_NAME, Contexts.class, !deploymentPhase));
configuration.setCreationalContexts(getInstanceValue(CreationalContexts.PROPERTY_NAME, CreationalContexts.class, !deploymentPhase));

configuration.setLibraryDirectory(getStringValue(Configuration.LIBRARY_DIRECTORY_PROPERTY_NAME, null, deploymentPhase));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import jakarta.enterprise.event.Reception;

/**
* Simple web bean that conditionally listens to events.
* Simple bean that conditionally listens to events.
*
*/
@RequestScoped
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2023, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.cdi.tck.test.porting;

import jakarta.enterprise.context.spi.Contextual;
import org.jboss.cdi.tck.spi.CreationalContexts;

public class DummyCreationalContexts implements CreationalContexts {
@Override
public <T> Inspectable<T> create(Contextual<T> contextual) {
throw new UnsupportedOperationException();
}
}
1 change: 1 addition & 0 deletions web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@
<!-- Dummy porting package impls -->
<org.jboss.cdi.tck.spi.Beans>org.jboss.cdi.tck.test.porting.DummyBeans</org.jboss.cdi.tck.spi.Beans>
<org.jboss.cdi.tck.spi.Contexts>org.jboss.cdi.tck.test.porting.DummyContexts</org.jboss.cdi.tck.spi.Contexts>
<org.jboss.cdi.tck.spi.CreationalContexts>org.jboss.cdi.tck.test.porting.DummyCreationalContexts</org.jboss.cdi.tck.spi.CreationalContexts>
<org.jboss.cdi.tck.spi.EL>org.jboss.cdi.tck.test.porting.DummyEL</org.jboss.cdi.tck.spi.EL>
</systemPropertyVariables>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2023, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.cdi.tck.test.porting;

import jakarta.enterprise.context.spi.Contextual;
import org.jboss.cdi.tck.spi.CreationalContexts;

public class DummyCreationalContexts implements CreationalContexts {
@Override
public <T> Inspectable<T> create(Contextual<T> contextual) {
throw new UnsupportedOperationException();
}
}

0 comments on commit 770c00e

Please sign in to comment.