Refactor RpcRoutingStrategy
[mdsal.git] / dom / mdsal-dom-spi / src / test / java / org / opendaylight / mdsal / dom / spi / ContentRoutedRpcContextTest.java
similarity index 53%
rename from dom/mdsal-dom-spi/src/test/java/org/opendaylight/mdsal/dom/spi/RpcRoutingStrategyTest.java
rename to dom/mdsal-dom-spi/src/test/java/org/opendaylight/mdsal/dom/spi/ContentRoutedRpcContextTest.java
index 07bebbd34a6d04a3ccefd96d617866b6c3911a86..be1b6b368297b70454602805d052463447f3b347 100644 (file)
@@ -8,12 +8,9 @@
 package org.opendaylight.mdsal.dom.spi;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNull;
 
-import com.google.common.collect.Iterables;
 import java.util.List;
 import java.util.stream.Collectors;
 import org.junit.AfterClass;
@@ -21,23 +18,22 @@ import org.junit.BeforeClass;
 import org.junit.Test;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.yang.extension.yang.ext.rev130709.$YangModuleInfoImpl;
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.stmt.RpcEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
 import org.opendaylight.yangtools.yang.parser.api.YangParserConfiguration;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
-public class RpcRoutingStrategyTest {
+public class ContentRoutedRpcContextTest {
     private static List<RpcEffectiveStatement> RPCS;
 
     @BeforeClass
     public static void beforeClass() {
-        final EffectiveModelContext ctx = YangParserTestUtils.parseYangSources(YangParserConfiguration.DEFAULT, null,
+        final var ctx = YangParserTestUtils.parseYangSources(YangParserConfiguration.DEFAULT, null,
             YangTextSchemaSource.delegateForByteSource("yang-ext.yang",
                 $YangModuleInfoImpl.getInstance().getYangTextByteSource()),
-            YangTextSchemaSource.forResource(RpcRoutingStrategy.class, "/rpc-routing-strategy.yang"));
+            YangTextSchemaSource.forResource(ContentRoutedRpcContext.class, "/rpc-routing-strategy.yang"));
 
-        RPCS = Iterables.getOnlyElement(ctx.findModuleStatements("foo"))
+        RPCS = ctx.findModuleStatements("foo").iterator().next()
             .streamEffectiveSubstatements(RpcEffectiveStatement.class)
             .collect(Collectors.toUnmodifiableList());
     }
@@ -49,23 +45,15 @@ public class RpcRoutingStrategyTest {
 
     @Test
     public void unroutedRpcStrategyTest() {
-        final RpcRoutingStrategy strategy = RpcRoutingStrategy.from(Iterables.get(RPCS, 1));
-        assertNotNull(strategy);
-
-        assertEquals(QName.create("foo", "unrouted"), strategy.getIdentifier());
-        assertFalse(strategy.isContextBasedRouted());
-        assertThrows(UnsupportedOperationException.class, () -> strategy.getLeaf());
-        assertThrows(UnsupportedOperationException.class, () -> strategy.getContext());
+        assertNull(ContentRoutedRpcContext.forRpc(RPCS.get(1)));
     }
 
     @Test
     public void routedRpcStrategyTest() {
-        final RpcRoutingStrategy strategy = RpcRoutingStrategy.from(Iterables.get(RPCS, 0));
-        assertNotNull(strategy);
+        final var context = ContentRoutedRpcContext.forRpc(RPCS.get(0));
+        assertNotNull(context);
 
-        assertEquals(QName.create("foo", "routed"), strategy.getIdentifier());
-        assertTrue(strategy.isContextBasedRouted());
-        assertEquals(QName.create("foo", "identity"), strategy.getContext());
-        assertEquals(QName.create("foo", "ctx"), strategy.getLeaf());
+        assertEquals(QName.create("foo", "identity"), context.identity());
+        assertEquals(QName.create("foo", "ctx"), context.leaf());
     }
 }
\ No newline at end of file