package org.cache2k.test.osgi;

import org.cache2k.Cache;
import org.cache2k.CacheBuilder;
import org.junit.Ignore;
import org.junit.Test;
import static org.junit.Assert.*;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
import org.ops4j.pax.exam.spi.reactors.PerMethod;

import static org.ops4j.pax.exam.CoreOptions.options;
import static org.ops4j.pax.exam.CoreOptions.junitBundles;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;

/**
 * Test the OSGi enabled bundle. Not yet working.
 *
 * @author Jens Wilke
 */
@org.junit.runner.RunWith(PaxExam.class)
@ExamReactorStrategy(PerMethod.class)
public class OsgiTest {

  @Configuration
  public Option[] config() {
    return options(
      mavenBundle("org.cache2k", "cache2k-all", System.getProperty("cache2k.version", "0.24-SNAPSHOT")),
      junitBundles()
    );
  }

  @Test
  public void testSimple() {
    Cache<String, String> c = CacheBuilder.newCache(String.class, String.class).build();
    c.put("abc", "123");
    assertTrue(c.contains("abc"));
    assertEquals("123", c.peek("abc"));
    c.close();
  }

  @Test @Ignore("SPI for marshallers not working.")
  public void testWithSerialization() {
    Cache<String, String> c =
      CacheBuilder.newCache(String.class, String.class)
        .persistence()
        .build();
    c.put("abc", "123");
    assertTrue(c.contains("abc"));
    assertEquals("123", c.peek("abc"));
    c.close();
  }

}

@@ -25,16 +25,780 @@
 .osgi;%0A%0A
+/*%0A * #%25L%0A * osgi-test%0A * %25%25%0A * Copyright (C) 2000 - 2016 headissue GmbH, Munich%0A * %25%25%0A * This program is free software: you can redistribute it and/or modify%0A * it under the terms of the GNU General Public License as%0A * published by the Free Software Foundation, either version 3 of the %0A * License, or (at your option) any later version.%0A * %0A * This program is distributed in the hope that it will be useful,%0A * but WITHOUT ANY WARRANTY; without even the implied warranty of%0A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the%0A * GNU General Public License for more details.%0A * %0A * You should have received a copy of the GNU General Public %0A * License along with this program.  If not, see%0A * %3Chttp://www.gnu.org/licenses/gpl-3.0.html%3E.%0A * #L%25%0A */%0A%0A
 import o
@@ -1315,22 +1315,17 @@
 Options.
-mavenB
+b
 undle;%0A%0A
@@ -1565,58 +1565,358 @@
     
-return options(%0A      mavenBundle(%22org.cache2k%22, %22
+String _userDir = System.getProperty(%22user.dir%22);%0A    String _ownPath = %22/osgi-test%22;%0A    String _workspaceDir = _userDir;%0A    if (_workspaceDir.endsWith(_ownPath)) %7B%0A      _workspaceDir = _workspaceDir.substring(0,_workspaceDir.length() -  _ownPath.length());%0A    %7D%0A    return options(%0A      bundle(%22file:///%22 + _workspaceDir + %22/variant/all/target/
 cach
@@ -1922,18 +1922,20 @@
 he2k-all
-%22,
+-%22 +
  System.
@@ -1967,26 +1967,18 @@
 ion%22
-, %220.24-SNAPSHOT%22)
+) + %22.jar%22
 ),%0A 

resolve bundle from filesystem to enable reactor builds