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