@Test public void shouldMapSendOperationAttribute() throws JMSException { MappedApi service = service(new MappingBuilder("myop").build()); // When service.mappedNoArgCall(); // Then MapMessage message = (MapMessage) captureMessage(); assertEquals("mappedNoArgCall", message.getObject("myop")); }
@Test public void shouldCallServiceWithEmptyValueIfNotSendingOptionalParameter() { // Given Mapping mapping = new MappingBuilder(OPERATION_FIELD_NAME).build(); MappedApi service = service(mapping); // When service.optionalMappedCall(null); receive(captureMessage(), mapping); // Then verify(serviceMock).optionalMappedCall(null); }
@Test public void shouldMapSendAttributes() throws JMSException { // Given MappedApi proxy = MessageSender.of(MappedApi.class); // When proxy.mappedCall("a", 0L); // Then MapMessage message = (MapMessage) captureMessage(); assertEquals("a", message.getObject("A")); assertEquals("0", message.getObject("B")); }
@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 public void shouldMapSendOperationName() throws JMSException { // Given Mapping mapping = new MappingBuilder(OPERATION_FIELD_NAME) // .mapOperation("mappedNoArgCall", "MAPPED_NOARG_OP") .build(); MappedApi service = service(mapping); // When service.mappedNoArgCall(); // Then MapMessage message = (MapMessage) captureMessage(); assertEquals("MAPPED_NOARG_OP", message.getObject(OPERATION_FIELD_NAME)); }
@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); }
@Test public void sendShouldFailWithUnmappedName() { // Given Mapping mapping = partialMapping(); MappedApi service = service(mapping); // When String message = null; try { service.mappedCall("a", 0L); fail("IllegalArgumentException expected"); } catch (IllegalArgumentException e) { message = e.getMessage(); } // Then assertEquals("no mapping for field: s2", message); }
@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); }