コード例 #1
0
  @Test
  public void shouldReceiveAttributesUsingExplicitConversion(boolean flag) throws JMSException {
    // Given
    String pattern = "dd.MM.YYYY";
    LocalDate today = new LocalDate();
    Mapping mapping =
        new MappingBuilder(OPERATION_FIELD_NAME) //
            .mapField("date", FieldMapping.map("date", new JodaLocalDateConverter(pattern))) //
            .mapField("flag", FieldMapping.map("flag", new StringToBooleanConverter("1", "0"))) //
            .build();

    MapMessage message =
        createPayload(
            OPERATION_FIELD_NAME,
            "localDateCall",
            "date",
            today.toString(pattern),
            "flag",
            flag ? "1" : "0");

    // When
    JodaTimeApi mock = mock(JodaTimeApi.class);
    MapMessageDecoder.of(JodaTimeApi.class, mock, mapping).onMessage(message);

    // Then
    verify(mock).localDateCall(today, flag);
  }
コード例 #2
0
  @Test
  public void shouldMapReceiveOperationAttibute() throws JMSException {
    // Given
    MappingBuilder myMapping = new MappingBuilder("myop");

    MapMessage message = createPayload("myop", "mappedNoArgCall");

    // When
    MapMessageDecoder.of(MappedApi.class, serviceMock, myMapping.build()).onMessage(message);

    // Then
    verify(serviceMock).mappedNoArgCall();
  }
コード例 #3
0
  @Test
  public void shouldCallServiceOneCharMethod() {
    // Given
    JmsSenderFactory factory = new JmsSenderFactory(CONFIG, new MapJmsPayloadHandler());
    OneCharTestApi sendProxy = factory.create(OneCharTestApi.class);
    Mapping receiveMapping = new MappingBuilder("METHOD").build();

    // When
    sendProxy.a("content");
    MapMessageDecoder.of(OneCharTestApi.class, oneCharServiceMock, receiveMapping) //
        .onMessage(captureMessage());

    // Then
    verify(oneCharServiceMock).a("content");
  }
コード例 #4
0
  @Test
  @Ignore
  // TODO reenable
  public void shouldMapReceiveBoxedPrimitiveAttributesIfWrittenAsStrings(
      /* @Values("BOXED_PRIMITIVE_CALLS") */ SimpleServiceCall call) throws Exception {
    // Given
    MappingBuilder mapping = new MappingBuilder(OPERATION_FIELD_NAME);
    String operation = call.operation;
    String argument = call.argument;
    Class<?> type = call.type;
    Object value = call.value;
    mapping.mapField(argument, FieldMapping.map(argument));

    MapMessage message =
        createPayload(OPERATION_FIELD_NAME, operation, argument, String.valueOf(value));

    // When
    MapMessageDecoder.of(BoxedPrimitivesTestApi.class, boxedPrimitivesServiceMock, mapping.build())
        .onMessage(message);

    // Then
    invoke(verify(boxedPrimitivesServiceMock), operation, type, value);
  }
コード例 #5
0
  @Test
  public void receiveShouldFailWithUnmappedName() {
    // Given
    Mapping sendMapping =
        new MappingBuilder(OPERATION_FIELD_NAME).mapOperation("mappedCall", "OP").build();
    MappedApi service = service(sendMapping);
    service.mappedCall("a", 0L);

    Mapping receiveMapping = partialMapping();

    // When
    String message = null;
    try {
      MapMessageDecoder.of(MappedApi.class, serviceMock, receiveMapping)
          .onMessage(captureMessage());
      fail("RuntimeException expected");
    } catch (RuntimeException e) {
      message = e.getCause().getMessage();
    }

    // Then
    assertEquals("no mapping for field: s2", message);
  }
コード例 #6
0
 private void receive(Message message, Mapping mapping) {
   MapMessageDecoder.of(MappedApi.class, serviceMock, mapping).onMessage(message);
 }