org.junit.jupiter.api.TestFactory Java Examples

The following examples show how to use org.junit.jupiter.api.TestFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestAllFiles.java    From jhdf with MIT License 6 votes vote down vote up
@TestFactory
Stream<DynamicNode> allHdf5TestFiles() throws IOException, URISyntaxException {

	// Auto discover the test files assuming they exist in under the directory
	// containing test_file.hdf5
	URL resource = this.getClass().getResource("/hdf5/");
	Path path = Paths.get(resource.toURI()).getParent();
	List<Path> files = Files.walk(path).filter(HDF5::matches).collect(Collectors.toList());

	// Check at least some files have been discovered
	assertThat("Less than 3 HDF5 test files discovered searched paths below: " + path.toAbsolutePath(),
			files.size(), is(greaterThan(2)));

	// Make a test for each file
	return files.stream().map(this::createTest);
}
 
Example #2
Source File: Neo4jConversionsIT.java    From sdn-rx with Apache License 2.0 6 votes vote down vote up
@TestFactory
@DisplayName("Objects")
Stream<DynamicNode> objects() {
	Map<String, Map<String, Object>> supportedTypes = new HashMap<>();
	supportedTypes.put("CypherTypes", CYPHER_TYPES);
	supportedTypes.put("AdditionalTypes", ADDITIONAL_TYPES);
	supportedTypes.put("SpatialTypes", SPATIAL_TYPES);

	return supportedTypes.entrySet().stream()
		.map(types -> {

			DynamicContainer reads = DynamicContainer.dynamicContainer("read", types.getValue().entrySet().stream()
				.map(a -> dynamicTest(a.getKey(),
					() -> Neo4jConversionsIT.assertRead(types.getKey(), a.getKey(), a.getValue()))));

			DynamicContainer writes = DynamicContainer.dynamicContainer("write", types.getValue().entrySet().stream()
				.map(a -> dynamicTest(a.getKey(),
					() -> Neo4jConversionsIT.assertWrite(types.getKey(), a.getKey(), a.getValue()))));

			return DynamicContainer.dynamicContainer(types.getKey(), Arrays.asList(reads, writes));
		});
}
 
Example #3
Source File: ScreenshotOnFailureMonitorTests.java    From vividus with Apache License 2.0 6 votes vote down vote up
@TestFactory
Stream<DynamicTest> shouldProcessStepWithAnnotation() throws NoSuchMethodException
{
    return Stream.of(getClass().getDeclaredMethod(WHEN_STEP_METHOD),
            TestSteps.class.getDeclaredMethod("innerWhenStep"))
            .flatMap(method ->
            {
                reset(bddRunContext);
                mockScenarioAndStoryMeta(EMPTY_META);
                return Stream.of(
                        dynamicTest("beforePerformingProcessesStepWithAnnotation",
                            () -> monitor.beforePerforming(I_DO_ACTION, false, method)),
                        dynamicTest("afterPerformingProcessesStepWithAnnotation",
                            () -> monitor.afterPerforming(I_DO_ACTION, false, method))
                        );
            });
}
 
Example #4
Source File: RecordBatchesTest.java    From mongo-kafka with Apache License 2.0 6 votes vote down vote up
@TestFactory
@DisplayName("test batching with different config params for max.batch.size")
Stream<DynamicTest> testBatchingWithDifferentConfigsForBatchSize() {

  return Stream.iterate(0, r -> r + 1)
      .limit(NUM_FAKE_RECORDS + 1)
      .map(
          batchSize ->
              dynamicTest(
                  "test batching for "
                      + NUM_FAKE_RECORDS
                      + " records with batchsize="
                      + batchSize,
                  () -> {
                    RecordBatches batches = new RecordBatches(batchSize, NUM_FAKE_RECORDS);
                    assertEquals(LIST_INITIAL_EMPTY, batches.getBufferedBatches());
                    List<SinkRecord> recordList =
                        createSinkRecordList("foo", 0, 0, NUM_FAKE_RECORDS);
                    recordList.forEach(batches::buffer);
                    List<List<SinkRecord>> batchedList =
                        partition(recordList, batchSize > 0 ? batchSize : recordList.size());
                    assertEquals(batchedList, batches.getBufferedBatches());
                  }));
}
 
