use of org.junit.jupiter.api.TestFactory in project connect-utils by jcustenborder.
the class BaseDocumentationTest method sources.
@TestFactory
public Stream<DynamicTest> sources() {
final File parentDirectory = new File(outputDirectory, "sources");
final String templateName = "rst/source.rst.ftl";
return this.pluginTemplate.getSourceConnectors().stream().map(connectorTemplate -> connectorRstTest(connectorTemplate, templateName, parentDirectory));
}
use of org.junit.jupiter.api.TestFactory in project connect-utils by jcustenborder.
the class BaseDocumentationTest method schema.
@TestFactory
public Stream<DynamicTest> schema() throws IOException {
final File parentDirectory = new File(outputDirectory, "schemas");
if (!parentDirectory.exists()) {
parentDirectory.mkdirs();
}
List<Schema> schemas = schemas();
if (null != schemas && !schemas.isEmpty()) {
final File schemaRstPath = new File(outputDirectory, "schemas.rst");
final String schemaRst = "=======\n" + "Schemas\n" + "=======\n" + "\n" + ".. toctree::\n" + " :maxdepth: 0\n" + " :caption: Schemas:\n" + " :glob:\n" + "\n" + " schemas/*";
Files.write(schemaRst, schemaRstPath, Charsets.UTF_8);
}
final String templateName = "rst/schema.rst.ftl";
return this.schemas().stream().filter(schema -> !Strings.isNullOrEmpty(schema.name())).map(schema -> dynamicTest(String.format("%s.%s", schema.type(), schema.name()), () -> {
StringBuilder filenameBuilder = new StringBuilder().append(schema.type().toString().toLowerCase());
if (!Strings.isNullOrEmpty(schema.name())) {
filenameBuilder.append('.').append(schema.name());
}
filenameBuilder.append(".rst");
File outputFile = new File(parentDirectory, filenameBuilder.toString());
Template template = configuration.getTemplate(templateName);
log.info("Writing {}", outputFile);
try (Writer writer = Files.newWriter(outputFile, Charsets.UTF_8)) {
Map<String, Object> variables = ImmutableMap.of("input", TemplateSchema.of(schema), "helper", new RstTemplateHelper());
template.process(variables, writer);
}
}));
}
use of org.junit.jupiter.api.TestFactory in project connect-utils by jcustenborder.
the class JsonNodeTest method parseJsonNode.
@TestFactory
public Stream<DynamicTest> parseJsonNode() {
List<TestCase> tests = new ArrayList<>();
of(tests, Boolean.class, Schema.BOOLEAN_SCHEMA, Boolean.TRUE);
of(tests, Boolean.class, Schema.BOOLEAN_SCHEMA, Boolean.FALSE);
List<Float> floats = new ArrayList<>();
floats.add(Float.MAX_VALUE);
floats.add(Float.MIN_VALUE);
for (int i = 0; i < 30; i++) {
floats.add(this.random.nextFloat());
}
of(tests, Float.class, Schema.FLOAT32_SCHEMA, floats);
List<Double> doubles = new ArrayList<>();
doubles.add(Double.MAX_VALUE);
doubles.add(Double.MIN_VALUE);
for (int i = 0; i < 30; i++) {
doubles.add(this.random.nextDouble());
}
of(tests, Double.class, Schema.FLOAT64_SCHEMA, doubles);
List<Byte> bytes = new ArrayList<>();
bytes.add(Byte.MAX_VALUE);
bytes.add(Byte.MIN_VALUE);
byte[] buffer = new byte[30];
this.random.nextBytes(buffer);
for (Byte b : buffer) {
bytes.add(b);
}
of(tests, Byte.class, Schema.INT8_SCHEMA, bytes);
List<Short> shorts = new ArrayList<>();
shorts.add(Short.MAX_VALUE);
shorts.add(Short.MIN_VALUE);
for (int i = 0; i < 30; i++) {
shorts.add((short) this.random.nextInt(Short.MAX_VALUE));
}
of(tests, Short.class, Schema.INT16_SCHEMA, shorts);
List<Integer> ints = new ArrayList<>();
ints.add(Integer.MAX_VALUE);
ints.add(Integer.MIN_VALUE);
for (int i = 0; i < 30; i++) {
ints.add(this.random.nextInt());
}
of(tests, Integer.class, Schema.INT32_SCHEMA, ints);
List<Long> longs = new ArrayList<>();
longs.add(Long.MAX_VALUE);
longs.add(Long.MIN_VALUE);
for (int i = 0; i < 30; i++) {
longs.add(this.random.nextLong());
}
of(tests, Long.class, Schema.INT64_SCHEMA, longs);
// String
of(tests, String.class, Schema.STRING_SCHEMA, "");
of(tests, String.class, Schema.STRING_SCHEMA, "This is a string");
// Decimal
for (int SCALE = 3; SCALE < 30; SCALE++) {
of(tests, BigDecimal.class, Decimal.schema(SCALE), new BigDecimal("12345").setScale(SCALE));
of(tests, BigDecimal.class, Decimal.schema(SCALE), new BigDecimal("0").setScale(SCALE));
of(tests, BigDecimal.class, Decimal.schema(SCALE), new BigDecimal("-12345.001").setScale(SCALE));
of(tests, BigDecimal.class, Decimal.schema(SCALE), new BigDecimal("12345").setScale(SCALE).toString(), new BigDecimal("12345").setScale(SCALE));
of(tests, BigDecimal.class, Decimal.schema(SCALE), new BigDecimal("0").setScale(SCALE).toString(), new BigDecimal("0").setScale(SCALE));
of(tests, BigDecimal.class, Decimal.schema(SCALE), new BigDecimal("-12345.001").setScale(SCALE).toString(), new BigDecimal("-12345.001").setScale(SCALE));
}
// Timestamp
java.util.Date expectedDate = new java.util.Date(1494855736000L);
SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ss");
of(tests, java.util.Date.class, Timestamp.SCHEMA, expectedDate);
of(tests, java.util.Date.class, Timestamp.SCHEMA, inputFormat.format(expectedDate), expectedDate);
of(tests, java.util.Date.class, Timestamp.SCHEMA, expectedDate.getTime(), expectedDate);
// Date
expectedDate = new java.util.Date(994204800000L);
inputFormat = new SimpleDateFormat("yyyy-MM-dd");
inputFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
of(tests, java.util.Date.class, Date.SCHEMA, expectedDate);
of(tests, java.util.Date.class, Date.SCHEMA, inputFormat.format(expectedDate), expectedDate);
of(tests, java.util.Date.class, Date.SCHEMA, expectedDate.getTime(), expectedDate);
// Time
expectedDate = new java.util.Date(65336000L);
inputFormat = new SimpleDateFormat("HH:mm:ss");
of(tests, java.util.Date.class, Time.SCHEMA, new java.util.Date(65336000L));
of(tests, java.util.Date.class, Time.SCHEMA, inputFormat.format(expectedDate), expectedDate);
of(tests, java.util.Date.class, Time.SCHEMA, expectedDate.getTime(), expectedDate);
return tests.stream().map(testCase -> dynamicTest(testCase.toString(), () -> {
parseJsonNode(testCase);
}));
}
use of org.junit.jupiter.api.TestFactory in project connect-utils by jcustenborder.
the class StringParserTest method parseString.
@TestFactory
Stream<DynamicTest> parseString() {
List<TestCase> tests = new ArrayList<>();
of(tests, Schema.FLOAT64_SCHEMA, new Double(Double.MAX_VALUE).toString(), new Double(Double.MAX_VALUE));
of(tests, Schema.FLOAT64_SCHEMA, new Double(Double.MIN_VALUE).toString(), new Double(Double.MIN_VALUE));
of(tests, Schema.INT8_SCHEMA, new Byte(Byte.MAX_VALUE).toString(), new Byte(Byte.MAX_VALUE));
of(tests, Schema.INT8_SCHEMA, new Byte(Byte.MIN_VALUE).toString(), new Byte(Byte.MIN_VALUE));
of(tests, Schema.INT16_SCHEMA, new Short(Short.MAX_VALUE).toString(), new Short(Short.MAX_VALUE));
of(tests, Schema.INT16_SCHEMA, new Short(Short.MIN_VALUE).toString(), new Short(Short.MIN_VALUE));
of(tests, Schema.INT32_SCHEMA, new Integer(Integer.MAX_VALUE).toString(), new Integer(Integer.MAX_VALUE));
of(tests, Schema.INT32_SCHEMA, new Integer(Integer.MIN_VALUE).toString(), new Integer(Integer.MIN_VALUE));
of(tests, Schema.INT64_SCHEMA, new Long(Long.MAX_VALUE).toString(), new Long(Long.MAX_VALUE));
of(tests, Schema.INT64_SCHEMA, new Long(Long.MIN_VALUE).toString(), new Long(Long.MIN_VALUE));
of(tests, Schema.STRING_SCHEMA, "", "");
of(tests, Schema.STRING_SCHEMA, "mirror", "mirror");
for (int SCALE = 3; SCALE < 30; SCALE++) {
Schema schema = Decimal.schema(SCALE);
of(tests, schema, "12345", new BigDecimal("12345").setScale(SCALE));
of(tests, schema, "0", new BigDecimal("0").setScale(SCALE));
of(tests, schema, "-12345.001", new BigDecimal("-12345.001").setScale(SCALE));
}
return tests.stream().map(testCase -> dynamicTest(testCase.toString(), () -> {
final Object actual = parser.parseString(testCase.schema, testCase.input);
assertEquals(testCase.expected, actual);
}));
}
use of org.junit.jupiter.api.TestFactory in project connect-utils by jcustenborder.
the class StructSerializationModuleTest method roundtrip.
@TestFactory
public Stream<DynamicTest> roundtrip() {
Schema innerSchema = SchemaBuilder.struct().name("InnerSchema").optional().field("latitude", Schema.FLOAT32_SCHEMA).field("longitude", Schema.FLOAT32_SCHEMA).build();
Map<String, Struct> cityMap = ImmutableMap.of("Austin", new Struct(innerSchema).put("latitude", 30.2672F).put("longitude", 97.7431F), "San Francisco", new Struct(innerSchema).put("latitude", 37.7749F).put("longitude", 122.4194F));
List<Struct> cityList = ImmutableList.copyOf(cityMap.values());
List<Struct> testCases = Arrays.asList(new Struct(SchemaBuilder.struct().name("Testing").field("firstName", Schema.STRING_SCHEMA).build()).put("firstName", "Example"), new Struct(SchemaBuilder.struct().name("Nullable").field("firstName", Schema.OPTIONAL_STRING_SCHEMA).build()).put("firstName", null), new Struct(SchemaBuilder.struct().name("NestedOptionalStructWithValue").field("firstName", Schema.OPTIONAL_STRING_SCHEMA).field("inner", innerSchema).build()).put("inner", new Struct(innerSchema).put("latitude", 30.2672F).put("longitude", 97.7431F)), new Struct(SchemaBuilder.struct().name("NestedOptionalStructWithoutValue").field("firstName", Schema.OPTIONAL_STRING_SCHEMA).field("inner", innerSchema).build()).put("inner", null), new Struct(SchemaBuilder.struct().name("NestedMapStruct").field("firstName", Schema.OPTIONAL_STRING_SCHEMA).field("inner", SchemaBuilder.map(Schema.STRING_SCHEMA, innerSchema)).build()).put("inner", cityMap), new Struct(SchemaBuilder.struct().name("NestedArrayStruct").field("firstName", Schema.OPTIONAL_STRING_SCHEMA).field("inner", SchemaBuilder.array(innerSchema)).build()).put("inner", cityList));
return testCases.stream().map(expected -> dynamicTest(expected.schema().name(), () -> {
String input = ObjectMapperFactory.INSTANCE.writeValueAsString(expected);
log.trace(input);
Struct actual = ObjectMapperFactory.INSTANCE.readValue(input, Struct.class);
assertStruct(expected, actual);
}));
}
Aggregations