2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.mdsal.common.api;
10 import static org.junit.jupiter.api.Assertions.assertArrayEquals;
11 import static org.junit.jupiter.api.Assertions.assertEquals;
12 import static org.junit.jupiter.api.Assertions.assertSame;
13 import static org.junit.jupiter.api.Assertions.assertThrows;
15 import java.io.ByteArrayInputStream;
16 import java.io.ByteArrayOutputStream;
17 import java.io.DataInputStream;
18 import java.io.DataOutputStream;
19 import java.io.IOException;
20 import java.util.stream.Stream;
21 import org.junit.jupiter.api.Test;
22 import org.junit.jupiter.params.ParameterizedTest;
23 import org.junit.jupiter.params.provider.MethodSource;
25 class LogicalDatastoreTypeTest {
28 void serialization(final LogicalDatastoreType type, final byte[] expected) throws Exception {
29 final var bout = new ByteArrayOutputStream();
30 try (var out = new DataOutputStream(bout)) {
33 assertArrayEquals(expected, bout.toByteArray());
35 try (var in = new DataInputStream(new ByteArrayInputStream(expected))) {
36 assertSame(type, LogicalDatastoreType.readFrom(in));
40 static Stream<Object[]> serialization() {
42 new Object[] { LogicalDatastoreType.OPERATIONAL, new byte[] { 1 }},
43 new Object[] { LogicalDatastoreType.CONFIGURATION, new byte[] { 2 }});
47 void invalidSerialization() throws Exception {
48 try (var in = new DataInputStream(new ByteArrayInputStream(new byte[] { 0 }))) {
49 final var ex = assertThrows(IOException.class, () -> LogicalDatastoreType.readFrom(in));
50 assertEquals("Unknown type 0", ex.getMessage());