Example #5
Source File: MetricsCollectorWrapperTest.java    From rabbitmq-mock with Apache License 2.0 6 votes vote down vote up
@TestFactory
List<DynamicTest> noop_implementation_never_throws() {
    MetricsCollectorWrapper metricsCollectorWrapper = new NoopMetricsCollectorWrapper();
    return Arrays.asList(
        dynamicTest("newConnection", () -> metricsCollectorWrapper.newConnection(null)),
        dynamicTest("closeConnection", () -> metricsCollectorWrapper.closeConnection(null)),
        dynamicTest("newChannel", () -> metricsCollectorWrapper.newChannel(null)),
        dynamicTest("closeChannel", () -> metricsCollectorWrapper.closeChannel(null)),
        dynamicTest("basicPublish", () -> metricsCollectorWrapper.basicPublish(null)),
        dynamicTest("consumedMessage", () -> metricsCollectorWrapper.consumedMessage(null, 0L, true)),
        dynamicTest("consumedMessage (consumerTag)", () -> metricsCollectorWrapper.consumedMessage(null, 0L, null)),
        dynamicTest("basicAck", () -> metricsCollectorWrapper.basicAck(null, 0L, true)),
        dynamicTest("basicNack", () -> metricsCollectorWrapper.basicNack(null, 0L)),
        dynamicTest("basicReject", () -> metricsCollectorWrapper.basicReject(null, 0L)),
        dynamicTest("basicConsume", () -> metricsCollectorWrapper.basicConsume(null, null, true)),
        dynamicTest("basicCancel", () -> metricsCollectorWrapper.basicCancel(null, null))
    );
}
 
Example #6
Source File: HttpsAndAuthTest.java    From herd-mdl with Apache License 2.0 6 votes vote down vote up
@TestFactory
public Stream<DynamicTest> testHerdShellCommandWithWrongCredential() {
    String assertionPass = "status code is 200";
    String assertionFailure = "status code is 401";

    return getTestCases(HERD_AUTH_TESTCASES)
            .stream().map(command -> DynamicTest.dynamicTest(COMPONENT + command.getName(), () -> {
                String result = ShellHelper.executeShellTestCase(command, envVars);
                if (!IS_SSLAUTH_ENABLED) {
                    LogVerification("Verify herd shell command response pass without/with invalid credential provided when enableAuth is false");
                    assertThat(result, containsString(assertionPass));
                }
                else {
                    LogVerification("Verify herd shell command response failure without/with invalid credential provided when enableAuth is true");
                    assertThat(result, containsString(assertionFailure));
                }
            }));
}
 
Example #7
Source File: HttpsAndAuthTest.java    From herd-mdl with Apache License 2.0 6 votes vote down vote up
@TestFactory
public Stream<DynamicTest> testHerdHttpIsNotAllowedWhenHttpsEnabled() {
    return getTestCases(HTTP_TESTCASES)
            .stream().map(command -> DynamicTest.dynamicTest(COMPONENT + command.getName(), () -> {
                if (!IS_SSLAUTH_ENABLED) {
                    LogVerification("Verify herd/shepherd call pass with http url when enableSslAuth is false");
                    String result = ShellHelper.executeShellTestCase(command, envVars);
                    assertThat(command.getAssertVal(), notNullValue());
                    assertThat(result, containsString(command.getAssertVal()));
                }
                else {
                    LogVerification("Verify herd/shepherd call failed with http url when enableSslAuth is true");
                    assertThrows(RuntimeException.class, () -> {
                        ShellHelper.executeShellTestCase(command, envVars);
                    });
                }
            }));
}
 
Example #8
Source File: HttpsAndAuthTest.java    From herd-mdl with Apache License 2.0 6 votes vote down vote up
@TestFactory
public Stream<DynamicTest> testHerdHttpsIsNotAllowedWhenHttpsIsDisabled() {
    return getTestCases(HTTPS_TESTCASES)
            .stream().map(command -> DynamicTest.dynamicTest(COMPONENT + command.getName(), () -> {
                if (IS_SSLAUTH_ENABLED) {
                    LogVerification("Verify herd call pass with https url when enableSslAuth is true");
                    String result = ShellHelper.executeShellTestCase(command, envVars);
                    assertThat(command.getAssertVal(), notNullValue());
                    assertThat(result, containsString(command.getAssertVal()));
                }
                else {
                    LogVerification("Verify herd call failed with https url when enableSslAuth is false");
                    assertThrows(RuntimeException.class, () -> {
                        ShellHelper.executeShellTestCase(command, envVars);
                    });
                }
            }));
}
 
