Search in sources :

Example 1 with DaprException

use of io.dapr.exceptions.DaprException in project java-sdk by dapr.

the class MethodInvokeIT method testInvokeException.

@Test
public void testInvokeException() throws Exception {
    try (DaprClient client = new DaprClientBuilder().build()) {
        MethodInvokeServiceProtos.SleepRequest req = MethodInvokeServiceProtos.SleepRequest.newBuilder().setSeconds(-9).build();
        DaprException exception = assertThrows(DaprException.class, () -> client.invokeMethod(daprRun.getAppName(), "sleep", -9, HttpExtension.POST).block());
        assertEquals("UNKNOWN", exception.getErrorCode());
        assertNotNull(exception.getMessage());
        assertTrue(exception.getMessage().contains("Internal Server Error"));
    }
}
Also used : DaprException(io.dapr.exceptions.DaprException) DaprClientBuilder(io.dapr.client.DaprClientBuilder) DaprClient(io.dapr.client.DaprClient) MethodInvokeServiceProtos(io.dapr.it.MethodInvokeServiceProtos) Test(org.junit.Test)

Example 2 with DaprException

use of io.dapr.exceptions.DaprException in project java-sdk by dapr.

the class AbstractStateClientIT method testInvalidEtag.

@Test
public void testInvalidEtag() {
    DaprClient daprClient = buildDaprClient();
    DaprException exception = assertThrows(DaprException.class, () -> daprClient.saveState(STATE_STORE_NAME, "myKey", "badEtag", "value", null).block());
    assertNotNull(exception.getMessage());
    // This will assert that eTag is parsed correctly and is not corrupted. The quotation from runtime helps here.
    assertTrue(exception.getMessage().contains("\"badEtag\""));
}
Also used : DaprException(io.dapr.exceptions.DaprException) DaprClient(io.dapr.client.DaprClient) Test(org.junit.Test)

Example 3 with DaprException

use of io.dapr.exceptions.DaprException in project java-sdk by dapr.

the class TestUtils method assertThrowsDaprException.

public static <T extends Throwable> void assertThrowsDaprException(String expectedErrorCode, String expectedErrorMessage, Executable executable) {
    DaprException daprException = Assertions.assertThrows(DaprException.class, executable);
    Assertions.assertEquals(expectedErrorCode, daprException.getErrorCode());
    Assertions.assertEquals(expectedErrorMessage, daprException.getMessage());
}
Also used : DaprException(io.dapr.exceptions.DaprException)

Example 4 with DaprException

use of io.dapr.exceptions.DaprException in project java-sdk by dapr.

the class TestUtils method assertThrowsDaprExceptionSubstring.

public static <T extends Throwable> void assertThrowsDaprExceptionSubstring(String expectedErrorCode, String expectedErrorMessageSubstring, Executable executable) {
    DaprException daprException = Assertions.assertThrows(DaprException.class, executable);
    Assertions.assertEquals(expectedErrorCode, daprException.getErrorCode());
    Assertions.assertTrue(daprException.getMessage().contains(expectedErrorMessageSubstring));
}
Also used : DaprException(io.dapr.exceptions.DaprException)

Example 5 with DaprException

use of io.dapr.exceptions.DaprException in project java-sdk by dapr.

the class TestUtils method assertThrowsDaprException.

public static void assertThrowsDaprException(String expectedErrorCode, String expectedErrorMessage, Executable executable) {
    DaprException daprException = Assertions.assertThrows(DaprException.class, executable);
    Assertions.assertNull(daprException.getCause());
    Assertions.assertEquals(expectedErrorCode, daprException.getErrorCode());
    Assertions.assertEquals(expectedErrorMessage, daprException.getMessage());
}
Also used : DaprException(io.dapr.exceptions.DaprException)

Aggregations

DaprException (io.dapr.exceptions.DaprException)14 Test (org.junit.Test)7 DaprClient (io.dapr.client.DaprClient)4 TestUtils.assertThrowsDaprException (io.dapr.utils.TestUtils.assertThrowsDaprException)4 DaprClientBuilder (io.dapr.client.DaprClientBuilder)3 State (io.dapr.client.domain.State)1 TransactionalStateOperation (io.dapr.client.domain.TransactionalStateOperation)1 MethodInvokeServiceProtos (io.dapr.it.MethodInvokeServiceProtos)1 SleepRequest (io.dapr.it.MethodInvokeServiceProtos.SleepRequest)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1