af81a111f36146dca873f75163d7cb5d03e46b04
[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 com.fasterxml.jackson.core.JsonProcessingException;
24 import org.junit.Test;
25 import org.onap.holmes.common.dcae.entity.DcaeConfigurations;
26 import org.onap.holmes.common.dcae.entity.SecurityInfo;
27
28 public class Md5UtilTest {
29
30     @Test
31     public void testMd5NormalDiff() {
32         String contents1 = "contents1";
33         String contents2 = "contents2";
34
35         assertThat(Md5Util.md5(contents1), not(equalTo(Md5Util.md5(contents2))));
36     }
37
38     @Test
39     public void testMd5NormalSame() {
40         String contents1 = "contents";
41         String contents2 = "contents";
42
43         assertThat(Md5Util.md5(contents1), equalTo(Md5Util.md5(contents2)));
44     }
45
46     @Test
47     public void testMd5Null() {
48         String contents1 = null;
49         String contents2 = null;
50
51         assertThat(Md5Util.md5(contents1), equalTo(Md5Util.md5(contents2)));
52     }
53
54     @Test
55     public void testMd5ObjDiff() {
56         DcaeConfigurations config1 = new DcaeConfigurations();
57         DcaeConfigurations config2 = new DcaeConfigurations();
58
59         config1.addPubSecInfo("config1", new SecurityInfo());
60         config2.addPubSecInfo("config2", new SecurityInfo());
61         assertThat(Md5Util.md5(config1), not(equalTo(Md5Util.md5(config2))));
62
63     }
64
65     @Test
66     public void testMd5ObjSame() {
67         DcaeConfigurations config1 = new DcaeConfigurations();
68         DcaeConfigurations config2 = new DcaeConfigurations();
69
70         config1.addPubSecInfo("config", new SecurityInfo());
71         config2.addPubSecInfo("config", new SecurityInfo());
72
73         assertThat(Md5Util.md5(config1), equalTo(Md5Util.md5(config2)));
74
75     }
76 }