2 * Copyright (C) 2018 Huawei Intellectual Property. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.openecomp.sdc.action.types;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.openecomp.sdc.action.dao.types.ActionEntity;
23 import java.util.ArrayList;
24 import java.util.Date;
25 import java.util.HashMap;
27 import java.util.List;
28 import java.util.stream.Collectors;
30 import static org.junit.Assert.assertEquals;
31 import static org.junit.Assert.assertNotNull;
33 public class ActionTest {
38 public void setup() throws Exception {
40 Map<String, String> supportedcomponents = new HashMap<>();
41 supportedcomponents.put("Id","one");
42 List supportedcomponentsList = new ArrayList<Map<String, String>>();
43 supportedcomponentsList.add(supportedcomponents);
45 Map<String, String> supportedmodels = new HashMap<>();
46 supportedmodels.put("versionId","one");
47 List supportedmodelsList = new ArrayList<Map<String, String>>();
48 supportedmodelsList.add(supportedmodels);
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");
66 public void testActionUuid() {
67 assertEquals(action.getActionUuId(), "actionuuid");
71 public void testActionInvariantUuid() {
72 assertEquals(action.getActionInvariantUuId(), "actioninvariantuuid");
76 public void testData() {
77 assertEquals(action.getData(), "data");
81 public void testName() {
82 assertEquals(action.getName(), "NAME");
89 public void testToEntiry() {
90 ActionEntity destination = action.toEntity();
91 assertNotNull(destination);
92 assertEqualsMultipleAssert(action,destination);
98 public void testequal()
101 assertEquals(true,action.equals(action));
105 public void testhashcode()
107 assertEquals(action.hashCode(),31 * action.getVersion().hashCode() + action.getName().hashCode());
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());