X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=netconf%2Fsal-netconf-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Fsal%2Fconnect%2Fnetconf%2FNetconfToRpcRequestTest.java;h=0e0b8dee74884a133b3fb830a91aa5f6106dbf74;hb=982e75ece2483e413befe3edd8fd90022a644f72;hp=a9020f4ca450fd54c97f79f946aad60152c7bbcd;hpb=4c0c091813aea131d32dc70c5121a450eb9b7291;p=netconf.git diff --git a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/NetconfToRpcRequestTest.java b/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/NetconfToRpcRequestTest.java index a9020f4ca4..0e0b8dee74 100644 --- a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/NetconfToRpcRequestTest.java +++ b/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/NetconfToRpcRequestTest.java @@ -13,61 +13,52 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.toId; import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.toPath; -import com.google.common.collect.Sets; -import java.io.InputStream; -import java.util.Collections; -import java.util.List; + import java.util.Set; import org.junit.BeforeClass; import org.junit.Test; -import org.opendaylight.controller.config.util.xml.XmlUtil; import org.opendaylight.netconf.api.NetconfMessage; +import org.opendaylight.netconf.api.xml.XmlUtil; import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; import org.opendaylight.yangtools.yang.data.api.schema.LeafNode; import org.opendaylight.yangtools.yang.data.impl.schema.Builders; -import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder; +import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; +import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; import org.w3c.dom.Document; public class NetconfToRpcRequestTest { - private final static String TEST_MODEL_NAMESPACE = "urn:opendaylight:params:xml:ns:yang:controller:md:sal:rpc-test"; - private final static String REVISION = "2014-07-14"; - private final static QName INPUT_QNAME = QName.create(TEST_MODEL_NAMESPACE, REVISION, "input"); - private final static QName STREAM_NAME = QName.create(TEST_MODEL_NAMESPACE, REVISION, "stream-name"); - private final static QName SUBSCRIBE_RPC_NAME = QName.create(TEST_MODEL_NAMESPACE, REVISION, "subscribe"); - - private final static String CONFIG_TEST_NAMESPACE = "urn:opendaylight:params:xml:ns:yang:controller:md:sal:test:rpc:config:defs"; - private final static String CONFIG_TEST_REVISION = "2014-07-21"; - private final static QName EDIT_CONFIG_QNAME = QName.create(CONFIG_TEST_NAMESPACE, CONFIG_TEST_REVISION, "edit-config"); - private final static QName GET_QNAME = QName.create(CONFIG_TEST_NAMESPACE, CONFIG_TEST_REVISION, "get"); - private final static QName GET_CONFIG_QNAME = QName.create(CONFIG_TEST_NAMESPACE, CONFIG_TEST_REVISION, "get-config"); + private static final String TEST_MODEL_NAMESPACE = "urn:opendaylight:params:xml:ns:yang:controller:md:sal:rpc-test"; + private static final String REVISION = "2014-07-14"; + private static final QName INPUT_QNAME = QName.create(TEST_MODEL_NAMESPACE, REVISION, "input"); + private static final QName STREAM_NAME = QName.create(TEST_MODEL_NAMESPACE, REVISION, "stream-name"); + private static final QName SUBSCRIBE_RPC_NAME = QName.create(TEST_MODEL_NAMESPACE, REVISION, "subscribe"); + + private static final String CONFIG_TEST_NAMESPACE = + "urn:opendaylight:params:xml:ns:yang:controller:md:sal:test:rpc:config:defs"; + private static final String CONFIG_TEST_REVISION = "2014-07-21"; + private static final QName EDIT_CONFIG_QNAME = + QName.create(CONFIG_TEST_NAMESPACE, CONFIG_TEST_REVISION, "edit-config"); + private static final QName GET_QNAME = QName.create(CONFIG_TEST_NAMESPACE, CONFIG_TEST_REVISION, "get"); + private static final QName GET_CONFIG_QNAME = + QName.create(CONFIG_TEST_NAMESPACE, CONFIG_TEST_REVISION, "get-config"); static SchemaContext cfgCtx; static NetconfMessageTransformer messageTransformer; - @SuppressWarnings("deprecation") @BeforeClass - public static void setup() throws Exception { - List modelsToParse = Collections - .singletonList(NetconfToRpcRequestTest.class.getResourceAsStream("/schemas/rpc-notification-subscription.yang")); - YangContextParser parser = new YangParserImpl(); - final Set notifModules = parser.parseYangModelsFromStreams(modelsToParse); + public static void setup() { + final Set notifModules = YangParserTestUtils.parseYangResource( + "/schemas/rpc-notification-subscription.yang").getModules(); assertTrue(!notifModules.isEmpty()); - modelsToParse = Collections - .singletonList(NetconfToRpcRequestTest.class.getResourceAsStream("/schemas/config-test-rpc.yang")); - parser = new YangParserImpl(); - final Set configModules = parser.parseYangModelsFromStreams(modelsToParse); - cfgCtx = parser.resolveSchemaContext(Sets.union(configModules, notifModules)); - assertNotNull(cfgCtx); - + cfgCtx = YangParserTestUtils.parseYangResources(NetconfToRpcRequestTest.class, + "/schemas/config-test-rpc.yang", "/schemas/rpc-notification-subscription.yang"); messageTransformer = new NetconfMessageTransformer(cfgCtx, true); } @@ -77,7 +68,8 @@ public class NetconfToRpcRequestTest { @Test public void testUserDefinedRpcCall() throws Exception { - final DataContainerNodeAttrBuilder rootBuilder = Builders.containerBuilder(); + final DataContainerNodeBuilder rootBuilder = + Builders.containerBuilder(); rootBuilder.withNodeIdentifier(toId(SUBSCRIBE_RPC_NAME)); rootBuilder.withChild(buildLeaf(STREAM_NAME, "NETCONF")); @@ -102,11 +94,11 @@ public class NetconfToRpcRequestTest { @Test(expected = IllegalArgumentException.class) public void testRpcResponse() throws Exception { final NetconfMessage response = new NetconfMessage(XmlUtil.readXmlToDocument( - "\n" + - "" + - "module schema" + - "\n" + - "\n" + "\n" + + "" + + "module schema" + + "\n" + + "\n" )); messageTransformer.toRpcResult(response, toPath(EDIT_CONFIG_QNAME));