use of com.yahoo.athenz.common.messaging.MockDomainChangePublisher in project athenz by yahoo.
the class ZMSImplTest method testPublisherException.
@Test
public void testPublisherException() {
ZMSImpl zmsImpl = zmsTestInitializer.zmsInit();
String apiName = "postTopLevelDomain";
ResourceContext mockContext = Mockito.mock(ResourceContext.class);
when(mockContext.getApiName()).thenReturn(apiName);
when(mockContext.getDomainChangeMessages()).thenReturn(Collections.singletonList(new DomainChangeMessage()));
MockDomainChangePublisher mockDomainChangePublisher = new MockDomainChangePublisher("domainChanges");
mockDomainChangePublisher.setThrowPublishExceptions(true);
zmsImpl.domainChangePublishers = new ArrayList<>();
zmsImpl.domainChangePublishers.add(mockDomainChangePublisher);
// make sure no exceptions are thrown since we should catch and log them
zmsImpl.publishChangeMessage(mockContext, 200);
}
use of com.yahoo.athenz.common.messaging.MockDomainChangePublisher in project athenz by yahoo.
the class ZMSImplTest method testPublishEvent.
@Test
public void testPublishEvent() {
System.setProperty(ZMS_PROP_DOMAIN_CHANGE_PUBLISHER_FACTORY_CLASS, "com.yahoo.athenz.common.messaging.MockDomainChangePublisherFactory");
System.setProperty(ZMS_PROP_DOMAIN_CHANGE_TOPIC_NAMES, "topic1");
ZMSImpl zmsImpl = zmsTestInitializer.zmsInit();
assertNotNull(zmsImpl.domainChangePublishers);
List<String> topicNames = zmsImpl.domainChangePublishers.stream().map(publisher -> ((MockDomainChangePublisher) publisher).getTopicName()).collect(Collectors.toList());
assertThat(topicNames, containsInAnyOrder("topic1"));
ResourceContext mockContext = Mockito.mock(ResourceContext.class);
when(mockContext.getApiName()).thenReturn("apiName");
when(mockContext.getDomainChangeMessages()).thenReturn(Collections.singletonList(new DomainChangeMessage().setDomainName("domainName").setObjectName("objectName").setObjectType(DOMAIN).setApiName("apiName").setPublished(Instant.now().toEpochMilli()).setMessageId(java.util.UUID.randomUUID().toString())));
zmsImpl.publishChangeMessage(mockContext, 200);
// verify publish messages
MockDomainChangePublisher.Recorder evtRecorder = getEventRecorder(zmsImpl);
ArgumentCaptor<DomainChangeMessage> evtArgumentCaptor = ArgumentCaptor.forClass(DomainChangeMessage.class);
verify(evtRecorder, Mockito.times(1)).record(evtArgumentCaptor.capture());
DomainChangeMessage actual = evtArgumentCaptor.getValue();
assertEquals(actual.getDomainName(), "domainName");
assertEquals(actual.getApiName(), "apiName");
assertEquals(actual.getObjectType(), DOMAIN);
assertEquals(actual.getObjectName(), "objectName");
System.clearProperty(ZMS_PROP_DOMAIN_CHANGE_PUBLISHER_FACTORY_CLASS);
System.clearProperty(ZMS_PROP_DOMAIN_CHANGE_TOPIC_NAMES);
}
Aggregations