Package org.jboss.test.aspects.remoting

Source Code of org.jboss.test.aspects.remoting.ClusteredPojiProxyUnitTestCase

/*
* JBoss, Home of Professional Open Source.
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.jboss.test.aspects.remoting;

import java.util.Arrays;
import java.util.List;

import junit.framework.TestCase;

import org.jboss.aop.Dispatcher;
import org.jboss.aop.advice.Interceptor;
import org.jboss.aop.metadata.SimpleMetaData;
import org.jboss.aspects.remoting.ClusterConstants;
import org.jboss.aspects.remoting.ClusteredPojiProxy;
import org.jboss.aspects.remoting.FamilyWrapper;
import org.jboss.aspects.remoting.InvokeRemoteInterceptor;
import org.jboss.ha.client.loadbalance.LoadBalancePolicy;
import org.jboss.ha.client.loadbalance.RoundRobin;
import org.jboss.remoting.InvokerLocator;

/**
* Unit tests for {@link ClusteredPojiProxy}.
*
* @author Brian Stansberry
*
*/
public class ClusteredPojiProxyUnitTestCase extends TestCase
{
   protected static final String[] TARGETS = { "A", "B", "C" };
   protected static final String FAMILY_BASE = "ClusteredPojiProxy";
   protected static final String MOCK_URI = "http://localhost";
   protected static final String OK = "OK";
   protected static int testCount = 0;
  
   /**
    * Create a new ClusteredPojiProxyUnitTestCase.
    *
    * @param name
    */
   public ClusteredPojiProxyUnitTestCase(String name)
   {
      super(name);
   }

   /**
    * Tests that the proxy sets the expected metadata
    */
   public void testInvocationMetaData() throws Throwable
   {
      invocationMetaDataTest(TARGETS[0]);
   }

   /**
    * Tests that the proxy sets the expected metadata when no originTarget
    * is provided.
    */
   public void testNullOriginTarget() throws Throwable
   {
      invocationMetaDataTest(null);
   }
  
   private void invocationMetaDataTest(Object originTarget) throws Throwable
   {
      testCount++;
      List<String> targets = Arrays.asList(TARGETS);
      FamilyWrapper wrapper = new FamilyWrapper(FAMILY_BASE + testCount, targets);
     
      MockNextInterceptor interceptor = new MockNextInterceptor();
      interceptor.setReturnValue(OK);
     
      Object oid = new Object();
      LoadBalancePolicy lbp = new RoundRobin();
      InvokerLocator uri = new InvokerLocator(MOCK_URI);
      ClusteredPojiProxy proxy = new ClusteredPojiProxy(oid, uri, new Interceptor[]{interceptor}, wrapper, lbp, FAMILY_BASE, originTarget);
     
      assertEquals(OK, proxy.invoke(this, Object.class.getDeclaredMethod("toString", new Class[]{}), new Object[]{}));
     
      List<SimpleMetaData> history = interceptor.getInvocationHistory();
      SimpleMetaData metadata = history.get(0);
      assertSame(wrapper, metadata.getMetaData(ClusterConstants.CLUSTERED_REMOTING, ClusterConstants.CLUSTER_FAMILY_WRAPPER));
      assertSame(lbp, metadata.getMetaData(ClusterConstants.CLUSTERED_REMOTING, ClusterConstants.LOADBALANCE_POLICY));
      assertSame(FAMILY_BASE, metadata.getMetaData(ClusterConstants.CLUSTERED_REMOTING, ClusterConstants.PARTITION_NAME));
      assertSame(originTarget, metadata.getMetaData(ClusterConstants.CLUSTERED_REMOTING, ClusterConstants.HA_TARGET));
      assertSame(oid, metadata.getMetaData(Dispatcher.DISPATCHER, Dispatcher.OID));
      assertSame(uri, metadata.getMetaData(InvokeRemoteInterceptor.REMOTING, InvokeRemoteInterceptor.INVOKER_LOCATOR));
      assertEquals("AOP", metadata.getMetaData(InvokeRemoteInterceptor.REMOTING, InvokeRemoteInterceptor.SUBSYSTEM));
     
   }

}
TOP

Related Classes of org.jboss.test.aspects.remoting.ClusteredPojiProxyUnitTestCase

TOP
Copyright © 2018 www.massapi.com. 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.