Package com.kurento.tool.rom.test

Source Code of com.kurento.tool.rom.test.ReturnReferencesTest

package com.kurento.tool.rom.test;

import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.junit.Assert.assertEquals;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

import com.kurento.kmf.jsonrpcconnector.client.JsonRpcClientLocal;
import com.kurento.kmf.media.Continuation;
import com.kurento.tool.rom.client.RemoteObjectFactory;
import com.kurento.tool.rom.client.RemoteObjectTypedFactory;
import com.kurento.tool.rom.test.model.client.SampleClass;
import com.kurento.tool.rom.transport.jsonrpcconnector.RomClientJsonRpcClient;
import com.kurento.tool.rom.transport.jsonrpcconnector.RomServerJsonRpcHandler;

public class ReturnReferencesTest {

  private static RemoteObjectTypedFactory factory;

  @BeforeClass
  public static void initFactory() {
    factory = new RemoteObjectTypedFactory(new RemoteObjectFactory(
        new RomClientJsonRpcClient(new JsonRpcClientLocal(
            new RomServerJsonRpcHandler(
                "com.kurento.tool.rom.test.model.server",
                "Impl")))));
  }

  @Test
  public void objectRefTest() {

    SampleClass obj = factory.getFactory(SampleClass.Factory.class)
        .create("AAA", false).withAtt3(0.5f).withAtt4(22).build();

    SampleClass obj2 = factory.getFactory(SampleClass.Factory.class)
        .create("BBB", false).withAtt3(0.5f).withAtt4(22).build();

    SampleClass obj3 = obj.echoObjectRef(obj2);

    assertEquals(obj3.getAtt1(), obj2.getAtt1());
    assertEquals(obj3.getAtt2(), obj2.getAtt2());
  }

  @Test
  public void objectRefTestAsync() throws InterruptedException {

    SampleClass obj = factory.getFactory(SampleClass.Factory.class)
        .create("AAA", false).withAtt3(0.5f).withAtt4(22).build();

    final SampleClass obj2 = factory.getFactory(SampleClass.Factory.class)
        .create("BBB", false).withAtt3(0.5f).withAtt4(22).build();

    final BlockingQueue<SampleClass> queue = new ArrayBlockingQueue<>(1);

    obj.echoObjectRef(obj2, new Continuation<SampleClass>() {

      @Override
      public void onSuccess(SampleClass obj3) {
        queue.add(obj3);
      }

      @Override
      public void onError(Throwable cause) {

      }
    });

    SampleClass obj3 = queue.poll(10000, MILLISECONDS);

    Assert.assertNotNull(obj3);

    assertEquals(obj3.getAtt1(), obj2.getAtt1());
    assertEquals(obj3.getAtt2(), obj2.getAtt2());
  }

}
TOP

Related Classes of com.kurento.tool.rom.test.ReturnReferencesTest

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.