/*
 * Copyright 2019 LINE Corporation
 *
 * LINE Corporation licenses this file to you under the Apache License,
 * version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package com.linecorp.bot.client;

import java.io.IOException;
import java.net.URL;
import java.util.Map;

import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;
import org.yaml.snakeyaml.Yaml;

import com.fasterxml.jackson.databind.ObjectMapper;

import com.linecorp.bot.model.response.GetNumberOfFollowersResponse;
import com.linecorp.bot.model.response.GetNumberOfMessageDeliveriesResponse;
import com.linecorp.bot.model.response.NumberOfMessagesResponse;

import lombok.extern.slf4j.Slf4j;

/**
 * Integration test of {@link LineMessagingClient}.
 *
 * <p>To run this test, please put config file resources/integration_test_settings.yml.
 */
@Slf4j
public class LineMessagingClientImplIntegrationTest {
    public static final URL TEST_RESOURCE = ClassLoader.getSystemResource("integration_test_settings.yml");
    private LineMessagingClient target;

    @Before
    public void setUp() throws IOException {
        Assume.assumeTrue(TEST_RESOURCE != null);

        final Map<?, ?> map = new ObjectMapper()
                .convertValue(new Yaml().load(TEST_RESOURCE.openStream()), Map.class);

        target = LineMessagingClient
                .builder((String) map.get("token"))
                .apiEndPoint((String) map.get("endpoint"))
                .build();
    }

    @Test
    public void getNumberOfMessageDeliveries() throws Exception {
        final GetNumberOfMessageDeliveriesResponse getNumberOfMessageDeliveriesResponse =
                target.getNumberOfMessageDeliveries("20191231").get();

        log.info(getNumberOfMessageDeliveriesResponse.toString());
    }

    @Test
    public void getNumberOfSentBroadcastMessages() throws Exception {
        final NumberOfMessagesResponse getNumberOfSentBroadcastMessages =
                target.getNumberOfSentBroadcastMessages("20191231").get();

        log.info(getNumberOfSentBroadcastMessages.toString());
    }

    @Test
    public void getNumberOfFollowers() throws Exception {
        final GetNumberOfFollowersResponse getNumberOfFollowersResponse =
                target.getNumberOfFollowers("20191231").get();

        log.info(getNumberOfFollowersResponse.toString());
    }
}

@@ -661,16 +661,64 @@
 lient;%0A%0A
+import static java.util.Collections.singleton;%0A%0A
 import j
@@ -737,16 +737,16 @@
 eption;%0A
-
 import j
@@ -779,16 +779,54 @@
 til.Map;
+%0Aimport java.util.concurrent.Callable;
 %0A%0Aimport
@@ -978,16 +978,192 @@
 apper;%0A%0A
+import com.linecorp.bot.model.Broadcast;%0Aimport com.linecorp.bot.model.Multicast;%0Aimport com.linecorp.bot.model.PushMessage;%0Aimport com.linecorp.bot.model.message.TextMessage;%0A
 import c
@@ -1760,16 +1760,43 @@
  target;
+%0A    private String userId;
 %0A%0A    @B
@@ -2178,24 +2178,24 @@
 endpoint%22))%0A
-
             
@@ -2207,16 +2207,1250 @@
 build();
+%0A%0A        userId = (String) map.get(%22userId%22);%0A    %7D%0A%0A    private static void testApiCall(Callable%3CObject%3E f) throws Exception %7B%0A        final Object response = f.call();%0A        log.info(response.toString());%0A    %7D%0A%0A    @Test%0A    public void broadcast() throws Exception %7B%0A        testApiCall(%0A                () -%3E target.broadcast(new Broadcast(new TextMessage(%22Broadcast%22), true)).get()%0A        );%0A        testApiCall(%0A                () -%3E target.broadcast(new Broadcast(new TextMessage(%22Broadcast%22))).get()%0A        );%0A    %7D%0A%0A    @Test%0A    public void multicast() throws Exception %7B%0A        testApiCall(%0A                () -%3E target.multicast(new Multicast(singleton(userId), new TextMessage(%22Multicast%22), true))%0A                            .get()%0A        );%0A        testApiCall(%0A                () -%3E target.multicast(new Multicast(singleton(userId), new TextMessage(%22Multicast%22))).get()%0A        );%0A    %7D%0A%0A    @Test%0A    public void pushMessage() throws Exception %7B%0A        testApiCall(%0A                () -%3E target.pushMessage(new PushMessage(userId, new TextMessage(%22Push%22), true)).get()%0A        );%0A        testApiCall(%0A                () -%3E target.pushMessage(new PushMessage(userId, new TextMessage(%22Push%22))).get()%0A        );
 %0A    %7D%0A%0A

add client integration test