Add JUnit test for invalid TOSCA mappings JSON
[aai/babel.git] / src / test / java / org / onap / aai / babel / xml / generator / model / TestGeneratorUtil.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21
22 package org.onap.aai.babel.xml.generator.model;
23
24 import static org.hamcrest.core.Is.is;
25 import static org.junit.Assert.assertNull;
26 import static org.junit.Assert.assertThat;
27
28 import java.util.Base64;
29 import org.junit.Test;
30 import org.onap.aai.babel.xml.generator.data.GeneratorUtil;
31
32 public class TestGeneratorUtil {
33
34     private static final byte[] TEST_BYTES = "TestBytes".getBytes();
35     private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
36
37     @Test
38     public void shouldEncodeUsingBase64() {
39         byte[] expected = Base64.getEncoder().encode(TEST_BYTES);
40         byte[] result = GeneratorUtil.encode(TEST_BYTES);
41
42         assertThat(result, is(expected));
43     }
44
45     @Test
46     public void shouldReturnEmptyByteArrayWhenNullPassedToEncode() {
47         byte[] result = GeneratorUtil.encode(null);
48
49         assertThat(result, is(EMPTY_BYTE_ARRAY));
50     }
51
52     @Test
53     public void shouldDecodeUsingBase64() {
54         byte[] input = Base64.getEncoder().encode(TEST_BYTES);
55         byte[] expected = Base64.getDecoder().decode(input);
56
57         byte[] result = GeneratorUtil.decode(input);
58
59         assertThat(result, is(expected));
60     }
61
62     @Test
63     public void shouldReturnEmptyByteArrayWhenNullPassedToDecode() {
64         byte[] result = GeneratorUtil.decode(null);
65
66         assertThat(result, is(EMPTY_BYTE_ARRAY));
67     }
68
69     @Test
70     public void shouldReturnNullWhenNullPassedToCheckSum() {
71         assertNull(GeneratorUtil.checkSum(null));
72     }
73
74     @Test
75     public void shouldReturnSameCheckSumForIdenticalInput() {
76         String checkSum1 = GeneratorUtil.checkSum(TEST_BYTES);
77         String checkSum2 = GeneratorUtil.checkSum(TEST_BYTES);
78
79         assertThat(checkSum1, is(checkSum2));
80     }
81 }