blob: 67fbf699dd6cb730893ac97f7f79be3c07fab3d5 [file] [log] [blame]
Thomas Vachuska4d66d0a2016-04-15 15:48:13 -07001/*
Brian O'Connor0a4e6742016-09-15 23:03:10 -07002 * Copyright 2016-present Open Networking Laboratory
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 Huntd0fa2842016-10-24 18:04:05 -070022import org.onosproject.net.config.NetworkConfigRegistryAdapter;
Thomas Vachuska4d66d0a2016-04-15 15:48:13 -070023import org.onosproject.net.region.DefaultRegion;
24import org.onosproject.net.region.Region;
Thomas Vachuska4d66d0a2016-04-15 15:48:13 -070025import org.onosproject.ui.UiTopoLayoutService;
26import org.onosproject.ui.model.topo.UiTopoLayout;
27import org.onosproject.ui.model.topo.UiTopoLayoutId;
28
Simon Huntd0fa2842016-10-24 18:04:05 -070029import static org.junit.Assert.assertEquals;
30import static org.junit.Assert.assertNull;
31import static org.onosproject.net.region.Region.Type.CAMPUS;
32import static org.onosproject.net.region.RegionId.regionId;
33import static org.onosproject.ui.model.topo.UiTopoLayoutId.layoutId;
Thomas Vachuska4d66d0a2016-04-15 15:48:13 -070034
35/**
36 * Suite of unit tests for the UI topology layout manager.
37 */
38public class UiTopoLayoutManagerTest {
39
Simon Huntd0fa2842016-10-24 18:04:05 -070040 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 Vachuska4d66d0a2016-04-15 15:48:13 -070061 private UiTopoLayoutService svc;
62 private UiTopoLayoutManager mgr;
63
Thomas Vachuska4d66d0a2016-04-15 15:48:13 -070064
65 @Before
66 public void setUp() {
67 mgr = new UiTopoLayoutManager();
68 svc = mgr;
Simon Huntd0fa2842016-10-24 18:04:05 -070069
70 mgr.cfgService = new MockConfigService();
Thomas Vachuska4d66d0a2016-04-15 15:48:13 -070071 mgr.activate();
72 }
73
74 @After
75 public void tearDown() {
76 mgr.deactivate();
Simon Huntd0fa2842016-10-24 18:04:05 -070077 mgr.cfgService = null;
Thomas Vachuska4d66d0a2016-04-15 15:48:13 -070078 }
79
80 @Test
81 public void basics() {
Thomas Vachuska92b016b2016-05-20 11:37:57 -070082 assertEquals("should be just default layout", 1, svc.getLayouts().size());
Thomas Vachuska4d66d0a2016-04-15 15:48:13 -070083 svc.addLayout(L1);
84 svc.addLayout(L2);
Thomas Vachuska92b016b2016-05-20 11:37:57 -070085 assertEquals("incorrect number of layouts", 3, svc.getLayouts().size());
Thomas Vachuska4d66d0a2016-04-15 15:48:13 -070086 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 Vachuska92b016b2016-05-20 11:37:57 -070089 assertEquals("incorrect number of layouts", 2, svc.getLayouts().size());
Thomas Vachuska4d66d0a2016-04-15 15:48:13 -070090 assertNull("layout should be gone", svc.getLayout(L1.id()));
91 assertEquals("incorrect layout", L2.id(), svc.getLayout(L2.id()).id());
92 }
93
94
95}