Загрузка файла свойств diff в Guice Injection Throws Error - PullRequest
1 голос
/ 25 февраля 2020

Я пытаюсь загрузить другие файлы свойств. На основании вариантов тестирования. Ниже выдается ошибка, когда имя свойства обновляется и загружается. Пожалуйста, найдите полный журнал трассировки для справки

com.google.common.util.concurrent.UncheckedExecutionException: java.lang.IllegalArgumentException
    at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2217)
    at com.google.common.cache.LocalCache.get(LocalCache.java:4154)
    at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:4158)
    at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:5147)
    at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:5153)
    at com.google.inject.internal.util.StackTraceElements.forMember(StackTraceElements.java:71)
    at com.google.inject.internal.Messages.formatParameter(Messages.java:282)
    at com.google.inject.internal.Messages.formatInjectionPoint(Messages.java:273)
    at com.google.inject.internal.Messages.formatSource(Messages.java:229)
    at com.google.inject.internal.Messages.formatSource(Messages.java:220)
    at com.google.inject.internal.Messages.formatMessages(Messages.java:90)
    at com.google.inject.ConfigurationException.getMessage(ConfigurationException.java:73)
    at org.testng.internal.ConfigInvoker.handleConfigurationFailure(ConfigInvoker.java:423)
    at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:300)
    at org.testng.TestRunner.invokeTestConfigurations(TestRunner.java:623)
    at org.testng.TestRunner.beforeRun(TestRunner.java:613)
    at org.testng.TestRunner.run(TestRunner.java:584)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:402)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:396)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:355)
    at org.testng.SuiteRunner.run(SuiteRunner.java:304)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1180)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1102)
    at org.testng.TestNG.runSuites(TestNG.java:1032)
    at org.testng.TestNG.run(TestNG.java:1000)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Caused by: java.lang.IllegalArgumentException
    at com.google.inject.internal.asm.$ClassReader.<init>(ClassReader.java:160)
    at com.google.inject.internal.asm.$ClassReader.<init>(ClassReader.java:143)
    at com.google.inject.internal.asm.$ClassReader.<init>(ClassReader.java:418)
    at com.google.inject.internal.util.LineNumbers.<init>(LineNumbers.java:64)
    at com.google.inject.internal.util.StackTraceElements$1.load(StackTraceElements.java:49)
    at com.google.inject.internal.util.StackTraceElements$1.load(StackTraceElements.java:45)
    at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3716)
    at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2424)
    at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2298)
    at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2211)
    ... 29 more

Initiallize значение свойства из базового теста. Использование testng xml

public class Invoke {
    public static String env;

    static PropertiesModule propertiesModule=new PropertiesModule();
    public static void initializeVariables(String envType) throws IOException, IllegalAccessException {
        //initialize the variables only for the first time
        if (env == null) {
            if (envType != null)
                env = envType + ".properties";
            else
                env = "local.properties";
            if (!new File(env).exists())
                env = "/src/properties/" + env;
            propertiesModule.configure(env);
        }
    }
}

Загрузить файл свойств с помощью PropertiesModule

public class PropertiesModule extends AbstractModule {

    public static String env1;
    protected void configure(String env) {
        System.out.println("PropertiesModule is done"+env);
        env1 = env;

    }
    @Override
    protected void configure() {
        try {
            System.out.println("PropertiesModule is done"+env1);
            Properties props = new Properties();
            System.out.println("PropertiesModule is done");
            props.load(new FileInputStream(System.getProperty("user.dir")+env1));
            Names.bindProperties(binder(), props);
        } catch (IOException e) {
            e.printStackTrace();
            Assert.fail("Property File Not Loaded!");
        }

    }

Когда я запускаю с другим значением свойства. Я получаю указанное выше исключение.

Базовый класс

    @BeforeSuite(alwaysRun = true)
    @Parameters({"environment"})
    public void setUp(@Optional("local") String environment) throws ClassNotFoundException, SQLException, IOException, IllegalAccessException {
        Invoke.initializeVariables(environment);
    }

    @BeforeTest
    public void setup() throws Exception, DriverNotInitializedException {
        initBrowserAndNavigate();

    }

Пожалуйста, найдите фрагмент кода выше.

...