Java 类javax.enterprise.inject.spi.EventMetadata 实例源码

项目:ocelot    文件:TopicsMessagesObserversTest.java   
/**
 * Test of sendObjectToTopic method, of class TopicsMessagesBroadcaster.
 *
 * @throws org.ocelotds.marshalling.exceptions.JsonMarshallingException
 */
@Test
public void testSendObjectToTopicNotAnnotated() throws JsonMarshallingException {
    System.out.println("sendObjectToTopic");
    EventMetadata metadata = mock(EventMetadata.class);
    InjectionPoint injectionPoint = mock(InjectionPoint.class);
    Annotated annotated = mock(Annotated.class);

    when(metadata.getInjectionPoint()).thenReturn(injectionPoint);
    when(injectionPoint.getAnnotated()).thenReturn(annotated);
    when(annotated.getAnnotation(JsTopicEvent.class)).thenReturn(null);

    // no JsTopicEvent
    instance.sendObjectToTopic(PAYLOAD, metadata);
    verify(instance, never()).sendMessageToTopic(any(MessageToClient.class));
}
项目:ocelot    文件:TopicsMessagesObserversTest.java   
/**
 * Test of sendObjectToTopic method, of class TopicsMessagesBroadcaster.
 *
 * @throws org.ocelotds.marshalling.exceptions.JsonMarshallingException
 */
@Test
public void testSendObjectToTopicWithoutMarshaller() throws JsonMarshallingException {
    System.out.println("sendObjectToTopic");
    EventMetadata metadata = mock(EventMetadata.class);
    InjectionPoint injectionPoint = mock(InjectionPoint.class);
    Annotated annotated = mock(Annotated.class);
    JsTopicEvent jte = mock(JsTopicEvent.class);

    when(metadata.getInjectionPoint()).thenReturn(injectionPoint);
    when(injectionPoint.getAnnotated()).thenReturn(annotated);
    when(annotated.getAnnotation(JsTopicEvent.class)).thenReturn(jte);
    when(annotated.getAnnotation(JsonMarshaller.class)).thenReturn(null);
    when(jte.value()).thenReturn(TOPIC);

    // JsTopicEvent, no marshaller
    instance.sendObjectToTopic(PAYLOAD, metadata);

    ArgumentCaptor<MessageToClient> captureMtC = ArgumentCaptor.forClass(MessageToClient.class);
    ArgumentCaptor<Object> captureObject = ArgumentCaptor.forClass(Object.class);
    verify(topicsMessagesBroadcaster).sendMessageToTopic(captureMtC.capture(), captureObject.capture());

    assertThat(captureMtC.getValue().getResponse()).isEqualTo(PAYLOAD);
    assertThat(captureObject.getValue()).isEqualTo(PAYLOAD);
}
项目:ocelot    文件:TopicsMessagesObserversTest.java   
/**
 * Test of sendObjectToTopic method, of class TopicsMessagesBroadcaster.
 *
 * @throws org.ocelotds.marshalling.exceptions.JsonMarshallingException
 */
@Test
public void testSendObjectToTopicJsonPayload() throws JsonMarshallingException {
    System.out.println("sendObjectToTopic");
    EventMetadata metadata = mock(EventMetadata.class);
    InjectionPoint injectionPoint = mock(InjectionPoint.class);
    Annotated annotated = mock(Annotated.class);
    JsTopicEvent jte = mock(JsTopicEvent.class);

    when(metadata.getInjectionPoint()).thenReturn(injectionPoint);
    when(injectionPoint.getAnnotated()).thenReturn(annotated);
    when(annotated.getAnnotation(JsTopicEvent.class)).thenReturn(jte);
    when(annotated.getAnnotation(JsonMarshaller.class)).thenReturn(null);
    when(jte.value()).thenReturn(TOPIC);
    when(jte.jsonPayload()).thenReturn(true);

    // JsTopicEvent, jsonPayload <,no marshaller
    instance.sendObjectToTopic(PAYLOAD, metadata);

    ArgumentCaptor<MessageToClient> captureMtC = ArgumentCaptor.forClass(MessageToClient.class);
    ArgumentCaptor<Object> captureObject = ArgumentCaptor.forClass(Object.class);
    verify(topicsMessagesBroadcaster).sendMessageToTopic(captureMtC.capture(), captureObject.capture());

    assertThat(captureMtC.getValue().getJson()).isEqualTo(PAYLOAD);
    assertThat(captureObject.getValue()).isEqualTo(PAYLOAD);
}
项目:ocelot    文件:TopicsMessagesObserversTest.java   
/**
 * Test of sendObjectToTopic method, of class TopicsMessagesBroadcaster.
 *
 * @throws org.ocelotds.marshalling.exceptions.JsonMarshallingException
 */
@Test
public void testSendObjectToTopicJsonPayloadFailed() throws JsonMarshallingException {
    System.out.println("sendObjectToTopic");
    EventMetadata metadata = mock(EventMetadata.class);
    InjectionPoint injectionPoint = mock(InjectionPoint.class);
    Annotated annotated = mock(Annotated.class);
    JsTopicEvent jte = mock(JsTopicEvent.class);

    when(metadata.getInjectionPoint()).thenReturn(injectionPoint);
    when(injectionPoint.getAnnotated()).thenReturn(annotated);
    when(annotated.getAnnotation(JsTopicEvent.class)).thenReturn(jte);
    when(annotated.getAnnotation(JsonMarshaller.class)).thenReturn(null);
    when(jte.value()).thenReturn(TOPIC);
    when(jte.jsonPayload()).thenReturn(true);

    // JsTopicEvent, jsonPayload <,no marshaller
    instance.sendObjectToTopic(new Long(5), metadata);

    verify(topicsMessagesBroadcaster, never()).sendMessageToTopic(any(MessageToClient.class), anyObject());
}
项目:ocelot    文件:TopicsMessagesObserversTest.java   
/**
 * Test of sendObjectToTopic method, of class TopicsMessagesBroadcaster.
 *
 * @throws org.ocelotds.marshalling.exceptions.JsonMarshallingException
 * @throws org.ocelotds.marshalling.exceptions.JsonMarshallerException
 */