Example #9
Source File: OperandSerializationTestCase.java    From yare with MIT License 6 votes vote down vote up
@TestFactory
Stream<DynamicTest> operandSerializationTestFactory() {
    return Stream.of(
            DynamicTest.dynamicTest(
                    "Should serialize value operand",
                    () -> shouldSerializeOperand(createValueOperandModel(), getSerializedValueOperand())
            ),
            DynamicTest.dynamicTest(
                    "Should serialize values operand",
                    () -> shouldSerializeOperand(createValuesOperandModel(), getSerializedValuesOperand())
            ),
            DynamicTest.dynamicTest(
                    "Should serialize function operand",
                    () -> shouldSerializeOperand(createFunctionOperandModel(), getSerializedFunctionOperand())
            ),
            DynamicTest.dynamicTest(
                    "Should serialize operator operand",
                    () -> shouldSerializeOperand(createOperatorOperandModel(), getSerializedOperatorOperand())
            )
    );
}
 
Example #10
Source File: OperandSerializationTestCase.java    From yare with MIT License 6 votes vote down vote up
@TestFactory
Stream<DynamicTest> operandDeserializationTestFactory() {
    return Stream.of(
            DynamicTest.dynamicTest(
                    "Should deserialize value operand",
                    () -> shouldDeserializeOperand(createValueOperandModel(), getSerializedValueOperand())
            ),
            DynamicTest.dynamicTest(
                    "Should deserialize values operand",
                    () -> shouldDeserializeOperand(createValuesOperandModel(), getSerializedValuesOperand())
            ),
            DynamicTest.dynamicTest(
                    "Should deserialize function operand",
                    () -> shouldDeserializeOperand(createFunctionOperandModel(), getSerializedFunctionOperand())
            ),
            DynamicTest.dynamicTest(
                    "Should deserialize operator operand",
                    () -> shouldDeserializeOperand(createOperatorOperandModel(), getSerializedOperatorOperand())
            )
    );
}
 
Example #11
Source File: ParameterSerializationTestCase.java    From yare with MIT License 6 votes vote down vote up
@TestFactory
Stream<DynamicTest> parameterSerializationTestFactory() {
    return Stream.of(
            DynamicTest.dynamicTest(
                    "Should serialize value parameter",
                    () -> shouldSerializeParameter(createValueParameterModel(), getSerializedValueParameter())
            ),
            DynamicTest.dynamicTest(
                    "Should serialize values parameter",
                    () -> shouldSerializeParameter(createValuesParameterModel(), getSerializedValuesParameter())
            ),
            DynamicTest.dynamicTest(
                    "Should serialize function parameter",
                    () -> shouldSerializeParameter(createFunctionParameterModel(), getSerializedFunctionParameter())
            )
    );
}
 
Example #12
Source File: ParameterSerializationTestCase.java    From yare with MIT License 6 votes vote down vote up
@TestFactory
Stream<DynamicTest> parameterDeserializeTestFactory() {
    return Stream.of(
            DynamicTest.dynamicTest(
                    "Should deserialize value parameter",
                    () -> shouldDeserializeParameter(createValueParameterModel(), getSerializedValueParameter())
            ),
            DynamicTest.dynamicTest(
                    "Should deserialize values parameter",
                    () -> shouldDeserializeParameter(createValuesParameterModel(), getSerializedValuesParameter())
            ),
            DynamicTest.dynamicTest(
                    "Should deserialize function parameter",
                    () -> shouldDeserializeParameter(createFunctionParameterModel(), getSerializedFunctionParameter())
            )
    );
}
 
Example #13
Source File: ValueSerializationTestCase.java    From yare with MIT License 6 votes vote down vote up
@TestFactory
Stream<DynamicTest> valueSerializationTestFactory() {
    return Stream.of(
            DynamicTest.dynamicTest(
                    "Should serialize build-in type value",
                    () -> shouldSerializeValue(createBuildInTypeValueModel(), getSerializedBuildInTypeValue())
            ),
            DynamicTest.dynamicTest(
                    "Should serialize string type value",
                    () -> shouldSerializeValue(createStringTypeValueModel(), getSerializedStringTypeValue())
            ),
            DynamicTest.dynamicTest(
                    "Should serialize custom type value",
                    () -> shouldSerializeValue(createCustomTypeValueModel(), getSerializedCustomTypeValue())
            )
    );
}
 
