Skip to content

Commit

Permalink
SUFM-15 Add integration test and fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
laszlocsontos committed Jul 2, 2018
1 parent b7b6385 commit 76f269a
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@RequiredArgsConstructor
public class MailerLiteRequestInterceptor implements ClientHttpRequestInterceptor {

static final String MAILERLITE_API_KEY = "MailerLite-ApiKey";
static final String MAILERLITE_API_KEY = "X-MailerLite-ApiKey";

@NonNull
private final String apiKey;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.springuni.forgetme.datahandler.adapter.mailerlite;

import static java.util.Collections.singletonList;
import static org.junit.Assert.assertTrue;

import com.springuni.forgetme.core.integration.DataHandlerGateway;
import com.springuni.forgetme.core.model.ForgetRequest;
import com.springuni.forgetme.core.model.ForgetResponse;
import com.springuni.forgetme.datahandler.adapter.mailerlite.MailerLiteGatewayIT.TestConfig;
import java.util.UUID;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.retry.support.RetryTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.client.RestTemplate;

@Ignore
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = {TestConfig.class})
public class MailerLiteGatewayIT {

@Autowired
private DataHandlerGateway dataHandlerGateway;

@Test
public void shouldForgetSubscriber() {
ForgetRequest forgetRequest = new ForgetRequest(UUID.randomUUID(), "test@springuni.com");
ForgetResponse forgetResponse = dataHandlerGateway.handleForget(forgetRequest);
assertTrue(forgetResponse.isAcknowledged());
}

@Configuration
static class TestConfig {

@Bean
RestTemplate restTemplate(Environment environment) {
RestTemplate restTemplate = new RestTemplate();
ClientHttpRequestInterceptor requestInterceptor =
new MailerLiteRequestInterceptor(environment.getProperty("MAILERLITE_API_KEY"));

restTemplate.setInterceptors(singletonList(requestInterceptor));

return restTemplate;
}

@Bean
RetryTemplate retryTemplate() {
return new RetryTemplate();
}

@Bean
DataHandlerGateway dataHandlerGateway(RestTemplate restTemplate, RetryTemplate retryTemplate) {
return new MailerLiteGateway(restTemplate, retryTemplate);
}

}

}

0 comments on commit 76f269a

Please sign in to comment.