import com.google.gson.stream.JsonWriter;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.opendaylight.yangtools.yang.common.QName;
}
@Test
- @Disabled("YT-1473: Instance-identifier values need to be recognized and properly encoded and escaped")
void testSerializeInstanceIdentifierRef() throws Exception {
assertSerdes("/foo:baz[id=\"/foo:bar[qname='bar:two']\"]",
buildYangInstanceIdentifier(FOO_BAZ, FOO_ID, buildYangInstanceIdentifier(FOO_BAR, FOO_QNAME, BAR_TWO)));
}
@Test
- @Disabled("YT-1473: Instance-identifier values need to be recognized and properly encoded and escaped")
void testSerializeInstanceIdentifierValue() throws Exception {
assertSerdes("/bar:bar[.=\"/foo:bar[qname='bar:two']\"]",
buildYangInstanceIdentifier(BAR_BAR, buildYangInstanceIdentifier(FOO_BAR, FOO_QNAME, BAR_TWO)));
}
@Test
- @Disabled("YT-1473: bits values need to be recognized and properly encoded")
void testSerializeBits() throws Exception {
assertSerdes("/foo:bee[bts='']", buildYangInstanceIdentifier(FOO_BEE, FOO_BTS, ImmutableSet.of()));
assertSerdes("/foo:bee[bts='one']", buildYangInstanceIdentifier(FOO_BEE, FOO_BTS, ImmutableSet.of("one")));
}
@Test
- @Disabled("YT-1473: bits values need to be recognized and properly encoded")
void testSerializeBitsValue() throws Exception {
assertSerdes("/bar:bee[.='']", buildYangInstanceIdentifier(BAR_BEE, ImmutableSet.of()));
assertSerdes("/bar:bee[.='one']", buildYangInstanceIdentifier(BAR_BEE, ImmutableSet.of("one")));
import javax.xml.stream.XMLStreamWriter;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.opendaylight.yangtools.yang.common.QName;
}
@Test
- @Disabled("YT-1473: Instance-identifier values need to be recognized and properly encoded and escaped")
public void testSerializeInstanceIdentifierRef() throws Exception {
assertSerdes("/foo:baz[foo:id=\"/foo:bar[foo:qname='bar:two']\"]",
buildYangInstanceIdentifier(FOO_BAZ, FOO_ID, buildYangInstanceIdentifier(FOO_BAR, FOO_QNAME, BAR_TWO)));
}
@Test
- @Disabled("YT-1473: Instance-identifier values need to be recognized and properly encoded and escaped")
public void testSerializeInstanceIdentifierValue() throws Exception {
assertSerdes("/bar:bar[.=\"/foo:bar[foo:qname='foo:one']\"]",
buildYangInstanceIdentifier(BAR_BAR, buildYangInstanceIdentifier(FOO_BAR, FOO_QNAME, FOO_ONE)));
}
@Test
- @Disabled("YT-1473: bits values need to be recognized and properly encoded and escaped")
public void testSerializeBits() throws Exception {
assertSerdes("/foo:bee[foo:bts='']", buildYangInstanceIdentifier(FOO_BEE, FOO_BTS, ImmutableSet.of()));
assertSerdes("/foo:bee[foo:bts='one']", buildYangInstanceIdentifier(FOO_BEE, FOO_BTS, ImmutableSet.of("one")));
}
@Test
- @Disabled("YT-1473: bits values need to be recognized and properly encoded and escaped")
public void testSerializeBitsValue() throws Exception {
assertSerdes("/bar:bee[.='']", buildYangInstanceIdentifier(BAR_BEE, ImmutableSet.of()));
assertSerdes("/bar:bee[.='one']", buildYangInstanceIdentifier(BAR_BEE, ImmutableSet.of("one")));
import com.google.common.annotations.Beta;
import com.google.common.escape.Escaper;
import com.google.common.escape.Escapers;
+import java.util.Set;
import javax.xml.XMLConstants;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
// QName implies identity-ref, which can never be escaped
return appendQName(sb.append('\''), (QName) value, currentModule).append('\'');
}
+ // FIXME: YANGTOOLS-1426: update once we have a dedicated type
+ if (value instanceof Set) {
+ final var bits = (Set<?>) value;
+ // Set implies bits, which can never be escaped and need to be serialized as space-separated items
+ sb.append('\'');
- final var str = String.valueOf(value);
+ final var it = bits.iterator();
+ if (it.hasNext()) {
+ sb.append(checkBitsItem(it.next()));
+ while (it.hasNext()) {
+ sb.append(' ').append(checkBitsItem(it.next()));
+ }
+ }
+
+ return sb.append('\'');
+ }
+
+ final String str = value instanceof YangInstanceIdentifier ? serialize((YangInstanceIdentifier) value)
+ : String.valueOf(value);
// We have two specifications here: Section 6.1.3 of both RFC6020 and RFC7950:
//
// which is the same thing: always encode prefixes
return createQName(XMLConstants.DEFAULT_NS_PREFIX, localName);
}
+
+ // FIXME: YANGTOOLS-1426: this will not be necessary when we have dedicated bits type
+ private static @NonNull String checkBitsItem(final Object obj) {
+ if (obj instanceof String) {
+ return (String) obj;
+ }
+ throw new IllegalArgumentException("Unexpected bits component " + obj);
+ }
}