Bug 2907 - corrections for upgrade to karaf 3.0.3
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / test / TestUtils.java
index bfd14834d2ce13a7f98d615fcbc15b17bbca2e60..090b060c23496eeea97febe50ca066be120a6301 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.controller.sal.restconf.impl.test;
 
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -34,9 +33,6 @@ import java.util.Map;
 import java.util.Set;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.ext.MessageBodyReader;
-import javax.ws.rs.ext.MessageBodyWriter;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
@@ -46,34 +42,17 @@ import javax.xml.transform.TransformerException;
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
 import org.opendaylight.controller.sal.restconf.impl.BrokerFacade;
-import org.opendaylight.controller.sal.restconf.impl.CompositeNodeWrapper;
 import org.opendaylight.controller.sal.restconf.impl.ControllerContext;
-import org.opendaylight.controller.sal.restconf.impl.InstanceIdentifierContext;
-import org.opendaylight.controller.sal.restconf.impl.NodeWrapper;
-import org.opendaylight.controller.sal.restconf.impl.NormalizedNodeContext;
-import org.opendaylight.controller.sal.restconf.impl.RestconfDocumentedException;
-import org.opendaylight.controller.sal.restconf.impl.RestconfError;
-import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorTag;
-import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorType;
 import org.opendaylight.controller.sal.restconf.impl.RestconfImpl;
-import org.opendaylight.controller.sal.restconf.impl.StructuredData;
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.CompositeNode;
-import org.opendaylight.yangtools.yang.data.api.Node;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.composite.node.schema.cnsn.parser.CnSnToNormalizedNodeParserFactory;
-import org.opendaylight.yangtools.yang.data.impl.ImmutableCompositeNode;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapEntryNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.util.CompositeNodeBuilder;
-import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 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;
@@ -166,29 +145,6 @@ public final class TestUtils {
 
     }
 
