New Package dealing with device rollback
[transportpce.git] / renderer / src / test / java / org / opendaylight / transportpce / renderer / provisiondevice / transaction / ConnectionTest.java
1 /*
2  * Copyright © 2024 Smartoptics and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.transportpce.renderer.provisiondevice.transaction;
10
11 import java.util.ArrayList;
12 import java.util.List;
13 import org.junit.Assert;
14 import org.junit.jupiter.api.Test;
15 import org.mockito.Mockito;
16 import org.opendaylight.transportpce.renderer.provisiondevice.transaction.delete.Delete;
17
18 class ConnectionTest {
19
20     @Test
21     void rollback() {
22         Delete delete = Mockito.mock(Delete.class);
23         Mockito.when(delete.deleteCrossConnect("ROADM-A", "DEG1", false))
24                 .thenReturn(List.of("Interface1"));
25
26         Connection n1 = new Connection("ROADM-A", "DEG1", false);
27
28         Assert.assertTrue(n1.rollback(delete));
29
30         Mockito.verify(delete, Mockito.times(1))
31                 .deleteCrossConnect("ROADM-A", "DEG1", false);
32     }
33
34     @Test
35     void testTwoObjectsWithSameInformationIsEqual() {
36         Connection n1 = new Connection("ROADM-A", "DEG1", false);
37         Connection n2 = new Connection("ROADM-A", "DEG1", false);
38
39         Assert.assertTrue(n1.equals(n2));
40     }
41
42     @Test
43     void testTwoObjectsWithDifferentInformationIsNotEqual() {
44         Connection n1 = new Connection("ROADM-A", "DEG1", true);
45         Connection n2 = new Connection("ROADM-A", "DEG1", false);
46
47         Assert.assertFalse(n1.equals(n2));
48     }
49
50     @Test
51     void testTwoDifferentRoadmNodesAreNotEqual() {
52         Connection n1 = new Connection("ROADM-A", "DEG1", false);
53         Connection n2 = new Connection("ROADM-B", "DEG1", false);
54
55         Assert.assertFalse(n1.equals(n2));
56     }
57
58
59     @Test
60     void deleteReturnNull() {
61         Delete delete = Mockito.mock(Delete.class);
62         Mockito.when(delete.deleteCrossConnect("ROADM-A", "DEG1", false))
63                 .thenReturn(null);
64
65         Connection n1 = new Connection("ROADM-A", "DEG1", false);
66
67         Assert.assertFalse(n1.rollback(delete));
68
69         Mockito.verify(delete, Mockito.times(1))
70                 .deleteCrossConnect("ROADM-A", "DEG1", false);
71     }
72
73     @Test
74     void deleteReturnEmptyList() {
75         Delete delete = Mockito.mock(Delete.class);
76         Mockito.when(delete.deleteCrossConnect("ROADM-A", "DEG1", false))
77                 .thenReturn(new ArrayList<>());
78
79         Connection n1 = new Connection("ROADM-A", "DEG1", false);
80
81         Assert.assertFalse(n1.rollback(delete));
82
83         Mockito.verify(delete, Mockito.times(1))
84                 .deleteCrossConnect("ROADM-A", "DEG1", false);
85     }
86 }