Search in sources :

Example 56 with DefaultMessage

use of org.apache.camel.impl.DefaultMessage in project webcert by sklintyg.

the class RouteTest method testRoutesToAggregatorForLuaeFsAndrat.

@Test
public void testRoutesToAggregatorForLuaeFsAndrat() throws InterruptedException, ModuleException {
    // This is just a hack in order to not fail subsequent tests due to camel unit tests leaking context between
    // tests. This one just makes sure the notficationAggregator doesn't cause the subsequent "split(body())"
    // to throw some exception caught by later tests.
    notificationAggregator.whenAnyExchangeReceived(exchange -> {
        Message msg = new DefaultMessage();
        exchange.setOut(msg);
    });
    // Given
    notificationWSClient.expectedMessageCount(0);
    notificationAggregator.expectedMessageCount(1);
    permanentErrorHandlerEndpoint.expectedMessageCount(0);
    temporaryErrorHandlerEndpoint.expectedMessageCount(0);
    signatWireTap.expectedMessageCount(1);
    // When
    Map<String, Object> headers = new HashMap<>();
    headers.put(NotificationRouteHeaders.INTYGS_TYP, "luae_fs");
    headers.put(NotificationRouteHeaders.HANDELSE, HandelsekodEnum.ANDRAT.value());
    producerTemplate.sendBodyAndHeaders(createNotificationMessage(SchemaVersion.VERSION_3, "luae_fs"), headers);
    // Then
    assertIsSatisfied(notificationWSClient);
    assertIsSatisfied(notificationAggregator);
    assertIsSatisfied(permanentErrorHandlerEndpoint);
    assertIsSatisfied(temporaryErrorHandlerEndpoint);
    assertIsSatisfied(signatWireTap);
}
Also used : DefaultMessage(org.apache.camel.impl.DefaultMessage) Message(org.apache.camel.Message) DefaultMessage(org.apache.camel.impl.DefaultMessage) HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 57 with DefaultMessage

use of org.apache.camel.impl.DefaultMessage in project webcert by sklintyg.

the class NotificationTransformerTest method testSendBackwardsCompatibility.

@Test
public void testSendBackwardsCompatibility() throws Exception {
    // Given
    NotificationMessage notificationMessage = new NotificationMessage(INTYGS_ID, FK7263, LocalDateTime.now(), HandelsekodEnum.SKAPAT, LOGISK_ADRESS, "{ }", FragorOchSvar.getEmpty(), null, null, null, "ref");
    Message message = spy(new DefaultMessage());
    message.setBody(notificationMessage);
    setupInternalToNotification();
    // When
    transformer.process(message);
    // Then
    assertEquals(INTYGS_ID, ((CertificateStatusUpdateForCareType) message.getBody()).getUtlatande().getUtlatandeId().getExtension());
    assertEquals(HandelsekodEnum.SKAPAT.value(), message.getHeader(NotificationRouteHeaders.HANDELSE));
    assertEquals(INTYGS_ID, message.getHeader(NotificationRouteHeaders.INTYGS_ID));
    assertEquals(LOGISK_ADRESS, message.getHeader(NotificationRouteHeaders.LOGISK_ADRESS));
    assertEquals(SchemaVersion.VERSION_1.name(), message.getHeader(NotificationRouteHeaders.VERSION));
    verify(message, times(1)).setHeader(eq(NotificationRouteHeaders.LOGISK_ADRESS), eq(LOGISK_ADRESS));
    verify(message, times(1)).setHeader(eq(NotificationRouteHeaders.INTYGS_ID), eq(INTYGS_ID));
    verify(message, times(1)).setHeader(eq(NotificationRouteHeaders.HANDELSE), eq(HandelsekodEnum.SKAPAT.value()));
    verify(message, times(1)).setHeader(eq(NotificationRouteHeaders.VERSION), eq(SchemaVersion.VERSION_1.name()));
    verify(internalToNotification, times(1)).createCertificateStatusUpdateForCareType(any());
    verifyZeroInteractions(notificationPatientEnricher);
}
Also used : DefaultMessage(org.apache.camel.impl.DefaultMessage) NotificationMessage(se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage) Message(org.apache.camel.Message) NotificationMessage(se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage) DefaultMessage(org.apache.camel.impl.DefaultMessage) Test(org.junit.Test)

Example 58 with DefaultMessage

use of org.apache.camel.impl.DefaultMessage in project webcert by sklintyg.

the class NotificationTransformerTest method testSend.

