Ray Milkey | 9ed4b96 | 2014-08-20 15:43:40 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.matchaction; |
| 2 | |
| 3 | import net.onrc.onos.core.util.IdBlock; |
| 4 | import net.onrc.onos.core.util.IdBlockAllocator; |
| 5 | import org.junit.Before; |
| 6 | import org.junit.Test; |
| 7 | |
| 8 | import static org.easymock.EasyMock.createMock; |
| 9 | import static org.easymock.EasyMock.expect; |
| 10 | import static org.easymock.EasyMock.replay; |
| 11 | import static org.hamcrest.Matchers.is; |
| 12 | import static org.junit.Assert.assertThat; |
| 13 | |
| 14 | /** |
| 15 | * Tests MatchActionIdGeneratorWithIdBlockAllocator. |
| 16 | */ |
| 17 | public 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 | } |