blob: 28023a23094cee56f329be10d0f481790ee0bee3 [file] [log] [blame]
Carmelo Cascone42fdec32019-12-09 22:36:48 -08001/*
2 * Copyright 2019-present Open Networking Foundation
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 */
16
17package org.onosproject.pipelines.fabric.impl.behaviour.bng;
18
19import org.junit.After;
20import org.junit.Before;
21import org.junit.Test;
22import org.onosproject.net.DeviceId;
23
24import static org.junit.Assert.assertEquals;
25import static org.junit.Assert.assertNotEquals;
26import static org.junit.Assert.fail;
27
28/**
29 * Tests for FabricBngProgrammableService.
30 */
31public class FabricBngProgrammableServiceTest {
32
33 private static final int SIZE = 10;
34 private static final DeviceId DEVICE_ID_1 = DeviceId.deviceId("device:1");
35 private static final DeviceId DEVICE_ID_2 = DeviceId.deviceId("device:2");
36
37 private final FabricBngProgrammableService service = new FabricBngProgrammableService();
38
39 @Before
40 public void setUp() throws Exception {
41 service.deviceService = new MockDeviceService();
42 service.activate();
43 }
44
45 @After
46 public void tearDown() throws Exception {
47 service.deactivate();
48 try {
49 service.getLineIdAllocator(DEVICE_ID_1, SIZE);
50 fail("Service methods should fail after deactivation");
51 } catch (NullPointerException e) {
52 // Expected.
53 }
54 }
55
56 @Test
57 public void getLineIdAllocatorTest() {
58 var allocator1 = service.getLineIdAllocator(DEVICE_ID_1, SIZE);
59 var sameAsAllocator1 = service.getLineIdAllocator(DEVICE_ID_1, SIZE);
60 var allocator2 = service.getLineIdAllocator(DEVICE_ID_2, SIZE);
61
62 assertEquals(allocator1.size(), SIZE);
63 assertEquals(allocator1, sameAsAllocator1);
64 assertNotEquals(allocator1, allocator2);
65
66 try {
67 service.getLineIdAllocator(DEVICE_ID_1, SIZE + 1);
68 fail("Retrieving allocators with different size should fail");
69 } catch (IllegalArgumentException e) {
70 // Expected.
71 }
72 }
73}