Thomas Vachuska | 4d66d0a | 2016-04-15 15:48:13 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0a4e674 | 2016-09-15 23:03:10 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Thomas Vachuska | 4d66d0a | 2016-04-15 15:48:13 -0700 | [diff] [blame] | 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; |
Simon Hunt | d0fa284 | 2016-10-24 18:04:05 -0700 | [diff] [blame] | 22 | import org.onosproject.net.config.NetworkConfigRegistryAdapter; |
Thomas Vachuska | 4d66d0a | 2016-04-15 15:48:13 -0700 | [diff] [blame] | 23 | import org.onosproject.net.region.DefaultRegion; |
| 24 | import org.onosproject.net.region.Region; |
Thomas Vachuska | 4d66d0a | 2016-04-15 15:48:13 -0700 | [diff] [blame] | 25 | import org.onosproject.ui.UiTopoLayoutService; |
| 26 | import org.onosproject.ui.model.topo.UiTopoLayout; |
| 27 | import org.onosproject.ui.model.topo.UiTopoLayoutId; |
| 28 | |
Simon Hunt | d0fa284 | 2016-10-24 18:04:05 -0700 | [diff] [blame] | 29 | import static org.junit.Assert.assertEquals; |
| 30 | import static org.junit.Assert.assertNull; |
| 31 | import static org.onosproject.net.region.Region.Type.CAMPUS; |
| 32 | import static org.onosproject.net.region.RegionId.regionId; |
| 33 | import static org.onosproject.ui.model.topo.UiTopoLayoutId.layoutId; |
Thomas Vachuska | 4d66d0a | 2016-04-15 15:48:13 -0700 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * Suite of unit tests for the UI topology layout manager. |
| 37 | */ |
| 38 | public class UiTopoLayoutManagerTest { |
| 39 | |
Simon Hunt | d0fa284 | 2016-10-24 18:04:05 -0700 | [diff] [blame] | 40 | private static class MockConfigService extends NetworkConfigRegistryAdapter { |
| 41 | } |
| 42 | |
| 43 | private static Region region(String id, String name, Region.Type type) { |
| 44 | return new DefaultRegion(regionId(id), name, type, null); |
| 45 | } |
| 46 | |
| 47 | private static UiTopoLayout layout(String id, Region region, String parentId) { |
| 48 | UiTopoLayoutId parent = parentId == null ? null : layoutId(parentId); |
| 49 | UiTopoLayout layout = new UiTopoLayout(layoutId(id)); |
| 50 | // TODO: set region and parent |
| 51 | return layout; |
| 52 | } |
| 53 | |
| 54 | private static final Region R1 = region("r1", "R1", CAMPUS); |
| 55 | private static final Region R2 = region("r2", "R2", CAMPUS); |
| 56 | |
| 57 | private static final UiTopoLayout L1 = layout("l1", R1, null); |
| 58 | private static final UiTopoLayout L2 = layout("l2", R2, null); |
| 59 | |
| 60 | |
Thomas Vachuska | 4d66d0a | 2016-04-15 15:48:13 -0700 | [diff] [blame] | 61 | private UiTopoLayoutService svc; |
| 62 | private UiTopoLayoutManager mgr; |
| 63 | |
Thomas Vachuska | 4d66d0a | 2016-04-15 15:48:13 -0700 | [diff] [blame] | 64 | |
| 65 | @Before |
| 66 | public void setUp() { |
| 67 | mgr = new UiTopoLayoutManager(); |
| 68 | svc = mgr; |
Simon Hunt | d0fa284 | 2016-10-24 18:04:05 -0700 | [diff] [blame] | 69 | |
| 70 | mgr.cfgService = new MockConfigService(); |
Thomas Vachuska | 4d66d0a | 2016-04-15 15:48:13 -0700 | [diff] [blame] | 71 | mgr.activate(); |
| 72 | } |
| 73 | |
| 74 | @After |
| 75 | public void tearDown() { |
| 76 | mgr.deactivate(); |
Simon Hunt | d0fa284 | 2016-10-24 18:04:05 -0700 | [diff] [blame] | 77 | mgr.cfgService = null; |
Thomas Vachuska | 4d66d0a | 2016-04-15 15:48:13 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | @Test |
| 81 | public void basics() { |
Thomas Vachuska | 92b016b | 2016-05-20 11:37:57 -0700 | [diff] [blame] | 82 | assertEquals("should be just default layout", 1, svc.getLayouts().size()); |
Thomas Vachuska | 4d66d0a | 2016-04-15 15:48:13 -0700 | [diff] [blame] | 83 | svc.addLayout(L1); |
| 84 | svc.addLayout(L2); |
Thomas Vachuska | 92b016b | 2016-05-20 11:37:57 -0700 | [diff] [blame] | 85 | assertEquals("incorrect number of layouts", 3, svc.getLayouts().size()); |
Thomas Vachuska | 4d66d0a | 2016-04-15 15:48:13 -0700 | [diff] [blame] | 86 | assertEquals("incorrect layout", L1.id(), svc.getLayout(L1.id()).id()); |
| 87 | assertEquals("incorrect layout", L2.id(), svc.getLayout(L2.id()).id()); |
| 88 | svc.removeLayout(L1); |
Thomas Vachuska | 92b016b | 2016-05-20 11:37:57 -0700 | [diff] [blame] | 89 | assertEquals("incorrect number of layouts", 2, svc.getLayouts().size()); |
Thomas Vachuska | 4d66d0a | 2016-04-15 15:48:13 -0700 | [diff] [blame] | 90 | assertNull("layout should be gone", svc.getLayout(L1.id())); |
| 91 | assertEquals("incorrect layout", L2.id(), svc.getLayout(L2.id()).id()); |
| 92 | } |
| 93 | |
| 94 | |
| 95 | } |