* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.controller.cluster.datastore.node.utils.stream;
import static org.junit.Assert.assertEquals;
+import com.google.common.collect.ImmutableSet;
import com.google.common.io.ByteStreams;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Optional;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import org.opendaylight.yangtools.yang.common.Empty;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
-import org.opendaylight.yangtools.yang.data.api.schema.AnyXmlNode;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
nnout.writeNormalizedNode(toasterContainer);
final byte[] bytes = bos.toByteArray();
- assertEquals(1049950, bytes.length);
+ assertEquals(1049619, bytes.length);
NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput(bytes));
nnout.writeYangInstanceIdentifier(path);
final byte[] bytes = bos.toByteArray();
- assertEquals(161, bytes.length);
+ assertEquals(139, bytes.length);
NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput(bytes));
writer.writeYangInstanceIdentifier(path);
final byte[] bytes = bos.toByteArray();
- assertEquals(1163, bytes.length);
+ assertEquals(826, bytes.length);
NormalizedNodeDataInput reader = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput(bytes));
nnout.writeNormalizedNode(anyXmlContainer);
final byte[] bytes = bos.toByteArray();
- assertEquals(235, bytes.length);
+ assertEquals(229, bytes.length);
NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput(bytes));
StreamResult xmlOutput = new StreamResult(new StringWriter());
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
- transformer.transform(((AnyXmlNode)child.get()).getValue(), xmlOutput);
+ transformer.transform(((DOMSourceAnyxmlNode)child.get()).getValue(), xmlOutput);
assertEquals("XML", xml, xmlOutput.getWriter().toString());
- assertEquals("http://www.w3.org/TR/html4/", ((AnyXmlNode)child.get()).getValue().getNode().getNamespaceURI());
+ assertEquals("http://www.w3.org/TR/html4/",
+ ((DOMSourceAnyxmlNode)child.get()).getValue().getNode().getNamespaceURI());
}
@Test
}
final byte[] bytes = bos.toByteArray();
- assertEquals(100, bytes.length);
+ assertEquals(99, bytes.length);
NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput(bytes));
assertEquals(expected, nnin.readSchemaPath());
}
final byte[] bytes = bos.toByteArray();
- assertEquals(105, bytes.length);
+ assertEquals(103, bytes.length);
NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput(bytes));
assertEquals(expected, nnin.readPathArgument());
}
final byte[] bytes = bos.toByteArray();
- assertEquals(5_577_993, bytes.length);
+ assertEquals(2_289_103, bytes.length);
NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput(bytes));
assertEquals(expected, nnin.readNormalizedNode());
}
+ @Test
+ public void testAugmentationIdentifier() throws IOException {
+ final List<QName> qnames = new ArrayList<>();
+ for (int i = 0; i < 257; ++i) {
+ qnames.add(QName.create(TestModel.TEST_QNAME, "a" + i));
+ }
+
+ for (int i = 0; i < qnames.size(); ++i) {
+ final AugmentationIdentifier expected = AugmentationIdentifier.create(
+ ImmutableSet.copyOf(qnames.subList(0, i)));
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+
+ try (NormalizedNodeDataOutput nnout =
+ NormalizedNodeInputOutput.newDataOutput(ByteStreams.newDataOutput(bos),
+ NormalizedNodeStreamVersion.SODIUM_SR1)) {
+ nnout.writePathArgument(expected);
+ }
+
+ final byte[] bytes = bos.toByteArray();
+
+ NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput(bytes));
+ PathArgument arg = nnin.readPathArgument();
+ assertEquals(expected, arg);
+ }
+ }
+
private static String largeString(final int pow) {
StringBuilder sb = new StringBuilder("X");
for (int i = 0; i < pow; i++) {