X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=restconf%2Frestconf-nb%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Frestconf%2Fnb%2Frfc8040%2FAbstractJukeboxTest.java;h=cd0453594bc6f3180dae146ad2bc5f6620876076;hb=refs%2Fchanges%2F39%2F111339%2F3;hp=d0e592ab209752944e16ac72f4675a0605e3cbe3;hpb=b084f152b100fcba165350ac2629ef47e22514d3;p=netconf.git diff --git a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/AbstractJukeboxTest.java b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/AbstractJukeboxTest.java index d0e592ab20..cd0453594b 100644 --- a/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/AbstractJukeboxTest.java +++ b/restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/AbstractJukeboxTest.java @@ -7,10 +7,17 @@ */ package org.opendaylight.restconf.nb.rfc8040; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; import java.nio.charset.StandardCharsets; import org.eclipse.jdt.annotation.NonNull; +import org.opendaylight.restconf.api.FormatParameters; +import org.opendaylight.restconf.api.query.PrettyPrintParam; import org.opendaylight.restconf.server.api.DatabindContext; import org.opendaylight.yangtools.yang.common.Decimal64; import org.opendaylight.yangtools.yang.common.QName; @@ -27,6 +34,12 @@ import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; public abstract class AbstractJukeboxTest { + @FunctionalInterface + public interface FormatMethod { + + void invoke(@NonNull FormatParameters format, @NonNull OutputStream out) throws IOException; + } + // container jukebox protected static final QName JUKEBOX_QNAME = QName.create("http://example.com/ns/example-jukebox", "2015-04-04", "jukebox"); @@ -98,4 +111,15 @@ public abstract class AbstractJukeboxTest { protected static final InputStream stringInputStream(final String str) { return new ByteArrayInputStream(str.getBytes(StandardCharsets.UTF_8)); } + + public static void assertFormat(final String expected, final FormatMethod formatMethod, + final boolean prettyPrint) { + final var baos = new ByteArrayOutputStream(); + try { + formatMethod.invoke(new FormatParameters(PrettyPrintParam.of(prettyPrint)), baos); + } catch (IOException e) { + throw new AssertionError(e); + } + assertEquals(expected, baos.toString(StandardCharsets.UTF_8)); + } }