Example #14
Source File: ValueSerializationTestCase.java    From yare with MIT License 6 votes vote down vote up
@TestFactory
Stream<DynamicTest> valueDeserializationTestFactory() {
    return Stream.of(
            DynamicTest.dynamicTest(
                    "Should deserialize build-in type value",
                    () -> shouldDeserializeValue(createBuildInTypeValueModel(), getSerializedBuildInTypeValue())
            ),
            DynamicTest.dynamicTest(
                    "Should deserialize string type value",
                    () -> shouldDeserializeValue(createStringTypeValueModel(), getSerializedStringTypeValue())
            ),
            DynamicTest.dynamicTest(
                    "Should deserialize custom type value",
                    () -> shouldDeserializeValue(createCustomTypeValueModel(), getSerializedCustomTypeValue())
            )
    );
}
 
Example #15
Source File: CompressedChunkedDatasetTest.java    From jhdf with MIT License 6 votes vote down vote up
@TestFactory
Collection<DynamicNode> compressedChunkedDatasetReadTests() {
	// List of all the datasetPaths
	return Arrays.asList(
			dynamicContainer(HDF5_TEST_EARLIEST_FILE_NAME, Arrays.asList(
					dynamicTest("float32", createTest(earliestHdfFile,"/float/float32")),
					dynamicTest("float64", createTest(earliestHdfFile,"/float/float64")),
					dynamicTest("int8", createTest(earliestHdfFile,"/int/int8")),
					dynamicTest("int16", createTest(earliestHdfFile,"/int/int16")),
					dynamicTest("int32", createTest(earliestHdfFile,"/int/int32")))),

			dynamicContainer(HDF5_TEST_LATEST_FILE_NAME, Arrays.asList(
					dynamicTest("float32", createTest(latestHdfFile, "/float/float32")),
					dynamicTest("float64", createTest(latestHdfFile,"/float/float64")),
					dynamicTest("int8", createTest(latestHdfFile,"/int/int8")),
					dynamicTest("int16", createTest(latestHdfFile,"/int/int16")),
					dynamicTest("int32", createTest(latestHdfFile,"/int/int32")))));
}
 
Example #16
Source File: ChunkedDatasetTest.java    From jhdf with MIT License 6 votes vote down vote up
@TestFactory
Collection<DynamicNode> chunkedDatasetReadTests() {
	// List of all the datasetPaths
	return Arrays.asList(
			dynamicContainer(HDF5_TEST_EARLIEST_FILE_NAME, Arrays.asList(
					dynamicTest("float16", createTest(earliestHdfFile, "/float/float16")),
					dynamicTest("float32", createTest(earliestHdfFile, "/float/float32")),
					dynamicTest("float64", createTest(earliestHdfFile, "/float/float64")),
					dynamicTest("int8", createTest(earliestHdfFile, "/int/int8")),
					dynamicTest("int16", createTest(earliestHdfFile, "/int/int16")),
					dynamicTest("int32", createTest(earliestHdfFile, "/int/int32")))),

			dynamicContainer(HDF5_TEST_EARLIEST_FILE_NAME, Arrays.asList(
					dynamicTest("float16", createTest(latestHdfFile, "/float/float16")),
					dynamicTest("float32", createTest(latestHdfFile, "/float/float32")),
					dynamicTest("float64", createTest(latestHdfFile, "/float/float64")),
					dynamicTest("int8", createTest(latestHdfFile, "/int/int8")),
					dynamicTest("int16", createTest(latestHdfFile, "/int/int16")),
					dynamicTest("int32", createTest(latestHdfFile, "/int/int32"))))
	);
}
 
Example #17
Source File: FloatSpecialValuesTest.java    From jhdf with MIT License 6 votes vote down vote up
@TestFactory
Collection<DynamicNode> specialFloatValuesTests() {
    // List of all the datasetPaths
    return Arrays.asList(
            dynamicContainer("earliest", Arrays.asList(
                    dynamicTest("float16",
                            testFloat(earliestHdfFile, "float16")),
                    dynamicTest("float32",
                            testFloat(earliestHdfFile, "float32")),
                    dynamicTest("float64",
                            testDouble(earliestHdfFile, "float64")))),

            dynamicContainer("latest", Arrays.asList(
                    dynamicTest("float16",
                            testFloat(latestHdfFile, "float16")),
                    dynamicTest("float32",
                            testFloat(latestHdfFile, "float32")),
                    dynamicTest("float64",
                            testDouble(latestHdfFile, "float64")))));
}
 
