Merge "Use groupings instead of data containers"
[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.5-SNAPSHOT"));
59                 ret.add(mavenBundle("org.opendaylight.yangtools", "yang-binding", "0.5.9-SNAPSHOT"));
60                 ret.add(mavenBundle("org.opendaylight.yangtools", "yang-common", "0.5.9-SNAPSHOT"));
61                 ret.add(mavenBundle("org.opendaylight.yangtools.model", "ietf-inet-types", "2010.09.24.1"));
62
63                 return ret;
64         }
65
66         private Bundle getBundle(final String name) {
67                 final String bn = GROUP + "." + name;
68                 for (Bundle b : ctx.getBundles()) {
69                         if (bn.equals(b.getSymbolicName())) {
70                                 return b;
71                         }
72                 }
73                 return null;
74         }
75
76         private void testBundle(final String name) {
77                 final Bundle b = getBundle(name);
78                 assertNotNull("Bundle '" + name + "' not found", b);
79                 assertEquals("Bundle '" + name + "' is not in ACTIVE state", Bundle.ACTIVE, b.getState());
80         }
81
82         @Configuration
83         public final Option[] config() {
84                 final List<Option> options = coreBundles();
85
86                 for (final String s : prerequisiteBundles()) {
87                         options.add(mavenBundle(GROUP, s, VERSION));
88                 }
89
90                 for (final String s : requiredBundles()) {
91                         options.add(mavenBundle(GROUP, s, VERSION));
92                 }
93
94                 options.addAll(Arrays.asList(junitBundles()));
95                 return options.toArray(new Option[0]);
96         }
97
98         @Test
99         public final void testBundleActivation() throws BundleException {
100                 for (final String s : requiredBundles()) {
101                         testBundle(s);
102                 }
103         }
104 }