@Test
public void testSend() throws Exception {
    // Given
    NotificationMessage notificationMessage = new NotificationMessage(INTYGS_ID, FK7263, LocalDateTime.now(), HandelsekodEnum.SKAPAT, LOGISK_ADRESS, "{ }", FragorOchSvar.getEmpty(), null, null, SchemaVersion.VERSION_1, "ref");
    Message message = spy(new DefaultMessage());
    message.setBody(notificationMessage);
    setupInternalToNotification();
    // When
    transformer.process(message);
    // Then
    assertEquals(INTYGS_ID, ((CertificateStatusUpdateForCareType) message.getBody()).getUtlatande().getUtlatandeId().getExtension());
    assertEquals(HandelsekodEnum.SKAPAT.value(), message.getHeader(NotificationRouteHeaders.HANDELSE));
    assertEquals(INTYGS_ID, message.getHeader(NotificationRouteHeaders.INTYGS_ID));
    assertEquals(LOGISK_ADRESS, message.getHeader(NotificationRouteHeaders.LOGISK_ADRESS));
    assertEquals(SchemaVersion.VERSION_1.name(), message.getHeader(NotificationRouteHeaders.VERSION));
    verify(message, times(1)).setHeader(eq(NotificationRouteHeaders.LOGISK_ADRESS), eq(LOGISK_ADRESS));
    verify(message, times(1)).setHeader(eq(NotificationRouteHeaders.INTYGS_ID), eq(INTYGS_ID));
    verify(message, times(1)).setHeader(eq(NotificationRouteHeaders.HANDELSE), eq(HandelsekodEnum.SKAPAT.value()));
    verify(message, times(1)).setHeader(eq(NotificationRouteHeaders.VERSION), eq(SchemaVersion.VERSION_1.name()));
    verify(internalToNotification, times(1)).createCertificateStatusUpdateForCareType(any());
    verifyZeroInteractions(notificationPatientEnricher);
}
Also used : DefaultMessage(org.apache.camel.impl.DefaultMessage) NotificationMessage(se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage) Message(org.apache.camel.Message) NotificationMessage(se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage) DefaultMessage(org.apache.camel.impl.DefaultMessage) Test(org.junit.Test)

Example 59 with DefaultMessage

use of org.apache.camel.impl.DefaultMessage in project wildfly-camel by wildfly-extras.

the class OpenstackIntegrationTest method createSwiftContainer.

@Test
public void createSwiftContainer() throws Exception {
    CamelContext camelContext = Mockito.mock(CamelContext.class);
    when(camelContext.getHeadersMapFactory()).thenReturn(new DefaultHeadersMapFactory());
    Message msg = new DefaultMessage(camelContext);
    Exchange exchange = Mockito.mock(Exchange.class);
    when(exchange.getIn()).thenReturn(msg);
    when(containerService.create(anyString(), nullable(CreateUpdateContainerOptions.class))).thenReturn(actionResponse);
    when(actionResponse.isSuccess()).thenReturn(true);
    SwiftEndpoint endpoint = Mockito.mock(SwiftEndpoint.class);
    Producer producer = new ContainerProducer(endpoint, client);
    msg.setHeader(OpenstackConstants.OPERATION, OpenstackConstants.CREATE);
    msg.setHeader(SwiftConstants.CONTAINER_NAME, CONTAINER_NAME);
    producer.process(exchange);
    ArgumentCaptor<String> containerNameCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<CreateUpdateContainerOptions> optionsCaptor = ArgumentCaptor.forClass(CreateUpdateContainerOptions.class);
    verify(containerService).create(containerNameCaptor.capture(), optionsCaptor.capture());
    assertEquals(CONTAINER_NAME, containerNameCaptor.getValue());
    assertNull(optionsCaptor.getValue());
    assertFalse(msg.isFault());
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) DefaultMessage(org.apache.camel.impl.DefaultMessage) Exchange(org.apache.camel.Exchange) CreateUpdateContainerOptions(org.openstack4j.model.storage.object.options.CreateUpdateContainerOptions) Message(org.apache.camel.Message) DefaultMessage(org.apache.camel.impl.DefaultMessage) VolumeProducer(org.apache.camel.component.openstack.cinder.producer.VolumeProducer) ProjectProducer(org.apache.camel.component.openstack.keystone.producer.ProjectProducer) ContainerProducer(org.apache.camel.component.openstack.swift.producer.ContainerProducer) GlanceProducer(org.apache.camel.component.openstack.glance.GlanceProducer) KeypairProducer(org.apache.camel.component.openstack.nova.producer.KeypairProducer) Producer(org.apache.camel.Producer) NetworkProducer(org.apache.camel.component.openstack.neutron.producer.NetworkProducer) ContainerProducer(org.apache.camel.component.openstack.swift.producer.ContainerProducer) DefaultHeadersMapFactory(org.apache.camel.impl.DefaultHeadersMapFactory) SwiftEndpoint(org.apache.camel.component.openstack.swift.SwiftEndpoint) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 60 with DefaultMessage