Example #18
Source File: ExpressionSerializationTestCase.java    From yare with MIT License 6 votes vote down vote up
@TestFactory
Stream<DynamicTest> expressionSerializationTestFactory() {
    return Stream.of(
            DynamicTest.dynamicTest(
                    "Should serialize value expression",
                    () -> shouldSerializeExpression(createValueExpressionModel(), getSerializedValueExpression())
            ),
            DynamicTest.dynamicTest(
                    "Should serialize values expression",
                    () -> shouldSerializeExpression(createValuesExpressionModel(), getSerializedValuesExpression())
            ),
            DynamicTest.dynamicTest(
                    "Should serialize function expression",
                    () -> shouldSerializeExpression(createFunctionExpressionModel(), getSerializedFunctionExpression())
            )
    );
}
 
Example #19
Source File: StringDatasetTest.java    From jhdf with MIT License 6 votes vote down vote up
@TestFactory
Collection<DynamicNode> stringDataset1DTests() {
	// List of all the datasetPaths
	return Arrays.asList(
			dynamicContainer("earliest", Arrays.asList(
					dynamicTest("fixed ASCII",
							createTest(earliestHdfFile, "/fixed_length_ascii")),
					dynamicTest("fixed ASCII 1 char",
							createTest(earliestHdfFile, "/fixed_length_ascii_1_char")),
					dynamicTest("variable ASCII",
							createTest(earliestHdfFile, "/variable_length_ascii")),
					dynamicTest("variable UTF8",
							createTest(earliestHdfFile, "/variable_length_utf8")))),

			dynamicContainer("latest", Arrays.asList(
					dynamicTest("fixed ASCII",
							createTest(latestHdfFile, "/fixed_length_ascii")),
					dynamicTest("fixed ASCII 1 char",
							createTest(latestHdfFile, "/fixed_length_ascii_1_char")),
					dynamicTest("variable ASCII",
							createTest(latestHdfFile, "/variable_length_ascii")),
					dynamicTest("variable UTF8",
							createTest(latestHdfFile, "/variable_length_utf8")))));
}
 
Example #20
Source File: BrowserLogCleanningListenerTests.java    From vividus with Apache License 2.0 6 votes vote down vote up
@TestFactory
Stream<DynamicTest> testCleanBeforeNavigate()
{
    WebDriver driver = mock(WebDriver.class, withSettings().extraInterfaces(HasCapabilities.class));
    Consumer<Runnable> test = methodUnderTest ->
    {
        Options options = mock(Options.class);
        when(driver.manage()).thenReturn(options);
        Logs logs = mock(Logs.class);
        when(options.logs()).thenReturn(logs);
        when(logs.get(LogType.BROWSER)).thenReturn(mock(LogEntries.class));
        methodUnderTest.run();
    };
    return Stream.of(
            dynamicTest("beforeNavigateBack", () -> test.accept(() -> listener.beforeNavigateBack(driver))),
            dynamicTest("beforeNavigateForward", () -> test.accept(() -> listener.beforeNavigateForward(driver))),
            dynamicTest("beforeNavigateRefresh", () -> test.accept(() -> listener.beforeNavigateRefresh(driver))),
            dynamicTest("beforeNavigateTo", () -> test.accept(() -> listener.beforeNavigateTo("url", driver))));
}
 
Example #21
Source File: JUnitPlatformDynamicIntegrationTest.java    From BlockHound with Apache License 2.0 5 votes vote down vote up
@TestFactory
List<DynamicTest> tests() {
    return Arrays.asList(
            dynamicTest("simple dynamic test", () -> {
                assertThatBlockingCall().hasMessageContaining("Blocking call!");
            })
    );
}
 
Example #22
Source File: AbstractNodeTest.java    From gyro with Apache License 2.0 5 votes vote down vote up
@TestFactory
public List<DynamicTest> constructorNull() {
    List<DynamicTest> tests = new ArrayList<>();

    for (Constructor<?> constructor : nodeClass.getConstructors()) {
        Class<?>[] paramTypes = constructor.getParameterTypes();

        for (int i = 0, length = paramTypes.length; i < length; ++i) {
            StringBuilder name = new StringBuilder("(");
            Object[] params = new Object[length];

            for (int j = 0; j < length; ++j) {
                Class<?> paramType = paramTypes[j];

                name.append(paramType.getName());

                if (i == j) {
                    name.append("=null");

                } else {
                    params[j] = getTestValue(paramType);
                }

                name.append(", ");
            }

            name.setLength(name.length() - 2);
            name.append(")");

            tests.add(DynamicTest.dynamicTest(
                name.toString(),
                () -> assertThatExceptionOfType(InvocationTargetException.class)
                    .isThrownBy(() -> constructor.newInstance(params))
                    .withCauseInstanceOf(NullPointerException.class)
            ));
        }
    }

    return tests;
}
 
