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