Search in sources :

Example 31 with Condition

use of org.assertj.core.api.Condition in project java-chassis by ServiceComb.

the class TestUpload method should_failed_when_connect_failed.

@Test
public void should_failed_when_connect_failed() {
    Throwable throwable = catchThrowable(() -> consumersJaxrs.getIntf().uploadMultiformMix(EndpointUtils.parse(EndpointUtils.formatFromUri("http://149.159.169.179:54321")), fileSystemResource1, singletonList(fileSystemResource2), message, singletonList("2.中文测试")));
    assertThat(throwable).isInstanceOf(InvocationException.class);
    assertThat(throwable.toString()).is(anyOf(new Condition<>(v -> v.equals("InvocationException: code=500;msg=CommonExceptionData{code='SCB.00000000', message='connection timed out.', dynamic={}}"), "for filter"), new Condition<>(v -> v.equals("InvocationException: code=490;msg=CommonExceptionData [message=Unexpected consumer error, please check logs for details]"), "for handler")));
    assertThat(throwable.getCause()).isInstanceOf(ConnectTimeoutException.class).hasMessage("connection timed out: /149.159.169.179:54321");
}
Also used : Condition(org.assertj.core.api.Condition) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) ConnectTimeoutException(io.netty.channel.ConnectTimeoutException) Test(org.junit.Test)

Example 32 with Condition

use of org.assertj.core.api.Condition in project neo4j by neo4j.

the class QueryResultsSerializationTest method restContainsNestedDeleted.

/**
 * This condition is hardcoded to check for a list containing one deleted node and one map with a
 * deleted node mapped to the key `someKey`.
 */
private static Condition<? super Response> restContainsNestedDeleted() {
    return new Condition<>(response -> {
        try {
            JsonNode list = getJsonNodeWithName(response, "rest").iterator().next();
            assertThat(list.get(0).get("metadata").get("deleted").asBoolean()).isEqualTo(Boolean.TRUE);
            assertThat(list.get(1).get("someKey").get("metadata").get("deleted").asBoolean()).isEqualTo(Boolean.TRUE);
            return true;
        } catch (JsonParseException e) {
            return false;
        }
    }, "Contains deleted data.");
}
Also used : Condition(org.assertj.core.api.Condition) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonParseException(org.neo4j.server.rest.domain.JsonParseException)

Example 33 with Condition

use of org.assertj.core.api.Condition in project neo4j by neo4j.

the class FusionIndexTestHelp method verifyFusionCloseThrowIfAllThrow.

static void verifyFusionCloseThrowIfAllThrow(AutoCloseable fusionCloseable, AutoCloseable... autoCloseables) throws Exception {
    // given
    UncheckedIOException[] failures = new UncheckedIOException[autoCloseables.length];
    for (int i = 0; i < autoCloseables.length; i++) {
        failures[i] = new UncheckedIOException(new IOException("unknown"));
        doThrow(failures[i]).when(autoCloseables[i]).close();
    }
    try {
        // when
        fusionCloseable.close();
        fail("Should have failed");
    } catch (UncheckedIOException e) {
        // then
        List<Condition<Throwable>> conditions = new ArrayList<>();
        for (UncheckedIOException failure : failures) {
            conditions.add(new Condition<>(e1 -> e1 == failure, "Same exception"));
        }
        assertThat(e).is(anyOf(conditions));
    }
}
Also used : Condition(org.assertj.core.api.Condition) UncheckedIOException(java.io.UncheckedIOException) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Aggregations

Condition (org.assertj.core.api.Condition)33 Test (org.junit.Test)19 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)16 List (java.util.List)9 Before (org.junit.Before)7 File (java.io.File)5 IOException (java.io.IOException)5 Arrays (java.util.Arrays)5 ExecutorService (java.util.concurrent.ExecutorService)4 Assertions (org.assertj.core.api.Assertions)4 Rule (org.junit.Rule)4 Mock (org.mockito.Mock)4 When (io.cucumber.java.en.When)3 SupportPage (io.syndesis.qe.pages.SupportPage)3 InetAddress (java.net.InetAddress)3 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 Enumeration (java.util.Enumeration)3 TimeUnit (java.util.concurrent.TimeUnit)3 ZipEntry (java.util.zip.ZipEntry)3