@@ -0,0 +1,3487 @@
+/*******************************************************************************%0A * Licensed to the Apache Software Foundation (ASF) under one%0A * or more contributor license agreements.  See the NOTICE file%0A * distributed with this work for additional information%0A * regarding copyright ownership.  The ASF licenses this file%0A * to you under the Apache License, Version 2.0 (the%0A * %22License%22); you may not use this file except in compliance%0A * with the License.  You may obtain a copy of the License at%0A *  %0A *   http://www.apache.org/licenses/LICENSE-2.0%0A *  %0A *  Unless required by applicable law or agreed to in writing,%0A *  software distributed under the License is distributed on an%0A *  %22AS IS%22 BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY%0A *  KIND, either express or implied.  See the License for the%0A *  specific language governing permissions and limitations%0A *  under the License.%0A *  %0A *******************************************************************************/%0Apackage org.apache.wink.common.internal.registry;%0A%0Aimport java.lang.reflect.Field;%0Aimport java.util.concurrent.ConcurrentHashMap;%0A%0Aimport junit.framework.TestCase;%0A%0Aimport org.apache.wink.common.internal.application.ApplicationValidator;%0Aimport org.apache.wink.common.internal.lifecycle.LifecycleManagersRegistry;%0A%0Apublic class ProvidersRegistryTest extends TestCase %7B%0A    %0A    /**%0A     * Tests that the providersCache object is and remains instanceof ConcurrentHashMap.  %0A     * %0A     * ProvidersRegistry.MediaTypeMap uses type ConcurrentHashMap on the providersCache object to provide some lock protection on%0A     * the map when providers are dynamically added.  However, lock protection is already built into the ProvidersRegistry methods:%0A     * getContextResolver(), getMessageBodyReader(), and getMessageBodyWriter().%0A     * %0A     * However, the second protection (in the ProvidersRegistry methods) is for the cache itself which could be written to by two%0A     * different threads even if they both were getting a single MessageBodyReader (i.e. a cache value may be dropped and then two%0A     * threads come back later and try to write a new cache value).  Due to some weird HashMap properties, this can blow up in%0A     * weird ways.%0A     * %0A     * Thus, we need to ensure the providersCache continues to be instantiated with ConcurrentHashMap.%0A     */%0A    public void testProtectionModel() throws Exception %7B%0A%0A        // I need the instantiated object providersCache in the abstract private nested class MediaTypeMap, so here we go!%0A        ProvidersRegistry providersRegistry = new ProvidersRegistry(new LifecycleManagersRegistry(), new ApplicationValidator());%0A        Field field = providersRegistry.getClass().getDeclaredField(%22messageBodyReaders%22);%0A        field.setAccessible(true);%0A        Object messageBodyReaders = field.get(providersRegistry);%0A        System.out.println(messageBodyReaders.getClass().getSuperclass().getName());%0A        Field field2 = messageBodyReaders.getClass().getSuperclass().getDeclaredField(%22providersCache%22);%0A        field2.setAccessible(true);%0A        Object providersCache = field2.get(messageBodyReaders);%0A        %0A        assertTrue(providersCache instanceof ConcurrentHashMap);    %0A    %7D%0A    %0A    // TODO:  perhaps future tests should be added to actually exercise the providersCache code, but it would be an involved,%0A    // multi-threaded test that dynamically adds providers at just the right time to ensure no problems with%0A    // concurrent writes.%0A    %0A%7D%0A

Test to ensure map types in ProvidersRegistry