/*
 * Copyright 2006-2007 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.openspaces.utest.remoting;

import java.lang.reflect.Method;
import java.util.Map;

import com.gigaspaces.internal.reflection.IMethod;
import junit.framework.TestCase;
import org.openspaces.remoting.RemotingUtils;
import org.openspaces.remoting.RemotingUtils.MethodHash;

/**
 * GS-8294: Methods of a Remoting Service interface are not included when it extends from another interface
 * @author moran
 */
public class RemotingUtilsTests extends TestCase {

    @Override
    protected void setUp() throws Exception {
    }

    public void testFastReflection() {
        fastReflection(true);
    }
    
    public void testStandardReflection() {
        fastReflection(false);
    }
    
    private void fastReflection(boolean fastReflection) {
        Map<MethodHash, IMethod> mapA = RemotingUtils.buildHashToMethodLookupForInterface(A.class, fastReflection);
        assertEquals(1, mapA.values().size());
        
        Map<MethodHash, IMethod> mapB = RemotingUtils.buildHashToMethodLookupForInterface(B.class, fastReflection);
        assertEquals(2, mapB.values().size());
        
        Map<MethodHash, IMethod> mapC = RemotingUtils.buildHashToMethodLookupForInterface(C.class, fastReflection);
        assertEquals(2, mapC.values().size());
    }
    
    public void testBuildMethodToHashLookupForInterface() {
        Map<Method, MethodHash> mapA = RemotingUtils.buildMethodToHashLookupForInterface(A.class, "asyncPrefix");
        assertEquals(1, mapA.values().size());
        
        Map<Method, MethodHash> mapB = RemotingUtils.buildMethodToHashLookupForInterface(B.class, "asyncPrefix");
        assertEquals(2, mapB.values().size());
        
        Map<Method, MethodHash> mapC = RemotingUtils.buildMethodToHashLookupForInterface(C.class, "asyncPrefix");
        assertEquals(2, mapC.values().size());
    }
    
    public interface A {
        String a(String s);
    }
    
    public interface B extends A {
        String b(String s);
    }
    
    public interface C extends B {
    }
}

Test RemotingUtils.buildMethodToHashLookupForInterface which calls RemotingUtils.getAllInterfacesForInterface with the relevant change in interface hierarchy.
GS-8294: Test RemotingUtils.buildMethodToHashLookupForInterface which calls RemotingUtils.getAllInterfacesForInterface with the relevant change in interface hierarchy.

svn path=/trunk/openspaces/; revision=76211


Former-commit-id: 61f23ca90143c422ae5a470a53961765f42aec9b