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);
}
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));
}
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);
}
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));
}
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));
}
Aggregations