4c38a70cb3dde1c2798474f346f999d4937f025a
[sdc.git] /
1 /*
2  * Copyright (C) 2018 Huawei Intellectual Property. All rights reserved.
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.openecomp.sdc.action.types;
18
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.openecomp.sdc.action.dao.types.ActionEntity;
22
23 import java.util.ArrayList;
24 import java.util.Date;
25 import java.util.HashMap;
26 import java.util.Map;
27 import java.util.List;
28 import java.util.stream.Collectors;
29
30 import static org.junit.Assert.assertEquals;
31 import static org.junit.Assert.assertNotNull;
32
33 public class ActionTest {
34
35     Action action;
36
37     @Before
38     public void setup() throws Exception {
39
40         Map<String, String> supportedcomponents = new HashMap<>();
41         supportedcomponents.put("Id","one");
42         List supportedcomponentsList = new ArrayList<Map<String, String>>();
43         supportedcomponentsList.add(supportedcomponents);
44
45         Map<String, String> supportedmodels = new HashMap<>();
46         supportedmodels.put("versionId","one");
47         List supportedmodelsList = new ArrayList<Map<String, String>>();
48         supportedmodelsList.add(supportedmodels);
49
50         action= new Action();
51         action.setActionUuId("actionuuid");
52         action.setActionInvariantUuId("actioninvariantuuid");
53         action.setName("NAME");
54         action.setTimestamp(new Date());
55         action.setUser("User");
56         action.setStatus(ActionStatus.Available);
57         action.setVersion("11.10");
58         action.setVendorList(new ArrayList<String>());
59         action.setCategoryList(new ArrayList<String>());
60         action.setSupportedComponents( (List<Map<String,String>>) supportedcomponentsList);
61         action.setSupportedModels( (List<Map<String,String>>) supportedmodelsList);
62         action.setData("data");
63     }
64
65     @Test
66     public void testActionUuid() {
67         assertEquals(action.getActionUuId(), "actionuuid");
68     }
69
70     @Test
71     public void testActionInvariantUuid() {
72         assertEquals(action.getActionInvariantUuId(), "actioninvariantuuid");
73     }
74
75     @Test
76     public void testData() {
77         assertEquals(action.getData(), "data");
78     }
79
80     @Test
81     public void testName() {
82         assertEquals(action.getName(), "NAME");
83     }
84
85
86
87
88     @Test
89     public void testToEntiry() {
90         ActionEntity destination = action.toEntity();
91         assertNotNull(destination);
92         assertEqualsMultipleAssert(action,destination);
93     }
94
95
96
97     @Test
98     public void testequal()
99     {
100
101         assertEquals(true,action.equals(action));
102     }
103
104     @Test
105     public void testhashcode()
106     {
107         assertEquals(action.hashCode(),31 * action.getVersion().hashCode() + action.getName().hashCode());
108     }
109
110     private void assertEqualsMultipleAssert(Action source, ActionEntity destination) {
111         assertEquals(source.getName().toLowerCase(),destination.getName());
112         assertEquals(source.getActionUuId().toUpperCase(),destination.getActionUuId());
113         assertEquals(source.getActionInvariantUuId().toUpperCase(),destination.getActionInvariantUuId());
114         assertEquals(source.getTimestamp(),destination.getTimestamp());
115         assertEquals(source.getUser(),destination.getUser());
116         assertEquals(source.getStatus().name(),destination.getStatus());
117         assertEquals(source.getVersion(),destination.getVersion().toString());
118         assertEquals(source.getVendorList(), new ArrayList<String>(destination.getVendorList()));
119         assertEquals(source.getCategoryList(),new ArrayList<String>(destination.getCategoryList()));
120         assertEquals(source.getSupportedComponents().get(0).values().stream().collect(Collectors.toList()), new ArrayList<String>(destination.getSupportedComponents()));
121         assertEquals(source.getSupportedModels().get(0).values().stream().collect(Collectors.toList()),new ArrayList<String>(destination.getSupportedModels()));
122         assertEquals(source.getData(),destination.getData());
123     }
124 }