Search in sources :

Example 1 with Event

use of com.evolveum.midpoint.notifications.api.events.Event in project midpoint by Evolveum.

the class TestNotifications method test215SendSmsUsingGeneralPost.

@Test
public void test215SendSmsUsingGeneralPost() {
    given();
    Task task = getTestTask();
    OperationResult result = task.getResult();
    int messagesHandledOld = httpHandler.messagesHandled;
    when();
    Event event = new CustomEventImpl(lightweightIdentifierGenerator, "general-post", null, "hello world", EventOperationType.ADD, EventStatusType.SUCCESS, null);
    notificationManager.processEvent(event, task, result);
    then();
    result.computeStatus();
    TestUtil.assertSuccess("processEvent result", result);
    // 3 messages for 3 recipients
    assertThat(httpHandler.messagesHandled).isEqualTo(messagesHandledOld + 3);
    assertNotNull("No http request found", httpHandler.lastRequest);
    assertEquals("Wrong HTTP method", "POST", httpHandler.lastRequest.method);
    assertEquals("Wrong URI", "/send", httpHandler.lastRequest.uri.toString());
    assertEquals("Wrong Content-Type header", singletonList("application/x-www-form-urlencoded"), httpHandler.lastRequest.headers.get("content-type"));
    assertEquals("Wrong X-Custom header", singletonList("test"), httpHandler.lastRequest.headers.get("x-custom"));
    String username = "a9038321";
    String password = "5ecr3t";
    String expectedAuthorization = "Basic " + Base64.getEncoder().encodeToString((username + ":" + password).getBytes(StandardCharsets.ISO_8859_1));
    assertEquals("Wrong Authorization header", singletonList(expectedAuthorization), httpHandler.lastRequest.headers.get("authorization"));
    // only the last recipient here
    assertEquals("Wrong 1st line of body", "Body=\"body\"&To=[%2B789]&From=from", httpHandler.lastRequest.body.get(0));
}
Also used : Task(com.evolveum.midpoint.task.api.Task) Event(com.evolveum.midpoint.notifications.api.events.Event) CustomEventImpl(com.evolveum.midpoint.notifications.impl.events.CustomEventImpl) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Test(org.testng.annotations.Test)

Example 2 with Event

use of com.evolveum.midpoint.notifications.api.events.Event in project midpoint by Evolveum.

the class TestNotifications method test220SendSmsViaProxy.

@Test
public void test220SendSmsViaProxy() {
    given();
    Task task = getTestTask();
    OperationResult result = task.getResult();
    when();
    Event event = new CustomEventImpl(lightweightIdentifierGenerator, "get-via-proxy", null, "hello world via proxy", EventOperationType.ADD, EventStatusType.SUCCESS, null);
    notificationManager.processEvent(event, task, result);
    then();
    result.computeStatus();
    TestUtil.assertSuccess("processEvent result", result);
    assertNotNull("No http request found", httpHandler.lastRequest);
    assertEquals("Wrong HTTP method", "GET", httpHandler.lastRequest.method);
    assertTrue("Header proxy-connection not found in request headers", httpHandler.lastRequest.headers.containsKey("proxy-connection"));
    assertEquals("Wrong proxy-connection header", "Keep-Alive", httpHandler.lastRequest.headers.get("proxy-connection").get(0));
}
Also used : Task(com.evolveum.midpoint.task.api.Task) Event(com.evolveum.midpoint.notifications.api.events.Event) CustomEventImpl(com.evolveum.midpoint.notifications.impl.events.CustomEventImpl) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Example 3 with Event

use of com.evolveum.midpoint.notifications.api.events.Event in project midpoint by Evolveum.

the class TestNotifications method test200SendSmsUsingGet.

