Package org.apache.wink.common.internal.registry

Examples of org.apache.wink.common.internal.registry.ProvidersRegistry$ProviderRecord


            public String getFilterName() {
                return getServletName();
            }
        });

        ProvidersRegistry providers = config.getProvidersRegistry();
        providers.addProvider(new DataBindingJAXRSReader(registry), 0.001, true);
        providers.addProvider(new DataBindingJAXRSWriter(registry), 0.001, true);

        return config;
    }
View Full Code Here


            return Collections.emptyList();
        }
    }

    private ProvidersRegistry createProvidersRegistryImpl() {
        ProvidersRegistry providers =
            new ProvidersRegistry(new LifecycleManagersRegistry(), new ApplicationValidator());
        ;
        return providers;
    }
View Full Code Here

        ;
        return providers;
    }

    public void testContextResolvers() {
        ProvidersRegistry providers = createProvidersRegistryImpl();
        assertTrue(providers.addProvider(new AtomContextResolver()));
        assertTrue(providers.addProvider(new StringContextResolver()));
        assertTrue(providers.addProvider(new IntegerContextResolver()));
        assertTrue(providers.addProvider(new ByteContextResolver()));
        assertTrue(providers.addProvider(new ListContextResolver()));

        try {
            providers.addProvider(new NotAProvider());
            fail("expected IllegalArgumentException");
        } catch (IllegalArgumentException e) {
        }

        /*
         * String and text/pain, should invoke StringContextResolver
         */
        assertEquals(STRING, providers.getContextResolver(String.class,
                                                          MediaType.TEXT_PLAIN_TYPE,
                                                          null).getContext(null));

        /*
         * byte[] and text/plain, should invoke ByteContextResolver
         */
        assertEquals(BYTE, providers.getContextResolver(byte[].class,
                                                        MediaType.TEXT_PLAIN_TYPE,
                                                        null).getContext(null));

        /*
         * There is no context resolver that handlers Integer and /
         */
        assertEquals(_12345, providers.getContextResolver(Integer.class,
                                                          MediaType.WILDCARD_TYPE,
                                                          null).getContext(null));

        /*
         * AtomContextResolver comes before StringContextResolver, therefore it
         * should be invoked after
         */
        assertEquals(ATOM, providers
            .getContextResolver(String.class, MediaType.WILDCARD_TYPE, null).getContext(null));

        /*
         * AtomContextResolver returns null, if the parameter is not null,
         * therefore StringContextResolver should be invoked
         */
        assertEquals(STRING, providers.getContextResolver(String.class,
                                                          MediaType.WILDCARD_TYPE,
                                                          null).getContext(String.class));

        /*
         * test ContextResolver with collections
         */
        assertEquals(Collections.emptyList(), providers.getContextResolver(List.class,
                                                                           MediaType.WILDCARD_TYPE,
                                                                           null).getContext(null));
    }
View Full Code Here

                                                                           MediaType.WILDCARD_TYPE,
                                                                           null).getContext(null));
    }

    public void testContextResolverWildCards() {
        ProvidersRegistry providers = createProvidersRegistryImpl();
        assertTrue(providers.addProvider(new MyContextResolver()));
        assertTrue(providers.addProvider(new StringContextResolver3()));

        /*
         * Check various wildcard permutations
         */
        assertSame(MYCLASS, providers.getContextResolver(MyClass.class,
                                                         MediaType.WILDCARD_TYPE,
                                                         null).getContext(MyClass.class));
        assertSame(MYCLASS, providers.getContextResolver(MyClass.class,
                                                         new MediaType("*", "*"),
                                                         null).getContext(MyClass.class));
        assertSame(MYCLASS, providers.getContextResolver(MyClass.class,
                                                         new MediaType("application", "*"),
                                                         null).getContext(MyClass.class));
        assertSame(MYCLASS, providers.getContextResolver(MyClass.class,
                                                         new MediaType("application",
                                                                       "x-www-form-urlencoded"),
                                                         null).getContext(MyClass.class));
        assertSame(MYCLASS, providers
            .getContextResolver(MyClass.class, new MediaType("*", "x-www-form-urlencoded"), null)
            .getContext(MyClass.class));

        // should hit an exact match when search expands out to "text/*"
        assertSame(STRING3, providers.getContextResolver(String.class,
                                                         new MediaType("text", "blarg"),
                                                         null).getContext(String.class));
    }
View Full Code Here

                                                         new MediaType("text", "blarg"),
                                                         null).getContext(String.class));
    }

    public void testContextResolverSortingAlgorithm() {
        ProvidersRegistry providers = createProvidersRegistryImpl();
        // note: the order these are added is important to the test
        assertTrue(providers.addProvider(new StringContextResolver4()));
        assertTrue(providers.addProvider(new StringContextResolver3()));
        assertTrue(providers.addProvider(new StringContextResolver2()));

        // StringContextResolver2 takes priority over the others due to the
        // media type in @Produces
        assertSame(STRING2, providers.getContextResolver(String.class,
                                                         new MediaType("text", "*"),
                                                         null).getContext(String.class));

        // StringContextResolver2 takes priority over the others due to the
        // media type in @Produces
        assertSame(STRING2, providers.getContextResolver(String.class,
                                                         new MediaType("*", "*"),
                                                         null).getContext(String.class));

        // StringContextResolver2 takes priority over the others due to the
        // media type in @Produces
        assertSame(STRING2, providers.getContextResolver(String.class,
                                                         new MediaType("text", "plain"),
                                                         null).getContext(String.class));
    }