@Test
public void testSendObjectToTopicWithMarshallerFail() throws JsonMarshallingException, JsonMarshallerException {
    System.out.println("sendObjectToTopic");
    EventMetadata metadata = mock(EventMetadata.class);
    InjectionPoint injectionPoint = mock(InjectionPoint.class);
    Annotated annotated = mock(Annotated.class);
    JsTopicEvent event = mock(JsTopicEvent.class);

    when(metadata.getInjectionPoint()).thenReturn(injectionPoint);
    when(injectionPoint.getAnnotated()).thenReturn(annotated);
    when(annotated.getAnnotation(JsTopicEvent.class)).thenReturn(event);
    when(annotated.getAnnotation(JsonMarshaller.class)).thenReturn(mock(JsonMarshaller.class));
    when(argumentServices.getJsonResultFromSpecificMarshaller(any(JsonMarshaller.class), anyObject())).thenThrow(JsonMarshallingException.class).thenThrow(JsonMarshallerException.class).thenThrow(Throwable.class);
    when(event.value()).thenReturn(TOPIC);

    // JsTopicEvent, marshaller
    instance.sendObjectToTopic(PAYLOAD, metadata);
    instance.sendObjectToTopic(PAYLOAD, metadata);
    instance.sendObjectToTopic(PAYLOAD, metadata);

    verify(topicsMessagesBroadcaster, never()).sendMessageToTopic(any(MessageToClient.class), anyObject());
}
项目:camel-cdi    文件:RawEventEndpointTest.java   
@Test
public void sendMessageToProducer(@Uri("direct:produce") ProducerTemplate producer) throws InterruptedException {
    long random =  Math.round(Math.random() * Long.MAX_VALUE);

    produced.expectedMessageCount(1);
    produced.expectedBodiesReceived(random);
    produced.message(0).predicate(exchange -> {
        EventMetadata metadata = exchange.getIn().getHeader("metadata", EventMetadata.class);
        return metadata.getType().equals(Long.class) && metadata.getQualifiers().equals(new HashSet<>(Arrays.asList(new AnnotationLiteral<Any>() {}, new AnnotationLiteral<Default>() {})));
    });

    consumed.expectedMessageCount(1);
    consumed.expectedBodiesReceived(random);

    producer.sendBody(random);

    assertIsSatisfied(2L, TimeUnit.SECONDS, consumed, produced);
}
项目:ocelot    文件:TopicsMessagesObserversTest.java   
/**
 * Test of sendObjectToTopic method, of class TopicsMessagesBroadcaster.
 *
 * @throws org.ocelotds.marshalling.exceptions.JsonMarshallingException
 * @throws org.ocelotds.marshalling.exceptions.JsonMarshallerException
 */
@Test
public void testSendObjectToTopicWithMarshaller() throws JsonMarshallingException, JsonMarshallerException {
    System.out.println("sendObjectToTopic");
    EventMetadata metadata = mock(EventMetadata.class);
    InjectionPoint injectionPoint = mock(InjectionPoint.class);
    Annotated annotated = mock(Annotated.class);
    JsTopicEvent jte = mock(JsTopicEvent.class);
    JsonMarshaller jm = mock(JsonMarshaller.class);

    when(metadata.getInjectionPoint()).thenReturn(injectionPoint);
    when(injectionPoint.getAnnotated()).thenReturn(annotated);
    when(annotated.getAnnotation(JsTopicEvent.class)).thenReturn(jte);
    when(annotated.getAnnotation(JsonMarshaller.class)).thenReturn(jm);
    when(jte.value()).thenReturn(TOPIC);
    when(argumentServices.getJsonResultFromSpecificMarshaller(eq(jm), eq(PAYLOAD))).thenReturn("MARSHALLED");

    // JsTopicEvent, no marshaller
    instance.sendObjectToTopic(PAYLOAD, metadata);

    ArgumentCaptor<MessageToClient> captureMtC = ArgumentCaptor.forClass(MessageToClient.class);
    ArgumentCaptor<Object> captureObject = ArgumentCaptor.forClass(Object.class);
    verify(topicsMessagesBroadcaster).sendMessageToTopic(captureMtC.capture(), captureObject.capture());

    assertThat(captureMtC.getValue().getJson()).isEqualTo("MARSHALLED");
    assertThat(captureObject.getValue()).isEqualTo(PAYLOAD);
}
项目:microbean-kubernetes-client-cdi    文件:TestKubernetesClientExtension.java   
private final void onEvent(@Observes @Any final Event event, final EventMetadata eventMetadata) {
  System.out.println("*** event received: " + event);
  System.out.println("*** metadata: " + eventMetadata);
}
项目:javaee_projects    文件:CalculatorObserver.java   
public void registerDiscount(@Observes @DiscountObservable double newValue, EventMetadata metadata) {
    System.out.println("[ " + metadata.getType() + " - " + System.currentTimeMillis() + "] Value after apply discount: " + newValue);
}
项目:camel-cdi    文件:RawEventEndpointTest.java   
void collectEvents(@Observes long event, EventMetadata metadata, @Uri("mock:produced") ProducerTemplate producer) {
    producer.sendBodyAndHeader(event, "metadata", metadata);
}