package com.box.l10n.mojito.slack;

import com.box.l10n.mojito.mustache.MustacheTemplateEngine;
import com.box.l10n.mojito.slack.request.Channel;
import com.box.l10n.mojito.slack.request.Message;
import com.box.l10n.mojito.slack.response.ChatPostMessageResponse;
import org.junit.Assume;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.context.annotation.aspectj.EnableSpringConfigured;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = {SlackClientTest.class})
@EnableAutoConfiguration
@IntegrationTest("spring.datasource.initialize=false")
public class SlackClientTest {

    @Value("${l10n.slack.token:#{null}}")
    String token;

    @Value("${test.l10n.slack.email.destination:someemail@test.com}")
    String email;

    @Test
    public void testClient() throws SlackClientException {
        Assume.assumeNotNull(token);

        SlackClient slackClient = new SlackClient(token);

        Channel instantMessageChannel = slackClient.getInstantMessageChannel(email);

        Message message = new Message();
        message.setText("test");
        message.setChannel(instantMessageChannel.getId());
        ChatPostMessageResponse chatPostMessageResponse = slackClient.sendInstantMessage(message);

        Message reply = new Message();
        reply.setChannel(instantMessageChannel.getId());
        reply.setText("response");
        reply.setThreadTs(chatPostMessageResponse.getTs());

        slackClient.sendInstantMessage(reply);
    }
}
@@ -281,16 +281,41 @@
 Assume;%0A
+import org.junit.Before;%0A
 import o
@@ -387,16 +387,79 @@
 unWith;%0A
+import org.springframework.beans.factory.annotation.Autowired;%0A
 import o
@@ -1224,16 +1224,48 @@
 st.class
+, SlackClientConfiguration.class
 %7D)%0A@Enab
@@ -1380,61 +1380,63 @@
    @
-Value(%22$%7Bl10n.slack.token:#%7Bnull%7D%7D%22)%0A    String tok
+Autowired(required = false)%0A    SlackClient slackCli
 en
+t
 ;%0A%0A 
@@ -1528,20 +1528,22 @@
 ;%0A%0A    @
-Test
+Before
 %0A    pub
@@ -1555,20 +1555,22 @@
 oid 
-test
+assume
 Client()
  thr
@@ -1569,36 +1569,8 @@
 nt()
- throws SlackClientException
  %7B%0A 
@@ -1601,54 +1601,74 @@
 ull(
-tok
+slackCli
 en
+t
 );%0A
-%0A        SlackClient slackClient = new
+    %7D%0A%0A    @Test%0A    public void testClient() throws
  Sla
@@ -1679,17 +1679,19 @@
 ient
-(token);%0A
+Exception %7B
 %0A   

Refactor SlackClientTest to properly get the config