Test Replace Jackson with GSON
[holmes/common.git] / holmes-actions / src / test / java / org / onap / holmes / common / utils / Md5UtilTest.java
1 /*
2  * Copyright 2017 ZTE Corporation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.onap.holmes.common.utils;
18
19 import static org.hamcrest.core.IsEqual.equalTo;
20 import static org.hamcrest.core.IsNot.not;
21 import static org.junit.Assert.assertThat;
22
23 import org.junit.Test;
24 import org.onap.holmes.common.dcae.entity.DcaeConfigurations;
25 import org.onap.holmes.common.dcae.entity.SecurityInfo;
26
27 public class Md5UtilTest {
28
29     @Test
30     public void testMd5NormalDiff() {
31         String contents1 = "contents1";
32         String contents2 = "contents2";
33
34         assertThat(Md5Util.md5(contents1), not(equalTo(Md5Util.md5(contents2))));
35     }
36
37     @Test
38     public void testMd5NormalSame() {
39         String contents1 = "contents";
40         String contents2 = "contents";
41
42         assertThat(Md5Util.md5(contents1), equalTo(Md5Util.md5(contents2)));
43     }
44
45     @Test
46     public void testMd5Null() {
47         String contents1 = null;
48         String contents2 = null;
49
50         assertThat(Md5Util.md5(contents1), equalTo(Md5Util.md5(contents2)));
51     }
52
53     @Test
54     public void testMd5ObjDiff() {
55         DcaeConfigurations config1 = new DcaeConfigurations();
56         DcaeConfigurations config2 = new DcaeConfigurations();
57
58         config1.addPubSecInfo("config1", new SecurityInfo());
59         config2.addPubSecInfo("config2", new SecurityInfo());
60         assertThat(Md5Util.md5(config1), not(equalTo(Md5Util.md5(config2))));
61
62     }
63
64     @Test
65     public void testMd5ObjSame() {
66         DcaeConfigurations config1 = new DcaeConfigurations();
67         DcaeConfigurations config2 = new DcaeConfigurations();
68
69         config1.addPubSecInfo("config", new SecurityInfo());
70         config2.addPubSecInfo("config", new SecurityInfo());
71
72         assertThat(Md5Util.md5(config1), equalTo(Md5Util.md5(config2)));
73
74     }
75 }