blob: cb4ed35dbec2d6d169485d4226d6f07c35410928 [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 MatchActionIdGeneratorWithIdBlockAllocator.
16 */
17public class MatchActionIdGeneratorTest {
18 private IdBlockAllocator allocator;
19
20 @Before
21 public void setUp() {
22 allocator = createMock(IdBlockAllocator.class);
23
24 }
25
26 /**
27 * Tests generated MatchActionId sequences using two {@link net.onrc.onos.core.util.IdBlock blocks}.
28 */
29 @Test
30 public void testIds() {
31 expect(allocator.allocateUniqueIdBlock())
32 .andReturn(new IdBlock(0, 3))
33 .andReturn(new IdBlock(4, 3));
34
35 replay(allocator);
36 final MatchActionIdGeneratorWithIdBlockAllocator matchActionIdGenerator =
37 new MatchActionIdGeneratorWithIdBlockAllocator(allocator);
38
39 assertThat(matchActionIdGenerator.getNewId(), is(new MatchActionId(0L)));
40 assertThat(matchActionIdGenerator.getNewId(), is(new MatchActionId(1L)));
41 assertThat(matchActionIdGenerator.getNewId(), is(new MatchActionId(2L)));
42
43 assertThat(matchActionIdGenerator.getNewId(), is(new MatchActionId(4L)));
44 assertThat(matchActionIdGenerator.getNewId(), is(new MatchActionId(5L)));
45 assertThat(matchActionIdGenerator.getNewId(), is(new MatchActionId(6L)));
46 }
47}