Skip to content

Commit

Permalink
Merge pull request #1761 from schemacrawler/tweaks
Browse files Browse the repository at this point in the history
Fix tests
  • Loading branch information
sualeh authored Nov 24, 2024
2 parents 9d5c534 + 6647540 commit 132debf
Show file tree
Hide file tree
Showing 16 changed files with 84 additions and 127 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/database-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ jobs:
docker pull cassandra:4.1.0
dbproject="dbtest"
elif [ "${{ matrix.database }}" == "cockroachdb" ]; then
docker pull cockroachdb/cockroach:v19.2.12
docker pull cockroachdb/cockroach:v20.2.9
dbproject="dbtest"
elif [ "${{ matrix.database }}" == "firebird" ]; then
docker pull jacobalberty/firebird:v4.0.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,12 @@
import static schemacrawler.test.utility.FileHasContent.classpathResource;
import static schemacrawler.test.utility.FileHasContent.outputOf;
import static schemacrawler.test.utility.TestUtility.javaVersion;

import java.util.Arrays;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Stream;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import schemacrawler.schemacrawler.InfoLevel;
import schemacrawler.test.utility.AssertNoSystemErrOutput;
import schemacrawler.test.utility.AssertNoSystemOutOutput;
Expand All @@ -66,7 +63,7 @@ public static void clean() throws Exception {
}

private static Stream<InfoLevel> infoLevels() {
return Arrays.stream(InfoLevel.values()).filter(infoLevel -> infoLevel != InfoLevel.unknown);
return EnumSet.complementOf(EnumSet.of(InfoLevel.unknown)).stream();
}

private static String referenceFile(
Expand All @@ -87,7 +84,7 @@ private static String referenceFile(
}

private static Stream<SchemaTextDetailType> schemaTextDetailTypes() {
return Arrays.stream(SchemaTextDetailType.values());
return EnumSet.allOf(SchemaTextDetailType.class).stream();
}

@Test
Expand Down Expand Up @@ -142,5 +139,5 @@ public void spinThroughMain(final DatabaseConnectionInfo connectionInfo) throws
}))));
}

protected abstract Stream<OutputFormat> outputFormats();
protected abstract Stream<? extends OutputFormat> outputFormats();
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,12 @@
import static schemacrawler.test.utility.ExecutableTestUtility.hasSameContentAndTypeAs;
import static schemacrawler.test.utility.FileHasContent.classpathResource;
import static schemacrawler.test.utility.FileHasContent.outputOf;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Stream;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import schemacrawler.schemacrawler.InfoLevel;
import schemacrawler.test.utility.AssertNoSystemOutOutput;
import schemacrawler.test.utility.DatabaseConnectionInfo;
Expand Down Expand Up @@ -94,7 +91,7 @@ protected Stream<String> commands() {
return Arrays.asList("schema", "list").stream();
}

protected abstract Stream<OutputFormat> outputFormats();
protected abstract Stream<? extends OutputFormat> outputFormats();

