下面列出了怎么用org.junit.jupiter.params.provider.ValueSource的API类实例代码及写法,或者点击链接到github查看源代码。
@DisplayName("test getGenericArrayAsBoxedPrimitive(...) helper method")
@ParameterizedTest(name = "IoBuffer class - {0}")
@ValueSource(classes = { FastByteBuffer.class, ByteBuffer.class })
public void testgetGenericArrayAsBoxedPrimitiveHelper(final Class<? extends IoBuffer> bufferClass) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
assertNotNull(bufferClass, "bufferClass being not null");
assertNotNull(bufferClass.getConstructor(int.class), "Constructor(Integer) present");
final IoBuffer buffer = bufferClass.getConstructor(int.class).newInstance(2 * BUFFER_SIZE); // a bit larger buffer since we test more cases at once
putGenericTestArrays(buffer);
buffer.reset();
// test conversion to double array
assertThrows(IllegalArgumentException.class, () -> BinarySerialiser.getGenericArrayAsBoxedPrimitive(buffer, DataType.OTHER));
assertArrayEquals(new Boolean[] { true, false, true }, BinarySerialiser.getGenericArrayAsBoxedPrimitive(buffer, DataType.BOOL));
assertArrayEquals(new Byte[] { (byte) 1.0, (byte) 0.0, (byte) 2.0 }, BinarySerialiser.getGenericArrayAsBoxedPrimitive(buffer, DataType.BYTE));
assertArrayEquals(new Character[] { (char) 1.0, (char) 0.0, (char) 2.0 }, BinarySerialiser.getGenericArrayAsBoxedPrimitive(buffer, DataType.CHAR));
assertArrayEquals(new Short[] { (short) 1.0, (short) 0.0, (short) 2.0 }, BinarySerialiser.getGenericArrayAsBoxedPrimitive(buffer, DataType.SHORT));
assertArrayEquals(new Integer[] { (int) 1.0, (int) 0.0, (int) 2.0 }, BinarySerialiser.getGenericArrayAsBoxedPrimitive(buffer, DataType.INT));
assertArrayEquals(new Long[] { (long) 1.0, (long) 0.0, (long) 2.0 }, BinarySerialiser.getGenericArrayAsBoxedPrimitive(buffer, DataType.LONG));
assertArrayEquals(new Float[] { 1.0f, 0.0f, 2.0f }, BinarySerialiser.getGenericArrayAsBoxedPrimitive(buffer, DataType.FLOAT));
assertArrayEquals(new Double[] { 1.0, 0.0, 2.0 }, BinarySerialiser.getGenericArrayAsBoxedPrimitive(buffer, DataType.DOUBLE));
assertArrayEquals(new String[] { "1.0", "0.0", "2.0" }, BinarySerialiser.getGenericArrayAsBoxedPrimitive(buffer, DataType.STRING));
}
@ParameterizedTest
@ValueSource(strings = {"public", "custom"})
void getUnusedIndexesOnDatabaseWithThem(final String schemaName) {
executeTestOnDatabase(schemaName,
dbp -> dbp.withReferences().withData().withDuplicatedIndex(),
ctx -> {
final List<UnusedIndex> unusedIndexes = indexesMaintenance.getUnusedIndexes(ctx);
assertNotNull(unusedIndexes);
assertThat(unusedIndexes, hasSize(6));
final Set<String> names = unusedIndexes.stream().map(UnusedIndex::getIndexName).collect(toSet());
assertThat(names, containsInAnyOrder(
ctx.enrichWithSchema("i_clients_last_first"),
ctx.enrichWithSchema("i_clients_last_name"),
ctx.enrichWithSchema("i_accounts_account_number"),
ctx.enrichWithSchema("i_accounts_number_balance_not_deleted"),
ctx.enrichWithSchema("i_accounts_account_number_not_deleted"),
ctx.enrichWithSchema("i_accounts_id_account_number_not_deleted")));
});
}
@ParameterizedTest
@ValueSource(strings = {"/exec/single-inject-state.sw.json", "/exec/single-inject-state.sw.yml"})
public void testSingleInjectWorkflow(String workflowLocation) throws Exception {
RuleFlowProcess process = (RuleFlowProcess) getWorkflowParser(workflowLocation).parseWorkFlow(classpathResourceReader(workflowLocation));
assertEquals("function", process.getId());
assertEquals("test-wf", process.getName());
assertEquals("1.0", process.getVersion());
assertEquals("org.kie.kogito.serverless", process.getPackageName());
assertEquals(RuleFlowProcess.PUBLIC_VISIBILITY, process.getVisibility());
assertEquals(3, process.getNodes().length);
Node node = process.getNodes()[0];
assertTrue(node instanceof StartNode);
node = process.getNodes()[2];
assertTrue(node instanceof ActionNode);
node = process.getNodes()[1];
assertTrue(node instanceof EndNode);
ActionNode actionNode = (ActionNode) process.getNodes()[2];
assertEquals("SimpleInject", actionNode.getName());
}
@ParameterizedTest
@ValueSource(ints = { 1, 2, 3, 4, 5, 31, 32, 33, 34, 1023, 1024, 1025, 4095, 4096, 4097, (2 << 16) - 100, 2 << 16,
(2 << 16) + 100 })
public void
identityDSTTests(final int nSamples) {
FloatDST_1D fft = new FloatDST_1D(nSamples);
float[] testSignal1Ref = generateDelta(2 * nSamples);
float[] testSignal1 = generateDelta(2 * nSamples);
float[] testSignal2Ref = generateRamp(2 * nSamples, nSamples);
float[] testSignal2 = generateRamp(2 * nSamples, nSamples);
// basic identity tests
fft.forward(testSignal1, true);
fft.inverse(testSignal1, true);
assertArrayEquals(testSignal1Ref, testSignal1, nSamples * FFT_NUMERIC_LIMITS, "delta identity");
fft.forward(testSignal2, true);
fft.inverse(testSignal2, true);
assertArrayEquals(testSignal2Ref, testSignal2, nSamples * FFT_NUMERIC_LIMITS, "ramp identity");
}
@ParameterizedTest
@ValueSource(strings = {"/exec/parallel-state.sw.json", "/exec/parallel-state.sw.yml"})
public void testParallelWorkflow(String workflowLocation) throws Exception {
RuleFlowProcess process = (RuleFlowProcess) getWorkflowParser(workflowLocation).parseWorkFlow(classpathResourceReader(workflowLocation));
assertEquals("parallelworkflow", process.getId());
assertEquals("parallel-wf", process.getName());
assertEquals("1.0", process.getVersion());
assertEquals("org.kie.kogito.serverless", process.getPackageName());
assertEquals(RuleFlowProcess.PUBLIC_VISIBILITY, process.getVisibility());
assertEquals(6, process.getNodes().length);
Node node = process.getNodes()[0];
assertTrue(node instanceof StartNode);
node = process.getNodes()[1];
assertTrue(node instanceof EndNode);
node = process.getNodes()[2];
assertTrue(node instanceof Split);
node = process.getNodes()[3];
assertTrue(node instanceof Join);
node = process.getNodes()[4];
assertTrue(node instanceof SubProcessNode);
node = process.getNodes()[5];
assertTrue(node instanceof SubProcessNode);
}
@ParameterizedTest
@ValueSource(strings = {"public", "custom"})
void getTablesWithBloatOnDatabaseWithThem(final String schemaName) {
executeTestOnDatabase(schemaName,
dbp -> dbp.withReferences().withData().withStatistics(),
ctx -> {
waitForStatisticsCollector();
assertTrue(existsStatisticsForTable(ctx, "accounts"));
final List<TableWithBloat> tables = tablesMaintenance.getTablesWithBloat(ctx);
assertNotNull(tables);
assertThat(tables, hasSize(2));
final TableWithBloat table = tables.get(0);
assertEquals(ctx.enrichWithSchema("accounts"), table.getTableName());
assertEquals(114688L, table.getTableSizeInBytes());
assertEquals(0L, table.getBloatSizeInBytes());
assertEquals(0, table.getBloatPercentage());
});
}
@ParameterizedTest
@ValueSource(strings = {"serverless/single-operation-many-functions.sw.json", "serverless/single-operation-many-functions.sw.yml"})
public void testMultipleFunctionsCallWorkflow(String processLocation) throws Exception {
Application app = generateCodeProcessesOnly(processLocation);
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("function");
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
m.fromMap(parameters);
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}
@DisplayName("test getDoubleArray([boolean[], byte[], ..., String[]) helper method")
@ParameterizedTest(name = "IoBuffer class - {0}")
@ValueSource(classes = { FastByteBuffer.class, ByteBuffer.class })
public void testGetDoubleArrayHelper(final Class<? extends IoBuffer> bufferClass) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
assertNotNull(bufferClass, "bufferClass being not null");
assertNotNull(bufferClass.getConstructor(int.class), "Constructor(Integer) present");
final IoBuffer buffer = bufferClass.getConstructor(int.class).newInstance(2 * BUFFER_SIZE); // a bit larger buffer since we test more cases at once
putGenericTestArrays(buffer);
buffer.reset();
// test conversion to double array
assertThrows(IllegalArgumentException.class, () -> BinarySerialiser.getDoubleArray(buffer, DataType.OTHER));
assertArrayEquals(new double[] { 1.0, 0.0, 1.0 }, BinarySerialiser.getDoubleArray(buffer, DataType.BOOL_ARRAY));
assertArrayEquals(new double[] { 1.0, 0.0, 2.0 }, BinarySerialiser.getDoubleArray(buffer, DataType.BYTE_ARRAY));
assertArrayEquals(new double[] { 1.0, 0.0, 2.0 }, BinarySerialiser.getDoubleArray(buffer, DataType.CHAR_ARRAY));
assertArrayEquals(new double[] { 1.0, 0.0, 2.0 }, BinarySerialiser.getDoubleArray(buffer, DataType.SHORT_ARRAY));
assertArrayEquals(new double[] { 1.0, 0.0, 2.0 }, BinarySerialiser.getDoubleArray(buffer, DataType.INT_ARRAY));
assertArrayEquals(new double[] { 1.0, 0.0, 2.0 }, BinarySerialiser.getDoubleArray(buffer, DataType.LONG_ARRAY));
assertArrayEquals(new double[] { 1.0, 0.0, 2.0 }, BinarySerialiser.getDoubleArray(buffer, DataType.FLOAT_ARRAY));
assertArrayEquals(new double[] { 1.0, 0.0, 2.0 }, BinarySerialiser.getDoubleArray(buffer, DataType.DOUBLE_ARRAY));
assertArrayEquals(new double[] { 1.0, 0.0, 2.0 }, BinarySerialiser.getDoubleArray(buffer, DataType.STRING_ARRAY));
}
@ParameterizedTest
@ValueSource(strings = { "jms", "paho", "paho-ws", "sjms" })
public void testJmsComponent(String component) {
String message = "Hello Camel Quarkus " + component;
RestAssured.given()
.contentType(ContentType.TEXT)
.body(message)
.post("/messaging/" + component + "/{queueName}", component + "-test-queue")
.then()
.statusCode(201);
RestAssured.given()
.contentType(ContentType.TEXT)
.get("/messaging/" + component + "/{queueName}", component + "-test-queue")
.then()
.statusCode(200)
.body(is(message));
}
@ParameterizedTest
@ValueSource(strings = {"public", "custom"})
void getUnusedIndexesOnDatabaseWithThem(final String schemaName) {
executeTestOnDatabase(schemaName,
dbp -> dbp.withReferences().withData().withDuplicatedIndex(),
ctx -> {
final List<UnusedIndex> unusedIndexes = databaseHealth.getUnusedIndexes(ctx);
assertNotNull(unusedIndexes);
assertThat(unusedIndexes, hasSize(6));
final Set<String> names = unusedIndexes.stream().map(UnusedIndex::getIndexName).collect(toSet());
assertThat(names, containsInAnyOrder(
ctx.enrichWithSchema("i_clients_last_first"),
ctx.enrichWithSchema("i_clients_last_name"),
ctx.enrichWithSchema("i_accounts_account_number"),
ctx.enrichWithSchema("i_accounts_number_balance_not_deleted"),
ctx.enrichWithSchema("i_accounts_account_number_not_deleted"),
ctx.enrichWithSchema("i_accounts_id_account_number_not_deleted")));
});
}
@ParameterizedTest
@ValueSource(strings = {"serverless/multiple-operations.sw.json", "serverless/multiple-operations.sw.yml"})
public void testMultipleOperationsWorkflow(String processLocation) throws Exception {
Application app = generateCodeProcessesOnly(processLocation);
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("function");
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
m.fromMap(parameters);
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}
@ParameterizedTest
@ValueSource(strings = {"none", "gzip", "snappy", "zstd"})
final void nullKeyValueAndTimestamp(final String compression) {
properties.put(GcsSinkConfig.FILE_COMPRESSION_TYPE_CONFIG, compression);
properties.put(GcsSinkConfig.FORMAT_OUTPUT_FIELDS_CONFIG, "key,value,timestamp,offset");
final GcsSinkTask task = new GcsSinkTask(properties, storage);
final List<SinkRecord> records = Arrays.asList(
createNullRecord("topic0", 0, 10),
createNullRecord("topic0", 0, 11),
createNullRecord("topic0", 0, 12)
);
task.put(records);
task.flush(null);
final CompressionType compressionType = CompressionType.forName(compression);
assertIterableEquals(
Lists.newArrayList("topic0-0-10" + compressionType.extension()),
testBucketAccessor.getBlobNames());
assertIterableEquals(
Lists.newArrayList(",,,10", ",,,11", ",,,12"),
readRawLinesFromBlob("topic0-0-10" + compressionType.extension(), compression));
}
@ParameterizedTest
@ValueSource(strings = {
"randomInt(3)",
"randomInt(-3)",
"randomInt(+3)",
"randomInt(1.1, 1)",
"randomInt(0, 1.1)",
"randomInt(0, 1, 2)",
"randomInt(1aef)",
"randomInt(-)",
"randomInt()",
"randomInt(, 1)",
"randomInt(1, )"
})
void testDoesNotMatch(String expression)
{
assertFalse(processor.execute(expression).isPresent());
}
@ParameterizedTest
@ValueSource(ints = { 1, 2, 3, 4, 5, 1023, 1024, 1025, 4095, 4096, 4097, (2 << 16) - 100, 2 << 16,
(2 << 16) + 100 })
public void
identityComplexlFFTTests(final int nSamples) {
DoubleFFT_1D fft = new DoubleFFT_1D(nSamples);
double[] testSignal1Ref = generateDelta(2 * nSamples);
double[] testSignal1 = generateDelta(2 * nSamples);
double[] testSignal2Ref = generateRamp(2 * nSamples, nSamples);
double[] testSignal2 = generateRamp(2 * nSamples, nSamples);
// basic identity tests
fft.complexForward(testSignal1);
fft.complexInverse(testSignal1, true);
assertArrayEquals(testSignal1Ref, testSignal1, nSamples * FFT_NUMERIC_LIMITS, "delta identity");
fft.complexForward(testSignal2);
fft.complexInverse(testSignal2, true);
assertArrayEquals(testSignal2Ref, testSignal2, nSamples * FFT_NUMERIC_LIMITS, "ramp identity");
}
@ParameterizedTest
@ValueSource(ints = { 1, 2, 3, 4, 5, 31, 32, 33, 34, 1023, 1024, 1025, 4095, 4096, 4097, (2 << 16) - 100, 2 << 16,
(2 << 16) + 100 })
public void
identityDHTTests(final int nSamples) {
FloatDHT_1D fft = new FloatDHT_1D(nSamples);
float[] testSignal1Ref = generateDelta(2 * nSamples);
float[] testSignal1 = generateDelta(2 * nSamples);
float[] testSignal2Ref = generateRamp(2 * nSamples, nSamples);
float[] testSignal2 = generateRamp(2 * nSamples, nSamples);
// basic identity tests
fft.forward(testSignal1);
fft.inverse(testSignal1, true);
assertArrayEquals(testSignal1Ref, testSignal1, nSamples * FFT_NUMERIC_LIMITS, "delta identity");
fft.forward(testSignal2);
fft.inverse(testSignal2, true);
assertArrayEquals(testSignal2Ref, testSignal2, nSamples * FFT_NUMERIC_LIMITS, "ramp identity");
}
@ParameterizedTest
@ValueSource(ints = { 1, 2, 3, 4, 5, 31, 32, 33, 34, 1023, 1024, 1025, 4095, 4096, 4097, (2 << 16) - 100, 2 << 16,
(2 << 16) + 100 })
public void
identityDCTTests(final int nSamples) {
DoubleDCT_1D fft = new DoubleDCT_1D(nSamples);
double[] testSignal1Ref = generateDelta(2 * nSamples);
double[] testSignal1 = generateDelta(2 * nSamples);
double[] testSignal2Ref = generateRamp(2 * nSamples, nSamples);
double[] testSignal2 = generateRamp(2 * nSamples, nSamples);
// basic identity tests
fft.forward(testSignal1, true);
fft.inverse(testSignal1, true);
assertArrayEquals(testSignal1Ref, testSignal1, nSamples * FFT_NUMERIC_LIMITS, "delta identity");
fft.forward(testSignal2, true);
fft.inverse(testSignal2, true);
assertArrayEquals(testSignal2Ref, testSignal2, nSamples * FFT_NUMERIC_LIMITS, "ramp identity");
}
@ParameterizedTest
@ValueSource(strings = { "anyOf", "allOf", "oneOf" })
public void validateObject_invalidCombiner_messageShouldNotContainValue(final String keyword) {
final String propName = keyword + "Property";
final String propVal = "NotAnInteger";
final JSONObject object = new JSONObject().put(propName, propVal);
final ValidationException e = catchThrowableOfType(
() -> validator.validateObject(object, loadJSON(TEST_VALUE_SCHEMA_PATH)),
ValidationException.class);
final String pointer = "#/" + propName;
assertThat(e.getSchemaPointer()).isEqualTo(pointer);
assertThat(e.getKeyword()).isEqualTo(keyword);
assertThat(e).hasMessageNotContaining(propVal);
assertThat(e.getCausingExceptions()).hasSize(1);
final ValidationException enumEx = e.getCausingExceptions().get(0);
assertThat(enumEx.getSchemaPointer()).isEqualTo(pointer);
assertThat(enumEx).hasMessageNotContaining(propVal);
assertThat(enumEx.getKeyword()).isEqualTo("type");
assertThat(enumEx.getCausingExceptions()).isEmpty();
}
@ParameterizedTest
@ValueSource(strings = { "ahc", "http", "netty-http" })
public void basicProducer(String component) {
RestAssured
.given()
.queryParam("test-port", RestAssured.port)
.when()
.get("/test/client/{component}/get", component)
.then()
.body(is("get"));
RestAssured
.given()
.queryParam("test-port", RestAssured.port)
.body("message")
.when()
.post("/test/client/{component}/post", component)
.then()
.body(is("MESSAGE"));
}
@ParameterizedTest
@ValueSource(ints = { 1, 2, 3, 4, 5, 1023, 1024, 1025, 4095, 4096, 4097, (2 << 16) - 100, 2 << 16,
(2 << 16) + 100 })
public void
identityComplexlFFTTests(final int nSamples) {
FloatFFT_1D fft = new FloatFFT_1D(nSamples);
float[] testSignal1Ref = generateDelta(2 * nSamples);
float[] testSignal1 = generateDelta(2 * nSamples);
float[] testSignal2Ref = generateRamp(2 * nSamples, nSamples);
float[] testSignal2 = generateRamp(2 * nSamples, nSamples);
// basic identity tests
fft.complexForward(testSignal1);
fft.complexInverse(testSignal1, true);
assertArrayEquals(testSignal1Ref, testSignal1, nSamples * FFT_NUMERIC_LIMITS, "delta identity");
fft.complexForward(testSignal2);
fft.complexInverse(testSignal2, true);
assertArrayEquals(testSignal2Ref, testSignal2, nSamples * FFT_NUMERIC_LIMITS, "ramp identity");
}
@ParameterizedTest
@ValueSource(strings = {"/exec/single-subflow.sw.json", "/exec/single-subflow.sw.yml"})
public void testSingleSubFlowWorkflow(String workflowLocation) throws Exception {
RuleFlowProcess process = (RuleFlowProcess) getWorkflowParser(workflowLocation).parseWorkFlow(classpathResourceReader(workflowLocation));
assertEquals("function", process.getId());
assertEquals("test-wf", process.getName());
assertEquals("1.0", process.getVersion());
assertEquals("org.kie.kogito.serverless", process.getPackageName());
assertEquals(RuleFlowProcess.PUBLIC_VISIBILITY, process.getVisibility());
assertEquals(3, process.getNodes().length);
Node node = process.getNodes()[0];
assertTrue(node instanceof StartNode);
node = process.getNodes()[2];
assertTrue(node instanceof SubProcessNode);
node = process.getNodes()[1];
assertTrue(node instanceof EndNode);
SubProcessNode subProcessNode = (SubProcessNode) process.getNodes()[2];
assertEquals("abc", subProcessNode.getProcessId());
}
@ParameterizedTest
@ValueSource(strings = {"", "notauri"})
void testParseSqlConnectionInvalid(String text) {
assertEquals(
"error.invalidFormat",
assertThrows(TextException.class, () -> parseSqlConnection(text)).getMessage());
}
@ParameterizedTest
@ValueSource(strings = {
"adds-json-document-bodies.json",
"adds-path-timestamp-format.json",
"adds-query-timestamp-format.json",
"adds-query-blob-format.json",
"adds-header-timestamp-format.json",
"adds-header-mediatype-format.json",
"supports-payloads.json",
"aws-rest-json-uses-jsonname.json",
"synthesizes-contents.json"
})
public void testProtocolResult(String smithy) {
Model model = Model.assembler()
.addImport(getClass().getResource(smithy))
.discoverModels()
.assemble()
.unwrap();
OpenApiConfig config = new OpenApiConfig();
config.setService(ShapeId.from("smithy.example#Service"));
ObjectNode result = OpenApiConverter.create()
.config(config)
.convertToNode(model);
String openApiModel = smithy.replace(".json", ".openapi.json");
InputStream openApiStream = getClass().getResourceAsStream(openApiModel);
if (openApiStream == null) {
LOGGER.warning("OpenAPI model not found for test case: " + openApiModel);
} else {
Node expectedNode = Node.parse(IoUtils.toUtf8String(openApiStream));
Node.assertEquals(result, expectedNode);
}
}
@ParameterizedTest
@ValueSource(strings = {"=", " ", "&", "?", "#"})
void illegalDownStreamPathThrowsException(final String illegalChar) {
List<String> cmdLine = validBaseCommandOptions();
cmdLine = removeFieldsFrom(cmdLine, "downstream-http-path");
cmdLine.add("--downstream-http-path=path1/" + illegalChar + "path2 ");
cmdLine.add(subCommand.getCommandName());
final boolean result = parser.parseCommandLine(cmdLine.toArray(String[]::new));
assertThat(result).isFalse();
}
@ParameterizedTest
@ValueSource(strings = {"public", "custom"})
void getInvalidIndexesOnDatabaseWithoutThem(final String schemaName) {
executeTestOnDatabase(schemaName,
DatabasePopulator::withReferences,
ctx -> {
final List<Index> invalidIndexes = indexesMaintenance.getInvalidIndexes(ctx);
assertNotNull(invalidIndexes);
assertThat(invalidIndexes, empty());
});
}
@ParameterizedTest
@ValueSource(strings = {"public", "custom"})
void getInvalidIndexesOnDatabaseWithThem(final String schemaName) {
executeTestOnDatabase(schemaName,
dbp -> dbp.withReferences().withData().withInvalidIndex(),
ctx -> {
final List<Index> invalidIndexes = indexesMaintenance.getInvalidIndexes(ctx);
assertNotNull(invalidIndexes);
assertThat(invalidIndexes, hasSize(1));
final Index index = invalidIndexes.get(0);
assertEquals(ctx.enrichWithSchema("clients"), index.getTableName());
assertEquals(ctx.enrichWithSchema("i_clients_last_name_first_name"), index.getIndexName());
});
}
@ParameterizedTest
@ValueSource(strings = {"public", "custom"})
void getDuplicatedIndexesOnDatabaseWithoutThem(final String schemaName) {
executeTestOnDatabase(schemaName,
DatabasePopulator::withReferences,
ctx -> {
final List<DuplicatedIndexes> duplicatedIndexes = indexesMaintenance.getDuplicatedIndexes(ctx);
assertNotNull(duplicatedIndexes);
assertThat(duplicatedIndexes, empty());
});
}
@ParameterizedTest
@ValueSource(strings = {
"change-url",
"add-collection",
"remove-collection",
"add-header",
"change-header" // 2 diffs (removed, added) because no identity defined for header-entries and equals = false
})
public void shouldOnlyFindOneDiff(String dir) throws JsonParseException, JsonMappingException, IOException {
ObjectMapper mapper = new ObjectMapper();
List<Collection> remoteCollections = mapper.readValue(getClass().getResourceAsStream("/"+dir+"/basecopy.json"),
new TypeReference<List<Collection>>() {
});
List<Collection> workingCollection = mapper.readValue(getClass().getResourceAsStream("/"+dir+"/workingcopy.json"),
new TypeReference<List<Collection>>() {
});
CollectionDiffer differ = new CollectionDiffer();
DiffNode diffNode = differ.compare(workingCollection, remoteCollections);
String prettyDiff = printDiffs(remoteCollections, workingCollection, diffNode);
String expected = IOUtils.toString(getClass().getResourceAsStream("/"+dir+"/diffs.txt"));
assertThat(prettyDiff.replaceAll("\\r\\n|\\r|\\n", " "))
.withFailMessage("diffs are not as expected: \n" + prettyDiff)
.isEqualTo(expected.replaceAll("\\r\\n|\\r|\\n", " "));
}
@ParameterizedTest
@ValueSource(strings = {"public", "custom"})
void getDuplicatedHashIndexesOnDatabaseWithThem(final String schemaName) {
executeTestOnDatabase(schemaName,
dbp -> dbp.withReferences().withDuplicatedHashIndex(),
ctx -> {
final List<DuplicatedIndexes> duplicatedIndexes = indexesMaintenance.getDuplicatedIndexes(ctx);
assertNotNull(duplicatedIndexes);
assertThat(duplicatedIndexes, empty());
});
}
@ParameterizedTest
@ValueSource(strings = {"public", "custom"})
void getDuplicatedIndexesWithDifferentOpclassShouldReturnNothing(final String schemaName) {
executeTestOnDatabase(schemaName,
dbp -> dbp.withReferences().withDifferentOpclassIndexes(),
ctx -> {
final List<DuplicatedIndexes> duplicatedIndexes = indexesMaintenance.getDuplicatedIndexes(ctx);
assertNotNull(duplicatedIndexes);
assertThat(duplicatedIndexes, empty());
});
}
@ValueSource(strings = {"equal to ", " equal to "})
@ParameterizedTest
void testConversion(String valueToConvert)
{
assertEquals(ComparisonRule.EQUAL_TO,
fluentTrimmedEnumConverter.convertValue(valueToConvert, ComparisonRule.class));
}