X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-remoterpc-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fremote%2Frpc%2FAbstractRpcTest.java;h=32b54c4a8cf5470e2fa11060f17e48f88f7cff41;hb=b6fcc46c9b753a8c542456ea2b5d6cc20c266d7c;hp=431c4a86edef40173a4a4bb1a4fc22541ae1f87c;hpb=a58c23b491f665e6d5449e97d430a7e15d1ecda6;p=controller.git 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 431c4a86ed..32b54c4a8c 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 @@ -16,21 +16,16 @@ 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 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.mockito.Mock; +import org.mockito.MockitoAnnotations; 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.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.RpcError; import org.opendaylight.yangtools.yang.common.RpcError.ErrorSeverity; @@ -44,8 +39,7 @@ 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. @@ -64,7 +58,8 @@ public class AbstractRpcTest { static final SchemaPath TEST_RPC_TYPE = SchemaPath.create(true, TEST_RPC); - static final YangInstanceIdentifier TEST_PATH = YangInstanceIdentifier.create(new YangInstanceIdentifier.NodeIdentifier(TEST_RPC)); + static final YangInstanceIdentifier TEST_PATH = YangInstanceIdentifier.create( + new YangInstanceIdentifier.NodeIdentifier(TEST_RPC)); public static final DOMRpcIdentifier TEST_RPC_ID = DOMRpcIdentifier.create(TEST_RPC_TYPE, TEST_PATH); static ActorSystem node1; @@ -72,15 +67,17 @@ public class AbstractRpcTest { static RemoteRpcProviderConfig config1; static RemoteRpcProviderConfig config2; - protected ActorRef rpcBroker1; + protected ActorRef rpcInvoker1; protected JavaTestKit rpcRegistry1Probe; - protected ActorRef rpcBroker2; + protected ActorRef rpcInvoker2; protected JavaTestKit rpcRegistry2Probe; - protected Broker.ProviderSession brokerSession; protected SchemaContext schemaContext; protected RemoteRpcImplementation remoteRpcImpl1; protected RemoteRpcImplementation remoteRpcImpl2; + + @Mock protected DOMRpcService domRpcService1; + @Mock protected DOMRpcService domRpcService2; @BeforeClass @@ -100,37 +97,22 @@ public class AbstractRpcTest { } @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() throws ReactorException { + schemaContext = YangParserTestUtils.parseYangResources(AbstractRpcTest.class, "/test-rpc.yang"); + + MockitoAnnotations.initMocks(this); - domRpcService1 = Mockito.mock(DOMRpcService.class); - domRpcService2 = Mockito.mock(DOMRpcService.class); rpcRegistry1Probe = new JavaTestKit(node1); - rpcBroker1 = node1.actorOf(RpcBroker.props(domRpcService1)); + rpcInvoker1 = node1.actorOf(RpcInvoker.props(domRpcService1)); rpcRegistry2Probe = new JavaTestKit(node2); - rpcBroker2 = node2.actorOf(RpcBroker.props(domRpcService2)); - remoteRpcImpl1 = new RemoteRpcImplementation(rpcRegistry1Probe.getRef(), config1); - remoteRpcImpl2 = new RemoteRpcImplementation(rpcRegistry2Probe.getRef(), config2); - + 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, - final ErrorType errorType, final String tag, final String message, final String applicationTag, final String info, - final String causeMsg) { + final ErrorType errorType, final String tag, final String message, final String applicationTag, + final String info, final String causeMsg) { assertEquals("getSeverity", severity, rpcError.getSeverity()); assertEquals("getErrorType", errorType, rpcError.getErrorType()); assertEquals("getTag", tag, rpcError.getTag()); @@ -138,14 +120,14 @@ public class AbstractRpcTest { assertEquals("getApplicationTag", applicationTag, rpcError.getApplicationTag()); assertEquals("getInfo", info, rpcError.getInfo()); - if(causeMsg == null) { + if (causeMsg == null) { assertNull("Unexpected cause " + rpcError.getCause(), rpcError.getCause()); } else { assertEquals("Cause message", causeMsg, rpcError.getCause().getMessage()); } } - static void assertCompositeNodeEquals(final NormalizedNode exp, final NormalizedNode actual) { + static void assertCompositeNodeEquals(final NormalizedNode exp, final NormalizedNode actual) { assertEquals(exp, actual); } @@ -161,9 +143,8 @@ public class AbstractRpcTest { } static void assertFailedRpcResult(final DOMRpcResult rpcResult, final ErrorSeverity severity, - final ErrorType errorType, final String tag, final String message, final String applicationTag, final String info, - final String causeMsg) { - + final ErrorType errorType, final String tag, final String message, final String applicationTag, + final String info, final String causeMsg) { assertNotNull("RpcResult was null", rpcResult); final Collection rpcErrors = rpcResult.getErrors(); assertEquals("RpcErrors count", 1, rpcErrors.size());