blob: 626991e9bb22e2ed6a779b0c8e56db0aa8adfe4b [file] [log] [blame]
Thomas Vachuska4d66d0a2016-04-15 15:48:13 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Thomas Vachuska4d66d0a2016-04-15 15:48:13 -07003 *
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.ui.impl.topo;
18
19import org.junit.After;
20import org.junit.Before;
21import org.junit.Test;
Simon Hunt53612212016-12-04 17:19:52 -080022import org.onosproject.net.DefaultAnnotations;
Simon Huntd0fa2842016-10-24 18:04:05 -070023import org.onosproject.net.config.NetworkConfigRegistryAdapter;
Thomas Vachuska4d66d0a2016-04-15 15:48:13 -070024import org.onosproject.net.region.DefaultRegion;
25import org.onosproject.net.region.Region;
Thomas Vachuska4d66d0a2016-04-15 15:48:13 -070026import org.onosproject.ui.UiTopoLayoutService;
27import org.onosproject.ui.model.topo.UiTopoLayout;
28import org.onosproject.ui.model.topo.UiTopoLayoutId;
29
Simon Huntd0fa2842016-10-24 18:04:05 -070030import static org.junit.Assert.assertEquals;
31import static org.junit.Assert.assertNull;
32import static org.onosproject.net.region.Region.Type.CAMPUS;
33import static org.onosproject.net.region.RegionId.regionId;
34import static org.onosproject.ui.model.topo.UiTopoLayoutId.layoutId;
Thomas Vachuska4d66d0a2016-04-15 15:48:13 -070035
36/**
37 * Suite of unit tests for the UI topology layout manager.
38 */
39public class UiTopoLayoutManagerTest {
40
Simon Huntd0fa2842016-10-24 18:04:05 -070041 private static class MockConfigService extends NetworkConfigRegistryAdapter {
42 }
43
44 private static Region region(String id, String name, Region.Type type) {
Simon Hunt53612212016-12-04 17:19:52 -080045 return new DefaultRegion(regionId(id), name, type,
46 DefaultAnnotations.EMPTY, null);
Simon Huntd0fa2842016-10-24 18:04:05 -070047 }
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 Vachuska4d66d0a2016-04-15 15:48:13 -070063 private UiTopoLayoutService svc;
64 private UiTopoLayoutManager mgr;
65
Thomas Vachuska4d66d0a2016-04-15 15:48:13 -070066
67 @Before
68 public void setUp() {
69 mgr = new UiTopoLayoutManager();
70 svc = mgr;
Simon Huntd0fa2842016-10-24 18:04:05 -070071
72 mgr.cfgService = new MockConfigService();
Thomas Vachuska4d66d0a2016-04-15 15:48:13 -070073 mgr.activate();
74 }
75
76 @After
77 public void tearDown() {
78 mgr.deactivate();
Simon Huntd0fa2842016-10-24 18:04:05 -070079 mgr.cfgService = null;
Thomas Vachuska4d66d0a2016-04-15 15:48:13 -070080 }
81
82 @Test
83 public void basics() {
Thomas Vachuska92b016b2016-05-20 11:37:57 -070084 assertEquals("should be just default layout", 1, svc.getLayouts().size());
Thomas Vachuska4d66d0a2016-04-15 15:48:13 -070085 svc.addLayout(L1);
86 svc.addLayout(L2);
Thomas Vachuska92b016b2016-05-20 11:37:57 -070087 assertEquals("incorrect number of layouts", 3, svc.getLayouts().size());
Thomas Vachuska4d66d0a2016-04-15 15:48:13 -070088 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 Vachuska92b016b2016-05-20 11:37:57 -070091 assertEquals("incorrect number of layouts", 2, svc.getLayouts().size());
Thomas Vachuska4d66d0a2016-04-15 15:48:13 -070092 assertNull("layout should be gone", svc.getLayout(L1.id()));
93 assertEquals("incorrect layout", L2.id(), svc.getLayout(L2.id()).id());
94 }
95
96
97}