Search in sources :

Example 1 with DynamicFeature

use of jakarta.ws.rs.container.DynamicFeature in project resteasy by resteasy.

the class ClientDynamicFeaturesTest method testDynamicFeatures.

/**
 * @tpTestDetails Check dynamic feature counts.
 * @tpSince RESTEasy 3.0.16
 */
@Test
public void testDynamicFeatures() throws Exception {
    ResteasyProviderFactory factory = ResteasyProviderFactory.newInstance();
    RegisterBuiltin.register(factory);
    factory.registerProvider(ClientDynamicFeaturesClientFeature1.class, 0, false, null);
    factory.registerProvider(ClientDynamicFeaturesServerFeature1.class, 0, false, null);
    factory.registerProvider(ClientDynamicFeaturesDualFeature1.class, 0, false, null);
    ClientDynamicFeaturesClientFeature2 clientFeature = new ClientDynamicFeaturesClientFeature2();
    ClientDynamicFeaturesServerFeature2 serverFeature = new ClientDynamicFeaturesServerFeature2();
    ClientDynamicFeaturesDualFeature2 feature = new ClientDynamicFeaturesDualFeature2();
    factory.registerProviderInstance(clientFeature, null, 0, false);
    factory.registerProviderInstance(serverFeature, null, 0, false);
    factory.registerProviderInstance(feature, null, 0, false);
    Set<DynamicFeature> clientFeatureSet = factory.getClientDynamicFeatures();
    Set<DynamicFeature> serverFeatureSet = factory.getServerDynamicFeatures();
    Assert.assertEquals(CLIENT_FEATURE_ERROR_MSG, 1, countFeatures(clientFeatureSet, "ClientDynamicFeaturesClientFeature1"));
    Assert.assertEquals(CLIENT_FEATURE_ERROR_MSG, 1, countFeatures(clientFeatureSet, "ClientDynamicFeaturesClientFeature2"));
    Assert.assertEquals(CLIENT_FEATURE_ERROR_MSG, 1, countFeatures(clientFeatureSet, "ClientDynamicFeaturesDualFeature1"));
    Assert.assertEquals(CLIENT_FEATURE_ERROR_MSG, 1, countFeatures(clientFeatureSet, "ClientDynamicFeaturesDualFeature2"));
    Assert.assertEquals(SERVER_FEATURE_ERROR_MSG, 1, countFeatures(serverFeatureSet, "ClientDynamicFeaturesServerFeature1"));
    Assert.assertEquals(SERVER_FEATURE_ERROR_MSG, 1, countFeatures(serverFeatureSet, "ClientDynamicFeaturesServerFeature2"));
    Assert.assertEquals(SERVER_FEATURE_ERROR_MSG, 1, countFeatures(serverFeatureSet, "ClientDynamicFeaturesDualFeature1"));
    Assert.assertEquals(SERVER_FEATURE_ERROR_MSG, 1, countFeatures(serverFeatureSet, "ClientDynamicFeaturesDualFeature2"));
}
Also used : ClientDynamicFeaturesClientFeature2(org.jboss.resteasy.test.client.resource.ClientDynamicFeaturesClientFeature2) ClientDynamicFeaturesServerFeature2(org.jboss.resteasy.test.client.resource.ClientDynamicFeaturesServerFeature2) ClientDynamicFeaturesDualFeature2(org.jboss.resteasy.test.client.resource.ClientDynamicFeaturesDualFeature2) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) DynamicFeature(jakarta.ws.rs.container.DynamicFeature) Test(org.junit.Test)

Example 2 with DynamicFeature

use of jakarta.ws.rs.container.DynamicFeature in project minijax by minijax.

the class MinijaxApplication method addResourceMethod.

public void addResourceMethod(final MinijaxResourceMethod rm) {
    for (final DynamicFeature dynamicFeature : dynamicFeatures) {
        dynamicFeature.configure(rm, this);
    }
    resourceMethods.add(rm);
    MinijaxResourceMethod.sortByLiteralLength(resourceMethods);
}
Also used : DynamicFeature(jakarta.ws.rs.container.DynamicFeature)

Example 3 with DynamicFeature

use of jakarta.ws.rs.container.DynamicFeature in project resteasy by resteasy.

the class ProviderFactoryTest method testDeploymentStart.

@Test
public void testDeploymentStart() {
    ResteasyProviderFactory orig = ResteasyProviderFactory.peekInstance();
    try {
        ResteasyProviderFactory.setInstance(null);
        ResteasyProviderFactory rpf1 = ResteasyProviderFactory.newInstance();
        RegisterBuiltin.register(rpf1);
        rpf1.registerProvider(MyInterceptor.class);
        ResteasyDeployment dep1 = new ResteasyDeploymentImpl();
        dep1.setProviderFactory(rpf1);
        dep1.setDeploymentSensitiveFactoryEnabled(true);
        dep1.start();
        ResteasyProviderFactory rpf2 = ResteasyProviderFactory.newInstance();
        RegisterBuiltin.register(rpf2);
        rpf2.register(new DynamicFeature() {

            @Override
            public void configure(ResourceInfo resourceInfo, FeatureContext context) {
                if (ResteasyProviderFactory.getInstance().isRegistered(MyInterceptor.class)) {
                    Assert.fail("Second deployment consuming provider factory from first deployment");
                }
            }
        });
        ResteasyDeployment dep2 = new ResteasyDeploymentImpl();
        dep2.setProviderFactory(rpf2);
        dep2.setDeploymentSensitiveFactoryEnabled(true);
        dep2.start();
        dep1.stop();
        dep2.stop();
    } finally {
        ResteasyProviderFactory.setInstance(orig);
    }
}
Also used : ResteasyDeployment(org.jboss.resteasy.spi.ResteasyDeployment) ResourceInfo(jakarta.ws.rs.container.ResourceInfo) ResteasyDeploymentImpl(org.jboss.resteasy.core.ResteasyDeploymentImpl) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) DynamicFeature(jakarta.ws.rs.container.DynamicFeature) FeatureContext(jakarta.ws.rs.core.FeatureContext) Test(org.junit.Test)

Aggregations

DynamicFeature (jakarta.ws.rs.container.DynamicFeature)3 ResteasyProviderFactory (org.jboss.resteasy.spi.ResteasyProviderFactory)2 Test (org.junit.Test)2 ResourceInfo (jakarta.ws.rs.container.ResourceInfo)1 FeatureContext (jakarta.ws.rs.core.FeatureContext)1 ResteasyDeploymentImpl (org.jboss.resteasy.core.ResteasyDeploymentImpl)1 ResteasyDeployment (org.jboss.resteasy.spi.ResteasyDeployment)1 ClientDynamicFeaturesClientFeature2 (org.jboss.resteasy.test.client.resource.ClientDynamicFeaturesClientFeature2)1 ClientDynamicFeaturesDualFeature2 (org.jboss.resteasy.test.client.resource.ClientDynamicFeaturesDualFeature2)1 ClientDynamicFeaturesServerFeature2 (org.jboss.resteasy.test.client.resource.ClientDynamicFeaturesServerFeature2)1