Search in sources :

Example 1 with SourceAlertID

use of com.thinkbiganalytics.alerts.api.core.AggregatingAlertProvider.SourceAlertID in project kylo by Teradata.

the class AggregatingAlertProviderTest method testGetAlert.

@Test
public void testGetAlert() {
    TestAlert mgrAlert = new TestAlert(this.manager);
    TestAlert srcAlert = new TestAlert(this.source);
    SourceAlertID mgrId = new SourceAlertID(mgrAlert.getId(), this.manager);
    SourceAlertID srcId = new SourceAlertID(srcAlert.getId(), this.source);
    this.provider.addAlertSource(this.source);
    this.provider.addAlertManager(this.manager);
    when(this.source.getAlert(any(Alert.ID.class))).thenReturn(Optional.of(srcAlert));
    when(this.source.getAlertAsServiceAccount(any(Alert.ID.class))).thenReturn(Optional.of(srcAlert));
    when(this.manager.getAlert(any(Alert.ID.class))).thenReturn(Optional.of(mgrAlert));
    when(this.manager.getAlertAsServiceAccount(any(Alert.ID.class))).thenReturn(Optional.of(mgrAlert));
    Alert getMgrAlert = providerToSourceAlertFunction().apply(this.provider.getAlert(mgrId).get());
    Alert getSrcAlert = providerToSourceAlertFunction().apply(this.provider.getAlert(srcId).get());
    assertThat(getMgrAlert).isEqualTo(mgrAlert);
    assertThat(getSrcAlert).isEqualTo(srcAlert);
}
Also used : SourceAlertID(com.thinkbiganalytics.alerts.api.core.AggregatingAlertProvider.SourceAlertID) Alert(com.thinkbiganalytics.alerts.api.Alert) SourceAlertID(com.thinkbiganalytics.alerts.api.core.AggregatingAlertProvider.SourceAlertID) Test(org.junit.Test)

Example 2 with SourceAlertID

use of com.thinkbiganalytics.alerts.api.core.AggregatingAlertProvider.SourceAlertID in project kylo by Teradata.

the class AggregatingAlertProviderTest method testRespondToNonActionable.

@Test
public void testRespondToNonActionable() {
    TestAlert mgrAlert = new TestAlert(this.manager, false);
    this.provider.addAlertManager(this.manager);
    when(this.manager.getAlert(any(Alert.ID.class))).thenReturn(Optional.of(mgrAlert));
    when(this.manager.getAlertAsServiceAccount(any(Alert.ID.class))).thenReturn(Optional.of(mgrAlert));
    this.provider.respondTo(new SourceAlertID(mgrAlert.getId(), this.manager), this.responder);
    verify(this.responder, never()).alertChange(any(Alert.class), any(AlertResponse.class));
}
Also used : SourceAlertID(com.thinkbiganalytics.alerts.api.core.AggregatingAlertProvider.SourceAlertID) AlertResponse(com.thinkbiganalytics.alerts.api.AlertResponse) Alert(com.thinkbiganalytics.alerts.api.Alert) SourceAlertID(com.thinkbiganalytics.alerts.api.core.AggregatingAlertProvider.SourceAlertID) Test(org.junit.Test)

Example 3 with SourceAlertID

use of com.thinkbiganalytics.alerts.api.core.AggregatingAlertProvider.SourceAlertID in project kylo by Teradata.

the class AggregatingAlertProviderTest method testResolve.

@Test
public void testResolve() {
    TestAlert mgrAlert = new TestAlert(this.manager);
    TestAlert srcAlert = new TestAlert(this.source);
    SourceAlertID mgrId = new SourceAlertID(mgrAlert.getId(), this.manager);
    SourceAlertID srcId = new SourceAlertID(srcAlert.getId(), this.source);
    String mgrIdStr = mgrId.toString();
    String srcIdStr = srcId.toString();
    this.provider.addAlertSource(this.source);
    this.provider.addAlertManager(this.manager);
    when(this.source.resolve(any(TestID.class))).thenReturn(srcAlert.getId());
    when(this.manager.resolve(any(TestID.class))).thenReturn(mgrAlert.getId());
    when(this.source.resolve(any(String.class))).thenReturn(srcAlert.getId());
    when(this.manager.resolve(any(String.class))).thenReturn(mgrAlert.getId());
    Alert.ID mgrObjResolved = this.provider.resolve(mgrId);
    Alert.ID srcObjResolved = this.provider.resolve(srcId);
    Alert.ID mgrStrResolved = this.provider.resolve(mgrIdStr);
    Alert.ID srcStrResolved = this.provider.resolve(srcIdStr);
    assertThat(mgrObjResolved).isInstanceOf(SourceAlertID.class).isEqualTo(mgrId).isEqualTo(mgrStrResolved);
    assertThat(srcObjResolved).isInstanceOf(SourceAlertID.class).isEqualTo(srcId).isEqualTo(srcStrResolved);
}
Also used : SourceAlertID(com.thinkbiganalytics.alerts.api.core.AggregatingAlertProvider.SourceAlertID) Alert(com.thinkbiganalytics.alerts.api.Alert) Test(org.junit.Test)