Example #23
Source File: CustomerCrudSeparatedTestFactoryIT.java    From webtau with Apache License 2.0 5 votes vote down vote up
@TestFactory
public Stream<DynamicTest> crud() {
    AtomicInteger id = new AtomicInteger();

    return Stream.of(
            dynamicTest("create", () -> {
                id.set(http.post("/customers", customerPayload, ((header, body) -> {
                    return body.get("id").get();
                })));
            }),

            dynamicTest("read", () -> {
                http.get("/customers/" + id, ((header, body) -> {
                    body.should(equal(customerPayload));
                }));
            }),

            dynamicTest("update", () -> {
                http.put("/customers/" + id, changedCustomerPayload, ((header, body) -> {
                    body.should(equal(changedCustomerPayload));
                }));

                http.get("/customers/" + id, ((header, body) -> {
                    body.should(equal(changedCustomerPayload));
                }));
            }),

            dynamicTest("delete", () -> {
                http.delete("/customers/" + id, ((header, body) -> {
                    header.statusCode().should(equal(204));
                }));

                http.get("/customers/" + id, ((header, body) -> {
                    header.statusCode().should(equal(404));
                }));
            })
    );
}
 
Example #24
Source File: NodeAcceptTest.java    From gyro with Apache License 2.0 5 votes vote down vote up
@TestFactory
List<DynamicTest> accept() {
    return Arrays.asList(
        create(DirectiveNode.class, NodeVisitor::visitDirective),
        create(PairNode.class, NodeVisitor::visitPair),
        create(FileNode.class, NodeVisitor::visitFile),
        create(KeyBlockNode.class, NodeVisitor::visitKeyBlock),
        create(ResourceNode.class, NodeVisitor::visitResource),
        create(InterpolatedStringNode.class, NodeVisitor::visitInterpolatedString),
        create(ListNode.class, NodeVisitor::visitList),
        create(MapNode.class, NodeVisitor::visitMap),
        create(ReferenceNode.class, NodeVisitor::visitReference),
        create(ValueNode.class, NodeVisitor::visitValue)
    );
}
 
Example #25
Source File: SinkFieldConverterTest.java    From mongo-kafka with Apache License 2.0 5 votes vote down vote up
@TestFactory
@DisplayName("tests for int16 field conversions")
List<DynamicTest> testInt16FieldConverter() {

  SinkFieldConverter converter = new Int16FieldConverter();

  List<DynamicTest> tests = new ArrayList<>();
  asList(Short.MIN_VALUE, (short) 0, Short.MAX_VALUE)
      .forEach(
          el ->
              tests.add(
                  dynamicTest(
                      "conversion with " + converter.getClass().getSimpleName() + " for " + el,
                      () ->
                          assertEquals(
                              (short) el, ((BsonInt32) converter.toBson(el)).getValue()))));

  tests.add(
      dynamicTest(
          "optional type conversions",
          () -> {
            Schema valueOptionalDefault =
                SchemaBuilder.int16().optional().defaultValue((short) 0);
            assertAll(
                "checks",
                () ->
                    assertThrows(
                        DataException.class, () -> converter.toBson(null, Schema.INT16_SCHEMA)),
                () ->
                    assertEquals(
                        new BsonNull(), converter.toBson(null, Schema.OPTIONAL_INT16_SCHEMA)),
                () ->
                    assertEquals(
                        ((short) valueOptionalDefault.defaultValue()),
                        ((BsonInt32) converter.toBson(null, valueOptionalDefault)).getValue()));
          }));

  return tests;
}
 
