Skip to content

Commit

Permalink
add the Contextuals SPI
Browse files Browse the repository at this point in the history
  • Loading branch information
Ladicek authored and manovotn committed Sep 21, 2023
1 parent 5fff93b commit 7bda688
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 0 deletions.
8 changes: 8 additions & 0 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.Contextuals;
import org.jboss.cdi.tck.spi.CreationalContexts;
import org.jboss.cdi.tck.spi.EL;

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

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

/**
* The implementation of {@link CreationalContexts} in use.
*/
Expand All @@ -94,6 +100,8 @@ public interface Configuration {

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

public void setContextuals(Contextuals contextuals);

public void setCreationalContexts(CreationalContexts creationalContexts);

public void setEl(EL el);
Expand Down
80 changes: 80 additions & 0 deletions api/src/main/java/org/jboss/cdi/tck/spi/Contextuals.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* 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.Context;
import jakarta.enterprise.context.spi.Contextual;
import jakarta.enterprise.context.spi.CreationalContext;

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

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

/**
* Creates a dummy {@linkplain Inspectable inspectable} Contextual that will be used
* with given Context. The result does not necessarily fulfil the entire {@link Contextual}
* contract; the TCK only requires it to:
*
* <ul>
* <li>return the given {@code instance} from {@link Contextual#create(CreationalContext)};</li>
* <li>capture all the parameters passed to {@link Contextual} methods in order to fulfil
* the {@link Inspectable} contract.</li>
* </ul>
*
* @param instance the instance to be returned by {@link Contextual#create(CreationalContext)}
* @param context the Context that the returned Contextual can be used with
* @return a Contextual that can be inspected
* @param <T> type of the instance
*/
public <T> Inspectable<T> create(T instance, Context context);

/**
* A Contextual that can be inspected.
*
* @param <T> type of the instances
*/
public static interface Inspectable<T> extends Contextual<T> {
/**
* Returns the {@link CreationalContext} passed to {@link Contextual#create(CreationalContext)}.
* Returns {@code null} if {@code create} was not called yet.
*
* @return the {@link CreationalContext} passed to {@link Contextual#create(CreationalContext)}
*/
public CreationalContext<T> getCreationalContextPassedToCreate();

/**
* Returns the instance passed to {@link Contextual#destroy(Object, CreationalContext)}.
* Returns {@code null} if {@code destroy} was not called yet.
*
* @return the instance passed to {@link Contextual#destroy(Object, CreationalContext)}
*/
public T getInstancePassedToDestroy();

/**
* Returns the {@link CreationalContext} passed to {@link Contextual#destroy(Object, CreationalContext)}.
* Returns {@code null} if {@code destroy} was not called yet.
*
* @return the {@link CreationalContext} passed to {@link Contextual#destroy(Object, CreationalContext)}
*/
public CreationalContext<T> getCreationalContextPassedToDestroy();
}

}
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.Contextuals+
* +org.jboss.cdi.tck.spi.CreationalContexts+
* +org.jboss.cdi.tck.spi.EL+

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.Contextuals>org.jboss.cdi.tck.test.porting.DummyContextuals</org.jboss.cdi.tck.spi.Contextuals>
<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>
Expand Down
5 changes: 5 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 @@ -40,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.Contextuals;
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 @@ -100,6 +101,10 @@ protected <T> CreationalContexts.Inspectable<T> createInspectableCreationalConte
return getCurrentConfiguration().getCreationalContexts().create(contextual);
}

protected <T> Contextuals.Inspectable<T> createInspectableContextual(T instance, Context context) {
return getCurrentConfiguration().getContextuals().create(instance, context);
}

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.Contextuals;
import org.jboss.cdi.tck.spi.CreationalContexts;
import org.jboss.cdi.tck.spi.EL;

Expand All @@ -36,6 +37,7 @@ public class ConfigurationImpl implements Configuration {

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

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

public Contextuals getContextuals() {
return contextuals;
}

public void setContextuals(Contextuals contextuals) {
this.contextuals = contextuals;
}

public CreationalContexts getCreationalContexts() {
return creationalContexts;
}
Expand Down Expand Up @@ -159,6 +169,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("\tContextuals: ").append(getContextuals()).append("\n");
configuration.append("\tCreationalContexts: ").append(getCreationalContexts()).append("\n");
configuration.append("\tEL: ").append(getEl()).append("\n");
configuration.append("\tLibrary dir: ").append(getLibraryDirectory()).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.Contextuals;
import org.jboss.cdi.tck.spi.CreationalContexts;
import org.jboss.cdi.tck.spi.EL;

Expand Down Expand Up @@ -67,6 +68,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.setContextuals(getInstanceValue(Contextuals.PROPERTY_NAME, Contextuals.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
@@ -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.Context;
import org.jboss.cdi.tck.spi.Contextuals;

public class DummyContextuals implements Contextuals {
@Override
public <T> Inspectable<T> create(T instance, Context context) {
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.Contextuals>org.jboss.cdi.tck.test.porting.DummyContextuals</org.jboss.cdi.tck.spi.Contextuals>
<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>
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.Context;
import org.jboss.cdi.tck.spi.Contextuals;

public class DummyContextuals implements Contextuals {
@Override
public <T> Inspectable<T> create(T instance, Context context) {
throw new UnsupportedOperationException();
}
}

0 comments on commit 7bda688

Please sign in to comment.