/*
 * #%L
 * wcm.io
 * %%
 * Copyright (C) 2016 wcm.io
 * %%
 * 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.
 * #L%
 */
package io.wcm.testing.mock.wcmio.caconfig;

import org.apache.sling.testing.mock.osgi.context.AbstractContextPlugin;
import org.apache.sling.testing.mock.osgi.context.ContextPlugin;

import io.wcm.caconfig.application.impl.ApplicationAdapterFactory;
import io.wcm.caconfig.application.impl.ApplicationFinderImpl;
import io.wcm.caconfig.application.impl.ApplicationImplementationPicker;
import io.wcm.config.core.impl.ConfigurationAdapterFactory;
import io.wcm.config.core.impl.ConfigurationFinderStrategyBridge;
import io.wcm.config.core.impl.ParameterOverrideProviderBridge;
import io.wcm.config.core.impl.ParameterProviderBridge;
import io.wcm.config.core.persistence.impl.ToolsConfigPagePersistenceProvider;
import io.wcm.sling.commons.resource.ImmutableValueMap;
import io.wcm.testing.mock.aem.junit.AemContext;

/**
 * Mock context plugins.
 */
public final class ContextPlugins {

  private ContextPlugins() {
    // constants only
  }

  /**
   * Context plugin for wcm.io Context-Aware Configuration.
   */
  public static final ContextPlugin<AemContext> WCMIO_CACONFIG_COMPAT = new AbstractContextPlugin<AemContext>() {
    @Override
    public void afterSetUp(AemContext context) throws Exception {
      setUpCompat(context);
    }
  };

  /**
   * Set up all mandatory OSGi services for wcm.io Configuration support.
   * @param context Aem context
   */
  private static void setUpCompat(AemContext context) {

    // application detection
    context.registerInjectActivateService(new ApplicationFinderImpl());
    context.registerInjectActivateService(new ApplicationImplementationPicker());
    context.registerInjectActivateService(new io.wcm.config.core.impl.application.ApplicationImplementationPicker());
    context.registerInjectActivateService(new ApplicationAdapterFactory());

    // persistence providers
    context.registerInjectActivateService(new ToolsConfigPagePersistenceProvider(),
        ImmutableValueMap.of("enabled", true));

    // bridge services
    context.registerInjectActivateService(new ConfigurationFinderStrategyBridge());
    context.registerInjectActivateService(new ParameterOverrideProviderBridge());
    context.registerInjectActivateService(new ParameterProviderBridge());

    // adapter factory
    context.registerInjectActivateService(new ConfigurationAdapterFactory());

  }

}

@@ -1284,115 +1284,127 @@
 ore.
-persistence.impl.ToolsConfigPagePersistenceProvider;%0Aimport io.wcm.sling.commons.resource.ImmutableValueMap
+impl.application.ApplicationFinderBridge;%0Aimport io.wcm.config.core.persistence.impl.ToolsConfigPagePersistenceProvider
 ;%0Aim
@@ -2233,32 +2233,106 @@
 ationPicker());%0A
+    context.registerInjectActivateService(new ApplicationFinderBridge());%0A
     context.regi
@@ -2635,45 +2635,153 @@
     
-ImmutableValueMap.of(%22enabled%22, true)
+%22enabled%22, true,%0A        %22configPageTemplate%22, %22/apps/dummy/templates/config%22,%0A        %22structurePageTemplate%22, %22/apps/dummy/templates/structure%22
 );%0A%0A

fix mock setup