Merge "Bump yangtools to 0.6.0"
[bgpcep.git] / integration-tests / src / test / java / org / opendaylight / protocol / integration / AbstractBundleTest.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 package org.opendaylight.protocol.integration;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.ops4j.pax.exam.CoreOptions.junitBundles;
13 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
14
15 import java.util.ArrayList;
16 import java.util.Arrays;
17 import java.util.Collection;
18 import java.util.List;
19
20 import javax.inject.Inject;
21
22 import org.junit.Test;
23 import org.junit.runner.RunWith;
24 import org.ops4j.pax.exam.Configuration;
25 import org.ops4j.pax.exam.Option;
26 import org.ops4j.pax.exam.junit.PaxExam;
27 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
28 import org.ops4j.pax.exam.spi.reactors.PerMethod;
29 import org.osgi.framework.Bundle;
30 import org.osgi.framework.BundleContext;
31 import org.osgi.framework.BundleException;
32
33 @RunWith(PaxExam.class)
34 @ExamReactorStrategy(PerMethod.class)
35 public abstract class AbstractBundleTest {
36         private static final String GROUP = "org.opendaylight.bgpcep";
37         private static final String VERSION = "0.3.0-SNAPSHOT";
38
39         @Inject
40         BundleContext ctx;
41
42         abstract protected Collection<String> prerequisiteBundles();
43         abstract protected Collection<String> requiredBundles();
44
45         private List<Option> coreBundles() {
46                 final List<Option> ret = new ArrayList<>();
47
48                 ret.add(mavenBundle("ch.qos.logback", "logback-classic", "1.0.9"));
49                 ret.add(mavenBundle("ch.qos.logback", "logback-core", "1.0.9"));
50                 ret.add(mavenBundle("com.google.guava", "guava", "14.0.1"));
51                 ret.add(mavenBundle("commons-codec", "commons-codec", "1.7"));
52                 ret.add(mavenBundle("io.netty", "netty-buffer", "4.0.9.Final"));
53                 ret.add(mavenBundle("io.netty", "netty-codec", "4.0.9.Final"));
54                 ret.add(mavenBundle("io.netty", "netty-common", "4.0.9.Final"));
55                 ret.add(mavenBundle("io.netty", "netty-transport", "4.0.9.Final"));
56                 ret.add(mavenBundle("org.slf4j", "slf4j-api", "1.7.2"));
57
58                 ret.add(mavenBundle("org.opendaylight.yangtools", "concepts", "0.6.0-SNAPSHOT"));
59                 ret.add(mavenBundle("org.opendaylight.yangtools", "yang-binding", "0.6.0-SNAPSHOT"));
60                 ret.add(mavenBundle("org.opendaylight.yangtools", "yang-common", "0.6.0-SNAPSHOT"));
61                 ret.add(mavenBundle("org.opendaylight.yangtools.model", "ietf-inet-types", "2010.09.24.2-SNAPSHOT"));
62
63                 ret.add(mavenBundle("org.javassist", "javassist", "3.17.1-GA"));
64                 ret.add(mavenBundle("org.opendaylight.controller", "config-api", "0.2.3-SNAPSHOT"));
65                 ret.add(mavenBundle("org.opendaylight.controller", "protocol-framework", "0.4.0-SNAPSHOT"));
66                 ret.add(mavenBundle("org.opendaylight.controller", "sal-common-api", "1.0-SNAPSHOT"));
67                 ret.add(mavenBundle("org.opendaylight.controller", "sal-binding-api", "1.0-SNAPSHOT"));
68                 ret.add(mavenBundle("org.opendaylight.controller", "sal-binding-broker-impl", "1.0-SNAPSHOT"));
69                 ret.add(mavenBundle("org.opendaylight.controller", "sal-binding-config", "1.0-SNAPSHOT"));
70                 ret.add(mavenBundle("org.opendaylight.controller", "sal-common", "1.0-SNAPSHOT"));
71                 ret.add(mavenBundle("org.opendaylight.yangtools.thirdparty", "xtend-lib-osgi", "2.4.3"));
72
73                 return ret;
74         }
75
76         private Bundle getBundle(final String name) {
77                 final String bn = GROUP + "." + name;
78                 for (Bundle b : ctx.getBundles()) {
79                         if (bn.equals(b.getSymbolicName())) {
80                                 return b;
81                         }
82                 }
83                 return null;
84         }
85
86         private void testBundle(final String name) {
87                 final Bundle b = getBundle(name);
88                 assertNotNull("Bundle '" + name + "' not found", b);
89                 assertEquals("Bundle '" + name + "' is not in ACTIVE state", Bundle.ACTIVE, b.getState());
90         }
91
92         @Configuration
93         public final Option[] config() {
94                 final List<Option> options = coreBundles();
95
96                 for (final String s : prerequisiteBundles()) {
97                         options.add(mavenBundle(GROUP, s, VERSION));
98                 }
99
100                 for (final String s : requiredBundles()) {
101                         options.add(mavenBundle(GROUP, s, VERSION));
102                 }
103
104                 options.addAll(Arrays.asList(junitBundles()));
105                 return options.toArray(new Option[0]);
106         }
107
108         @Test
109         public final void testBundleActivation() throws BundleException {
110                 for (final String s : requiredBundles()) {
111                         testBundle(s);
112                 }
113         }
114 }