/*
 * Copyright (c) 2017 Public Library of Science
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

package org.ambraproject.rhino.service;

import com.google.gson.Gson;
import org.ambraproject.rhino.BaseRhinoTest;
import org.ambraproject.rhino.rest.response.ServiceResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.testng.annotations.Test;

import java.io.IOException;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;


public class ConfigurationReadServiceTest extends BaseRhinoTest {
  @Autowired
  private ConfigurationReadService configurationReadService;

  @Test
  public void testGetBuildProperties() throws IOException {
    Properties actualProperties = configurationReadService.getBuildProperties();

    assertTrue(actualProperties.containsKey("version"), "Did not contain version");
    assertTrue(actualProperties.containsKey("buildDate"), "Did not contain buildDate");
    assertTrue(actualProperties.containsKey("buildUser"), "Did not contain buildUser");
    assertTrue(actualProperties.containsKey("gitCommitIdAbbrev"), "Did not contain gitCommitIdAbbrev");
  }

  @Test
  public void testReadBuildProperties() throws IOException {
    assertNotNull(configurationReadService.readBuildConfig());
  }

  @Test
  public void testGetRepoConfig() throws IOException {
    Map<String, Object> repoConfigMap = configurationReadService.getRepoConfig();
    Map<String, Object> editorialConfigMap = (Map<String, Object>) repoConfigMap.get("editorial");

    String repoAddress = editorialConfigMap.get("address").toString();
    assertEquals(repoAddress, "http://path/to/content/repo", "Invalid/missing content repo URL");
    String repoBucket = editorialConfigMap.get("bucket").toString();
    assertEquals(repoBucket, "bucket_name", "Invalid/missing content repo bucket name");

    Map<String, Object> corpusConfigMap = (Map<String, Object>) repoConfigMap.get("corpus");
    final Set<String> secondaryBuckets = (Set<String>) corpusConfigMap.get("secondaryBuckets");
    assertEquals(secondaryBuckets.iterator().next(), "secondary_bucket");
  }

  @Test
  public void testReadRepoConfig() throws IOException {
    final ServiceResponse<Map<String, Object>> repoConfig = configurationReadService.readRepoConfig();
    assertNotNull(repoConfig);
    final ResponseEntity<?> responseEntity = repoConfig.asJsonResponse(new Gson());
    assertEquals(responseEntity.getStatusCode(), HttpStatus.OK);
  }

  @Test
  public void testReadRunInfo() throws IOException {
    final ServiceResponse<Map<String, String>> runConfig = configurationReadService.readRunInfo();
    assertNotNull(runConfig);
    final ResponseEntity<?> responseEntity = runConfig.asJsonResponse(new Gson());
    assertEquals(responseEntity.getStatusCode(), HttpStatus.OK);
  }

}

@@ -2470,64 +2470,291 @@
     
-assertNotNull(configurationReadService.readBuildConfig()
+final ServiceResponse%3CProperties%3E buildProperties = configurationReadService.readBuildConfig();%0A    assertNotNull(buildProperties);%0A    final ResponseEntity%3C?%3E responseEntity = buildProperties.asJsonResponse(new Gson());%0A    assertEquals(responseEntity.getStatusCode(), HttpStatus.OK
 );%0A 
@@ -4106,24 +4106,168 @@
 dRunInfo();%0A
+    assertResponseEntity(runConfig);%0A  %7D%0A%0A  private void assertResponseEntity(ServiceResponse%3CMap%3CString, String%3E%3E config) throws IOException %7B%0A
     assertNo
@@ -4272,20 +4272,17 @@
 NotNull(
-runC
+c
 onfig);%0A
@@ -4326,20 +4326,17 @@
 ntity = 
-runC
+c
 onfig.as

add some asserts