-    /**
-     * @deprecated method will be removed in Lithium release
-     *      we don't wish to use Node and CompositeNode anywhere -
-     *
-     * Fill missing data (namespaces) and build correct data type in {@code compositeNode} according to
-     * {@code dataSchemaNode}. The method {@link RestconfImpl#createConfigurationData createConfigurationData} is used
-     * because it contains calling of method {code normalizeNode}
-     */
-    @Deprecated
-    public static void normalizeCompositeNode(final Node<?> node, final Set<Module> modules, final String schemaNodePath) {
-        final RestconfImpl restconf = RestconfImpl.getInstance();
-        ControllerContext.getInstance().setSchemas(TestUtils.loadSchemaContext(modules));
-        prepareMocksForRestconf(modules, restconf);
-
-        final InstanceIdentifierContext iiContext = ControllerContext.getInstance().toInstanceIdentifier(schemaNodePath);
-        final DOMMountPoint mountPoint = iiContext.getMountPoint();
-        final CompositeNode value = RestconfImpl.getInstance().normalizeNode(node, iiContext.getSchemaNode(), mountPoint);
-        final NormalizedNode<?, ?> normNodePayload = compositeNodeToDatastoreNormalizedNode(value, iiContext.getSchemaNode());
-        final NormalizedNodeContext normlNodeContext = new NormalizedNodeContext(iiContext, normNodePayload);
-
-        restconf.updateConfigurationData(schemaNodePath, normlNodeContext);
-    }
-
     /**
      * Searches module with name {@code searchedModuleName} in {@code modules}. If module name isn't specified and
      * module set has only one element then this element is returned.
@@ -244,15 +200,6 @@ public final class TestUtils {
         return buildQName(name, "", null);
     }
 
-    private static void addDummyNamespaceToAllNodes(final NodeWrapper<?> wrappedNode) throws URISyntaxException {
-        wrappedNode.setNamespace(new URI(""));
-        if (wrappedNode instanceof CompositeNodeWrapper) {
-            for (final NodeWrapper<?> childNodeWrapper : ((CompositeNodeWrapper) wrappedNode).getValues()) {
-                addDummyNamespaceToAllNodes(childNodeWrapper);
-            }
-        }
-    }
-
     private static void prepareMocksForRestconf(final Set<Module> modules, final RestconfImpl restconf) {
         final ControllerContext controllerContext = ControllerContext.getInstance();
         final BrokerFacade mockedBrokerFacade = mock(BrokerFacade.class);
@@ -266,62 +213,6 @@ public final class TestUtils {
         restconf.setBroker(mockedBrokerFacade);
     }
 
-    public static Node<?> readInputToCnSn(final String path, final boolean dummyNamespaces,
-            final MessageBodyReader<Node<?>> reader) throws WebApplicationException {
-
-        final InputStream inputStream = TestUtils.class.getResourceAsStream(path);
-        try {
-            final Node<?> node = reader.readFrom(null, null, null, null, null, inputStream);
-            assertTrue(node instanceof CompositeNodeWrapper);
-            if (dummyNamespaces) {
-                try {
-                    TestUtils.addDummyNamespaceToAllNodes((CompositeNodeWrapper) node);
-                    return ((CompositeNodeWrapper) node).unwrap();
-                } catch (final URISyntaxException e) {
-                    LOG.error(e.getMessage());
-                    assertTrue(e.getMessage(), false);
-                }
-            }
-            return node;
-        } catch (final IOException e) {
-            LOG.error(e.getMessage());
-            assertTrue(e.getMessage(), false);
-        }
-        return null;
-    }
-
-//    public static Node<?> readInputToCnSnNew(String path, MessageBodyReader<Node<?>> reader) throws WebApplicationException {
-//        InputStream inputStream = TestUtils.class.getResourceAsStream(path);
-//        try {
-//            return reader.readFrom(null, null, null, null, null, inputStream);
-//        } catch (IOException e) {
-//            LOG.error(e.getMessage());
-//            assertTrue(e.getMessage(), false);
-//        }
-//        return null;
-//    }
-
-    public static Node<?> readInputToCnSn(final String path, final MessageBodyReader<Node<?>> reader) {
-        return readInputToCnSn(path, false, reader);
-    }
-
-    public static String writeCompNodeWithSchemaContextToOutput(final Node<?> node, final Set<Module> modules,
-            final DataSchemaNode dataSchemaNode, final MessageBodyWriter<StructuredData> messageBodyWriter) throws IOException,
-            WebApplicationException {
-
-        assertNotNull(dataSchemaNode);
-        assertNotNull("Composite node can't be null", node);
-        final ByteArrayOutputStream byteArrayOS = new ByteArrayOutputStream();
-
-        ControllerContext.getInstance().setSchemas(loadSchemaContext(modules));
-
-        assertTrue(node instanceof CompositeNode);
-        messageBodyWriter.writeTo(new StructuredData((CompositeNode)node, dataSchemaNode, null), null, null, null, null,
-                null, byteArrayOS);
-
-        return byteArrayOS.toString();
-    }
-
     public static String loadTextFile(final String filePath) throws IOException {
         final FileReader fileReader = new FileReader(filePath);
         final BufferedReader bufReader = new BufferedReader(fileReader);
@@ -352,24 +243,6 @@ public final class TestUtils {
         return matcher.matches();
     }
 
-    public static NormalizedNode compositeNodeToDatastoreNormalizedNode(final CompositeNode compositeNode,
-            final DataSchemaNode schema) {
-        final List<Node<?>> lst = new ArrayList<Node<?>>();
-        lst.add(compositeNode);
-        if (schema instanceof ContainerSchemaNode) {
-            return CnSnToNormalizedNodeParserFactory.getInstance().getContainerNodeParser()
-                    .parse(lst, (ContainerSchemaNode) schema);
-        } else if (schema instanceof ListSchemaNode) {
-            return CnSnToNormalizedNodeParserFactory.getInstance().getMapNodeParser()
-                    .parse(lst, (ListSchemaNode) schema);
-        }
-
-        LOG.error("Top level isn't of type container, list, leaf schema node but " + schema.getClass().getSimpleName());
-
-        throw new RestconfDocumentedException(new RestconfError(ErrorType.APPLICATION, ErrorTag.INVALID_VALUE,
-                "It wasn't possible to translate specified data to datastore readable form."));
-    }
-
     public static YangInstanceIdentifier.NodeIdentifier getNodeIdentifier(final String localName, final String namespace,
             final String revision) throws ParseException {
         return new YangInstanceIdentifier.NodeIdentifier(QName.create(namespace, revision, localName));
@@ -404,15 +277,6 @@ public final class TestUtils {
                 predicate);
     }
 
-    public static CompositeNode prepareCompositeNodeWithIetfInterfacesInterfacesData() {
-        final CompositeNodeBuilder<ImmutableCompositeNode> interfaceBuilder = ImmutableCompositeNode.builder();
-        interfaceBuilder.addLeaf(buildQName("name", "dummy", "2014-07-29"), "eth0");
-        interfaceBuilder.addLeaf(buildQName("type", "dummy", "2014-07-29"), "ethernetCsmacd");
-        interfaceBuilder.addLeaf(buildQName("enabled", "dummy", "2014-07-29"), "false");
-        interfaceBuilder.addLeaf(buildQName("description", "dummy", "2014-07-29"), "some interface");
-        return interfaceBuilder.toInstance();
-    }
-
     static NormalizedNode<?,?> prepareNormalizedNodeWithIetfInterfacesInterfacesData() throws ParseException {
         final String ietfInterfacesDate = "2013-07-04";
         final String namespace = "urn:ietf:params:xml:ns:yang:ietf-interfaces";