Fix star import and enable checkstyle rule to prevent it.
[controller.git] / opendaylight / topologymanager / integrationtest / src / test / java / org / opendaylight / controller / topologymanager / TopologyManagerIT.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.topologymanager;
10
11 import org.junit.Test;
12 import org.junit.runner.RunWith;
13 import org.opendaylight.controller.protocol_plugins.stub.internal.TopologyServices;
14 import org.opendaylight.controller.sal.core.Edge;
15 import org.opendaylight.controller.sal.core.Node;
16 import org.opendaylight.controller.sal.core.NodeConnector;
17 import org.opendaylight.controller.sal.core.Property;
18 import org.opendaylight.controller.sal.core.UpdateType;
19 import org.opendaylight.controller.sal.topology.IPluginInTopologyService;
20 import org.ops4j.pax.exam.Option;
21 import org.ops4j.pax.exam.Configuration;
22 import org.ops4j.pax.exam.junit.PaxExam;
23 import org.ops4j.pax.exam.util.PathUtils;
24 import org.osgi.framework.Bundle;
25 import org.osgi.framework.BundleContext;
26 import org.osgi.framework.ServiceReference;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 import javax.inject.Inject;
31 import java.util.HashSet;
32 import java.util.Set;
33
34 import static org.ops4j.pax.exam.CoreOptions.junitBundles;
35 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
36 import static org.ops4j.pax.exam.CoreOptions.options;
37 import static org.ops4j.pax.exam.CoreOptions.systemPackages;
38 import static org.ops4j.pax.exam.CoreOptions.systemProperty;
39
40
41 @RunWith(PaxExam.class)
42 public class TopologyManagerIT {
43     private Logger log = LoggerFactory
44             .getLogger(TopologyManagerIT.class);
45     // get the OSGI bundle context
46     @Inject
47     private BundleContext bc;
48     @Inject
49     private ITopologyManager manager = null;
50
51     // Configure the OSGi container
52     @Configuration
53     public Option[] config() {
54         return options(
55                 //
56                 systemProperty("logback.configurationFile").value(
57                         "file:" + PathUtils.getBaseDir()
58                                 + "/src/test/resources/logback.xml"),
59                 // To start OSGi console for inspection remotely
60                 systemProperty("osgi.console").value("2401"),
61                 // Set the systemPackages (used by clustering)
62                 systemPackages("sun.reflect", "sun.reflect.misc", "sun.misc"),
63                 // List framework bundles
64                 mavenBundle("equinoxSDK381", "org.eclipse.equinox.console").versionAsInProject(),
65                 mavenBundle("equinoxSDK381", "org.eclipse.equinox.util").versionAsInProject(),
66                 mavenBundle("equinoxSDK381", "org.eclipse.osgi.services").versionAsInProject(),
67                 mavenBundle("equinoxSDK381", "org.eclipse.equinox.ds").versionAsInProject(),
68                 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.command").versionAsInProject(),
69                 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.runtime").versionAsInProject(),
70                 mavenBundle("equinoxSDK381", "org.apache.felix.gogo.shell").versionAsInProject(),
71                 // List logger bundles
72                 mavenBundle("org.slf4j", "slf4j-api").versionAsInProject(),
73                 mavenBundle("org.slf4j", "log4j-over-slf4j")
74                         .versionAsInProject(),
75                 mavenBundle("ch.qos.logback", "logback-core")
76                         .versionAsInProject(),
77                 mavenBundle("ch.qos.logback", "logback-classic")
78                         .versionAsInProject(),
79                 // needed by statisticsmanager
80                 mavenBundle("org.opendaylight.controller", "containermanager")
81                     .versionAsInProject(),
82                 mavenBundle("org.opendaylight.controller", "containermanager.it.implementation")
83                     .versionAsInProject(),
84                 mavenBundle("org.opendaylight.controller", "clustering.services")
85                     .versionAsInProject(),
86                 mavenBundle("org.opendaylight.controller", "clustering.stub")
87                     .versionAsInProject(),
88                 // needed by forwardingrulesmanager
89                 mavenBundle("org.opendaylight.controller", "configuration")
90                     .versionAsInProject(),
91                 mavenBundle("org.opendaylight.controller", "configuration.implementation")
92                     .versionAsInProject(),
93                 mavenBundle("org.opendaylight.controller", "hosttracker")
94                     .versionAsInProject(),
95
96                 // List all the bundles on which the test case depends
97                 mavenBundle("org.opendaylight.controller", "sal")
98                     .versionAsInProject(),
99                 mavenBundle("org.opendaylight.controller", "sal.implementation")
100                     .versionAsInProject(),
101                 mavenBundle("org.opendaylight.controller", "protocol_plugins.stub")
102                     .versionAsInProject(),
103                 mavenBundle("org.opendaylight.controller", "switchmanager")
104                     .versionAsInProject(),
105                 mavenBundle("org.opendaylight.controller", "switchmanager.implementation")
106                     .versionAsInProject(),
107                 mavenBundle("org.opendaylight.controller", "statisticsmanager")
108                     .versionAsInProject(),
109                 mavenBundle("org.opendaylight.controller", "statisticsmanager.implementation")
110                     .versionAsInProject(),
111                 mavenBundle("org.opendaylight.controller", "forwardingrulesmanager")
112                     .versionAsInProject(),
113
114                 // needed by hosttracker
115                 mavenBundle("org.opendaylight.controller", "topologymanager")
116                         .versionAsInProject(),
117                 mavenBundle("org.jboss.spec.javax.transaction",
118                         "jboss-transaction-api_1.1_spec").versionAsInProject(),
119                 mavenBundle("org.apache.commons", "commons-lang3")
120                         .versionAsInProject(),
121                 mavenBundle("org.apache.felix",
122                         "org.apache.felix.dependencymanager")
123                         .versionAsInProject(), junitBundles());
124     }
125
126     private String stateToString(int state) {
127         switch (state) {
128         case Bundle.ACTIVE:
129             return "ACTIVE";
130         case Bundle.INSTALLED:
131             return "INSTALLED";
132         case Bundle.RESOLVED:
133             return "RESOLVED";
134         case Bundle.UNINSTALLED:
135             return "UNINSTALLED";
136         default:
137             return "Not CONVERTED";
138         }
139     }
140
141     /**
142      *  This test verifies that the isInternal method of the TopologyManager returns true when a node is internal and
143      *  not otherwise
144      *
145      *  To make a node interval we add a node using the plugin interface (TopologyServices.addEdge) this is to ensure
146      *  that when TopologyManager sees the edge is via it's dependency on the SAL ITopologyService.
147      *
148      * @throws Exception
149      */
150     @Test
151     public void testIsInternal() throws Exception{
152         Node node1 = new Node("STUB", 0xCAFE);
153         Node node2 = new Node("STUB", 0XFACE);
154
155         NodeConnector head = new NodeConnector("STUB", node1.getID(), node1);
156         NodeConnector tail = new NodeConnector("STUB", node2.getID(), node2);
157
158         assert(this.manager.isInternal(head));
159
160         Set<Property> properties = new HashSet<Property>();
161
162         ServiceReference r = bc.getServiceReference(IPluginInTopologyService.class
163                 .getName());
164         TopologyServices topologyServices = null;
165         if (r != null) {
166             if(bc.getService(r) instanceof TopologyServices) {
167                 topologyServices = (TopologyServices) bc.getService(r);
168             } else {
169                 throw new RuntimeException("topology service registered is not from the stub plugin implementation");
170             }
171         }
172
173         topologyServices.addEdge(new Edge(tail, head), properties, UpdateType.ADDED);
174
175         assert(this.manager.isInternal(head));
176     }
177
178 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.