PluginCfgTest.java 1.3 KB
Newer Older
1
package org.skywalking.apm.agent.core.plugin;
wu-sheng's avatar
wu-sheng 已提交
2 3 4 5 6 7 8

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.powermock.api.support.membermodification.MemberModifier;

P
pengys5 已提交
9 10 11 12 13
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

wu-sheng's avatar
wu-sheng 已提交
14 15 16 17 18 19
/**
 * Created by wusheng on 2017/2/27.
 */
public class PluginCfgTest {
    @Test
    public void testLoad() throws IOException {
20
        String data = "TestA=com.test.classA\r\nTestB=com.test.ClassB";
wu-sheng's avatar
wu-sheng 已提交
21 22 23 24 25 26 27 28 29 30 31 32 33
        final byte[] dataBytes = data.getBytes();
        PluginCfg.INSTANCE.load(new InputStream() {
            int index = 0;

            @Override
            public int read() throws IOException {
                if (index == dataBytes.length) {
                    return -1;
                }
                return dataBytes[index++];
            }
        });

34
        List<PluginDefine> list = PluginCfg.INSTANCE.getPluginClassList();
wu-sheng's avatar
wu-sheng 已提交
35
        Assert.assertEquals(2, list.size());
36 37
        Assert.assertEquals("com.test.classA", list.get(0).getDefineClass());
        Assert.assertEquals("com.test.ClassB", list.get(1).getDefineClass());
wu-sheng's avatar
wu-sheng 已提交
38 39 40 41 42 43 44 45
    }

    @Before
    @After
    public void clear() throws IllegalAccessException {
        MemberModifier.field(PluginCfg.class, "pluginClassList").set(PluginCfg.INSTANCE, new ArrayList<String>());
    }
}