Search in sources :

Example 1 with ClassBinding

use of org.glassfish.jersey.internal.inject.ClassBinding in project jersey by jersey.

the class AbstractBinderTest method testWithInstall.

@Test
public void testWithInstall() {
    AbstractBinder internalBinder = new AbstractBinder() {

        @Override
        protected void configure() {
            bind(MediaTypeProvider.class).to(HeaderDelegateProvider.class).in(Singleton.class);
            bind(NewCookieProvider.class).to(HeaderDelegateProvider.class).in(Singleton.class);
            bind(StringHeaderProvider.class).to(HeaderDelegateProvider.class).in(Singleton.class);
            bind(UriProvider.class).to(HeaderDelegateProvider.class).in(Singleton.class);
        }
    };
    AbstractBinder binder = new AbstractBinder() {

        @Override
        protected void configure() {
            bind(CacheControlProvider.class).to(HeaderDelegateProvider.class).in(Singleton.class);
            bind(CookieProvider.class).to(HeaderDelegateProvider.class).in(Singleton.class);
            bind(DateProvider.class).to(HeaderDelegateProvider.class).in(Singleton.class);
            bind(EntityTagProvider.class).to(HeaderDelegateProvider.class).in(Singleton.class);
            bind(LinkProvider.class).to(HeaderDelegateProvider.class).in(Singleton.class);
            install(internalBinder);
        }
    };
    List<Binding> bindings = new ArrayList<>(binder.getBindings());
    assertEquals(9, bindings.size());
    // Keep ordering.
    assertEquals(MediaTypeProvider.class, ((ClassBinding) bindings.get(0)).getService());
    assertEquals(NewCookieProvider.class, ((ClassBinding) bindings.get(1)).getService());
    assertEquals(StringHeaderProvider.class, ((ClassBinding) bindings.get(2)).getService());
    assertEquals(UriProvider.class, ((ClassBinding) bindings.get(3)).getService());
    assertEquals(CacheControlProvider.class, ((ClassBinding) bindings.get(4)).getService());
    assertEquals(CookieProvider.class, ((ClassBinding) bindings.get(5)).getService());
    assertEquals(DateProvider.class, ((ClassBinding) bindings.get(6)).getService());
    assertEquals(EntityTagProvider.class, ((ClassBinding) bindings.get(7)).getService());
    assertEquals(LinkProvider.class, ((ClassBinding) bindings.get(8)).getService());
}
Also used : Binding(org.glassfish.jersey.internal.inject.Binding) ClassBinding(org.glassfish.jersey.internal.inject.ClassBinding) HeaderDelegateProvider(org.glassfish.jersey.spi.HeaderDelegateProvider) AbstractBinder(org.glassfish.jersey.internal.inject.AbstractBinder) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with ClassBinding

use of org.glassfish.jersey.internal.inject.ClassBinding in project jersey by jersey.

the class AbstractBinderTest method testFirstLayer.

@Test
public void testFirstLayer() {
    AbstractBinder binder = new AbstractBinder() {

        @Override
        protected void configure() {
            bind(CacheControlProvider.class).to(HeaderDelegateProvider.class).in(Singleton.class);
            bind(CookieProvider.class).to(HeaderDelegateProvider.class).in(Singleton.class);
            bind(DateProvider.class).to(HeaderDelegateProvider.class).in(Singleton.class);
            bind(EntityTagProvider.class).to(HeaderDelegateProvider.class).in(Singleton.class);
            bind(LinkProvider.class).to(HeaderDelegateProvider.class).in(Singleton.class);
        }
    };
    List<Binding> bindings = new ArrayList<>(binder.getBindings());
    assertEquals(5, bindings.size());
    // Keep ordering.
    assertEquals(CacheControlProvider.class, ((ClassBinding) bindings.get(0)).getService());
    assertEquals(CookieProvider.class, ((ClassBinding) bindings.get(1)).getService());
    assertEquals(DateProvider.class, ((ClassBinding) bindings.get(2)).getService());
    assertEquals(EntityTagProvider.class, ((ClassBinding) bindings.get(3)).getService());
    assertEquals(LinkProvider.class, ((ClassBinding) bindings.get(4)).getService());
}
Also used : Binding(org.glassfish.jersey.internal.inject.Binding) ClassBinding(org.glassfish.jersey.internal.inject.ClassBinding) HeaderDelegateProvider(org.glassfish.jersey.spi.HeaderDelegateProvider) AbstractBinder(org.glassfish.jersey.internal.inject.AbstractBinder) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)2 AbstractBinder (org.glassfish.jersey.internal.inject.AbstractBinder)2 Binding (org.glassfish.jersey.internal.inject.Binding)2 ClassBinding (org.glassfish.jersey.internal.inject.ClassBinding)2 HeaderDelegateProvider (org.glassfish.jersey.spi.HeaderDelegateProvider)2 Test (org.junit.Test)2