Search in sources :

Example 1 with EventGridPublisherClientBuilder

use of com.azure.messaging.eventgrid.EventGridPublisherClientBuilder in project vividus by vividus-framework.

the class EventGridServiceTests method shouldSendCustomEvent.

@Test
void shouldSendCustomEvent() {
    @SuppressWarnings("unchecked") EventGridPublisherClient<BinaryData> client = mock(EventGridPublisherClient.class);
    try (MockedConstruction<EventGridPublisherClientBuilder> builderConstructor = mockConstruction(EventGridPublisherClientBuilder.class, (mock, context) -> {
        when(mock.endpoint(ENDPOINT)).thenReturn(mock);
        ArgumentMatcher<AzureKeyCredential> matcher = c -> KEY.equals(c.getKey());
        when(mock.credential(argThat(matcher))).thenReturn(mock);
        when(mock.buildCustomEventPublisherClient()).thenReturn(client);
    });
        MockedStatic<BinaryData> mockedEvent = mockStatic(BinaryData.class)) {
        BinaryData event = mock(BinaryData.class);
        mockedEvent.when(() -> BinaryData.fromString(PAYLOAD)).thenReturn(event);
        topic.setEventSchema(EventSchema.CUSTOM);
        SERVICE.sendEvent(topic, PAYLOAD);
        verify(client).sendEvents(List.of(event));
    }
}
Also used : EventSchema(org.vividus.azure.eventgrid.model.EventSchema) BeforeEach(org.junit.jupiter.api.BeforeEach) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) CloudEvent(com.azure.core.models.CloudEvent) Mockito.mockStatic(org.mockito.Mockito.mockStatic) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) ArgumentMatcher(org.mockito.ArgumentMatcher) List(java.util.List) EventGridPublisherClient(com.azure.messaging.eventgrid.EventGridPublisherClient) MockedStatic(org.mockito.MockedStatic) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) AzureKeyCredential(com.azure.core.credential.AzureKeyCredential) EventGridPublisherClientBuilder(com.azure.messaging.eventgrid.EventGridPublisherClientBuilder) Mockito.mockConstruction(org.mockito.Mockito.mockConstruction) EventGridEvent(com.azure.messaging.eventgrid.EventGridEvent) Topic(org.vividus.azure.eventgrid.model.Topic) BinaryData(com.azure.core.util.BinaryData) Mockito.mock(org.mockito.Mockito.mock) MockedConstruction(org.mockito.MockedConstruction) EventGridPublisherClientBuilder(com.azure.messaging.eventgrid.EventGridPublisherClientBuilder) AzureKeyCredential(com.azure.core.credential.AzureKeyCredential) BinaryData(com.azure.core.util.BinaryData) Test(org.junit.jupiter.api.Test)

Example 2 with EventGridPublisherClientBuilder

use of com.azure.messaging.eventgrid.EventGridPublisherClientBuilder in project vividus by vividus-framework.

the class EventGridService method sendEvent.

public void sendEvent(Topic topic, String payload) {
    EventGridPublisherClientBuilder builder = new EventGridPublisherClientBuilder().endpoint(topic.getEndpoint()).credential(new AzureKeyCredential(topic.getKey()));
    EventSchema eventSchema = topic.getEventSchema();
    eventSchema.sendEvent(builder, payload);
}
Also used : EventGridPublisherClientBuilder(com.azure.messaging.eventgrid.EventGridPublisherClientBuilder) AzureKeyCredential(com.azure.core.credential.AzureKeyCredential) EventSchema(org.vividus.azure.eventgrid.model.EventSchema)

Example 3 with EventGridPublisherClientBuilder

use of com.azure.messaging.eventgrid.EventGridPublisherClientBuilder in project DataSpaceConnector by eclipse-dataspaceconnector.

the class AzureEventExtension method registerListeners.

private void registerListeners(ServiceExtensionContext context) {
    var config = new AzureEventGridConfig(context);
    var topicName = config.getTopic();
    var endpoint = config.getEndpoint(topicName);
    monitor.info("AzureEventExtension: will use topic endpoint " + endpoint);
    var publisherClient = new EventGridPublisherClientBuilder().credential(new AzureKeyCredential(Objects.requireNonNull(vault.resolveSecret(topicName), "Did not find secret in vault: " + endpoint))).endpoint(endpoint).buildEventGridEventPublisherAsyncClient();
    AzureEventGridPublisher publisher = new AzureEventGridPublisher(context.getConnectorId(), monitor, publisherClient);
    var processObservable = context.getService(TransferProcessObservable.class, true);
    if (processObservable != null) {
        processObservable.registerListener(publisher);
    }
}
Also used : EventGridPublisherClientBuilder(com.azure.messaging.eventgrid.EventGridPublisherClientBuilder) AzureKeyCredential(com.azure.core.credential.AzureKeyCredential)

Aggregations

AzureKeyCredential (com.azure.core.credential.AzureKeyCredential)3 EventGridPublisherClientBuilder (com.azure.messaging.eventgrid.EventGridPublisherClientBuilder)3 EventSchema (org.vividus.azure.eventgrid.model.EventSchema)2 CloudEvent (com.azure.core.models.CloudEvent)1 BinaryData (com.azure.core.util.BinaryData)1 EventGridEvent (com.azure.messaging.eventgrid.EventGridEvent)1 EventGridPublisherClient (com.azure.messaging.eventgrid.EventGridPublisherClient)1 List (java.util.List)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)1 ArgumentMatcher (org.mockito.ArgumentMatcher)1 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)1 MockedConstruction (org.mockito.MockedConstruction)1 MockedStatic (org.mockito.MockedStatic)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.mockConstruction (org.mockito.Mockito.mockConstruction)1 Mockito.mockStatic (org.mockito.Mockito.mockStatic)1 Mockito.verify (org.mockito.Mockito.verify)1 Mockito.when (org.mockito.Mockito.when)1