Commit 2810cc5f authored by John Vester's avatar John Vester
Browse files

Removing log4j2 implementation to resolve issue with Spring Boot

parent 10e113ec
......@@ -42,4 +42,8 @@
#1.8
* minor fixes with logging
\ No newline at end of file
* minor fixes with logging
#1.9
* remove all logging to see if this fixes issue with Spring Boot
\ No newline at end of file
......@@ -23,7 +23,7 @@ Adding RandomGenerator to your Maven project simply requires adding the followin
<dependency>
<groupId>com.gitlab.johnjvester</groupId>
<artifactId>random-generator</artifactId>
<version>1.8</version>
<version>1.9</version>
</dependency>
~~~~
......
......@@ -4,7 +4,7 @@
<groupId>com.gitlab.johnjvester</groupId>
<artifactId>random-generator</artifactId>
<version>1.8</version>
<version>1.9</version>
<packaging>jar</packaging>
......@@ -27,7 +27,6 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<log4j.version>2.8.2</log4j.version>
<junit.version>4.12</junit.version>
<lombok.version>1.18.8</lombok.version>
<snakeyaml.version>1.24</snakeyaml.version>
......@@ -42,7 +41,7 @@
</licenses>
<scm>
<url>https://gitlab.com/johnjvester/RandomGenerator/tags/random-generator-1.8</url>
<url>https://gitlab.com/johnjvester/RandomGenerator/tags/random-generator-1.9</url>
</scm>
<dependencies>
......@@ -56,16 +55,6 @@
<artifactId>snakeyaml</artifactId>
<version>${snakeyaml.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
......
package com.gitlab.johnjvester.randomizer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.yaml.snakeyaml.Yaml;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
public class Main {
final static Logger logger = LogManager.getLogger(Main.class);
/**
* <h3>CLI for RandomGenerator</h3>
* <p>Usage: java -jar random-generator-version listString [options]</p>
......@@ -63,7 +58,6 @@ public class Main {
Map<String, Object> result = (Map<String, Object>) yaml.load(is);
String currentVersion = result.get("version").toString();
logger.debug("currentVersion = " + currentVersion);
writeMessage("", false);
writeMessage("RandomGenerator version " + currentVersion, true);
......@@ -72,12 +66,6 @@ public class Main {
Integer returnListSize = null;
if (args != null && (args.length == 1 || args.length == 3 || args.length == 5)) {
logger.debug("args.length = " + args.length);
for (int i = 0; i < args.length; i++) {
logger.debug("args[" + i + "] = " + args[i]);
}
if (args.length == 1) {
writeMessage("Randomizing string with default delimiter (" + randomGenerator.DEFAULT_DELIMITER + ")", false);
writeMessage("String to randomize:", false);
......@@ -108,9 +96,6 @@ public class Main {
}
}
logger.debug("hasCustomDelimiter = " + hasCustomDelimiter);
logger.debug("hasReturnListSize = " + hasReturnListSize);
if (hasReturnListSize != null) {
returnListSize = new Integer(hasReturnListSize);
}
......@@ -139,8 +124,6 @@ public class Main {
}
}
logger.debug("returnString = " + returnString);
writeMessage("Randomized string:", false);
writeMessage(returnString, false);
......@@ -177,8 +160,6 @@ public class Main {
List<String> fullNames = randomGeneratorData.randomizeFullNames(nameFormat, returnSize);
returnString = String.join("\n", fullNames);
logger.debug("returnString = " + returnString);
writeMessage("Randomized names:", false);
writeMessage(returnString, false);
} else {
......@@ -193,7 +174,6 @@ public class Main {
try {
is.close();
} catch (IOException ioe) {
logger.error(ioe.getMessage());
writeMessage("An error occurred while trying to read the properties.yml file.", true);
writeMessage(ioe.getMessage(), true);
}
......
package com.gitlab.johnjvester.randomizer;
import lombok.Data;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.lang.reflect.Field;
import java.util.ArrayList;
......@@ -14,9 +12,6 @@ import java.util.Random;
import java.util.TreeMap;
public class RandomGenerator<T> {
final static Logger logger = LogManager.getLogger(RandomGenerator.class);
private static final Integer ZERO = new Integer("0");
private Utility utility = new Utility();
......@@ -108,7 +103,6 @@ public class RandomGenerator<T> {
* @since 1.0
*/
public List<T> randomize(List<T> tList) {
logger.debug("calling preProcessing(tList, ZERO, false)");
return preProcessing(tList, ZERO, RATING_LEVEL_OFF);
}
......@@ -129,7 +123,6 @@ public class RandomGenerator<T> {
* @since 1.0
*/
public List<T> randomize(List<T> tList, Boolean useRating) {
logger.debug("calling preProcessing(tlist, ZERO, " + useRating + ")");
return preProcessing(tList, ZERO, useRating ? RATING_LEVEL_LOW : RATING_LEVEL_OFF);
}
......@@ -150,7 +143,6 @@ public class RandomGenerator<T> {
* @since 1.4
*/
public List<T> randomize(List<T> tList, int ratingLevel) {
logger.debug("calling preProcessing(tlist, ZERO, " + ratingLevel + ")");
return preProcessing(tList, ZERO, ratingLevel);
}
......@@ -168,7 +160,6 @@ public class RandomGenerator<T> {
* @since 1.0
*/
public List<T> randomize(List<T> tList, Integer maxResults) {
logger.debug("calling preProcessing(tList, " + maxResults + ", false)");
return preProcessing(tList, maxResults != null ? maxResults : ZERO, RATING_LEVEL_OFF);
}
......@@ -193,7 +184,6 @@ public class RandomGenerator<T> {
* @since 1.0
*/
public List<T> randomize(List<T> tList, Integer maxResults, Boolean useRating) {
logger.debug("calling preProcessing(tList, " + maxResults + ", " + useRating + ")");
return preProcessing(tList, maxResults != null ? maxResults : ZERO, useRating ? RATING_LEVEL_LOW : RATING_LEVEL_OFF);
}
......@@ -215,7 +205,6 @@ public class RandomGenerator<T> {
* @since 1.4
*/
public List<T> randomize(List<T> tList, Integer maxResults, int ratingLevel) {
logger.debug("calling preProcessing(tList, " + maxResults + ", " + ratingLevel + ")");
return preProcessing(tList, maxResults != null ? maxResults : ZERO, ratingLevel);
}
......@@ -230,9 +219,7 @@ public class RandomGenerator<T> {
* @since 1.0
*/
public String randomize(String thisString, String thisSeparator) {
logger.debug("calling convertStringToList(thisString, " + thisSeparator + ")");
List<T> thisList = utility.convertStringToList(thisString, thisSeparator);
logger.debug("calling convertListToString(preProcessing(thisList, ZERO, false), " + thisSeparator + ")");
return utility.convertListToString(preProcessing(thisList, ZERO, RATING_LEVEL_OFF), thisSeparator);
}
......@@ -253,29 +240,23 @@ public class RandomGenerator<T> {
* @since 1.0
*/
public String randomize(String thisString, String thisSeparator, Integer maxResults) {
logger.debug("calling convertStringToList(thisString, " + thisSeparator + ")");
List<T> thisList = utility.convertStringToList(thisString, thisSeparator);
logger.debug("calling convertListToString(preProcessing(thisList, " + maxResults != null ? maxResults : ZERO + ", false), " + thisSeparator + ")");
return utility.convertListToString(preProcessing(thisList, maxResults != null ? maxResults : ZERO, RATING_LEVEL_OFF), thisSeparator);
}
private List<T> preProcessing(List<T> tList, Integer maxResults, Integer ratingLevel) {
logger.debug("begin preProcessing(tList, " + maxResults + ", " + ratingLevel + ")");
List<RandomListItem> returnList = new ArrayList<RandomListItem>();
if (tList != null && tList.size() > 0) {
logger.debug("tList.size() = " + tList.size());
if (tList.size() == 1) {
return tList;
} else {
if (ratingLevel != null && ratingLevel > 0 && !utility.isListSizeValid(tList, ratingLevel)) {
logger.error("The list size being processed (" + tList.size() + ") is too large to include rating functionality.");
ratingLevel = 0;
}
if (maxResults.intValue() > ZERO) {
if (maxResults.intValue() >= tList.size()) {
logger.debug("maxResults (" + maxResults + ") is greater than tList.size() (" + tList.size() + ")");
handleRandomization(expandListForRatings(tList, ratingLevel), returnList, ZERO);
} else {
handleRandomization(expandListForRatings(tList, ratingLevel), returnList, maxResults);
......@@ -286,37 +267,28 @@ public class RandomGenerator<T> {
}
}
logger.debug("returnList.size() = " + returnList.size());
logger.debug("end preProcessing(tList, " + maxResults + ")");
return convertToGenericList(returnList);
}
private void handleRandomization(List<RandomListItem> randomListItems, List<RandomListItem> returnList, Integer maxResults) {
logger.debug("begin handleRandomization(tList, returnList, " + maxResults + ")");
while (randomListItems.size() > 0 && (maxResults.intValue() == ZERO || maxResults.intValue() > returnList.size())) {
int listSize = randomListItems.size();
logger.debug("listSize = " + listSize);
int winner = 0;
if (listSize != 1) {
Random random = new Random();
winner = random.nextInt(listSize);
}
logger.debug("winner = " + winner);
RandomListItem randomListItem = randomListItems.get(winner);
returnList.add(randomListItem);
removeSimilarItems(randomListItems, randomListItem.randomInt);
logger.debug("returnList.size() = " + returnList.size());
logger.debug("randomListItems.size() = " + randomListItems.size());
}
logger.debug("end handleRandomization(tList, returnList, " + maxResults + ")");
}
private List<RandomListItem> expandListForRatings(List<T> tList, Integer ratingLevel) {
logger.debug("begin expandListForRatings(tList, " + ratingLevel + ")");
TreeMap<Integer, Rating> ratingMap = new TreeMap<>();
List<RandomListItem> newList = new ArrayList<>();
......@@ -348,9 +320,8 @@ public class RandomGenerator<T> {
try {
Object o = field.get(tItem);
rating = (Integer) o;
logger.debug(RATING + " = " + rating);
} catch (Exception e) {
logger.debug("Exception occurred trying to get " + RATING + " field value");
// NOOP
}
}
}
......@@ -397,7 +368,6 @@ public class RandomGenerator<T> {
}
private void removeSimilarItems(List<RandomListItem> randomListItems, int thisRandomInt) {
logger.debug("begin removeSimilarItems(randomListItems, " + thisRandomInt + ")");
Iterator<RandomListItem> itemIterator = randomListItems.iterator();
int count = 0;
......@@ -409,23 +379,13 @@ public class RandomGenerator<T> {
count++;
}
}
logger.debug("Removed " + count + " instance(s) of " + thisRandomInt);
}
private TreeMap<Integer, Rating> processRatingMap(List<T> tList, Integer ratingLevel) {
logger.debug("begin processRatingMap(tList)");
TreeMap<Integer, Rating> ratingMap = buildRatingMap(tList);
Integer minimumRating = Collections.min(ratingMap.keySet());
logger.debug("minimumRating = " + minimumRating);
Integer maximumRating = Collections.max(ratingMap.keySet());
logger.debug("maximumRating = " + maximumRating);
Integer range = maximumRating - minimumRating;
logger.debug("range = " + range);
Integer segmentSize;
if (range >= 20) {
......@@ -434,8 +394,6 @@ public class RandomGenerator<T> {
segmentSize = 1;
}
logger.debug("segmentSize = " + segmentSize);
TreeMap<Integer, Integer> treeMap = getMultiplier(minimumRating, segmentSize, ratingLevel);
for (Map.Entry<Integer, Rating> entry : ratingMap.entrySet()) {
......@@ -447,7 +405,6 @@ public class RandomGenerator<T> {
}
private TreeMap<Integer, Rating> buildRatingMap(List<T> tList) {
logger.debug("begin buildRatingMap(tList)");
TreeMap<Integer, Rating> returnMap = new TreeMap();
if (tList != null && tList.size() > 0) {
......@@ -464,7 +421,6 @@ public class RandomGenerator<T> {
}
private TreeMap<Integer, Integer> getMultiplier(Integer startPoint, Integer segmentSize, Integer ratingLevel) {
logger.debug("begin getMultiplier(" + startPoint + ", " + segmentSize + ")");
TreeMap<Integer, Integer> returnMap = new TreeMap();
Integer keyValue = startPoint;
......
package com.gitlab.johnjvester.randomizer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.LogManager;
import java.util.logging.Logger;
import java.util.stream.Collectors;
public class RandomGeneratorData {
final static Logger logger = LogManager.getLogger(RandomGenerator.class);
RandomGenerator randomGenerator = new RandomGenerator();
/**
......@@ -23,7 +20,6 @@ public class RandomGeneratorData {
* @throws RandomGeneratorException when the {@link NameFormat} cannot be determined
*/
public List<String> randomizeFullNames(NameFormat nameFormat, Integer returnSize) throws RandomGeneratorException {
logger.debug("getting random list of " + returnSize + " full names");
List<String> fullNames = new ArrayList<>();
List<String> firstNames = randomGenerator.randomize(getFirstNames(returnSize));
......@@ -44,19 +40,14 @@ public class RandomGeneratorData {
}
}
logger.debug("fullNames.size() = " + fullNames.stream());
return fullNames;
}
private List<String> getFirstNames(Integer returnSize) {
List<String> firstNames = RandomData.getFirstNames();
logger.debug("returnSize = " + returnSize);
logger.debug("firstNames.size() = " + firstNames.size());
if (returnSize > firstNames.size()) {
double value = returnSize / firstNames.size();
logger.debug("value = " + value);
for (int i = 0; i < (int) value; i++) {
firstNames.addAll(RandomData.getFirstNames());
......@@ -69,12 +60,8 @@ public class RandomGeneratorData {
private List<String> getLastNames(Integer returnSize) {
List<String> lastNames = RandomData.getLastNames();
logger.debug("returnSize = " + returnSize);
logger.debug("lastNames.size() = " + lastNames.size());
if (returnSize > lastNames.size()) {
double value = returnSize / lastNames.size();
logger.debug("value = " + value);
for (int i = 0; i < (int) value; i++) {
lastNames.addAll(RandomData.getLastNames());
......
package com.gitlab.johnjvester.randomizer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
public class Utility<T> {
final static Logger logger = LogManager.getLogger(Utility.class);
final static Integer MAX_MULTIPLIER_LOW = 5;
final static Integer MAX_MULTIPLIER_MEDIUM = 21;
final static Integer MAX_MULTIPLIER_HIGH = 210;
......@@ -65,16 +60,12 @@ public class Utility<T> {
}
Integer findValueInMap(Integer value, TreeMap<Integer, Integer> treeMap) {
logger.debug("begin findValueInMap(" + value + ", treeMap)");
Map.Entry<Integer, Integer> entry = treeMap.floorEntry(value);
logger.debug("entry.getValue() = " + entry.getValue());
return entry.getValue();
}
Integer findValueInRatingMap(Integer value, TreeMap<Integer, Rating> treeMap) {
logger.debug("begin findValueInRatingMap(" + value + ", treeMap)");
Map.Entry<Integer, Rating> entry = treeMap.floorEntry(value);
logger.debug("entry.getValue() = " + entry.getValue().getMultiplier());
return entry.getValue().getMultiplier();
}
......@@ -104,7 +95,6 @@ public class Utility<T> {
20. 190 + 20 = 210 21 5
*/
logger.debug("begin getMultiplier(" + segment + ", " + ratingLevel + ")");
switch (segment) {
case 1:
return 1;
......
package com.gitlab.johnjvester.randomizer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Test;
import java.util.List;
......@@ -11,47 +9,33 @@ import static org.junit.Assert.fail;
public class RandomGeneratorDataTest {
final static Logger logger = LogManager.getLogger(RandomGeneratorDataTest.class);
RandomGeneratorData randomGeneratorData = new RandomGeneratorData();
@Test
public void firstNameLastNameTest() throws RandomGeneratorException {
logger.debug("begin firstNameLastNameTest()");
List<String> sixtySevenFullNamesFirstLast = randomGeneratorData.randomizeFullNames(NameFormat.FIRST_LAST, 67);
assertEquals(67, sixtySevenFullNamesFirstLast.size());
assert(sixtySevenFullNamesFirstLast.get(0).indexOf(" ") > 0);
assert(sixtySevenFullNamesFirstLast.get(66).indexOf(" ") > 0);
logger.debug("end firstNameLastNameTest()");
}
@Test
public void lastNameFirstNameTest() throws RandomGeneratorException {
logger.debug("begin lastNameFirstNameTest()");
List<String> sixtySevenFullNamesFirstLast = randomGeneratorData.randomizeFullNames(NameFormat.LAST_FIRST, 1973);
assertEquals(1973, sixtySevenFullNamesFirstLast.size());
assert(sixtySevenFullNamesFirstLast.get(0).indexOf(", ") > 0);
assert(sixtySevenFullNamesFirstLast.get(1972).indexOf(", ") > 0);
logger.debug("end lastNameFirstNameTest()");
}
@Test
public void nameFormatException() {
logger.debug("begin nameFormatException()");
try {
randomGeneratorData.randomizeFullNames(null, 1);
fail();
} catch (RandomGeneratorException e) {
assert(e.getErrorCode() == ErrorCode.UNKNOWN_NAME_FORMAT);
}
logger.debug("end nameFormatException()");
}
}
package com.gitlab.johnjvester.randomizer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class RandomGeneratorExceptionTest {
final static Logger logger = LogManager.getLogger(RandomGeneratorExceptionTest.class);
@Test
public void testRandomGeneratorExceptionEmptyConstructor() {
logger.debug("starting testRandomGeneratorExceptionEmptyConstructor()");
RandomGeneratorException randomGeneratorException = new RandomGeneratorException();
assertEquals(ErrorCode.UNKNOWN_ERROR, randomGeneratorException.getErrorCode());
logger.debug("end testRandomGeneratorExceptionEmptyConstructor()");
}
@Test
public void testRandomGeneratorExceptionCodeOnly() {
logger.debug("starting testRandomGeneratorExceptionCodeOnly()");
RandomGeneratorException randomGeneratorException = new RandomGeneratorException(ErrorCode.UNKNOWN_NAME_FORMAT);
assertEquals(ErrorCode.UNKNOWN_NAME_FORMAT, randomGeneratorException.getErrorCode());
logger.debug("end testRandomGeneratorExceptionCodeOnly()");
}
@Test
public void testRandomGeneratorExceptionCodeAndMessage() {
logger.debug("starting testRandomGeneratorExceptionCodeAndMessage()");
String message = "Some message";
RandomGeneratorException randomGeneratorException = new RandomGeneratorException(ErrorCode.UNKNOWN_NAME_FORMAT, message);
assertEquals(ErrorCode.UNKNOWN_NAME_FORMAT, randomGeneratorException.getErrorCode());
assertEquals(message, randomGeneratorException.getMessage());
logger.debug("end testRandomGeneratorExceptionCodeAndMessage()");
}
}
package com.gitlab.johnjvester.randomizer;
import lombok.Data;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Test;
import java.util.ArrayList;
......@@ -14,7 +12,6 @@ import static org.junit.Assert.assertTrue;
public class RandomGeneratorTest {
final static Logger logger = LogManager.getLogger(RandomGeneratorTest.class);
private static final Integer ONE = 1;
private static final Integer TWO = 2;
private static final Integer THREE = 3;
......@@ -24,278 +21,160 @@ public class RandomGeneratorTest {
@Test
public void standardTest() {
logger.debug("begin standardTest()");
List<TestObject> testList = new ArrayList<TestObject>();
generateTestData(testList, 25, false);
for (TestObject testObject : testList) {
logger.debug("testObject.getValue() = " + testObject.getValue());
}
RandomGenerator randomGenerator = new RandomGenerator();
List<TestObject> resultList = randomGenerator.randomize(testList);
for (TestObject resultObject : resultList) {
logger.debug("resultObject.getValue() = " + resultObject.getValue());
}
assertNotSame("Objects should be in a different order", testList, resultList);
logger.debug("end standardTest()");
}
@Test
public void standardTestWithRatingType() {
logger.debug("begin standardTestWithRatingType()");
List<TestObject> testList = new ArrayList<TestObject>();
generateTestData(testList, 25, true);
for (TestObject testObject : testList) {
logger.debug("testObject.getValue() = " + testObject.getValue());
}
RandomGenerator randomGenerator = new RandomGenerator();
List<TestObject> resultList = randomGenerator.randomize(testList, true);