Search in sources :

Example 1 with ProviderCircularReferenceException

use of org.apache.openejb.config.provider.ProviderCircularReferenceException in project tomee by apache.

the class ProviderManagerTest method testCircularDependency.

public void testCircularDependency() throws Exception {
    final ProviderManager manager = new ProviderManager(new ProviderLoader() {

        @Override
        public ServiceProvider load(final ID id) {
            if ("color".equalsIgnoreCase(id.getName())) {
                final ServiceProvider color = new ServiceProvider(Color.class, "Color", "Resource");
                color.setParent("Orange");
                color.getProperties().setProperty("red", "0");
                color.getProperties().setProperty("green", "0");
                color.getProperties().setProperty("blue", "0");
                return color;
            }
            if ("red".equalsIgnoreCase(id.getName())) {
                final ServiceProvider red = new ServiceProvider();
                red.setId("Red");
                red.setParent("Color");
                red.getProperties().setProperty("red", "255");
                return red;
            }
            if ("orange".equalsIgnoreCase(id.getName())) {
                final ServiceProvider orange = new ServiceProvider();
                orange.setId("Orange");
                orange.setParent("Red");
                orange.getProperties().setProperty("green", "200");
                return orange;
            }
            throw new IllegalStateException(id.toString());
        }

        @Override
        public List<ServiceProvider> load(final String namespace) {
            return null;
        }
    });
    assertEquals(0, manager.getAll().size());
    try {
        manager.get("dEFAUlT", "orAngE");
        fail("ProviderCircularReferenceException should have been thrown");
    } catch (final ProviderCircularReferenceException e) {
    // pass
    }
}
Also used : ProviderManager(org.apache.openejb.config.provider.ProviderManager) ServiceProvider(org.apache.openejb.config.sys.ServiceProvider) ProviderCircularReferenceException(org.apache.openejb.config.provider.ProviderCircularReferenceException) List(java.util.List) ArrayList(java.util.ArrayList) ID(org.apache.openejb.config.provider.ID) ProviderLoader(org.apache.openejb.config.provider.ProviderLoader)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 ID (org.apache.openejb.config.provider.ID)1 ProviderCircularReferenceException (org.apache.openejb.config.provider.ProviderCircularReferenceException)1 ProviderLoader (org.apache.openejb.config.provider.ProviderLoader)1 ProviderManager (org.apache.openejb.config.provider.ProviderManager)1 ServiceProvider (org.apache.openejb.config.sys.ServiceProvider)1