1 package org.onap.appc.util;
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertTrue;
6 import com.google.common.collect.Maps;
7 import java.util.HashMap;
11 import org.apache.commons.lang3.StringUtils;
12 import org.junit.Test;
14 public class MessageFormatterTest {
17 public void format_should_return_empty_string_when_given_null_or_empty_message_template() {
18 assertEquals(StringUtils.EMPTY, MessageFormatter.format(null, Maps.newHashMap()));
19 assertEquals(StringUtils.EMPTY, MessageFormatter.format(StringUtils.EMPTY, Maps.newHashMap()));
23 public void should_return_same_string_when_given_null_or_empty_params() {
24 String message = "message";
26 assertEquals(message, MessageFormatter.format(message, null));
27 assertEquals(message, MessageFormatter.format(message, Maps.newHashMap()));
31 public void should_return_same_string_when_given_non_dollar_string() {
34 Map<String, Object> respMsg = new HashMap<>();
35 respMsg.put("vnfid", "SYNC_NEW201");
37 assertEquals(msg, MessageFormatter.format(msg, respMsg));
42 public void should_replace_dollar_sign_statement_with_map_value() {
43 String message = "${vnfid} some sample text ${pnfid} additional sample text";
45 Map<String, Object> respMsg = new HashMap<>();
46 respMsg.put("vnfid", "SYNC_NEW201");
47 respMsg.put("pnfid", "TEST-ID");
49 assertEquals("SYNC_NEW201 some sample text TEST-ID additional sample text",
50 MessageFormatter.format(message, respMsg));
54 public void getParamsNamesList_should_return_null_when_given_null_or_empty_message_template() {
55 assertEquals(null, MessageFormatter.getParamsNamesList(null));
56 assertEquals(null, MessageFormatter.getParamsNamesList(StringUtils.EMPTY));
58 assertEquals(null, MessageFormatter.getParamsNamesSet(null));
59 assertEquals(null, MessageFormatter.getParamsNamesSet(StringUtils.EMPTY));
63 public void should_recognize_params_inside_message_string() {
64 String message = "${vnfid} some sample text ${pnfid} additional sample text";
66 List<String> resultList = MessageFormatter.getParamsNamesList(message);
68 assertEquals(2, resultList.size());
69 assertTrue(resultList.contains("vnfid"));
70 assertTrue(resultList.contains("pnfid"));
72 Set<String> resultSet = MessageFormatter.getParamsNamesSet(message);
74 assertEquals(2, resultList.size());
75 assertTrue(resultSet.contains("vnfid"));
76 assertTrue(resultSet.contains("pnfid"));