2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 Nokia Networks Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.aai.babel.xml.generator.model;
23 import static org.hamcrest.core.Is.is;
24 import static org.junit.Assert.assertNull;
25 import static org.junit.Assert.assertThat;
27 import java.util.Base64;
28 import org.junit.Test;
29 import org.onap.aai.babel.xml.generator.data.GeneratorUtil;
31 public class TestGeneratorUtil {
33 private static final byte[] TEST_BYTES = "TestBytes".getBytes();
34 private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
37 public void shouldEncodeUsingBase64() {
38 byte[] expected = Base64.getEncoder().encode(TEST_BYTES);
39 byte[] result = GeneratorUtil.encode(TEST_BYTES);
41 assertThat(result, is(expected));
45 public void shouldReturnEmptyByteArrayWhenNullPassedToEncode() {
46 byte[] result = GeneratorUtil.encode(null);
48 assertThat(result, is(EMPTY_BYTE_ARRAY));
52 public void shouldDecodeUsingBase64() {
53 byte[] input = Base64.getEncoder().encode(TEST_BYTES);
54 byte[] expected = Base64.getDecoder().decode(input);
56 byte[] result = GeneratorUtil.decode(input);
58 assertThat(result, is(expected));
62 public void shouldReturnEmptyByteArrayWhenNullPassedToDecode() {
63 byte[] result = GeneratorUtil.decode(null);
65 assertThat(result, is(EMPTY_BYTE_ARRAY));
69 public void shouldReturnNullWhenNullPassedToCheckSum() {
70 assertNull(GeneratorUtil.checkSum(null));
74 public void shouldReturnSameCheckSumForIdenticalInput() {
75 String checkSum1 = GeneratorUtil.checkSum(TEST_BYTES);
76 String checkSum2 = GeneratorUtil.checkSum(TEST_BYTES);
78 assertThat(checkSum1, is(checkSum2));