Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mocking ProducerTemplate #2067

Closed
ismailbaskin opened this issue Dec 10, 2020 · 2 comments
Closed

Mocking ProducerTemplate #2067

ismailbaskin opened this issue Dec 10, 2020 · 2 comments

Comments

@ismailbaskin
Copy link
Contributor

I want to write a unit test for sms method by mocking ProducerTemplate.

@Path("/")
public class SmsResource {

  @Inject
  ProducerTemplate producerTemplate;

  @POST
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  @Path("/sms")
  public Message sms() {
    return producerTemplate
        .requestBody("twilio://message/creator?from=RAW(+15005550006)&to=RAW(+15005550006)&body=TestMessage", 
            null, Message.class);
  }
}

I've tried that but it doesn't work.

@QuarkusTest
class SmsControllerTest {

  @Inject
  SmsResource smsResource;

  @InjectMocks
  ProducerTemplate producerTemplate;

  @BeforeEach
  public void setup() throws Exception {
    MockitoAnnotations.openMocks(this);
  }

  @Test
  void sendSms() throws Exception {
    Message message = Message.fromJson("{\"body\":\"Test Message\",\"status\": \"queued\"}", new ObjectMapper());
    when(producerTemplate.requestBody(anyString(), null, Message.class)).thenReturn(message);
    smsResource.sms();
  }
}
@ppalaga
Copy link
Contributor

ppalaga commented Dec 10, 2020

Which part does not work as expected and what do you expect actually?

@ppalaga
Copy link
Contributor

ppalaga commented May 26, 2021

Closing as stale

@ppalaga ppalaga closed this as completed May 26, 2021
@ppalaga ppalaga added this to the No fix/wont't fix milestone May 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants