Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ dependencies {
implementation 'org.apache.commons:commons-csv:1.9.0'
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.13.0'
implementation 'com.google.code.gson:gson:2.8.8'
testImplementation 'junit:junit:[4.13.2,)'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
testImplementation 'org.mockito:mockito-all:1.10.19'
}

Expand All @@ -52,12 +53,13 @@ shadowJar {
}

test {
useJUnitPlatform()
finalizedBy jacocoTestReport
}
jacocoTestReport {
dependsOn test
reports {
xml.enabled true
xml.required = true
}
}

Expand Down Expand Up @@ -103,7 +105,7 @@ if (isForSigning && isForOssrhPublishing) {
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
url = 'https://www.apache.org/licenses/LICENSE-2.0.txt'
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/test/java/com/sonalake/utah/ExamplesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.sonalake.utah.config.Config;
import com.sonalake.utah.config.ConfigLoader;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.io.InputStreamReader;
Expand Down Expand Up @@ -346,7 +346,7 @@ public void testGetHeaderNames() throws IOException {

String[] expectedHeaderNames = {"remoteIp", "uptime", "activeV4", "receivedV4", "accepted_V4", "activeV6",
"receivedV6", "accepted_V6", "activeV4", "receivedV4", "accepted_V4", "activeV6", "receivedV6", "accepted_V6"};
Assert.assertEquals(Arrays.asList(expectedHeaderNames), config.getHeaderNames());
Assertions.assertEquals(Arrays.asList(expectedHeaderNames), config.getHeaderNames());
}

/**
Expand Down Expand Up @@ -378,7 +378,7 @@ private void testFileProcessing(String configResource, String fileResource, List
}
}

Assert.assertEquals(expectedResults, observedValues);
Assertions.assertEquals(expectedResults, observedValues);
}

}
35 changes: 18 additions & 17 deletions src/test/java/com/sonalake/utah/cli/CliConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import com.sonalake.utah.Parser;
import com.sonalake.utah.config.Config;
import org.apache.commons.io.FileUtils;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.FileNotFoundException;
Expand All @@ -14,19 +15,16 @@
import java.util.Map;
import java.util.UUID;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

public class CliConfigTest {

@Test
public void testLoadWorks() throws IOException, IOException {
public void testLoadWorks() throws IOException {

File testFile = getConfigFileForCiscoBGPSummary();

CLIConfig cliConfig = new CLIConfig(CLIConfig.Format.CSV, testFile.getAbsolutePath());
Config config = cliConfig.loadConfig();
assertNotNull("No config created", config);
Assertions.assertNotNull(config, "No config created");
}

private File getConfigFileForCiscoBGPSummary() throws IOException {
Expand All @@ -37,10 +35,12 @@ private File getConfigFileForCiscoBGPSummary() throws IOException {
}


@Test(expected = FileNotFoundException.class)
public void testLoadHandlesErrors() throws IOException {
CLIConfig cliConfig = new CLIConfig(CLIConfig.Format.CSV, UUID.randomUUID().toString());
cliConfig.loadConfig();
@Test
public void testLoadHandlesErrors() {
Assertions.assertThrows(FileNotFoundException.class, () -> {
CLIConfig cliConfig = new CLIConfig(CLIConfig.Format.CSV, UUID.randomUUID().toString());
cliConfig.loadConfig();
});
}

@Test
Expand All @@ -58,12 +58,13 @@ public void testParser() throws IOException {
Parser parser = cli.parseInput(cliConfig, reader);

Map<String, String> result = parser.next();
assertNotNull("Expected results from parser", result);
assertEquals("routerId record field incorrect", "192.0.2.70", result.get("routerId"));
assertEquals("localAS record field incorrect", "65550", result.get("localAS"));
assertEquals("remoteIp record field incorrect", "192.0.2.77", result.get("remoteIp"));
assertEquals("remoteAS record field incorrect", "65551", result.get("remoteAS"));
assertEquals("uptime record field incorrect", "5w4d", result.get("uptime"));
assertEquals("status record field incorrect", "1", result.get("status"));
Assertions.assertAll(
() -> Assertions.assertNotNull(result, "Expected results from parser"),
() -> Assertions.assertEquals( "192.0.2.70", result.get("routerId"), "routerId record field incorrect"),
() -> Assertions.assertEquals( "65550", result.get("localAS"), "localAS record field incorrect"),
() -> Assertions.assertEquals( "192.0.2.77", result.get("remoteIp"), "remoteIp record field incorrect"),
() -> Assertions.assertEquals( "65551", result.get("remoteAS"), "remoteAS record field incorrect"),
() -> Assertions.assertEquals( "5w4d", result.get("uptime"), "uptime record field incorrect"),
() -> Assertions.assertEquals( "1", result.get("status"), "status record field incorrect"));
}
}
61 changes: 26 additions & 35 deletions src/test/java/com/sonalake/utah/cli/CommandLineInterfaceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.*;

import static org.junit.Assert.*;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.*;

Expand All @@ -28,12 +28,8 @@ public void testLogHelp() {

@Test
public void testRequiredArgsMissing() {
try {
generateCommandline("");
fail("This should have failed, no args were supplied");
} catch (ParseException expected) {
assertTrue(expected.getMessage().contains("No configuration file supplied"));
}
Throwable exception = Assertions.assertThrows(ParseException.class, () -> generateCommandline(""));
Assertions.assertTrue(exception.getMessage().contains("No configuration file supplied"));
}

/*
Expand All @@ -43,9 +39,9 @@ public void testRequiredArgsMissing() {
public void testArgCsv() throws ParseException {
CLIConfig config = generateCommandline(" -o csv -f config.xml");

assertEquals(CLIConfig.Format.CSV, config.getFormat());
assertEquals("config.xml", config.getPathToConfig());

Assertions.assertAll(
() -> Assertions.assertEquals(CLIConfig.Format.CSV, config.getFormat()),
() -> Assertions.assertEquals("config.xml", config.getPathToConfig()));
}

/*
Expand All @@ -55,9 +51,9 @@ public void testArgCsv() throws ParseException {
public void testArgJson() throws ParseException {
CLIConfig config = generateCommandline(" -o json -f config.xml");

assertEquals(CLIConfig.Format.JSON, config.getFormat());
assertEquals("config.xml", config.getPathToConfig());

Assertions.assertAll(
() -> Assertions.assertEquals(CLIConfig.Format.JSON, config.getFormat()),
() -> Assertions.assertEquals("config.xml", config.getPathToConfig()));
}

/*
Expand All @@ -67,22 +63,18 @@ public void testArgJson() throws ParseException {
public void testArgDefaultToCSV() throws ParseException {
CLIConfig config = generateCommandline(" -f config.xml");

assertEquals(CLIConfig.Format.CSV, config.getFormat());
assertEquals("config.xml", config.getPathToConfig());

Assertions.assertAll(
() -> Assertions.assertEquals(CLIConfig.Format.CSV, config.getFormat()),
() -> Assertions.assertEquals("config.xml", config.getPathToConfig()));
}

/*
* Tests to assure invalid formats don't work
*/
@Test
public void testArgBadFormat() {
try {
generateCommandline(" -o monkey -f config.xml");
fail("This should have failed, monkey is not a valid format");
} catch (ParseException expected) {
assertTrue(expected.getMessage().contains("monkey is not a valid format"));
}
Throwable exception = Assertions.assertThrows(ParseException.class, () -> generateCommandline(" -o monkey -f config.xml"));
Assertions.assertTrue(exception.getMessage().contains("monkey is not a valid format"));
}

/*
Expand All @@ -96,7 +88,7 @@ public void testPrintOutputJSON() {
map.put("name", "23");
map.put("gender", "23");
mapList.add(map);
assertTrue(CommandLineInterface.mapListToJSON(mapList).contains("\"age\": \"23\","));
Assertions.assertTrue(CommandLineInterface.mapListToJSON(mapList).contains("\"age\": \"23\","));
}

/*
Expand Down Expand Up @@ -124,7 +116,7 @@ public void testJsonFormat() {
String expected = new GsonBuilder().setPrettyPrinting().create().toJson(parsedRecords);
String observed =helper.getOutputAsString();

assertEquals(expected, observed);
Assertions.assertEquals(expected, observed);
}

private class OutputHelper {
Expand Down Expand Up @@ -180,9 +172,8 @@ public void testHelpOutputForNoArgs() {
new StringReader("some input file \n with another line"),
helper.target);

assertTrue(String.format("Wrong message: %s", helper.getOutputAsString()),
helper.getOutputAsString().contains("usage: "));

Assertions.assertTrue(helper.getOutputAsString().contains("usage: "),
String.format("Wrong message: %s", helper.getOutputAsString()));
}

/**
Expand All @@ -196,8 +187,8 @@ public void testBranchingForCsv() throws ParseException, IOException {

OutputHelper helper = processMockOutput(format);

assertTrue(String.format("Wrong message:\n%s", helper.getOutputAsString()),
helper.getOutputAsString().contains("xyz"));
Assertions.assertTrue(helper.getOutputAsString().contains("xyz"),
String.format("Wrong message:\n%s", helper.getOutputAsString()));
}

@Test
Expand All @@ -206,8 +197,8 @@ public void testBranchingForWrongFormat() throws ParseException, IOException {

OutputHelper helper = processMockOutput(format);

assertTrue(String.format("Wrong message:\n%s", helper.getOutputAsString()),
helper.getOutputAsString().contains("xyz"));
Assertions.assertTrue(helper.getOutputAsString().contains("xyz"),
String.format("Wrong message:\n%s", helper.getOutputAsString()));
}

/**
Expand All @@ -221,8 +212,8 @@ public void testBranchingForJson() throws ParseException, IOException {

OutputHelper helper = processMockOutput(format);

assertTrue(String.format("Wrong message:\n %s", helper.getOutputAsString()),
helper.getOutputAsString().contains("\"a\": \"xyz\""));
Assertions.assertTrue(helper.getOutputAsString().contains("\"a\": \"xyz\""),
String.format("Wrong message:\n %s", helper.getOutputAsString()));
}

/**
Expand Down Expand Up @@ -258,7 +249,7 @@ private void assertCsvContent(String content, List<List<String>> expected) throw
}
observed.add(lineValues);
}
assertEquals(expected, observed);
Assertions.assertEquals(expected, observed);
}

private CLIConfig generateCommandline(String cli) throws ParseException {
Expand Down
Loading