Search in sources :

Example 1 with BinaryData

use of com.azure.core.util.BinaryData 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 BinaryData

use of com.azure.core.util.BinaryData in project DataSpaceConnector by eclipse-dataspaceconnector.

the class AzureEventGridPublisher method sendEvent.

private Mono<Void> sendEvent(String what, String where, Object payload) {
    BinaryData data = BinaryData.fromObject(payload);
    var evt = new EventGridEvent(what, where, data, "0.1");
    return client.sendEvent(evt);
}
Also used : BinaryData(com.azure.core.util.BinaryData) EventGridEvent(com.azure.messaging.eventgrid.EventGridEvent)

Aggregations

BinaryData (com.azure.core.util.BinaryData)2 EventGridEvent (com.azure.messaging.eventgrid.EventGridEvent)2 AzureKeyCredential (com.azure.core.credential.AzureKeyCredential)1 CloudEvent (com.azure.core.models.CloudEvent)1 EventGridPublisherClient (com.azure.messaging.eventgrid.EventGridPublisherClient)1 EventGridPublisherClientBuilder (com.azure.messaging.eventgrid.EventGridPublisherClientBuilder)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 MockitoExtension (org.mockito.junit.jupiter.MockitoExtension)1