/*
 * #%L
 * wcm.io
 * %%
 * Copyright (C) 2015 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.devops.conga.plugins.sling;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import io.wcm.devops.conga.generator.spi.PostProcessorPlugin;
import io.wcm.devops.conga.generator.util.PluginManager;

import java.io.File;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.CharEncoding;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.LoggerFactory;

public class ProvisioningOsgiConfigPostProcessorTest {

  private PostProcessorPlugin underTest;

  @Before
  public void setUp() {
    underTest = new PluginManager().get(ProvisioningOsgiConfigPostProcessor.NAME, PostProcessorPlugin.class);
  }

  @Test
  public void testPostProcess() throws Exception {

    // prepare provisioning file
    File target = new File("target/postprocessor-test");
    if (target.exists()) {
      FileUtils.deleteDirectory(target);
    }
    File provisioningFile = new File(target, "test.txt");
    FileUtils.copyFile(new File(getClass().getResource("/validProvisioning.txt").toURI()), provisioningFile);

    // post-process
    assertTrue(underTest.accepts(provisioningFile, CharEncoding.UTF_8));
    underTest.postProcess(provisioningFile, CharEncoding.UTF_8, LoggerFactory.getLogger(ProvisioningOsgiConfigPostProcessor.class));

    // validate
    assertFalse(provisioningFile.exists());

  }

}

@@ -665,16 +665,111 @@
 sling;%0A%0A
+import static org.junit.Assert.assertArrayEquals;%0Aimport static org.junit.Assert.assertEquals;%0A
 import s
@@ -804,16 +804,16 @@
 tFalse;%0A
-
 import s
@@ -987,16 +987,77 @@
 io.File;
+%0Aimport java.io.FileInputStream;%0Aimport java.util.Dictionary;
 %0A%0Aimport
@@ -1136,16 +1136,70 @@
 coding;%0A
+import org.apache.felix.cm.file.ConfigurationHandler;%0A
 import o
@@ -2154,16 +2154,16 @@
 alidate%0A
-
     asse
@@ -2199,15 +2199,866 @@
 ts());%0A%0A
+    File mypid = new File(target, %22my.pid.config%22);%0A    assertTrue(mypid.exists());%0A%0A    try (FileInputStream is = new FileInputStream(mypid)) %7B%0A      Dictionary%3C?, ?%3E config = ConfigurationHandler.read(is);%0A      assertEquals(%22value1%22, config.get(%22stringProperty%22));%0A      assertArrayEquals(new String%5B%5D %7B%0A          %22v1%22, %22v2%22, %22v3%22%0A      %7D, (String%5B%5D)config.get(%22stringArrayProperty%22));%0A      assertEquals(true, config.get(%22booleanProperty%22));%0A      assertEquals(999999999999L, config.get(%22longProperty%22));%0A    %7D%0A%0A    File myfactory_mypid = new File(target, %22my.factory-my.pid.config%22);%0A    assertTrue(myfactory_mypid.exists());%0A%0A    File myfactory_mypid2 = new File(target, %22mode1/my.factory-my.pid2.config%22);%0A    assertTrue(myfactory_mypid2.exists());%0A%0A    File mypid2 = new File(target, %22mode2/my.pid2.config%22);%0A    assertTrue(mypid2.exists());%0A%0A
   %7D%0A%0A%7D%0A

update unit test