AlarmMessageFormatterTest.java 2.8 KB
Newer Older
wu-sheng's avatar
wu-sheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package org.apache.skywalking.oap.server.core.alarm.provider;

import org.apache.skywalking.oap.server.core.alarm.MetaInAlarm;
22 23
import org.junit.Assert;
import org.junit.Test;
wu-sheng's avatar
wu-sheng 已提交
24 25 26 27 28 29 30

public class AlarmMessageFormatterTest {
    @Test
    public void testStringFormatWithNoArg() {
        AlarmMessageFormatter formatter = new AlarmMessageFormatter("abc words {sdf");
        String message = formatter.format(new MetaInAlarm() {

31 32
            @Override
            public String getScope() {
33 34 35
                return "SERVICE";
            }

36 37
            @Override
            public int getScopeId() {
wu-sheng's avatar
wu-sheng 已提交
38
                return -1;
wu-sheng's avatar
wu-sheng 已提交
39 40
            }

41 42
            @Override
            public String getName() {
wu-sheng's avatar
wu-sheng 已提交
43 44 45
                return null;
            }

46 47
            @Override
            public String getMetricsName() {
wu-sheng's avatar
wu-sheng 已提交
48 49 50
                return null;
            }

51
            @Override
52 53
            public String getId0() {
                return "";
wu-sheng's avatar
wu-sheng 已提交
54 55
            }

56
            @Override
57 58
            public String getId1() {
                return "";
wu-sheng's avatar
wu-sheng 已提交
59 60 61 62 63 64 65 66 67 68 69
            }
        });

        Assert.assertEquals("abc words {sdf", message);
    }

    @Test
    public void testStringFormatWithArg() {
        AlarmMessageFormatter formatter = new AlarmMessageFormatter("abc} words {name} - {id} .. {");
        String message = formatter.format(new MetaInAlarm() {

70 71
            @Override
            public String getScope() {
72 73 74
                return "SERVICE";
            }

75 76
            @Override
            public int getScopeId() {
wu-sheng's avatar
wu-sheng 已提交
77
                return -1;
wu-sheng's avatar
wu-sheng 已提交
78 79
            }

80 81
            @Override
            public String getName() {
wu-sheng's avatar
wu-sheng 已提交
82 83 84
                return "service";
            }

85 86
            @Override
            public String getMetricsName() {
wu-sheng's avatar
wu-sheng 已提交
87 88 89
                return null;
            }

90
            @Override
91 92
            public String getId0() {
                return "1290";
wu-sheng's avatar
wu-sheng 已提交
93 94
            }

95
            @Override
96 97
            public String getId1() {
                return "";
wu-sheng's avatar
wu-sheng 已提交
98 99 100 101 102
            }
        });
        Assert.assertEquals("abc} words service - 1290 .. {", message);
    }
}