com.amazonaws.athena.connector.integ.data.TestConfig Maven / Gradle / Ivy
/*-
* #%L
* Amazon Athena Query Federation Integ Test
* %%
* Copyright (C) 2019 - 2021 Amazon Web Services
* %%
* 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 com.amazonaws.athena.connector.integ.data;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
/**
* This class is responsible for extracting the attributes from the test config file (test-config.json), and provides
* simple extractors for the attributes within.
*/
public class TestConfig
{
private static final String TEST_CONFIG_FILE_NAME = "etc/test-config.json";
private final Map config;
/**
* The constructor loads the test configuration attributes from a file into a config Map.
*/
public TestConfig()
{
config = setUpTestConfig();
}
/**
* Loads the test configuration attributes from a file into a Map.
* @return Map(String, Object) containing the test configuration attributes.
* @throws RuntimeException Error encountered while trying to access or parse the config file.
*/
private Map setUpTestConfig()
throws RuntimeException
{
try {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
return objectMapper.readValue(new File(TEST_CONFIG_FILE_NAME), HashMap.class);
}
catch (IOException e) {
throw new RuntimeException("Unable to parse test-config.json: " + e.getMessage(), e);
}
}
/**
* Gets a single item from the config file.
* @param attribute The name of the item being extracted from the config file.
* @return Optional Object, or empty Optional if the retrieval of the attribute results in a null value.
*/
public Optional