Update unit tests
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / registry / group / DeviceGroupRegistryImplTest.java
1 /*
2  * Copyright (c) 2015 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.openflowplugin.impl.registry.group;
10
11 import java.util.concurrent.atomic.AtomicInteger;
12 import org.junit.Assert;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId;
16
17 /**
18  * Test for {@link DeviceGroupRegistryImpl}.
19  */
20 public class DeviceGroupRegistryImplTest {
21
22     private GroupId groupId;
23     private GroupId groupId2;
24     private DeviceGroupRegistryImpl deviceGroupRegistry;
25
26     @Before
27     public void setUp() throws Exception {
28         deviceGroupRegistry = new DeviceGroupRegistryImpl();
29         groupId = new GroupId(42L);
30         groupId2 = new GroupId(84L);
31         Assert.assertEquals(0, deviceGroupRegistry.getAllGroupIds().size());
32         deviceGroupRegistry.store(groupId);
33         Assert.assertEquals(1, deviceGroupRegistry.getAllGroupIds().size());
34     }
35
36     @Test
37     public void testStore() throws Exception {
38         deviceGroupRegistry.store(groupId2);
39         Assert.assertEquals(2, deviceGroupRegistry.getAllGroupIds().size());
40     }
41
42     @Test
43     public void testRemoveMarked() throws Exception {
44         deviceGroupRegistry.addMark(groupId);
45         deviceGroupRegistry.processMarks();
46         Assert.assertEquals(0, deviceGroupRegistry.getAllGroupIds().size());
47     }
48
49     @Test
50     public void testRemoveMarkedNegative() throws Exception {
51         deviceGroupRegistry.addMark(groupId2);
52         deviceGroupRegistry.processMarks();
53         Assert.assertEquals(1, deviceGroupRegistry.getAllGroupIds().size());
54     }
55
56     @Test
57     public void testClose() throws Exception {
58         deviceGroupRegistry.addMark(groupId);
59         deviceGroupRegistry.close();
60
61         Assert.assertEquals(0, deviceGroupRegistry.getAllGroupIds().size());
62         deviceGroupRegistry.store(groupId);
63         Assert.assertEquals(1, deviceGroupRegistry.getAllGroupIds().size());
64         deviceGroupRegistry.processMarks();
65         Assert.assertEquals(1, deviceGroupRegistry.getAllGroupIds().size());
66     }
67
68     @Test
69     public void testForEach() throws Exception {
70         final AtomicInteger counter = new AtomicInteger(0);
71         deviceGroupRegistry.store(groupId2);
72         deviceGroupRegistry.forEach(group -> counter.incrementAndGet());
73         Assert.assertEquals(2, counter.get());
74     }
75 }