@Test
public void test200SendSmsUsingGet() {
    given();
    Task task = getTestTask();
    OperationResult result = task.getResult();
    when();
    Event event = new CustomEventImpl(lightweightIdentifierGenerator, "get", null, "hello world", EventOperationType.ADD, EventStatusType.SUCCESS, null);
    notificationManager.processEvent(event, task, result);
    then();
    result.computeStatus();
    TestUtil.assertSuccess("processEvent result", result);
    assertNotNull("No http request found", httpHandler.lastRequest);
    assertEquals("Wrong HTTP method", "GET", httpHandler.lastRequest.method);
    assertEquals("Wrong URI", "/send?number=%2B421905123456&text=hello+world", httpHandler.lastRequest.uri.toString());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) Event(com.evolveum.midpoint.notifications.api.events.Event) CustomEventImpl(com.evolveum.midpoint.notifications.impl.events.CustomEventImpl) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Example 4 with Event

use of com.evolveum.midpoint.notifications.api.events.Event in project midpoint by Evolveum.

the class TestNotifications method test210SendSmsUsingPost.

@Test
public void test210SendSmsUsingPost() {
    given();
    Task task = getTestTask();
    OperationResult result = task.getResult();
    when();
    Event event = new CustomEventImpl(lightweightIdentifierGenerator, "post", null, "hello world", EventOperationType.ADD, EventStatusType.SUCCESS, null);
    notificationManager.processEvent(event, task, result);
    then();
    result.computeStatus();
    TestUtil.assertSuccess("processEvent result", result);
    assertNotNull("No http request found", httpHandler.lastRequest);
    assertEquals("Wrong HTTP method", "POST", httpHandler.lastRequest.method);
    assertEquals("Wrong URI", "/send", httpHandler.lastRequest.uri.toString());
    assertEquals("Wrong Content-Type header", singletonList("application/x-www-form-urlencoded"), httpHandler.lastRequest.headers.get("content-type"));
    assertEquals("Wrong X-Custom header", singletonList("test"), httpHandler.lastRequest.headers.get("x-custom"));
    String username = "a9038321";
    String password = "5ecr3t";
    String expectedAuthorization = "Basic " + Base64.getEncoder().encodeToString((username + ":" + password).getBytes(StandardCharsets.ISO_8859_1));
    assertEquals("Wrong Authorization header", singletonList(expectedAuthorization), httpHandler.lastRequest.headers.get("authorization"));
    assertEquals("Wrong 1st line of body", "Body=\"hello+world\"&To=%2B421905123456&From=%2B421999000999", httpHandler.lastRequest.body.get(0));
}
Also used : Task(com.evolveum.midpoint.task.api.Task) Event(com.evolveum.midpoint.notifications.api.events.Event) CustomEventImpl(com.evolveum.midpoint.notifications.impl.events.CustomEventImpl) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Test(org.testng.annotations.Test)

Example 5 with Event

use of com.evolveum.midpoint.notifications.api.events.Event in project midpoint by Evolveum.

the class TestNotifications method test300CheckVariables.

@Test
public void test300CheckVariables() {
    given();
    Task task = getTestTask();
    OperationResult result = task.getResult();
    prepareNotifications();
    when();
    Event event = new CustomEventImpl(lightweightIdentifierGenerator, "check-variables", null, "hello world", EventOperationType.ADD, EventStatusType.SUCCESS, null);
    notificationManager.processEvent(event, task, result);
    then();
    result.computeStatus();
    TestUtil.assertSuccess("processEvent result", result);
    displayAllNotifications();
    assertSingleDummyTransportMessage("check-variables", "variables ok");
}
Also used : Task(com.evolveum.midpoint.task.api.Task) Event(com.evolveum.midpoint.notifications.api.events.Event) CustomEventImpl(com.evolveum.midpoint.notifications.impl.events.CustomEventImpl) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Aggregations

Event (com.evolveum.midpoint.notifications.api.events.Event)5 CustomEventImpl (com.evolveum.midpoint.notifications.impl.events.CustomEventImpl)5 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)5 Task (com.evolveum.midpoint.task.api.Task)5 Test (org.testng.annotations.Test)5 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2