Example #26
Source File: RuleSerializationTestCase.java    From yare with MIT License 5 votes vote down vote up
@TestFactory
Stream<DynamicTest> ruleSerializationTestFactory() {
    return Stream.of(
            DynamicTest.dynamicTest(
                    "Should serialize rule",
                    () -> shouldSerializeRule(createRuleModel(), getSerializedRule())
            ),
            DynamicTest.dynamicTest(
                    "Should serialize empty rule",
                    () -> shouldSerializeRule(createEmptyRuleModel(), getSerializedEmptyRule())
            )
    );
}
 
Example #27
Source File: RuleSerializationTestCase.java    From yare with MIT License 5 votes vote down vote up
@TestFactory
Stream<DynamicTest> ruleDeserializationTestFactory() {
    return Stream.of(
            DynamicTest.dynamicTest(
                    "Should deserialize rule",
                    () -> shouldDeserializeRule(createRuleModel(), getSerializedRule())
            ),
            DynamicTest.dynamicTest(
                    "Should deserialize empty rule",
                    () -> shouldDeserializeRule(createEmptyRuleModel(), getSerializedEmptyRule())
            )
    );
}
 
Example #28
Source File: SinkFieldConverterTest.java    From mongo-kafka with Apache License 2.0 5 votes vote down vote up
@TestFactory
@DisplayName("tests for int8 field conversions")
List<DynamicTest> testInt8FieldConverter() {

  SinkFieldConverter converter = new Int8FieldConverter();

  List<DynamicTest> tests = new ArrayList<>();
  asList(Byte.MIN_VALUE, (byte) 0, Byte.MAX_VALUE)
      .forEach(
          el ->
              tests.add(
                  dynamicTest(
                      "conversion with " + converter.getClass().getSimpleName() + " for " + el,
                      () ->
                          assertEquals(
                              (int) el, ((BsonInt32) converter.toBson(el)).getValue()))));

  tests.add(
      dynamicTest(
          "optional type conversions",
          () -> {
            Schema valueOptionalDefault = SchemaBuilder.int8().optional().defaultValue((byte) 0);
            assertAll(
                "checks",
                () ->
                    assertThrows(
                        DataException.class, () -> converter.toBson(null, Schema.INT8_SCHEMA)),
                () ->
                    assertEquals(
                        new BsonNull(), converter.toBson(null, Schema.OPTIONAL_INT8_SCHEMA)),
                () ->
                    assertEquals(
                        ((Byte) valueOptionalDefault.defaultValue()).intValue(),
                        ((BsonInt32) converter.toBson(null, valueOptionalDefault)).getValue()));
          }));

  return tests;
}
 
Example #29
Source File: SinkFieldConverterTest.java    From mongo-kafka with Apache License 2.0 5 votes vote down vote up
@TestFactory
@DisplayName("tests for boolean field conversions")
List<DynamicTest> testBooleanFieldConverter() {

  SinkFieldConverter converter = new BooleanFieldConverter();

  List<DynamicTest> tests = new ArrayList<>();
  asList(true, false)
      .forEach(
          el ->
              tests.add(
                  dynamicTest(
                      "conversion with " + converter.getClass().getSimpleName() + " for " + el,
                      () -> assertEquals(el, ((BsonBoolean) converter.toBson(el)).getValue()))));

  tests.add(
      dynamicTest(
          "optional type conversion checks",
          () -> {
            Schema valueOptionalDefault = SchemaBuilder.bool().optional().defaultValue(true);
            assertAll(
                "",
                () ->
                    assertThrows(
                        DataException.class, () -> converter.toBson(null, Schema.BOOLEAN_SCHEMA)),
                () ->
                    assertEquals(
                        new BsonNull(), converter.toBson(null, Schema.OPTIONAL_BOOLEAN_SCHEMA)),
                () ->
                    assertEquals(
                        valueOptionalDefault.defaultValue(),
                        converter.toBson(null, valueOptionalDefault).asBoolean().getValue()));
          }));

  return tests;
}
 
Example #30
Source File: AttributeSerializationTestCase.java    From yare with MIT License 5 votes vote down vote up
@TestFactory
Stream<DynamicTest> attributeDeserializationTestFactory() {
    return Stream.of(
            DynamicTest.dynamicTest(
                    "Should deserialize build-in type attribute",
                    () -> shouldDeserializeAttribute(createBuildInTypeAttributeModel(), getSerializedBuildInTypeAttribute())
            ),
            DynamicTest.dynamicTest(
                    "Should deserialize custom type attribute",
                    () -> shouldDeserializeAttribute(createCustomTypeAttributeModel(), getSerializedCustomTypeAttribute())
            )
    );
}