/**
 *  Copyright 2005-2016 Red Hat, Inc.
 *
 *  Red Hat licenses this file to you 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.jboss.fuse.vault.karaf.core;

import java.util.HashMap;
import java.util.Map;

import org.jboss.security.vault.SecurityVaultException;
import org.junit.Before;
import org.junit.Test;
import org.picketbox.plugins.vault.PicketBoxSecurityVault;

import static org.assertj.core.api.Assertions.assertThat;

public class FuseVaultActivatorTest {

    final FuseVaultActivator activator = new FuseVaultActivator();

    @Before
    public void initialize() throws SecurityVaultException {
        final String keyStoreUrl = FuseVaultActivatorTest.class.getResource("/vault.keystore").getFile().toString();
        final String markerPath = FuseVaultActivatorTest.class.getResource("/file-enc-dir/.marker").getFile()
                .toString();
        final String fileEncDir = markerPath.substring(0, markerPath.length() - 7);

        final Map<String, Object> env = new HashMap<>();
        env.put(PicketBoxSecurityVault.KEYSTORE_URL, keyStoreUrl);
        env.put(PicketBoxSecurityVault.KEYSTORE_PASSWORD, "MASK-EdCIIJbZZAl");
        env.put(PicketBoxSecurityVault.KEYSTORE_ALIAS, "vault");
        env.put(PicketBoxSecurityVault.ENC_FILE_DIR, fileEncDir);
        env.put(PicketBoxSecurityVault.SALT, "Mxyzptlk");
        env.put(PicketBoxSecurityVault.ITERATION_COUNT, "50");

        VaultHelper.initializeVault(env);
    }

    @Test
    public void shouldNotReplaceSystemPropertiesNotInVaultFormat() {
        activator.replace("key", "value");
    }

    @Test
    public void shouldReplaceSystemPropertiesInVaultFormat() {
        activator.replace("key", "VAULT::block1::key::1");

        assertThat(System.getProperty("key")).isEqualTo("this is a password");
    }
}

@@ -674,16 +674,89 @@
 .core;%0A%0A
+import java.io.UnsupportedEncodingException;%0Aimport java.net.URLDecoder;%0A
 import j
@@ -1196,16 +1196,46 @@
 xception
+, UnsupportedEncodingException
  %7B%0A     
@@ -1264,16 +1264,51 @@
 reUrl = 
+URLDecoder%0A                .decode(
 FuseVaul
@@ -1371,32 +1371,42 @@
 ile().toString()
+, %22UTF-8%22)
 ;%0A        final 
@@ -1424,16 +1424,51 @@
 erPath =
+ URLDecoder.decode(%0A               
  FuseVau
@@ -1535,33 +1535,16 @@
 etFile()
-%0A                
 .toStrin
@@ -1545,16 +1545,26 @@
 oString(
+), %22UTF-8%22
 );%0A     

Support encoded (%20) paths for tests