View Full Code Here

    @Provider
    private static class String2Provider extends StringProvider {
    }

    private ProvidersRegistry createProvidersRegistryImpl() {
        ProvidersRegistry providers =
            new ProvidersRegistry(new LifecycleManagersRegistry(), new ApplicationValidator());
        return providers;
    }
View Full Code Here

            new ProvidersRegistry(new LifecycleManagersRegistry(), new ApplicationValidator());
        return providers;
    }

    public void testMessageBodyWriters() {
        ProvidersRegistry providers = createProvidersRegistryImpl();

        ByteArrayProvider byteArrayProvider = new ByteArrayProvider();
        InputStreamProvider inputStreamProvider = new InputStreamProvider();
        StringProvider stringProvider = new StringProvider();
        String2Provider string2Provider = new String2Provider();
        FileProvider fileProvider = new FileProvider();
        IntegerMessageBodyProvider objectMessageBodyProvider = new IntegerMessageBodyProvider();

        providers.addProvider(byteArrayProvider);
        providers.addProvider(inputStreamProvider);
        providers.addProvider(string2Provider);
        providers.addProvider(stringProvider);
        providers.addProvider(fileProvider);
        providers.addProvider(objectMessageBodyProvider);

        assertEquals(byteArrayProvider, providers
            .getMessageBodyReader(byte[].class, null, null, MediaType.APPLICATION_JSON_TYPE, null));
        assertEquals(stringProvider, providers.getMessageBodyReader(String.class,
                                                                    null,
                                                                    null,
                                                                    MediaType.WILDCARD_TYPE,
                                                                    null));
        assertEquals(fileProvider, providers
            .getMessageBodyReader(File.class, null, null, MediaType.APPLICATION_SVG_XML_TYPE, null));

        assertEquals(byteArrayProvider, providers
            .getMessageBodyWriter(byte[].class,
                                  null,
                                  null,
                                  MediaType.APPLICATION_ATOM_XML_TYPE,
                                  null));
        assertEquals(stringProvider, providers.getMessageBodyWriter(String.class,
                                                                    null,
                                                                    null,
                                                                    MediaType.WILDCARD_TYPE,
                                                                    null));
        assertEquals(fileProvider, providers
            .getMessageBodyWriter(File.class, null, null, MediaType.APPLICATION_SVG_XML_TYPE, null));

        assertEquals(IntegerMessageBodyProvider.class, providers
            .getMessageBodyWriter(Integer.class, null, null, MediaType.WILDCARD_TYPE, null)
            .getClass());
    }
View Full Code Here

            .getMessageBodyWriter(Integer.class, null, null, MediaType.WILDCARD_TYPE, null)
            .getClass());
    }

    public void testMessageBodyWritersMediaTypes() {
        ProvidersRegistry providers = createProvidersRegistryImpl();

        ByteArrayProvider byteArrayProvider = new ByteArrayProvider();
        InputStreamProvider inputStreamProvider = new InputStreamProvider();
        StringProvider stringProvider = new StringProvider();
        String2Provider string2Provider = new String2Provider();
        FileProvider fileProvider = new FileProvider();
        IntegerMessageBodyProvider objectMessageBodyProvider = new IntegerMessageBodyProvider();

        providers.addProvider(byteArrayProvider);
        providers.addProvider(inputStreamProvider);
        providers.addProvider(string2Provider, 0.6);
        providers.addProvider(stringProvider);
        providers.addProvider(fileProvider);
        providers.addProvider(objectMessageBodyProvider);

        Set<MediaType> integerWriterMediaType =
            providers.getMessageBodyWriterMediaTypes(Integer.class);
        assertTrue(integerWriterMediaType.contains(MediaType.WILDCARD_TYPE));
        assertTrue(integerWriterMediaType.contains(MediaType.TEXT_PLAIN_TYPE));
        Set<MediaType> stringWriterMediaTypes =
            providers.getMessageBodyWriterMediaTypes(String.class);
        assertTrue(stringWriterMediaTypes.contains(MediaType.WILDCARD_TYPE));
        Set<MediaType> ioWriterMediaTypes =
            providers.getMessageBodyWriterMediaTypes(InputStream.class);
        assertTrue(ioWriterMediaTypes.contains(MediaType.WILDCARD_TYPE));
        assertTrue(ioWriterMediaTypes.contains(MediaType.APPLICATION_OCTET_STREAM_TYPE));
    }
View Full Code Here

TOP

Related Classes of org.apache.wink.common.internal.registry.ProvidersRegistry$ProviderRecord

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.