Example 4 with SourceAlertID

use of com.thinkbiganalytics.alerts.api.core.AggregatingAlertProvider.SourceAlertID in project kylo by Teradata.

the class AggregatingAlertProviderTest method testRespondToActionable.

@Test
public void testRespondToActionable() {
    TestAlert mgrAlert = new TestAlert(this.manager, true);
    this.provider.addAlertManager(this.manager);
    when(this.manager.getAlert(any(Alert.ID.class))).thenReturn(Optional.of(mgrAlert));
    when(this.manager.getAlertAsServiceAccount(any(Alert.ID.class))).thenReturn(Optional.of(mgrAlert));
    this.provider.respondTo(new SourceAlertID(mgrAlert.getId(), this.manager), this.responder);
    verify(this.responder).alertChange(any(Alert.class), any(AlertResponse.class));
}
Also used : SourceAlertID(com.thinkbiganalytics.alerts.api.core.AggregatingAlertProvider.SourceAlertID) AlertResponse(com.thinkbiganalytics.alerts.api.AlertResponse) Alert(com.thinkbiganalytics.alerts.api.Alert) SourceAlertID(com.thinkbiganalytics.alerts.api.core.AggregatingAlertProvider.SourceAlertID) Test(org.junit.Test)

Example 5 with SourceAlertID

use of com.thinkbiganalytics.alerts.api.core.AggregatingAlertProvider.SourceAlertID in project kylo by Teradata.

the class AggregatingAlertProviderTest method testRespondToChange.

@Test
public void testRespondToChange() throws InterruptedException {
    TestAlert initMgrAlert = new TestAlert(this.manager, true);
    CountDownLatch latch = new CountDownLatch(1);
    this.provider.addAlertManager(this.manager);
    when(this.manager.getAlert(any(Alert.ID.class))).thenReturn(Optional.of(initMgrAlert));
    when(this.manager.getAlertAsServiceAccount(any(Alert.ID.class))).thenReturn(Optional.of(initMgrAlert));
    when(this.manager.getResponse(any(Alert.class))).thenReturn(this.response);
    when(this.response.handle(any(String.class), any(Serializable.class))).thenReturn(initMgrAlert);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            latch.countDown();
            return null;
        }
    }).when(this.listener).alertChange(any(Alert.class));
    this.provider.respondTo(new SourceAlertID(initMgrAlert.getId(), this.manager), new AlertResponder() {

        @Override
        public void alertChange(Alert alert, AlertResponse response) {
            response.handle(null, "handled");
        }
    });
    latch.await(10, TimeUnit.SECONDS);
    verify(this.response).handle(eq(null), eq("handled"));
    verify(this.listener, atLeastOnce()).alertChange(any(Alert.class));
}
Also used : Serializable(java.io.Serializable) AlertResponse(com.thinkbiganalytics.alerts.api.AlertResponse) CountDownLatch(java.util.concurrent.CountDownLatch) AlertResponder(com.thinkbiganalytics.alerts.api.AlertResponder) SourceAlertID(com.thinkbiganalytics.alerts.api.core.AggregatingAlertProvider.SourceAlertID) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Alert(com.thinkbiganalytics.alerts.api.Alert) SourceAlertID(com.thinkbiganalytics.alerts.api.core.AggregatingAlertProvider.SourceAlertID) Test(org.junit.Test)

Aggregations

Alert (com.thinkbiganalytics.alerts.api.Alert)5 SourceAlertID (com.thinkbiganalytics.alerts.api.core.AggregatingAlertProvider.SourceAlertID)5 Test (org.junit.Test)5 AlertResponse (com.thinkbiganalytics.alerts.api.AlertResponse)3 AlertResponder (com.thinkbiganalytics.alerts.api.AlertResponder)1 Serializable (java.io.Serializable)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1