Thomas Vachuska | 4d66d0a | 2016-04-15 15:48:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 | */ |
| 16 | |
| 17 | package org.onosproject.ui.impl.topo; |
| 18 | |
| 19 | import org.junit.After; |
| 20 | import org.junit.Before; |
| 21 | import org.junit.Test; |
| 22 | import org.onosproject.net.region.DefaultRegion; |
| 23 | import org.onosproject.net.region.Region; |
| 24 | import org.onosproject.net.region.RegionId; |
| 25 | import org.onosproject.store.service.TestStorageService; |
| 26 | import org.onosproject.ui.UiTopoLayoutService; |
| 27 | import org.onosproject.ui.model.topo.UiTopoLayout; |
| 28 | import org.onosproject.ui.model.topo.UiTopoLayoutId; |
| 29 | |
| 30 | import static org.junit.Assert.*; |
| 31 | |
| 32 | /** |
| 33 | * Suite of unit tests for the UI topology layout manager. |
| 34 | */ |
| 35 | public class UiTopoLayoutManagerTest { |
| 36 | |
| 37 | private UiTopoLayoutService svc; |
| 38 | private UiTopoLayoutManager mgr; |
| 39 | |
| 40 | private static final UiTopoLayout L1 = |
| 41 | new UiTopoLayout(UiTopoLayoutId.layoutId("l1"), |
| 42 | new DefaultRegion(RegionId.regionId("r1"), "R1", |
Thomas Vachuska | 92b016b | 2016-05-20 11:37:57 -0700 | [diff] [blame] | 43 | Region.Type.CAMPUS, null), null); |
Thomas Vachuska | 4d66d0a | 2016-04-15 15:48:13 -0700 | [diff] [blame] | 44 | private static final UiTopoLayout L2 = |
| 45 | new UiTopoLayout(UiTopoLayoutId.layoutId("l2"), |
| 46 | new DefaultRegion(RegionId.regionId("r2"), "R2", |
Thomas Vachuska | 92b016b | 2016-05-20 11:37:57 -0700 | [diff] [blame] | 47 | Region.Type.CAMPUS, null), null); |
Thomas Vachuska | 4d66d0a | 2016-04-15 15:48:13 -0700 | [diff] [blame] | 48 | |
| 49 | @Before |
| 50 | public void setUp() { |
| 51 | mgr = new UiTopoLayoutManager(); |
| 52 | svc = mgr; |
| 53 | mgr.storageService = new TestStorageService(); |
| 54 | mgr.activate(); |
| 55 | } |
| 56 | |
| 57 | @After |
| 58 | public void tearDown() { |
| 59 | mgr.deactivate(); |
| 60 | mgr.storageService = null; |
| 61 | } |
| 62 | |
| 63 | @Test |
| 64 | public void basics() { |
Thomas Vachuska | 92b016b | 2016-05-20 11:37:57 -0700 | [diff] [blame] | 65 | assertEquals("should be just default layout", 1, svc.getLayouts().size()); |
Thomas Vachuska | 4d66d0a | 2016-04-15 15:48:13 -0700 | [diff] [blame] | 66 | svc.addLayout(L1); |
| 67 | svc.addLayout(L2); |
Thomas Vachuska | 92b016b | 2016-05-20 11:37:57 -0700 | [diff] [blame] | 68 | assertEquals("incorrect number of layouts", 3, svc.getLayouts().size()); |
Thomas Vachuska | 4d66d0a | 2016-04-15 15:48:13 -0700 | [diff] [blame] | 69 | assertEquals("incorrect layout", L1.id(), svc.getLayout(L1.id()).id()); |
| 70 | assertEquals("incorrect layout", L2.id(), svc.getLayout(L2.id()).id()); |
| 71 | svc.removeLayout(L1); |
Thomas Vachuska | 92b016b | 2016-05-20 11:37:57 -0700 | [diff] [blame] | 72 | assertEquals("incorrect number of layouts", 2, svc.getLayouts().size()); |
Thomas Vachuska | 4d66d0a | 2016-04-15 15:48:13 -0700 | [diff] [blame] | 73 | assertNull("layout should be gone", svc.getLayout(L1.id())); |
| 74 | assertEquals("incorrect layout", L2.id(), svc.getLayout(L2.id()).id()); |
| 75 | } |
| 76 | |
| 77 | |
| 78 | } |