@Test
public void testConditionalOutput() {

    UserService userService = system.getServiceFactory().getUserService();
    String alertName = "alert_name-" + TestUtils.createRandomName();
    Alert alert = new Alert(userService.findAdminUser(),
                            userService.findAdminUser(),
                            alertName,
                            expression,
                            "* * * * *");
    Notification notification = new Notification("notification_name", alert, "notifier_name", new ArrayList<String>(), 23);
    Trigger trigger = new Trigger(alert, Trigger.TriggerType.GREATER_THAN_OR_EQ, "trigger_name", 2D, 7.1D,5);
    alert.setNotifications(Arrays.asList(new Notification[] { notification }));
    alert.setTriggers(Arrays.asList(new Trigger[] { trigger }));
    alert = system.getServiceFactory().getAlertService().updateAlert(alert);
    Metric m = new Metric("scope", "metric");
    Map<String, String> tags = new HashMap<>();
    tags.put("tag","val");
    m.setTags(tags);
    History history = new History(History.JobStatus.SUCCESS.getDescription(), "localhost", BigInteger.ONE, History.JobStatus.SUCCESS);
    DefaultAlertService.NotificationContext context = new DefaultAlertService.NotificationContext(alert, alert.getTriggers().get(0), notification,
            1418319600000L, 1.5, m, history);
    String customTemplate = "<#if trigger.threshold <= 4> Primary Threshold is less than 4 </#if>, \n" +
            "<#if (trigger.secondaryThreshold == 7.1)> Secondary Threshold is 7.1 </#if>, \n" +
            "<#if trigger.inertia == 5 && (trigger.threshold > 5)> Inertia is 5, Primary Threshold more than 5 <#elseif  (trigger.threshold > 5)>Primary Threshold more than 5 <#elseif trigger.inertia == 5> Inertia is 5 </#if>, \n" +
            "<#if trigger.name?matches('trigger_name') && triggerValue < 2.0> Trigger name matches and trigger value is < 1 </#if>, \n" +
            "<#if triggerValue?round == 2> Trigger fired rounded value is 2 </#if>, \n" +
            "<#assign dt = triggerTimestamp?datetime> Trigger fired date-time: ${dt?iso('GMT')}, \n" +
            " Time before 2.5 hrs of firing: ${dt?iso('GMT-02:30')}";
    String expectedOutput = " Primary Threshold is less than 4 , \n" +
            " Secondary Threshold is 7.1 , \n" +
            " Inertia is 5 , \n" +
            " Trigger name matches and trigger value is < 1 , \n" +
            " Trigger fired rounded value is 2 , \n" +
            " Trigger fired date-time: 2014-12-11T17:40:00Z, \n" +
            " Time before 2.5 hrs of firing: 2014-12-11T15:10:00-02:30";
    assertEquals(expectedOutput, TemplateReplacer.applyTemplateChanges(context, customTemplate));
}