/** * Expose {@link ChannelManagementSyncClient} as {@link Bean}. */ @Bean public ChannelManagementSyncClient channelManagementClient( final ChannelTokenSupplier channelTokenSupplier) { return ChannelManagementSyncClient.builder(channelTokenSupplier) .build(); } }
@Override public void execute() { final LiffView liffView = payloadProvider.read(LiffView.class); log.info("Request View : {}", liffView); final LiffAppAddRequest liffAppAddRequest = new LiffAppAddRequest(liffView); final LiffAppAddResponse liffAppAddResponse; try { liffAppAddResponse = channelManagementClient.addLiffApp(liffAppAddRequest); } catch (Exception e) { log.error("Failed : {}", e.getMessage()); return; } log.info("Successfully finished. Response : {}", liffAppAddResponse); } }
@Override public void execute() { checkNotNull(arguments.getLiffId(), "--liff-id= is not set."); try { channelManagementClient.deleteLiffApp(arguments.getLiffId()); } catch (Exception e) { log.error("Failed : {}", e.getMessage()); return; } log.info("Successfully finished."); } }
@Override public void execute() { final List<LiffApp> allLiffApps; try { allLiffApps = channelManagementClient.getAllLiffApps().getApps(); } catch (Exception e) { log.error("Failed : {}", e.getMessage()); return; } log.info("Successfully finished."); log.info("You have {} LIFF apps.", allLiffApps.size()); allLiffApps.forEach(liffApp -> { log.info("{}", liffApp); }); } }
@Override public void execute() { checkNotNull(arguments.getLiffId(), "--liff-id= is not set."); final LiffView liffView = payloadProvider.read(LiffView.class); try { channelManagementClient .updateLiffApp(arguments.getLiffId(), liffView); } catch (Exception e) { log.error("Failed : {}", e.getMessage()); return; } log.info("Successfully finished."); } }
/** * Expose {@link ChannelManagementSyncClient} as {@link Bean}. */ @Bean public ChannelManagementSyncClient channelManagementClient( final ChannelTokenSupplier channelTokenSupplier) { return ChannelManagementSyncClient.builder(channelTokenSupplier) .build(); } }
@Test(timeout = ASYNC_TEST_TIMEOUT) public void testAddLiffMenu() throws Exception { // Mocking LiffAppAddResponse response = new LiffAppAddResponse("NEW_LIFF_ID"); mockWebServer.enqueue(new MockResponse().setResponseCode(200) .setBody(OBJECT_MAPPER.writeValueAsString(response))); // Do LiffView liffView = new LiffView(Type.COMPACT, URI.create("https://example.com")); LiffAppAddRequest request = new LiffAppAddRequest(liffView); final LiffAppAddResponse liffAppAddResponse = channelManagementSyncClient.addLiffApp(request); // Verify final RecordedRequest recordedRequest = mockWebServer.takeRequest(); final LiffAppAddRequest requestedBody = OBJECT_MAPPER .readValue(recordedRequest.getBody().readString(StandardCharsets.UTF_8), LiffAppAddRequest.class); assertThat(requestedBody) .isEqualTo(request); assertThat(recordedRequest.getPath()) .isEqualTo("/liff/v1/apps"); assertThat(liffAppAddResponse.getLiffId()) .isEqualTo("NEW_LIFF_ID"); } }
protected ChannelManagementSyncClient createChannelManagementSyncClient(final MockWebServer mockWebServer) { return ChannelManagementSyncClient .builder(() -> "token") .apiEndPoint(URI.create("http://localhost:" + mockWebServer.getPort())) .build(); } }