use of org.apache.camel.impl.DefaultMessage in project wildfly-camel by wildfly-extras.

the class OpenstackIntegrationTest method createNeutronNetwork.

@Test
public void createNeutronNetwork() throws Exception {
    CamelContext camelContext = Mockito.mock(CamelContext.class);
    when(camelContext.getHeadersMapFactory()).thenReturn(new DefaultHeadersMapFactory());
    Message msg = new DefaultMessage(camelContext);
    Exchange exchange = Mockito.mock(Exchange.class);
    when(exchange.getIn()).thenReturn(msg);
    msg.setHeader(OpenstackConstants.OPERATION, OpenstackConstants.CREATE);
    msg.setHeader(OpenstackConstants.NAME, dummyNetwork.getName());
    msg.setHeader(NeutronConstants.NETWORK_TYPE, dummyNetwork.getNetworkType());
    msg.setHeader(NeutronConstants.TENANT_ID, dummyNetwork.getTenantId());
    NeutronEndpoint endpoint = Mockito.mock(NeutronEndpoint.class);
    Producer producer = new NetworkProducer(endpoint, client);
    producer.process(exchange);
    ArgumentCaptor<Network> captor = ArgumentCaptor.forClass(Network.class);
    verify(networkService).create(captor.capture());
    assertEqualsNetwork(dummyNetwork, captor.getValue());
    assertNotNull(msg.getBody(Network.class).getId());
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) DefaultMessage(org.apache.camel.impl.DefaultMessage) Exchange(org.apache.camel.Exchange) Message(org.apache.camel.Message) DefaultMessage(org.apache.camel.impl.DefaultMessage) NeutronEndpoint(org.apache.camel.component.openstack.neutron.NeutronEndpoint) VolumeProducer(org.apache.camel.component.openstack.cinder.producer.VolumeProducer) ProjectProducer(org.apache.camel.component.openstack.keystone.producer.ProjectProducer) ContainerProducer(org.apache.camel.component.openstack.swift.producer.ContainerProducer) GlanceProducer(org.apache.camel.component.openstack.glance.GlanceProducer) KeypairProducer(org.apache.camel.component.openstack.nova.producer.KeypairProducer) Producer(org.apache.camel.Producer) NetworkProducer(org.apache.camel.component.openstack.neutron.producer.NetworkProducer) Network(org.openstack4j.model.network.Network) DefaultHeadersMapFactory(org.apache.camel.impl.DefaultHeadersMapFactory) NetworkProducer(org.apache.camel.component.openstack.neutron.producer.NetworkProducer) Test(org.junit.Test)

Aggregations

DefaultMessage (org.apache.camel.impl.DefaultMessage)66 Message (org.apache.camel.Message)59 Exchange (org.apache.camel.Exchange)32 Test (org.junit.Test)31 DefaultExchange (org.apache.camel.impl.DefaultExchange)24 HashMap (java.util.HashMap)19 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)11 CamelContext (org.apache.camel.CamelContext)7 Producer (org.apache.camel.Producer)6 VolumeProducer (org.apache.camel.component.openstack.cinder.producer.VolumeProducer)6 GlanceProducer (org.apache.camel.component.openstack.glance.GlanceProducer)6 ProjectProducer (org.apache.camel.component.openstack.keystone.producer.ProjectProducer)6 NetworkProducer (org.apache.camel.component.openstack.neutron.producer.NetworkProducer)6 KeypairProducer (org.apache.camel.component.openstack.nova.producer.KeypairProducer)6 ContainerProducer (org.apache.camel.component.openstack.swift.producer.ContainerProducer)6 DefaultHeadersMapFactory (org.apache.camel.impl.DefaultHeadersMapFactory)6 NotificationMessage (se.inera.intyg.common.support.modules.support.api.notification.NotificationMessage)5 IOException (java.io.IOException)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 Method (java.lang.reflect.Method)3