*/
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;
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");
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));
+ }
}