blob: 8a4e61858af5cb822e1e78a4c1a4b6a0a3f534b5 [file] [log] [blame]
alshabibab984662014-12-04 18:56:18 -08001/*
2 * Copyright 2014 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.core.impl;
Brian O'Connor520c0522014-11-23 23:50:47 -080017
18import org.easymock.EasyMock;
19import org.hamcrest.Matchers;
20import org.junit.Assert;
21import org.junit.Before;
22import org.junit.Test;
Brian O'Connorabafb502014-12-02 22:26:20 -080023import org.onosproject.core.IdBlock;
Brian O'Connor520c0522014-11-23 23:50:47 -080024
25/**
Brian O'Connorabafb502014-12-02 22:26:20 -080026 * Suites of test of {@link org.onosproject.core.impl.BlockAllocatorBasedIdGenerator}.
Brian O'Connor520c0522014-11-23 23:50:47 -080027 */
28public class IdBlockAllocatorBasedIdGeneratorTest {
29 private IdBlockAllocator allocator;
30 private BlockAllocatorBasedIdGenerator sut;
31
32 @Before
33 public void setUp() {
34 allocator = EasyMock.createMock(IdBlockAllocator.class);
35
36 }
37
38 /**
Brian O'Connorabafb502014-12-02 22:26:20 -080039 * Tests generated IntentId sequences using two {@link org.onosproject.core.IdBlock blocks}.
Brian O'Connor520c0522014-11-23 23:50:47 -080040 */
41 @Test
42 public void testIds() {
43 EasyMock.expect(allocator.allocateUniqueIdBlock())
44 .andReturn(new IdBlock(0, 3))
45 .andReturn(new IdBlock(4, 3));
46
47 EasyMock.replay(allocator);
48 sut = new BlockAllocatorBasedIdGenerator(allocator);
49
50 Assert.assertThat(sut.getNewId(), Matchers.is(0L));
51 Assert.assertThat(sut.getNewId(), Matchers.is(1L));
52 Assert.assertThat(sut.getNewId(), Matchers.is(2L));
53
54 Assert.assertThat(sut.getNewId(), Matchers.is(4L));
55 Assert.assertThat(sut.getNewId(), Matchers.is(5L));
56 Assert.assertThat(sut.getNewId(), Matchers.is(6L));
57 }
58}