private String referenceFile(final String command, final OutputFormat outputFormat) {
final String referenceFile =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,14 @@

package schemacrawler.test;

import java.util.Arrays;
import java.util.EnumSet;
import java.util.stream.Stream;

import schemacrawler.tools.command.text.schema.options.TextOutputFormat;
import schemacrawler.tools.options.OutputFormat;

public class SpinThroughCommandLineTest extends AbstractSpinThroughCommandLineTest {

@Override
public Stream<OutputFormat> outputFormats() {
return Arrays.stream(new OutputFormat[] {TextOutputFormat.text, TextOutputFormat.html});
public Stream<TextOutputFormat> outputFormats() {
return EnumSet.of(TextOutputFormat.text, TextOutputFormat.html).stream();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,19 @@
package schemacrawler.test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertAll;
import static schemacrawler.test.utility.CommandlineTestUtility.commandlineExecution;
import static schemacrawler.test.utility.ExecutableTestUtility.hasSameContentAndTypeAs;
import static schemacrawler.test.utility.FileHasContent.classpathResource;
import static schemacrawler.test.utility.FileHasContent.outputOf;

import java.util.Arrays;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Stream;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import schemacrawler.schemacrawler.InfoLevel;
import schemacrawler.test.utility.AssertNoSystemErrOutput;
import schemacrawler.test.utility.AssertNoSystemOutOutput;
Expand All @@ -65,16 +64,17 @@ public static void clean() throws Exception {
TestUtility.clean(SPIN_THROUGH_OPERATIONS_OUTPUT);
}

private static Stream<InfoLevel> infoLevels() {
return Arrays.stream(InfoLevel.values()).filter(infoLevel -> infoLevel != InfoLevel.unknown);
}

private static Stream<OperationType> operations() {
return Arrays.stream(OperationType.values());
}

private static Stream<TextOutputFormat> outputFormats() {
return Arrays.stream(new TextOutputFormat[] {TextOutputFormat.text, TextOutputFormat.html});
protected static Stream<Arguments> spinThroughArguments() {
return EnumSet.allOf(OperationType.class).stream()
.flatMap(
operation ->
EnumSet.complementOf(EnumSet.of(InfoLevel.unknown)).stream()
.flatMap(
infoLevel ->
EnumSet.of(TextOutputFormat.text, TextOutputFormat.html).stream()
.map(
outputFormat ->
Arguments.of(operation, infoLevel, outputFormat))));
}

private static String referenceFile(
Expand All @@ -90,51 +90,34 @@ private static String referenceFile(
return referenceFile;
}

@Test
public void spinThroughMain(final DatabaseConnectionInfo connectionInfo) throws Exception {
assertAll(
infoLevels()
.flatMap(
infoLevel ->
outputFormats()
.flatMap(
outputFormat ->
operations()
.map(
operation ->
() -> {

// Special case where no output is generated
if (infoLevel == InfoLevel.minimum
&& operation == OperationType.dump) {
return;
}

final String referenceFile =
referenceFile(operation, infoLevel, outputFormat);

final String command = operation.name();

final Map<String, String> argsMap = new HashMap<>();
argsMap.put("--sequences", ".*");
argsMap.put("--synonyms", ".*");
argsMap.put("--routines", ".*");
argsMap.put("--no-info", Boolean.FALSE.toString());
argsMap.put("--info-level", infoLevel.name());

assertThat(
outputOf(
commandlineExecution(
connectionInfo,
command,
argsMap,
true,
outputFormat)),
hasSameContentAndTypeAs(
classpathResource(
SPIN_THROUGH_OPERATIONS_OUTPUT
+ referenceFile),
outputFormat));
}))));
@DisplayName("Spin through operations for output")
@ParameterizedTest()
@MethodSource("spinThroughArguments")
public void spinThroughMain(
final OperationType operation,
final InfoLevel infoLevel,
final TextOutputFormat outputFormat,
final DatabaseConnectionInfo connectionInfo)
throws Exception {

// Special case where no output is generated
if (infoLevel == InfoLevel.minimum && operation == OperationType.dump) {
return;
}

final String command = operation.name();

final Map<String, String> argsMap = new HashMap<>();
argsMap.put("--sequences", ".*");
argsMap.put("--synonyms", ".*");
argsMap.put("--routines", ".*");
argsMap.put("--no-info", Boolean.FALSE.toString());
argsMap.put("--info-level", infoLevel.name());

final String referenceFile =
SPIN_THROUGH_OPERATIONS_OUTPUT + referenceFile(operation, infoLevel, outputFormat);
assertThat(
outputOf(commandlineExecution(connectionInfo, command, argsMap, true, outputFormat)),
hasSameContentAndTypeAs(classpathResource(referenceFile), outputFormat));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,14 @@

package schemacrawler.test;

import java.util.Arrays;
import java.util.EnumSet;
import java.util.stream.Stream;

import schemacrawler.tools.command.text.schema.options.TextOutputFormat;
import schemacrawler.tools.options.OutputFormat;

public class TitleTest extends AbstractTitleTest {

@Override
public Stream<OutputFormat> outputFormats() {
return Arrays.stream(new OutputFormat[] {TextOutputFormat.text, TextOutputFormat.html});
public Stream<TextOutputFormat> outputFormats() {
return EnumSet.of(TextOutputFormat.text, TextOutputFormat.html).stream();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,15 @@

package schemacrawler.test.schemacrawler.integration.test;

import java.util.Arrays;
import java.util.EnumSet;
import java.util.stream.Stream;

import schemacrawler.test.AbstractTitleTest;
import schemacrawler.tools.command.text.diagram.options.DiagramOutputFormat;
import schemacrawler.tools.options.OutputFormat;

public class GraphTitleTest extends AbstractTitleTest {

@Override
public Stream<OutputFormat> outputFormats() {
return Arrays.stream(new OutputFormat[] {DiagramOutputFormat.scdot, DiagramOutputFormat.htmlx});
public Stream<DiagramOutputFormat> outputFormats() {
return EnumSet.of(DiagramOutputFormat.scdot, DiagramOutputFormat.htmlx).stream();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,15 @@

package schemacrawler.test.schemacrawler.integration.test;

import java.util.Arrays;
import java.util.EnumSet;
import java.util.stream.Stream;

import schemacrawler.test.AbstractSpinThroughCommandLineTest;
import schemacrawler.tools.command.text.diagram.options.DiagramOutputFormat;
import schemacrawler.tools.options.OutputFormat;

public class SpinThroughGraphCommandLineTest extends AbstractSpinThroughCommandLineTest {

@Override
public Stream<OutputFormat> outputFormats() {
return Arrays.stream(new OutputFormat[] {DiagramOutputFormat.scdot, DiagramOutputFormat.htmlx});
public Stream<DiagramOutputFormat> outputFormats() {
return EnumSet.of(DiagramOutputFormat.scdot, DiagramOutputFormat.htmlx).stream();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,15 @@

package schemacrawler.integration.test;

import java.util.Arrays;
import java.util.EnumSet;
import java.util.stream.Stream;

import schemacrawler.test.AbstractSchemaCrawlerOutputTest;
import schemacrawler.tools.command.text.diagram.options.DiagramOutputFormat;
import schemacrawler.tools.options.OutputFormat;

public class SchemaCrawlerDiagramOutputTest extends AbstractSchemaCrawlerOutputTest {

@Override
public Stream<OutputFormat> outputFormats() {
return Arrays.stream(new OutputFormat[] {DiagramOutputFormat.scdot});
public Stream<DiagramOutputFormat> outputFormats() {
return EnumSet.of(DiagramOutputFormat.scdot).stream();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,15 @@

package schemacrawler.integration.test;

import java.util.Arrays;
import java.util.EnumSet;
import java.util.stream.Stream;

import schemacrawler.test.AbstractSpinThroughExecutableTest;
import schemacrawler.tools.command.text.diagram.options.DiagramOutputFormat;
import schemacrawler.tools.options.OutputFormat;

public class SpinThroughDiagramExecutableTest extends AbstractSpinThroughExecutableTest {

@Override
public Stream<OutputFormat> outputFormats() {
return Arrays.stream(new OutputFormat[] {DiagramOutputFormat.scdot, DiagramOutputFormat.htmlx});
public Stream<DiagramOutputFormat> outputFormats() {
return EnumSet.of(DiagramOutputFormat.scdot, DiagramOutputFormat.htmlx).stream();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ public void schemaRetrievalOptions() throws IOException {
schemaRetrievalOptions = TestUtility.newSchemaRetrievalOptions();
}

protected abstract Stream<OutputFormat> outputFormats();
protected abstract Stream<? extends OutputFormat> outputFormats();

private void compareHideConstraintNamesOutput(
final DatabaseConnectionSource dataSource,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import static schemacrawler.test.utility.FileHasContent.classpathResource;
import static schemacrawler.test.utility.FileHasContent.outputOf;
import static schemacrawler.test.utility.TestUtility.javaVersion;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.stream.Stream;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -69,7 +69,7 @@ public static void clean() throws Exception {
}

private static Stream<InfoLevel> infoLevels() {
return Arrays.stream(InfoLevel.values()).filter(infoLevel -> infoLevel != InfoLevel.unknown);
return EnumSet.complementOf(EnumSet.of(InfoLevel.unknown)).stream();
}

private static String referenceFile(
Expand Down Expand Up @@ -114,7 +114,7 @@ public void spinThroughExecutable(
})));
}

protected abstract Stream<OutputFormat> outputFormats();
protected abstract Stream<? extends OutputFormat> outputFormats();

private void spinThroughExecutable(
final DatabaseConnectionSource dataSource,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,14 @@

package schemacrawler.test;

import java.util.Arrays;
import java.util.EnumSet;
import java.util.stream.Stream;

import schemacrawler.tools.command.text.schema.options.TextOutputFormat;
import schemacrawler.tools.options.OutputFormat;

public class SchemaCrawlerOutputTest extends AbstractSchemaCrawlerOutputTest {

@Override
public Stream<OutputFormat> outputFormats() {
return Arrays.stream(new OutputFormat[] {TextOutputFormat.text, TextOutputFormat.html});
public Stream<TextOutputFormat> outputFormats() {
return EnumSet.of(TextOutputFormat.text, TextOutputFormat.html).stream();
}
}
Loading

0 comments on commit 132debf

Please sign in to comment.