@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);
  }
  @Test
  public void shouldCallServiceWhenSendingAsMapMessage() {
    // Given
    MappedApi sendProxy = MessageSender.of(MappedApi.class);
    Mapping receiveMapping =
        new MappingBuilder(OPERATION_FIELD_NAME) //
            .mapField("s1", FieldMapping.map("A")) //
            .mapField("s2", FieldMapping.map("B")) //
            .build();

    // When
    sendProxy.mappedCall("a", 0L);
    receive(captureMessage(), receiveMapping);

    // Then
    verify(serviceMock).mappedCall("a", 0L);
  }
 private Mapping partialMapping() {
   Mapping mapping = mock(Mapping.class);
   given(mapping.getOperationMessageAttibute()).willReturn(OPERATION_FIELD_NAME);
   given(mapping.getOperationForMethod("mappedCall")).willReturn("OP");
   given(mapping.getMethodForOperation("OP")).willReturn("mappedCall");
   givenFieldMapping(mapping, "s1", FieldMapping.map("a"));
   return new CheckedMapping(mapping);
 }
  @Test
  public void shouldSendAttributesUsingExplicitConversion(boolean flag) throws JMSException {
    // Given
    LocalDate today = new LocalDate();
    String pattern = "dd.MM.YYYY";
    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();
    MapJmsPayloadHandler payloadHandler = new MapJmsPayloadHandler(mapping);
    JodaTimeApi service = JmsSenderFactory.create(CONFIG, payloadHandler).create(JodaTimeApi.class);

    // When
    service.localDateCall(today, flag);

    // Then
    MapMessage message = (MapMessage) captureMessage();
    assertEquals(today.toString(pattern), message.getString("date"));
    assertEquals(flag ? "1" : "0", message.getString("flag"));
  }
  @Test
  public void shouldCallServiceWithDefaultValueIfNotSendingMandatoryParameter() {
    // Given
    Mapping mapping =
        new MappingBuilder(OPERATION_FIELD_NAME)
            .mapField("s1", FieldMapping.mapWithDefault("s1", "default value"))
            .build();
    MappedApi service = service(mapping);

    // When
    service.mappedCall(null, 1L);
    receive(captureMessage(), mapping);

    // Then
    verify(serviceMock).mappedCall("default value", 1L);
  }
  @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);
  }