/*
 * Copyright 2015 Harald Wellmann.
 *
 * 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 org.ops4j.pax.cdi.test;

import static org.ops4j.pax.cdi.test.support.TestConfiguration.cdiProviderBundles;
import static org.ops4j.pax.cdi.test.support.TestConfiguration.paxCdiProviderAdapter;
import static org.ops4j.pax.cdi.test.support.TestConfiguration.regressionDefaults;
import static org.ops4j.pax.cdi.test.support.TestConfiguration.workspaceBundle;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
import static org.ops4j.pax.exam.CoreOptions.options;

import javax.inject.Inject;

import org.apache.deltaspike.security.api.authorization.AccessDeniedException;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.ops4j.pax.cdi.sample8.service.SecuredClient;
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.PerClass;

@RunWith(PaxExam.class)
@ExamReactorStrategy(PerClass.class)
@Ignore
public class SecurityTest {

    @Rule
    public ExpectedException thrown = ExpectedException.none();

    @Inject
    private SecuredClient securedService;

    @Configuration
    public Option[] config() {
        return options(
            regressionDefaults(),
            paxCdiProviderAdapter(),
            cdiProviderBundles(),

            mavenBundle("org.osgi", "org.osgi.enterprise").versionAsInProject(),

            // DeltaSpike bundles
            mavenBundle("org.apache.deltaspike.core", "deltaspike-core-api").versionAsInProject(),
            mavenBundle("org.apache.deltaspike.core", "deltaspike-core-impl").versionAsInProject(),
            mavenBundle("org.apache.deltaspike.modules", "deltaspike-security-module-api").versionAsInProject(),
            mavenBundle("org.apache.deltaspike.modules", "deltaspike-security-module-impl").versionAsInProject(),

            // Sample bundles
            workspaceBundle("org.ops4j.pax.cdi.samples", "pax-cdi-sample8"));
    }

    @Test
    public void shouldNotInvokeBlockService() {
        thrown.expect(AccessDeniedException.class);
        securedService.getBlockedResult();
    }
}

@@ -1071,16 +1071,76 @@
 options;
+%0Aimport static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
 %0A%0Aimport
@@ -1245,33 +1245,8 @@
 on;%0A
-import org.junit.Ignore;%0A
 impo
@@ -1709,16 +1709,8 @@
 ss)%0A
-@Ignore%0A
 publ
@@ -2351,32 +2351,33 @@
 nAsInProject(),%0A
+%0A
             mave
@@ -2363,32 +2363,121 @@
 (),%0A%0A           
+ // Uncomment this section and delete the next after upgrading to DS 1.4.2%0A            //
  mavenBundle(%22or
@@ -2565,32 +2565,35 @@
 t(),%0A           
+ //
  mavenBundle(%22or
@@ -2672,32 +2672,962 @@
 AsInProject(),%0A%0A
+            wrappedBundle(mavenBundle(%22org.apache.deltaspike.modules%22, %22deltaspike-security-module-api%22)%0A                .versionAsInProject())%0A                .instructions(%0A                    %22overwrite=merge%22,%0A                    %22Bundle-SymbolicName=org.apache.deltaspike.modules.deltaspike-security-module-api%22),%0A            wrappedBundle(mavenBundle(%22org.apache.deltaspike.modules%22, %22deltaspike-security-module-impl%22).versionAsInProject())%0A                .instructions(%0A                    %22overwrite=merge%22,%0A                    %22Bundle-SymbolicName=org.apache.deltaspike.modules.deltaspike-security-module-impl%22,%0A                    %22Provide-Capability=org.ops4j.pax.cdi.extension;extension=%5C%22deltaspike-security-module-impl%5C%22%22,%0A                    %22Require-Capability=org.ops4j.pax.cdi.extension; filter:=%5C%22(extension=pax-cdi-extension)%5C%22, %22%0A                    + %22osgi.extender; filter:=%5C%22(osgi.extender=pax.cdi)%5C%22%22),%0A%0A
             // S
@@ -3735,16 +3735,16 @@
   @Test%0A
-
     publ
@@ -3771,16 +3771,18 @@
 okeBlock
+ed
 Service(

enable test with wrapped DS Security bundles