// Path: src/main/java/com/thoughtworks/go/strongauth/config/PluginConfiguration.java
// @Value
// public class PluginConfiguration {
// 
//     public static final String DEFAULT_SOURCE_FILE_PATH = "/etc/go/passwd";
//     private final File principalSourceFile;
// 
//     public PluginConfiguration() {
//         this(DEFAULT_SOURCE_FILE_PATH);
//     }
// 
//     public PluginConfiguration(final String principalSourceFilePath) {
//         this.principalSourceFile = principalSourceFilePath != null ?
//                 new File(principalSourceFilePath) :
//                 new File(DEFAULT_SOURCE_FILE_PATH);
//     }
// 
//     @Override
//     public String toString() {
//         return "PluginConfiguration{" +
//                 "principalSourceFilePath='" + principalSourceFile + '\'' +
//                 '}';
//     }
// }
// 
// Path: src/main/java/com/thoughtworks/go/strongauth/util/Json.java
// public class Json {
//     private static Gson gson = new Gson();
// 
//     public static Map<String, String> toMapOfStrings(String jsonValue) {
//         Type mapOfStringToStringType = new TypeToken<LinkedTreeMap<String, String>>() {}.getType();
//         return gson.fromJson(jsonValue, mapOfStringToStringType);
//     }
// 
//     public static Map toMap(String jsonValue) {
//         return gson.fromJson(jsonValue, Map.class);
//     }
// 
//     public static String toJson(Object anything) {
//         return gson.toJson(anything);
//     }
// }


import com.google.common.base.Optional;
import com.google.common.collect.ImmutableMap;
import com.thoughtworks.go.plugin.api.response.DefaultGoApiResponse;
import com.thoughtworks.go.strongauth.config.PluginConfiguration;
import com.thoughtworks.go.strongauth.util.Json;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
package com.thoughtworks.go.strongauth.wire;



public class PluginConfigurationDecoderTest {

    @Test
    public void testValidConfiguration() {
        DefaultGoApiResponse response = new DefaultGoApiResponse(200);
        response.setResponseBody(Json.toJson(ImmutableMap.of("PASSWORD_FILE_PATH", "/foo/bar")));
        PluginConfiguration configuration = new PluginConfigurationDecoder().decode(response);
        assertThat(configuration, is(new PluginConfiguration("/foo/bar")));
    }

    @Test
    public void testHandleNon200() {
        DefaultGoApiResponse response = new DefaultGoApiResponse(500);
        PluginConfiguration configuration = new PluginConfigurationDecoder().decode(response);
        assertThat(configuration, is(new PluginConfiguration("/etc/go/passwd")));
    }

    @Test
    public void testNotConfigured() {
        DefaultGoApiResponse response = new DefaultGoApiResponse(200);
        PluginConfiguration configuration = new PluginConfigurationDecoder().decode(response);
// Path: src/main/java/com/thoughtworks/go/strongauth/config/PluginConfiguration.java
// @Value
// public class PluginConfiguration {
// 
//     public static final String DEFAULT_SOURCE_FILE_PATH = "/etc/go/passwd";
//     private final File principalSourceFile;
// 
//     public PluginConfiguration() {
//         this(DEFAULT_SOURCE_FILE_PATH);
//     }
// 
//     public PluginConfiguration(final String principalSourceFilePath) {
//         this.principalSourceFile = principalSourceFilePath != null ?
//                 new File(principalSourceFilePath) :
//                 new File(DEFAULT_SOURCE_FILE_PATH);
//     }
// 
//     @Override
//     public String toString() {
//         return "PluginConfiguration{" +
//                 "principalSourceFilePath='" + principalSourceFile + '\'' +
//                 '}';
//     }
// }
// 
// Path: src/main/java/com/thoughtworks/go/strongauth/util/Json.java
// public class Json {
//     private static Gson gson = new Gson();
// 
//     public static Map<String, String> toMapOfStrings(String jsonValue) {
//         Type mapOfStringToStringType = new TypeToken<LinkedTreeMap<String, String>>() {}.getType();
//         return gson.fromJson(jsonValue, mapOfStringToStringType);
//     }
// 
//     public static Map toMap(String jsonValue) {
//         return gson.fromJson(jsonValue, Map.class);
//     }
// 
//     public static String toJson(Object anything) {
//         return gson.toJson(anything);
//     }
// }


// Path: src/test/java/com/thoughtworks/go/strongauth/wire/PluginConfigurationDecoderTest.java
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableMap;
import com.thoughtworks.go.plugin.api.response.DefaultGoApiResponse;
import com.thoughtworks.go.strongauth.config.PluginConfiguration;
import com.thoughtworks.go.strongauth.util.Json;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

package com.thoughtworks.go.strongauth.wire;



public class PluginConfigurationDecoderTest {

    @Test
    public void testValidConfiguration() {
        DefaultGoApiResponse response = new DefaultGoApiResponse(200);
        response.setResponseBody(Json.toJson(ImmutableMap.of("PASSWORD_FILE_PATH", "/foo/bar")));
        PluginConfiguration configuration = new PluginConfigurationDecoder().decode(response);
        assertThat(configuration, is(new PluginConfiguration("/foo/bar")));
    }

    @Test
    public void testHandleNon200() {
        DefaultGoApiResponse response = new DefaultGoApiResponse(500);
        PluginConfiguration configuration = new PluginConfigurationDecoder().decode(response);
        assertThat(configuration, is(new PluginConfiguration("/etc/go/passwd")));
    }

    @Test
    public void testNotConfigured() {
        DefaultGoApiResponse response = new DefaultGoApiResponse(200);
        PluginConfiguration configuration = new PluginConfigurationDecoder().decode(response);
        assertThat(configuration, is(new PluginConfiguration("/etc/go/passwd")));