Debian Codegraph @

src/test/java/com/zaxxer/hikari/osgi/OSGiBundleTest.java

raw
1 /*
2 * Copyright (C) 2013 Brett Wooldridge
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 package com.zaxxer.hikari.osgi;
17
18 import org.junit.Test;
19 import org.junit.runner.RunWith;
20 import org.junit.runner.manipulation.Filter;
21 import org.junit.runner.manipulation.NoTestsRemainException;
22 import org.junit.runner.notification.RunNotifier;
23 import org.junit.runners.model.InitializationError;
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.osgi.framework.Bundle;
28 import org.osgi.framework.BundleContext;
29
30 import javax.inject.Inject;
31 import java.io.File;
32
33 import static com.zaxxer.hikari.pool.TestElf.isJava9;
34 import static org.junit.Assert.assertNotNull;
35 import static org.junit.Assert.assertTrue;
36 import static org.ops4j.pax.exam.CoreOptions.*;
37
38 /**
39 * @author lburgazzoli
40 */
41 @RunWith(OSGiBundleTest.ConditionalPaxExam.class)
42 public class OSGiBundleTest
43 {
44 @Test
45 public void checkInject()
46 {
47 assertNotNull(context);
48 }
49
50 @Test
51 public void checkBundle()
52 {
53 Boolean bundleFound = false;
54 Boolean bundleActive = false;
55
56 Bundle[] bundles = context.getBundles();
57 for (Bundle bundle : bundles) {
58 if (bundle != null) {
59 if (bundle.getSymbolicName().equals("com.zaxxer.HikariCP")) {
60 bundleFound = true;
61 if (bundle.getState() == Bundle.ACTIVE) {
62 bundleActive = true;
63 }
64 }
65 }
66 }
67
68 assertTrue(bundleFound);
69 assertTrue(bundleActive);
70 }
71
72 @Inject
73 BundleContext context;
74
75 @Configuration
76 public Option[] config()
77 {
78 return options(
79 systemProperty("org.osgi.framework.storage.clean").value("true"),
80 systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN"),
81 mavenBundle("org.slf4j", "slf4j-api", "1.7.5"),
82 mavenBundle("org.slf4j", "slf4j-simple", "1.7.5").noStart(),
83 new File("target/classes").exists()
84 ? bundle("reference:file:target/classes")
85 : bundle("reference:file:../target/classes"),
86 junitBundles(),
87 cleanCaches()
88 );
89 }
90
91 public static class ConditionalPaxExam extends PaxExam
92 {
93 public ConditionalPaxExam(Class<?> klass) throws InitializationError {
94 super(klass);
95 }
96
97 @Override
98 public void run(RunNotifier notifier) {
99 if (!isJava9()) {
100 super.run(notifier);
101 }
102 }
103
104 @Override
105 public void filter(Filter filter) throws NoTestsRemainException {
106 if (isJava9()) {
107 throw new NoTestsRemainException();
108 }
109
110 super.filter(filter);
111 }
112 }
113 }