2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (c) 2017-2018 Nokia Networks Intellectual Property. All rights reserved.
6 * Copyright (c) 2017-2019 European Software Marketing Ltd.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.aai.babel.xml.generator.model;
24 import static org.hamcrest.core.Is.is;
25 import static org.junit.Assert.assertNull;
26 import static org.junit.Assert.assertThat;
28 import java.util.Base64;
29 import org.junit.Test;
30 import org.onap.aai.babel.xml.generator.data.GeneratorUtil;
32 public class TestGeneratorUtil {
34 private static final byte[] TEST_BYTES = "TestBytes".getBytes();
35 private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
38 public void shouldEncodeUsingBase64() {
39 byte[] expected = Base64.getEncoder().encode(TEST_BYTES);
40 byte[] result = GeneratorUtil.encode(TEST_BYTES);
42 assertThat(result, is(expected));
46 public void shouldReturnEmptyByteArrayWhenNullPassedToEncode() {
47 byte[] result = GeneratorUtil.encode(null);
49 assertThat(result, is(EMPTY_BYTE_ARRAY));
53 public void shouldReturnNullWhenNullPassedToCheckSum() {
54 assertNull(GeneratorUtil.checkSum(null));
58 public void shouldReturnSameCheckSumForIdenticalInput() {
59 String checkSum1 = GeneratorUtil.checkSum(TEST_BYTES);
60 String checkSum2 = GeneratorUtil.checkSum(TEST_BYTES);
62 assertThat(checkSum1, is(checkSum2));