@Test
public void testObjectTemplateReplacement() {

    UserService userService = system.getServiceFactory().getUserService();
    Alert alert = new Alert(userService.findAdminUser(), userService.findAdminUser(), "alert_name-${mETRIc}", expression, "* * * * *");
    Notification notification = new Notification("notification_name-${tag.tAg}", alert, "notifier_name", new ArrayList<String>(), 23);
    Trigger trigger = new Trigger(alert, Trigger.TriggerType.GREATER_THAN_OR_EQ, "${sCopE}-trigger_name", 2D, 7D,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, 0.0, m, history);
    String customTemplate = "Alert Name = ${alert.name?upper_case}, \n" +
            "Alert Expression = ${alert.expression}, \n" +
            "Alert cronEntry = ${alert.cronEntry}, \n" +
            "Alert enabled = ${alert.enabled?then('alert enabled', 'alert not enabled')}, \n" +
            "Alert Expression = ${alert.expression}, \n" +
            "Trigger Name = ${trigger.name}, \n" +
            "Trigger type = ${trigger.type}, \n" +
            "Trigger threshold = ${trigger.threshold}, \n" +
            "Trigger secondaryThreshold = ${trigger.secondaryThreshold}, \n" +
            "Trigger Inertia = ${trigger.inertia}, \n" +
            "Trigger Value = ${triggerValue}, \n" +
            "Trigger Timestamp = ${triggerTimestamp?datetime?iso('GMT')}, \n" +
            "Notification Name = ${notification.name?cap_first}, \n" +
            "Notification cooldownPeriod = ${notification.cooldownPeriod}, \n" +
            "Notification SRActionable = ${notification.SRActionable?then('SR Actionable','Not SR Actionable')}, \n" +
            "Notification severityLevel = ${notification.severityLevel}";
    String expectedOutput = "Alert Name = ALERT_NAME-metric, \n" +
            "Alert Expression = DIVIDE(-1h:argus.jvm:file.descriptor.open{host=unknown-host}:avg, -1h:argus.jvm:file.descriptor.max{host=unknown-host}:avg), \n" +
            "Alert cronEntry = * * * * *, \n" +
            "Alert enabled = alert not enabled, \n" +
            "Alert Expression = DIVIDE(-1h:argus.jvm:file.descriptor.open{host=unknown-host}:avg, -1h:argus.jvm:file.descriptor.max{host=unknown-host}:avg), \n" +
            "Trigger Name = scope-trigger_name, \n" +
            "Trigger type = GREATER_THAN_OR_EQ, \n" +
            "Trigger threshold = 2, \n" +
            "Trigger secondaryThreshold = 7, \n" +
            "Trigger Inertia = 5, \n" +
            "Trigger Value = 0, \n" +
            "Trigger Timestamp = 2014-12-11T17:40:00Z, \n" +
            "Notification Name = Notification_name-val, \n" +
            "Notification cooldownPeriod = 23, \n" +
            "Notification SRActionable = Not SR Actionable, \n" +
            "Notification severityLevel = 5";
    assertEquals(expectedOutput, TemplateReplacer.applyTemplateChanges(context, customTemplate));
}