// Path: harahachibu/src/main/java/uk/co/flax/harahachibu/services/DiskSpaceThreshold.java
// public class DiskSpaceThreshold {
// 
// 	private static final Logger LOGGER = LoggerFactory.getLogger(DiskSpaceThreshold.class);
// 
// 	private static final Pattern THRESHOLD_PATTERN = Pattern.compile("^(\\d+)\\s*([KMG%])?$", Pattern.CASE_INSENSITIVE);
// 
// 	private static final int KILOBYTE = 1024;
// 
// 	private long thresholdValue;
// 	private boolean percentage;
// 
// 	DiskSpaceThreshold(final long threshold, final boolean isPercentage) {
// 		this.thresholdValue = threshold;
// 		this.percentage = isPercentage;
// 	}
// 
// 	/**
// 	 * Parse a threshold string and return the corresponding DiskSpaceThreshold object.
// 	 * @param thresholdString the string to parse.
// 	 * @return a DiskSpaceThreshold representing the threshold value, and whether it
// 	 * is a percentage.
// 	 * @throws DiskSpaceCheckerException if the string cannot be parsed, or the value
// 	 * makes no sense (percentage above 100, negative value, etc.).
// 	 */
// 	public static DiskSpaceThreshold parse(String thresholdString) throws DiskSpaceCheckerException {
// 		if (thresholdString.startsWith("-")) {
// 			throw new DiskSpaceCheckerException("Negative threshold string not allowed: " + thresholdString);
// 		}
// 
// 		Matcher m = THRESHOLD_PATTERN.matcher(thresholdString);
// 		if (!m.matches()) {
// 			throw new DiskSpaceCheckerException("Cannot parse threshold string " + thresholdString);
// 		}
// 
// 		DiskSpaceThreshold t;
// 
// 		long value = Long.valueOf(m.group(1));
// 		if (StringUtils.isBlank(m.group(2))) {
// 			t = new DiskSpaceThreshold(value, false);
// 		} else {
// 			String unit = m.group(2).toUpperCase();
// 
// 			switch (unit) {
// 				case "%":
// 					if (value > 100) {
// 						throw new DiskSpaceCheckerException("Percentage value higher than 100%: " + thresholdString);
// 					} else {
// 						t = new DiskSpaceThreshold(value, true);
// 					}
// 					break;
// 				case "G":
// 					value = value * KILOBYTE;
// 					// FALL THROUGH
// 				case "M":
// 					value = value * KILOBYTE;
// 					// FALL THROUGH
// 				case "K":
// 					value = value * KILOBYTE;
// 					t = new DiskSpaceThreshold(value, false);
// 					break;
// 				default:
// 					throw new DiskSpaceCheckerException("Unexpected unit value: " + unit);
// 			}
// 		}
// 
// 		return t;
// 	}
// 
// 	public long getThresholdValue() {
// 		return thresholdValue;
// 	}
// 
// 	public boolean isPercentage() {
// 		return percentage;
// 	}
// 
// 	/**
// 	 * Check whether or not a {@link DiskSpace} object representing
// 	 * space on a server is within this threshold.
// 	 * @param diskSpace the disk space data.
// 	 * @return {code true} if the space available is within the threshold value.
// 	 */
// 	public boolean withinThreshold(DiskSpace diskSpace) {
// 		return withinThreshold(diskSpace.getFreeSpace(), diskSpace.getMaxSpace());
// 	}
// 
// 	/**
// 	 * Check whether or not the space available is within this threshold.
// 	 * @param freeSpace the free space on the drive.
// 	 * @param maxSpace the maximum space on the drive (required for percentage
// 	 * thresholds).
// 	 * @return {code true} if the space is within the threshold value.
// 	 */
// 	public boolean withinThreshold(long freeSpace, long maxSpace) {
// 		boolean ret = true;
// 
// 		if (isPercentage()) {
// 			// Work out percentage free space
// 			if (maxSpace == 0) {
// 				LOGGER.warn("Skipping withinThreshold() percentage calculation - maxSpace == 0");
// 				ret = false;
// 			} else {
// 				int freePercent = Math.round(((float) freeSpace / maxSpace) * 100);
// 				if (freePercent <= thresholdValue) {
// 					LOGGER.debug("Threshold percentage check fails: freeSpace={}, maxSpace={}, percent free={}, threshold={}%",
// 							freeSpace, maxSpace, freePercent, thresholdValue);
// 					ret = false;
// 				}
// 			}
// 		} else {
// 			if (freeSpace <= thresholdValue) {
// 				LOGGER.debug("Threshold check fails: freeSpace={}, threshold={}", freeSpace, thresholdValue);
// 				ret = false;
// 			}
// 		}
// 
// 		return ret;
// 	}
// 
// }


import org.junit.Before;
import org.junit.Test;
import uk.co.flax.harahachibu.services.DiskSpaceThreshold;
import java.io.IOException;
import java.nio.file.FileStore;
import java.util.HashMap;
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/**
 * Copyright (c) 2016 Lemur Consulting Ltd.
 * <p/>
 * 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
 * <p/>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p/>
 * 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 uk.co.flax.harahachibu.services.impl;




/**
 * Unit tests for the local Solr disk space checker implementation.
 *
 * Created by mlp on 18/04/16.
 */
public class SolrDiskSpaceCheckerTest {

