Package org.jboss.aspects.remoting.test.simple.unit

Source Code of org.jboss.aspects.remoting.test.simple.unit.RemoteTestCase

/*
* 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.aspects.remoting.test.simple.unit;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

import java.rmi.dgc.VMID;
import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;

import org.jboss.aspects.remoting.test.common.Fork;
import org.jboss.aspects.remoting.test.common.RemoteKernelController;
import org.jboss.aspects.remoting.test.simple.VMIdentifier;
import org.jboss.aspects.remoting.test.simple.VMIdentifierImpl;
import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
import org.jboss.kernel.plugins.bootstrap.standalone.StandaloneBootstrap;
import org.jboss.logging.Logger;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

/**
* @author <a href="mailto:carlo.dewolf@jboss.com">Carlo de Wolf</a>
* @version $Revision: $
*/
public class RemoteTestCase
{
   private static final Logger log = Logger.getLogger(RemoteTestCase.class);
  
   private static Fork fork;
  
   /**
    * @throws java.lang.Exception
    */
   @BeforeClass
   public static void setUpBeforeClass() throws Exception
   {
      fork = new Fork(StandaloneBootstrap.class);
      // TODO: how do I know the server has started?
      Thread.sleep(5000);
   }

   /**
    * @throws java.lang.Exception
    */
   @AfterClass
   public static void tearDownAfterClass() throws Exception
   {
      fork.kill();
   }

   @Test
   public void test1() throws Throwable
   {
      Properties props = new Properties();
      // For some reason surefire finds the wrong jndi.properties, so we specify the factory here.
      props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      props.put(Context.PROVIDER_URL, "jnp://localhost:1099");
     
      InitialContext ctx = new InitialContext(props);
      RemoteKernelController controller = (RemoteKernelController) ctx.lookup("RemoteKernelController");
      System.out.println(controller);
     
      AbstractBeanMetaData bmd = new AbstractBeanMetaData("VMIdentifier", VMIdentifierImpl.class.getName());
      controller.install(bmd);
     
      VMIdentifier identifierHere = new VMIdentifierImpl();
     
      VMID firstHere = identifierHere.getCurrentVMID();
      VMID secondHere = identifierHere.getCurrentVMID();
      assertEquals(firstHere, secondHere);
     
      VMIdentifier identifierThere = (VMIdentifier) ctx.lookup("VMIdentifier");
     
      VMID firstThere = identifierThere.getCurrentVMID();
      VMID secondThere = identifierThere.getCurrentVMID();
      assertEquals(firstThere, secondThere);
     
      assertFalse(firstHere.equals(firstThere));
   }
}
TOP

Related Classes of org.jboss.aspects.remoting.test.simple.unit.RemoteTestCase

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.