com.rapiddweller.common.DatabeneTestUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rd-lib-common Show documentation
Show all versions of rd-lib-common Show documentation
'rapiddweller Common' is an open source Java library
forked from Databene Commons by Volker Bergmann.
It provides extensions to the Java core library by utility classes, abstract concepts
and concrete implementations.
/*
* Copyright (C) 2004-2015 Volker Bergmann ([email protected]).
* All rights reserved.
*
* 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.
*/
package com.rapiddweller.common;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
* Provides test settings from a file ${user.home}/databene.test.properties
.
* Created at 01.10.2009 15:30:51
*
* @author Volker Bergmann
* @since 0.5.0
*/
public class DatabeneTestUtil {
private static final String DATABENE_TEST_PROPERTIES = "test.properties";
private static final Logger LOGGER = LogManager.getLogger(DatabeneTestUtil.class);
private static Map properties;
static {
init();
}
private static void init() {
File file = new File(SystemInfo.getUserHome() + File.separator + "rapiddweller", DATABENE_TEST_PROPERTIES);
if (file.exists()) {
try {
properties = IOUtil.readProperties(file.getAbsolutePath());
} catch (IOException e) {
LOGGER.error("Error reading " + file.getAbsolutePath(), e);
createDefaultProperties();
}
} else {
createDefaultProperties();
try {
IOUtil.writeProperties(properties, file.getAbsolutePath());
} catch (Exception e) {
LOGGER.error("Error writing " + file.getAbsolutePath(), e);
}
}
}
private static void createDefaultProperties() {
properties = new HashMap<>();
properties.put("online", "false");
}
/**
* Is online boolean.
*
* @return the boolean
*/
public static boolean isOnline() {
String setting = properties.get("online");
if (StringUtil.isEmpty(setting)) {
return false;
} else {
return setting.equalsIgnoreCase("true");
}
}
/**
* Ftp download url string.
*
* @return the string
*/
public static String ftpDownloadUrl() {
return properties.get("ftp.download.url");
}
/**
* Ftp upload url string.
*
* @return the string
*/
public static String ftpUploadUrl() {
return properties.get("ftp.upload.url");
}
/**
* Gets properties.
*
* @return the properties
*/
public static Map getProperties() {
return properties;
}
}