Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/externalize-email-and-slack-templates-#51 #109

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import freemarker.template.Configuration;
import freemarker.template.Template;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.ui.freemarker.FreeMarkerTemplateUtils;
Expand All @@ -31,9 +30,11 @@
@Slf4j
public class MessageComposer {

@Autowired
@Qualifier("freemarkerConfig")
private Configuration freemarkerConfig;
private final Configuration freemarkerConfig;

public MessageComposer(@Qualifier("freemarkerConfig") Configuration freemarkerConfig) {
this.freemarkerConfig = freemarkerConfig;
}

public String buildContent(Alert alert, String templateName) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public ConcurrentKafkaListenerContainerFactory<String, Alert> kafkaListenerConta
@Bean("freemarkerConfig")
public FreeMarkerConfigurationFactoryBean getFreeMarkerConfiguration() {
FreeMarkerConfigurationFactoryBean bean = new FreeMarkerConfigurationFactoryBean();
bean.setTemplateLoaderPath("classpath:/templates/");
bean.setTemplateLoaderPath("../templates/");
return bean;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.expedia.alertmanager.notifier.builder;

import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.IOException;

import org.junit.Before;
import org.junit.Test;

import com.expedia.alertmanager.model.Alert;
import freemarker.template.Configuration;

public class MessageComposerTest {

private MessageComposer messageComposer;

private Configuration freemarkerConfig;

@Before
public void setUp() throws IOException {
freemarkerConfig = new Configuration(Configuration.VERSION_2_3_28);
freemarkerConfig.setDirectoryForTemplateLoading(new File("../templates/"));
messageComposer = new MessageComposer(freemarkerConfig);
}

@Test
public void test_buildContent_For_Email_Template() {
String out = messageComposer.buildContent(new Alert(), "email-template.ftl");
assertTrue("Email template exists", out.contains("You have one alert."));
}

@Test
public void test_buildContent_For_Slack_Template() {
String out = messageComposer.buildContent(new Alert(), "slack-message-template.ftl");
assertTrue("Slack template exists", out.contains("You have one alert."));
}
}