Fix test cases failing incorrectly
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / path / ForwardingPathChangeVersionTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.be.components.path;
22
23 import org.javatuples.Pair;
24 import org.junit.jupiter.api.Test;
25 import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
26 import org.openecomp.sdc.be.impl.ForwardingPathUtils;
27
28 import java.util.HashMap;
29 import java.util.Map;
30 import java.util.Set;
31
32 import static org.junit.Assert.assertEquals;
33 import static org.junit.Assert.assertNotNull;
34 public class ForwardingPathChangeVersionTest extends BaseForwardingPathVersionChangeTest {
35
36
37     @Test
38     public void updateForwardingPath() {
39         Pair<Map<String, ForwardingPathDataDefinition>, Map<String, ForwardingPathDataDefinition>> pair = new ForwardingPathUtils()
40             .updateForwardingPathOnVersionChange(service,dataHolder,newNodeAC, newNodeA);
41         Map<String, ForwardingPathDataDefinition> updated = pair.getValue0();
42         assertNotNull(updated);
43         assertEquals(1, updated.size());
44         assertEquals(newNodeA, updated.values().iterator().next().getPathElements().getListToscaDataDefinition().get(0).getFromNode());
45         Map<String, ForwardingPathDataDefinition> deleted = pair.getValue1();
46         assertNotNull(deleted);
47         assertEquals(0, deleted.size());
48     }
49
50     @Test
51     public void deleteForwardingPath(){
52         newNodeAC.setCapabilities(new HashMap<>());
53         Pair<Map<String, ForwardingPathDataDefinition>, Map<String, ForwardingPathDataDefinition>> pair = new ForwardingPathUtils()
54             .updateForwardingPathOnVersionChange(service,dataHolder,newNodeAC, newNodeA);
55         Map<String, ForwardingPathDataDefinition> updated = pair.getValue0();
56         assertNotNull(updated);
57         assertEquals(0, updated.size());
58
59         Map<String, ForwardingPathDataDefinition> deleted = pair.getValue1();
60         assertNotNull(deleted);
61         assertEquals(1, deleted.size());
62         assertEquals(FPId, deleted.keySet().stream().findAny().get());
63     }
64
65     @Test
66     public void fetchPathsToBeDeletedZeroPaths(){
67         Set<String> data=new ForwardingPathUtils().getForwardingPathsToBeDeletedOnVersionChange(service,
68             dataHolder,newNodeAC);
69         assertEquals(0,data.size());
70     }
71
72     @Test
73     public void fetchPathsToBeDeleted(){
74         Set<String> data=new ForwardingPathUtils().getForwardingPathsToBeDeletedOnVersionChange(service,
75             dataHolder,newNodeWithoutCapability);
76         assertEquals(1,data.size());
77     }
78
79
80 }