	private SolrDiskSpaceChecker checker;
	private Map<String, Object> configuration = new HashMap<>();
// Path: harahachibu/src/main/java/uk/co/flax/harahachibu/services/DiskSpaceThreshold.java
// public class DiskSpaceThreshold {
// 
// 	private static final Logger LOGGER = LoggerFactory.getLogger(DiskSpaceThreshold.class);
// 
// 	private static final Pattern THRESHOLD_PATTERN = Pattern.compile("^(\\d+)\\s*([KMG%])?$", Pattern.CASE_INSENSITIVE);
// 
// 	private static final int KILOBYTE = 1024;
// 
// 	private long thresholdValue;
// 	private boolean percentage;
// 
// 	DiskSpaceThreshold(final long threshold, final boolean isPercentage) {
// 		this.thresholdValue = threshold;
// 		this.percentage = isPercentage;
// 	}
// 
// 	/**
// 	 * Parse a threshold string and return the corresponding DiskSpaceThreshold object.
// 	 * @param thresholdString the string to parse.
// 	 * @return a DiskSpaceThreshold representing the threshold value, and whether it
// 	 * is a percentage.
// 	 * @throws DiskSpaceCheckerException if the string cannot be parsed, or the value
// 	 * makes no sense (percentage above 100, negative value, etc.).
// 	 */
// 	public static DiskSpaceThreshold parse(String thresholdString) throws DiskSpaceCheckerException {
// 		if (thresholdString.startsWith("-")) {
// 			throw new DiskSpaceCheckerException("Negative threshold string not allowed: " + thresholdString);
// 		}
// 
// 		Matcher m = THRESHOLD_PATTERN.matcher(thresholdString);
// 		if (!m.matches()) {
// 			throw new DiskSpaceCheckerException("Cannot parse threshold string " + thresholdString);
// 		}
// 
// 		DiskSpaceThreshold t;
// 
// 		long value = Long.valueOf(m.group(1));
// 		if (StringUtils.isBlank(m.group(2))) {
// 			t = new DiskSpaceThreshold(value, false);
// 		} else {
// 			String unit = m.group(2).toUpperCase();
// 
// 			switch (unit) {
// 				case "%":
// 					if (value > 100) {
// 						throw new DiskSpaceCheckerException("Percentage value higher than 100%: " + thresholdString);
// 					} else {
// 						t = new DiskSpaceThreshold(value, true);
// 					}
// 					break;
// 				case "G":
// 					value = value * KILOBYTE;
// 					// FALL THROUGH
// 				case "M":
// 					value = value * KILOBYTE;
// 					// FALL THROUGH
// 				case "K":
// 					value = value * KILOBYTE;
// 					t = new DiskSpaceThreshold(value, false);
// 					break;
// 				default:
// 					throw new DiskSpaceCheckerException("Unexpected unit value: " + unit);
// 			}
// 		}
// 
// 		return t;
// 	}
// 
// 	public long getThresholdValue() {
// 		return thresholdValue;
// 	}
// 
// 	public boolean isPercentage() {
// 		return percentage;
// 	}
// 
// 	/**
// 	 * Check whether or not a {@link DiskSpace} object representing
// 	 * space on a server is within this threshold.
// 	 * @param diskSpace the disk space data.
// 	 * @return {code true} if the space available is within the threshold value.
// 	 */
// 	public boolean withinThreshold(DiskSpace diskSpace) {
// 		return withinThreshold(diskSpace.getFreeSpace(), diskSpace.getMaxSpace());
// 	}
// 
// 	/**
// 	 * Check whether or not the space available is within this threshold.
// 	 * @param freeSpace the free space on the drive.
// 	 * @param maxSpace the maximum space on the drive (required for percentage
// 	 * thresholds).
// 	 * @return {code true} if the space is within the threshold value.
// 	 */
// 	public boolean withinThreshold(long freeSpace, long maxSpace) {
// 		boolean ret = true;
// 
// 		if (isPercentage()) {
// 			// Work out percentage free space
// 			if (maxSpace == 0) {
// 				LOGGER.warn("Skipping withinThreshold() percentage calculation - maxSpace == 0");
// 				ret = false;
// 			} else {
// 				int freePercent = Math.round(((float) freeSpace / maxSpace) * 100);
// 				if (freePercent <= thresholdValue) {
// 					LOGGER.debug("Threshold percentage check fails: freeSpace={}, maxSpace={}, percent free={}, threshold={}%",
// 							freeSpace, maxSpace, freePercent, thresholdValue);
// 					ret = false;
// 				}
// 			}
// 		} else {
// 			if (freeSpace <= thresholdValue) {
// 				LOGGER.debug("Threshold check fails: freeSpace={}, threshold={}", freeSpace, thresholdValue);
// 				ret = false;
// 			}
// 		}
// 
// 		return ret;
// 	}
// 
// }


// Path: harahachibu/src/test/java/uk/co/flax/harahachibu/services/impl/SolrDiskSpaceCheckerTest.java
import org.junit.Before;
import org.junit.Test;
import uk.co.flax.harahachibu.services.DiskSpaceThreshold;
import java.io.IOException;
import java.nio.file.FileStore;
import java.util.HashMap;
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

/**
 * Copyright (c) 2016 Lemur Consulting Ltd.
 * <p/>
 * 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
 * <p/>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p/>
 * 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 uk.co.flax.harahachibu.services.impl;




/**
 * Unit tests for the local Solr disk space checker implementation.
 *
 * Created by mlp on 18/04/16.
 */
public class SolrDiskSpaceCheckerTest {

	private SolrDiskSpaceChecker checker;
	private Map<String, Object> configuration = new HashMap<>();
	private DiskSpaceThreshold threshold = mock(DiskSpaceThreshold.class);