/** * Expose {@link LineMessagingClient} as {@link Bean}. */ @Bean public LineMessagingClient lineMessagingClient( final ChannelTokenSupplier channelTokenSupplier) { return LineMessagingClient .builder(channelTokenSupplier) .apiEndPoint(lineBotProperties.getApiEndPoint()) .connectTimeout(lineBotProperties.getConnectTimeout()) .readTimeout(lineBotProperties.getReadTimeout()) .writeTimeout(lineBotProperties.getWriteTimeout()) .build(); }
@Override protected LineMessagingClient createLineMessagingClient(final MockWebServer mockWebServer) { return LineMessagingClient.builder(channelTokenSupplier) .apiEndPoint("http://localhost:" + mockWebServer.getPort()) .build(); } }
protected LineMessagingClient createLineMessagingClient(final MockWebServer mockWebServer) { return LineMessagingClient.builder("token") .apiEndPoint("http://localhost:" + mockWebServer.getPort()) .build(); }
/** * Expose {@link LineMessagingClient} as {@link Bean}. */ @Bean public LineMessagingClient lineMessagingClient( final ChannelTokenSupplier channelTokenSupplier) { return LineMessagingClient .builder(channelTokenSupplier) .apiEndPoint(lineBotProperties.getApiEndPoint()) .connectTimeout(lineBotProperties.getConnectTimeout()) .readTimeout(lineBotProperties.getReadTimeout()) .writeTimeout(lineBotProperties.getWriteTimeout()) .build(); }
@Test public void testBuilderWithChannelTokenSupplier() throws InterruptedException { lineMessagingClient = LineMessagingClient.builder(() -> "MOCKED_TOKEN") .apiEndPoint("http://localhost:" + mockWebServer.getPort()) .build(); // Do lineMessagingClient.getProfile("TEST"); // Verify final RecordedRequest recordedRequest = mockWebServer.takeRequest(); assertThat(recordedRequest.getHeader("Authorization")) .isEqualTo("Bearer MOCKED_TOKEN"); }
@Test public void testBuildWithFixedToken() throws InterruptedException { lineMessagingClient = new LineMessagingClientBuilder() .channelToken("MOCKED_TOKEN") .apiEndPoint("http://localhost:" + mockWebServer.getPort()) .build(); // Do lineMessagingClient.getProfile("TEST"); // Verify final RecordedRequest recordedRequest = mockWebServer.takeRequest(); assertThat(recordedRequest.getHeader("Authorization")) .isEqualTo("Bearer MOCKED_TOKEN"); }
@Test(timeout = ASYNC_TEST_TIMEOUT) public void relativeRequestTest() throws Exception { final String apiEndPoint = "http://" + mockWebServer.getHostName() + ':' + mockWebServer.getPort() + "/CanContainsRelative/"; lineMessagingClient = LineMessagingClient .builder("SECRET") .apiEndPoint(apiEndPoint) .build(); final UserProfileResponse profileResponseMock = new UserProfileResponse("name", "userId", "https://line.me/picture_url", "Status message"); mockWebServer.enqueue(new MockResponse() .setResponseCode(200) .setBody(new ObjectMapper() .writeValueAsString(profileResponseMock))); // Do final UserProfileResponse actualResponse = lineMessagingClient.getProfile("USER_TOKEN").get(); // Verify final RecordedRequest recordedRequest = mockWebServer.takeRequest(); assertThat(recordedRequest.getPath()) .isEqualTo("/CanContainsRelative/v2/bot/profile/USER_TOKEN"); assertThat(actualResponse).isEqualTo(profileResponseMock); }
@Before public void setUp() throws Exception { mockWebServer = new MockWebServer(); final String apiEndPoint = "http://" + mockWebServer.getHostName() + ':' + mockWebServer.getPort() + "/CanContainsRelative/"; target = LineMessagingClient .builder("SECRET") .apiEndPoint(apiEndPoint) .build(); }