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.yangtools.yang.data.impl.codecs;
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12 import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.getCodec;
14 import java.util.Base64;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.data.api.codec.BinaryCodec;
17 import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
20 * Unit tests for BinaryCodecString.
22 * @author Thomas Pantelis
24 public class BinaryCodecStringTest {
25 private static final byte[] FOUR_ELEMENTS = { 1, 2, 3, 4 };
27 @SuppressWarnings("unchecked")
29 public void testSerialize() {
30 BinaryCodec<String> codec = getCodec(BaseTypes.binaryType(), BinaryCodec.class);
31 assertEquals(Base64.getEncoder().encodeToString(FOUR_ELEMENTS), codec.serialize(FOUR_ELEMENTS));
34 @SuppressWarnings("unchecked")
36 public void testDererialize() {
37 BinaryCodec<String> codec = getCodec(BaseTypes.binaryType(), BinaryCodec.class);
38 assertArrayEquals(FOUR_ELEMENTS, codec.deserialize(Base64.getEncoder().encodeToString(FOUR_ELEMENTS)));