/*
 * Copyright 2013 Peter Lawrey
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.openhft.chronicle.osgi;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;

import javax.inject.Inject;
import org.slf4j.LoggerFactory;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;

import static junit.framework.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.ops4j.pax.exam.CoreOptions.cleanCaches;
import static org.ops4j.pax.exam.CoreOptions.junitBundles;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
import static org.ops4j.pax.exam.CoreOptions.options;
import static org.ops4j.pax.exam.CoreOptions.systemPackage;
import static org.ops4j.pax.exam.CoreOptions.systemProperty;

@RunWith(PaxExam.class)
public class ChronicleBundleTest {
    @Inject
    BundleContext context;

    @Configuration
    public Option[] config() {
        Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
        root.setLevel(Level.INFO);

        return options(
            //systemProperty("org.osgi.framework.storage").value("/tmp/felix-cache"),
            systemProperty("org.osgi.framework.storage.clean").value("true"),
            systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN"),
            mavenBundle("net.openhft","lang","6.1"),
            mavenBundle("net.openhft","chronicle","2.0.2-SNAPSHOT"),
            junitBundles(),
            systemPackage("sun.misc"),
            systemPackage("sun.nio.ch"),
            cleanCaches()
        );
    }

    @Test
    public void checkInject() {
        assertNotNull(context);
    }

    @Test
    public void checkHelloBundle() {
        Boolean bundleChronicleFound = false;
        Boolean bundleChronicleActive = false;

        Bundle[] bundles = context.getBundles();
        for (Bundle bundle : bundles) {
            if (bundle != null) {
                if (bundle.getSymbolicName().equals("net.openhft.chronicle")) {
                    bundleChronicleFound = true;
                    if (bundle.getState() == Bundle.ACTIVE) {
                        bundleChronicleActive = true;
                    }
                }
            }
        }

        assertTrue(bundleChronicleFound);
        assertTrue(bundleChronicleActive);
    }
}

@@ -593,16 +593,17 @@
 se.%0A */%0A
+%0A
 package 
@@ -631,16 +631,91 @@
 .osgi;%0A%0A
+import ch.qos.logback.classic.Level;%0Aimport ch.qos.logback.classic.Logger;%0A
 import o
@@ -956,37 +956,8 @@
 ext;
-%0A%0Aimport javax.inject.Inject;
 %0Aimp
@@ -989,81 +989,35 @@
 ry;%0A
+%0A
 import 
-ch.qos.logback.classic.Level;%0Aimport ch.qos.logback.classic.Logger
+javax.inject.Inject
 ;%0A%0Ai
@@ -1159,313 +1159,113 @@
 ons.
-cleanCaches;%0Aimport static org.ops4j.pax.exam.CoreOptions.junitBundles;%0Aimport static org.ops4j.pax.exam.CoreOptions.mavenBundle;%0Aimport static org.ops4j.pax.exam.CoreOptions.options;%0Aimport static org.ops4j.pax.exam.CoreOptions.systemPackage;%0Aimport static org.ops4j.pax.exam.CoreOptions.systemProperty;%0A
+*;%0A%0A/**%0A * @author lburgazzoli%0A *         %3Cp/%3E%0A *         Thank for adding OSGi testing to Chronicle.%0A */
 %0A@Ru
@@ -1563,16 +1563,20 @@
         
+    
 //system
@@ -1645,32 +1645,36 @@
 %22),%0A            
+    
 systemProperty(%22
@@ -1727,32 +1727,36 @@
 %22),%0A            
+   
+ 
 systemProperty(%22
@@ -1822,32 +1822,36 @@
 %22),%0A            
+    
 mavenBundle(%22net
@@ -1864,15 +1864,17 @@
 ft%22,
+ 
 %22lang%22,
+ 
 %226.1
@@ -1881,32 +1881,36 @@
 %22),%0A            
+ 
+   
 mavenBundle(%22net
@@ -1919,16 +1919,17 @@
 penhft%22,
+ 
 %22chronic
@@ -1932,16 +1932,17 @@
 onicle%22,
+ 
 %222.0.2-S
@@ -1964,16 +1964,20 @@
         
+  
+  
 junitBun
@@ -1984,16 +1984,20 @@
 dles(),%0A
+    
         
@@ -2031,32 +2031,36 @@
 %22),%0A            
+ 
+   
 systemPackage(%22s
@@ -2068,24 +2068,28 @@
 n.nio.ch%22),%0A
+    
             

Add OSGi author.