Search in sources :

Example 1 with InstrumentationTestConfig

use of com.newrelic.agent.introspec.InstrumentationTestConfig in project newrelic-java-agent by newrelic.

the class IntrospectorConfig method readConfig.

public static Map<String, Object> readConfig(Class<?> classUnderTest) throws Exception {
    Map<String, Object> config = new HashMap<>();
    for (Annotation annotation : classUnderTest.getAnnotations()) {
        if (annotation instanceof InstrumentationTestConfig) {
            String configPath = ((InstrumentationTestConfig) annotation).configName();
            if (!configPath.isEmpty()) {
                URL resource = IntrospectorConfig.class.getClassLoader().getResource(configPath);
                if (resource == null) {
                    throw new InitializationError("Unable to find config file " + configPath);
                }
                File configFile = new File(resource.toURI());
                return AgentConfigHelper.getConfigurationFileSettings(configFile);
            }
        }
    }
    return config;
}
Also used : HashMap(java.util.HashMap) InitializationError(org.junit.runners.model.InitializationError) InstrumentationTestConfig(com.newrelic.agent.introspec.InstrumentationTestConfig) File(java.io.File) Annotation(java.lang.annotation.Annotation) URL(java.net.URL)

Aggregations

InstrumentationTestConfig (com.newrelic.agent.introspec.InstrumentationTestConfig)1 File (java.io.File)1 Annotation (java.lang.annotation.Annotation)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 InitializationError (org.junit.runners.model.InitializationError)1