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