Java Code Examples for javax.ws.rs.core.Configurable#getConfiguration()

The following examples show how to use javax.ws.rs.core.Configurable#getConfiguration() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfigurationImplTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test 
public void testIsEnabledWithMultipleFeaturesOfSameType() {
    FeatureContextImpl featureContext = new FeatureContextImpl();
    Configurable<FeatureContext> configurable = new ConfigurableImpl<>(featureContext, RuntimeType.SERVER);
    featureContext.setConfigurable(configurable);

    featureContext.register(new DisablableFeature());
    featureContext.register(new DisablableFeature());
    featureContext.register(new DisablableFeature());

    Configuration config = configurable.getConfiguration();
    assertEquals(3, config.getInstances().size());
    assertFalse(config.isEnabled(DisablableFeature.class));

    DisablableFeature enabledFeature = new DisablableFeature();
    enabledFeature.enabled = true;

    featureContext.register(enabledFeature);
    assertEquals(4, config.getInstances().size());
    assertTrue(config.isEnabled(DisablableFeature.class));

    featureContext.register(new DisablableFeature());
    assertEquals(5, config.getInstances().size());
    assertTrue(config.isEnabled(DisablableFeature.class));
}
 
Example 2
Source File: ConfigurationImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testSubClassIsRegisteredOnConfigurable() {
    FeatureContextImpl featureContext = new FeatureContextImpl();
    Configurable<FeatureContext> configurable = new ConfigurableImpl<>(featureContext, RuntimeType.SERVER);
    featureContext.setConfigurable(configurable);
    featureContext.register(ContainerResponseFilterSubClassImpl.class);
    Configuration config = configurable.getConfiguration();
    Map<Class<?>, Integer> contracts = config.getContracts(ContainerResponseFilter.class);
    assertEquals(1, contracts.size());
    assertTrue(contracts.containsKey(ContainerResponseFilter.class));
}
 
Example 3
Source File: ConfigurationImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testClientFilterContractsOnServerFeatureIsRejected() {
    FeatureContextImpl featureContext = new FeatureContextImpl();
    Configurable<FeatureContext> configurable = new ConfigurableImpl<>(featureContext, RuntimeType.SERVER);
    featureContext.setConfigurable(configurable);
    featureContext.register(TestFilter.class);
    Configuration config = configurable.getConfiguration();
    Map<Class<?>, Integer> contracts = config.getContracts(TestFilter.class);
    assertFalse(contracts.containsKey(ClientRequestFilter.class));
    assertFalse(contracts.containsKey(ClientResponseFilter.class));
    assertTrue(contracts.containsKey(ContainerRequestFilter.class));
    assertTrue(contracts.containsKey(ContainerResponseFilter.class));
}
 
Example 4
Source File: ConfigurationImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testFeatureDisabledClass() {
    FeatureContextImpl featureContext = new FeatureContextImpl();
    Configurable<FeatureContext> configurable = new ConfigurableImpl<>(featureContext, RuntimeType.SERVER);
    featureContext.setConfigurable(configurable);
    featureContext.register(DisablableFeature.class);

    Configuration config = configurable.getConfiguration();
    assertFalse(config.isEnabled(DisablableFeature.class));
}
 
Example 5
Source File: ConfigurationImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testFeatureDisabledInstance() {
    FeatureContextImpl featureContext = new FeatureContextImpl();
    Configurable<FeatureContext> configurable = new ConfigurableImpl<>(featureContext, RuntimeType.SERVER);
    featureContext.setConfigurable(configurable);
    Feature feature = new DisablableFeature();
    featureContext.register(feature);

    Configuration config = configurable.getConfiguration();
    assertFalse(config.isEnabled(feature));
}