X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-remoterpc-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fremote%2Frpc%2FAbstractRpcTest.java;h=e512938b712f070c956d131e4c8f4d304f72002b;hp=afe351f2a0b524c1df8bb98b12dc47213378e2de;hb=0f02b7edeb1454c1a568f0f1b050757e7503ddf7;hpb=9ddc65e1ddae50f691566cd9382707679436c055 diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/AbstractRpcTest.java b/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/AbstractRpcTest.java index afe351f2a0..e512938b71 100644 --- a/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/AbstractRpcTest.java +++ b/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/AbstractRpcTest.java @@ -15,22 +15,17 @@ import static org.junit.Assert.assertTrue; import akka.actor.ActorRef; import akka.actor.ActorSystem; -import akka.testkit.JavaTestKit; -import com.google.common.collect.Lists; -import com.google.common.io.ByteSource; -import java.io.IOException; -import java.io.InputStream; +import akka.testkit.javadsl.TestKit; import java.net.URI; -import java.util.ArrayList; import java.util.Collection; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; -import org.mockito.Mockito; -import org.opendaylight.controller.md.sal.dom.api.DOMRpcIdentifier; -import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult; -import org.opendaylight.controller.md.sal.dom.api.DOMRpcService; -import org.opendaylight.controller.sal.core.api.Broker; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.opendaylight.mdsal.dom.api.DOMRpcIdentifier; +import org.opendaylight.mdsal.dom.api.DOMRpcResult; +import org.opendaylight.mdsal.dom.api.DOMRpcService; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.RpcError; import org.opendaylight.yangtools.yang.common.RpcError.ErrorSeverity; @@ -43,9 +38,7 @@ import org.opendaylight.yangtools.yang.data.impl.schema.Builders; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.SchemaPath; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline; +import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; /** * Base class for RPC tests. @@ -60,7 +53,7 @@ public class AbstractRpcTest { static final QName TEST_RPC_INPUT = QName.create(TEST_NS, TEST_REV, "input"); static final QName TEST_RPC_INPUT_DATA = QName.create(TEST_NS, TEST_REV, "input-data"); static final QName TEST_RPC_OUTPUT = QName.create(TEST_NS, TEST_REV, "output"); - static final QName TEST_RPC_OUTPUT_DATA = new QName(TEST_URI, "output-data"); + static final QName TEST_RPC_OUTPUT_DATA = QName.create(TEST_URI, "output-data"); static final SchemaPath TEST_RPC_TYPE = SchemaPath.create(true, TEST_RPC); @@ -73,19 +66,21 @@ public class AbstractRpcTest { static RemoteRpcProviderConfig config1; static RemoteRpcProviderConfig config2; - protected ActorRef rpcBroker1; - protected JavaTestKit rpcRegistry1Probe; - protected ActorRef rpcBroker2; - protected JavaTestKit rpcRegistry2Probe; - protected Broker.ProviderSession brokerSession; + protected ActorRef rpcInvoker1; + protected TestKit rpcRegistry1Probe; + protected ActorRef rpcInvoker2; + protected TestKit rpcRegistry2Probe; protected SchemaContext schemaContext; protected RemoteRpcImplementation remoteRpcImpl1; protected RemoteRpcImplementation remoteRpcImpl2; + + @Mock protected DOMRpcService domRpcService1; + @Mock protected DOMRpcService domRpcService2; @BeforeClass - public static void setup() throws InterruptedException { + public static void setup() { config1 = new RemoteRpcProviderConfig.Builder("memberA").build(); config2 = new RemoteRpcProviderConfig.Builder("memberB").build(); node1 = ActorSystem.create("opendaylight-rpc", config1.get()); @@ -94,39 +89,24 @@ public class AbstractRpcTest { @AfterClass public static void teardown() { - JavaTestKit.shutdownActorSystem(node1); - JavaTestKit.shutdownActorSystem(node2); + TestKit.shutdownActorSystem(node1); + TestKit.shutdownActorSystem(node2); node1 = null; node2 = null; } @Before - public void setUp() throws Exception { - final ByteSource byteSource = new ByteSource() { - @Override - public InputStream openStream() throws IOException { - return AbstractRpcTest.this.getClass().getResourceAsStream("/test-rpc.yang"); - } - }; - - final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(); - final ArrayList sources = Lists.newArrayList(byteSource); - - try { - schemaContext = reactor.buildEffective(sources); - } catch (ReactorException e) { - throw new RuntimeException("Unable to build schema context from " + sources, e); - } + public void setUp() { + schemaContext = YangParserTestUtils.parseYangResources(AbstractRpcTest.class, "/test-rpc.yang"); - domRpcService1 = Mockito.mock(DOMRpcService.class); - domRpcService2 = Mockito.mock(DOMRpcService.class); - rpcRegistry1Probe = new JavaTestKit(node1); - rpcBroker1 = node1.actorOf(RpcBroker.props(domRpcService1)); - rpcRegistry2Probe = new JavaTestKit(node2); - rpcBroker2 = node2.actorOf(RpcBroker.props(domRpcService2)); - remoteRpcImpl1 = new RemoteRpcImplementation(rpcRegistry1Probe.getRef(), config1); - remoteRpcImpl2 = new RemoteRpcImplementation(rpcRegistry2Probe.getRef(), config2); + MockitoAnnotations.initMocks(this); + rpcRegistry1Probe = new TestKit(node1); + rpcInvoker1 = node1.actorOf(RpcInvoker.props(domRpcService1)); + rpcRegistry2Probe = new TestKit(node2); + rpcInvoker2 = node2.actorOf(RpcInvoker.props(domRpcService2)); + remoteRpcImpl1 = new RemoteRpcImplementation(rpcInvoker2, config1); + remoteRpcImpl2 = new RemoteRpcImplementation(rpcInvoker1, config2); } static void assertRpcErrorEquals(final RpcError rpcError, final ErrorSeverity severity,