299446b16ef0c381485690e9de9635a16f18f5eb
[controller.git] / opendaylight / config / config-api / src / test / java / org / opendaylight / controller / config / api / jmx / CommitStatusTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. 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.controller.config.api.jmx;
10
11 import java.util.ArrayList;
12 import java.util.List;
13 import javax.management.ObjectName;
14 import org.junit.Assert;
15 import org.junit.Before;
16 import org.junit.Test;
17
18 public class CommitStatusTest {
19     List<ObjectName> newInst = new ArrayList<>();
20     List<ObjectName> reusedInst = new ArrayList<>();
21     List<ObjectName> recreatedInst = new ArrayList<>();
22
23     @Before
24     public void setUp() throws Exception {
25         newInst.add(new ObjectName("domain: key1 = value1 , key2 = value2"));
26         reusedInst.add(new ObjectName("o2: key = val"));
27         recreatedInst.add(new ObjectName("o3: key = k"));
28     }
29     @Test
30     public void testCommitStatus() throws Exception {
31         CommitStatus status = new CommitStatus(newInst, reusedInst, recreatedInst);
32         Assert.assertEquals(status.getNewInstances(), newInst);
33         Assert.assertEquals(status.getRecreatedInstances(), recreatedInst);
34         Assert.assertEquals(status.getReusedInstances(), reusedInst);
35     }
36
37     @Test
38     public void testEqual() throws Exception {
39         CommitStatus status = new CommitStatus(newInst, reusedInst, recreatedInst);
40         Assert.assertEquals(status, new CommitStatus(newInst, reusedInst, recreatedInst));
41         Assert.assertEquals(status.toString(), new CommitStatus(newInst, reusedInst, recreatedInst).toString());
42         Assert.assertEquals(status, status);
43     }
44
45     @Test
46     public void testHashCode() throws Exception {
47         CommitStatus status = new CommitStatus(newInst, reusedInst, recreatedInst);
48         Assert.assertEquals(status.hashCode(), new CommitStatus(newInst, reusedInst, recreatedInst).hashCode());
49     }
50
51     @Test
52     public void testNotEqual() throws Exception {
53         List<ObjectName> newInst2 = new ArrayList<>();
54         List<ObjectName> reusedInst2 = new ArrayList<>();
55         List<ObjectName> recreatedInst2 = new ArrayList<>();
56
57         newInst2.add(new ObjectName("first: key1 = value1"));
58         reusedInst2.add(new ObjectName("second: key = val"));
59         recreatedInst2.add(new ObjectName("third: key = k"));
60
61         CommitStatus status = new CommitStatus(newInst, reusedInst, recreatedInst);
62         Assert.assertNotEquals(status, null);
63         Assert.assertNotEquals(status, new Object());
64         Assert.assertNotEquals(status, new CommitStatus(newInst2, reusedInst, recreatedInst));
65         Assert.assertNotEquals(status, new CommitStatus(newInst, reusedInst2, recreatedInst));
66         Assert.assertNotEquals(status, new CommitStatus(newInst, reusedInst, recreatedInst2));
67
68         CommitStatus status2 = new CommitStatus(newInst, reusedInst, recreatedInst);
69     }
70 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.