incubator-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vin...@apache.org
Subject cvs commit: incubator-altrmi/integrationtests/src/test/org/apache/altrmi/test/classretrievers ClassRetrievingTestCase.java TestImpl.java TestInterface.java
Date Thu, 18 Mar 2004 18:59:15 GMT
vinayc      2004/03/18 10:59:15

  Added:       integrationtests/src/test/org/apache/altrmi/test/classretrievers
                        ClassRetrievingTestCase.java TestImpl.java
                        TestInterface.java
  Log:
  migrating classretriever test case
  
  Revision  Changes    Path
  1.1                  incubator-altrmi/integrationtests/src/test/org/apache/altrmi/test/classretrievers/ClassRetrievingTestCase.java
  
  Index: ClassRetrievingTestCase.java
  ===================================================================
  /* ====================================================================
   * Copyright 2001 - 2004
   *
   * 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.apache.altrmi.test.classretrievers;
  
  import org.apache.altrmi.server.impl.AbstractServer;
  import org.apache.altrmi.server.impl.DefaultAuthenticator;
  import org.apache.altrmi.server.impl.NullServerMonitor;
  import org.apache.altrmi.server.impl.DefaultServerSideClientContextFactory;
  import org.apache.altrmi.server.impl.classretrievers.BcelDynamicGeneratorClassRetriever;
  import org.apache.altrmi.server.impl.classretrievers.AbstractDynamicGeneratorClassRetriever;
  import org.apache.altrmi.server.impl.piped.PipedCustomStreamServer;
  import org.apache.altrmi.client.Factory;
  import org.apache.altrmi.client.impl.ServerSideClassFactory;
  import org.apache.altrmi.client.impl.piped.PipedCustomStreamHostContext;
  import org.apache.altrmi.common.DefaultThreadPool;
  
  import java.io.PipedInputStream;
  import java.io.PipedOutputStream;
  
  import junit.framework.TestCase;
  
  /**
   * A special test case that tests dynamic class generation on the server side.
   * @author Paul Hammant
   */
  public class ClassRetrievingTestCase extends TestCase
  {
  
      protected AbstractServer server;
      protected TestImpl testServer;
      protected TestInterface testClient;
  
      public ClassRetrievingTestCase(String name)
      {
          super(name);
      }
  
      protected void setUp() throws Exception
      {
          super.setUp();
  
          // server side setup.
          AbstractDynamicGeneratorClassRetriever dyncgen = new BcelDynamicGeneratorClassRetriever();
          server = new PipedCustomStreamServer(dyncgen, new DefaultAuthenticator(), new NullServerMonitor(),
                  new DefaultThreadPool(), new DefaultServerSideClientContextFactory());
          testServer = new TestImpl();
          server.publish(testServer, "Kewl", TestInterface.class);
          dyncgen.generate("Kewl", TestInterface.class, this.getClass().getClassLoader());
  
          server.start();
  
          // For piped, server and client can see each other
          PipedInputStream in = new PipedInputStream();
          PipedOutputStream out = new PipedOutputStream();
          ((PipedCustomStreamServer) server).makeNewConnection(in, out);
  
          // Client side setup
          Factory af = new ServerSideClassFactory(new PipedCustomStreamHostContext.WithSimpleDefaults(in,
out), false);
          testClient = (TestInterface) af.lookup("Kewl");
  
          // just a kludge for unit testing given we are intrinsically dealing with
          // threads, AltRMI being a client/server thing
          Thread.yield();
      }
  
      protected void tearDown() throws Exception
      {
          server.stop();
          Thread.yield();
          server = null;
          testServer = null;
          super.tearDown();
      }
  
  
      /**
       * This is the only testXX() method in this class.  Other features of
       * AltRMI are given a thorough test in the 'test' package.
       *
       * @throws Exception as per Junit contract
       */
      public void testDynamicallyGeneratedProxyMethodInvocation() throws Exception
      {
          // lookup worked ?
          assertNotNull(testClient);
  
          // Invoke a method over AltRMI.
          testClient.method0();
  
          // test the server has logged the message.
          assertEquals("called", (testServer).getStoredState("method0"));
      }
  
  
  
  }
  
  
  
  1.1                  incubator-altrmi/integrationtests/src/test/org/apache/altrmi/test/classretrievers/TestImpl.java
  
  Index: TestImpl.java
  ===================================================================
  /* ====================================================================
   * Copyright 2001 - 2004
   *
   * 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.apache.altrmi.test.classretrievers;
  
  import java.util.HashMap;
  
  public class TestImpl implements TestInterface
  {
      HashMap map = new HashMap();
  
      public Object getStoredState(String key)
      {
          return map.get(key);
      }
  
  
      public void method0()
      {
          map.put("method0", "called");
      }
  }
  
  
  
  1.1                  incubator-altrmi/integrationtests/src/test/org/apache/altrmi/test/classretrievers/TestInterface.java
  
  Index: TestInterface.java
  ===================================================================
  /* ====================================================================
   * Copyright 2001 - 2004
   *
   * 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.apache.altrmi.test.classretrievers;
  
  public interface TestInterface
  {
      void method0();
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@incubator.apache.org
For additional commands, e-mail: cvs-help@incubator.apache.org


Mime
View raw message