blob: e95f1df7a243887e6805a72d668bde6bbede4c78 [file] [log] [blame]
Ray Milkey9ed4b962014-08-20 15:43:40 -07001package net.onrc.onos.core.matchaction;
2
3import net.onrc.onos.core.util.IdBlock;
4import net.onrc.onos.core.util.IdBlockAllocator;
5import org.junit.Before;
6import org.junit.Test;
7
8import static org.easymock.EasyMock.createMock;
9import static org.easymock.EasyMock.expect;
10import static org.easymock.EasyMock.replay;
11import static org.hamcrest.Matchers.is;
12import static org.junit.Assert.assertThat;
13
14/**
15 * Tests MatchActionOperationsIdGeneratorWithIdBlockAllocator.
16 */
17public class MatchActionOperationsIdGeneratorTest {
18
19 private IdBlockAllocator allocator;
20
21 @Before
22 public void setUp() {
23 allocator = createMock(IdBlockAllocator.class);
24
25 }
26
27 /**
28 * Tests generated MatchActionOperationsId sequences using two {@link net.onrc.onos.core.util.IdBlock blocks}.
29 */
30 @Test
31 public void testIds() {
32 expect(allocator.allocateUniqueIdBlock())
33 .andReturn(new IdBlock(0, 3))
34 .andReturn(new IdBlock(4, 3));
35
36 replay(allocator);
37 final MatchActionOperationsIdGeneratorWithIdBlockAllocator generator =
38 new MatchActionOperationsIdGeneratorWithIdBlockAllocator(allocator);
39
40 assertThat(generator.getNewId(), is(new MatchActionOperationsId(0L)));
41 assertThat(generator.getNewId(), is(new MatchActionOperationsId(1L)));
42 assertThat(generator.getNewId(), is(new MatchActionOperationsId(2L)));
43
44 assertThat(generator.getNewId(), is(new MatchActionOperationsId(4L)));
45 assertThat(generator.getNewId(), is(new MatchActionOperationsId(5L)));
46 assertThat(generator.getNewId(), is(new MatchActionOperationsId(6L)));
47 }
48}
49