blob: 17302f1d13fd0d0632923e6e4b68770854136b21 [file] [log] [blame]
Thomas Vachuska4d66d0a2016-04-15 15:48:13 -07001/*
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
17package org.onosproject.ui.impl.topo;
18
19import org.junit.After;
20import org.junit.Before;
21import org.junit.Test;
22import org.onosproject.net.region.DefaultRegion;
23import org.onosproject.net.region.Region;
24import org.onosproject.net.region.RegionId;
25import org.onosproject.store.service.TestStorageService;
26import org.onosproject.ui.UiTopoLayoutService;
27import org.onosproject.ui.model.topo.UiTopoLayout;
28import org.onosproject.ui.model.topo.UiTopoLayoutId;
29
30import static org.junit.Assert.*;
31
32/**
33 * Suite of unit tests for the UI topology layout manager.
34 */
35public 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 Vachuska92b016b2016-05-20 11:37:57 -070043 Region.Type.CAMPUS, null), null);
Thomas Vachuska4d66d0a2016-04-15 15:48:13 -070044 private static final UiTopoLayout L2 =
45 new UiTopoLayout(UiTopoLayoutId.layoutId("l2"),
46 new DefaultRegion(RegionId.regionId("r2"), "R2",
Thomas Vachuska92b016b2016-05-20 11:37:57 -070047 Region.Type.CAMPUS, null), null);
Thomas Vachuska4d66d0a2016-04-15 15:48:13 -070048
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 Vachuska92b016b2016-05-20 11:37:57 -070065 assertEquals("should be just default layout", 1, svc.getLayouts().size());
Thomas Vachuska4d66d0a2016-04-15 15:48:13 -070066 svc.addLayout(L1);
67 svc.addLayout(L2);
Thomas Vachuska92b016b2016-05-20 11:37:57 -070068 assertEquals("incorrect number of layouts", 3, svc.getLayouts().size());
Thomas Vachuska4d66d0a2016-04-15 15:48:13 -070069 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 Vachuska92b016b2016-05-20 11:37:57 -070072 assertEquals("incorrect number of layouts", 2, svc.getLayouts().size());
Thomas Vachuska4d66d0a2016-04-15 15:48:13 -070073 assertNull("layout should be gone", svc.getLayout(L1.id()));
74 assertEquals("incorrect layout", L2.id(), svc.getLayout(L2.id()).id());
75 }
76
77
78}