Skip to content

Commit

Permalink
Add check property
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaromudr committed Nov 16, 2017
1 parent 8063157 commit 49304e0
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-4.1-bin.zip
distributionUrl=https://services.gradle.org/distributions/gradle-4.2.1-bin.zip
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ru.colibri.ui.core.exception;

import static java.lang.String.format;

public class PropertyNotFoundException extends IllegalArgumentException {
public PropertyNotFoundException(String message) {
super(message);
}

public PropertyNotFoundException(String propertyName, String propertyPath) {
this(format("Property %s not found on file: %s", propertyName, propertyPath));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package ru.colibri.ui.settings.loaders;

import lombok.extern.java.Log;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.InitializingBean;
import ru.colibri.ui.core.exception.PropertyNotFoundException;
import ru.colibri.ui.core.settings.TestSettings;
import ru.colibri.ui.settings.general.PropertyUtils;

Expand Down Expand Up @@ -45,7 +47,11 @@ protected void takeArtifact(String from, String to) {
@Override
public TestSettings loadTestSettings(String testType) {
Properties props = PropertyUtils.readProperty(TEST_TYPE_FILTER);
List<String> testCycleFilters = asList(props.getProperty(testType).split(","));
String property = props.getProperty(testType);
if (StringUtils.isEmpty(property)) {
throw new PropertyNotFoundException(testType, TEST_TYPE_FILTER);
}
List<String> testCycleFilters = asList(property.split(","));
return TestSettings.builder()
.flagsMetaFilters(testCycleFilters)
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ru.colibri.ui.settings.loaders;

import ru.colibri.ui.core.settings.AppSettings;
import ru.colibri.ui.core.settings.DriversSettings;

public class AbsSettingsLoaderFake extends AbsSettingsLoader {
@Override
public AppSettings loadAppSettings(String userName) {
return null;
}

@Override
public DriversSettings loadDriverSettings(String platformName) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package ru.colibri.ui.settings.loaders;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import ru.colibri.ui.core.exception.PropertyNotFoundException;
import ru.colibri.ui.core.settings.TestSettings;

import static java.lang.String.format;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {SettingsLoaderConfig.class})
public class AbsSettingsLoaderTest {

private static final String TEST_TYPE_FILTER = "src/test/resources/planTestCycle/testCycle.properties";

@Autowired
private ISettingsLoader settingsLoader;

@Test
public void loadTestSettings() throws Exception {
TestSettings testSettings = settingsLoader.loadTestSettings("actual.property");
Assert.assertEquals(testSettings.getFlagsMetaFilters().size(), 2);
Assert.assertEquals(testSettings.getFlagsMetaFilters().get(0), "hello");
}


@Test(expected = PropertyNotFoundException.class)
public void loadTestSettingsBad() throws Exception {
settingsLoader.loadTestSettings("bad.property");
}

@Test
public void loadTestSettingsBadWithText() throws Exception {
String propertyName = "bad.property";
try {
settingsLoader.loadTestSettings(propertyName);
} catch (PropertyNotFoundException e) {
Assert.assertEquals(e.getMessage(), format("Property %s not found on file: %s", propertyName, TEST_TYPE_FILTER));
}
}

@Test(expected = IllegalArgumentException.class)
public void loadTestSettingsEmpty() throws Exception {
settingsLoader.loadTestSettings("empty.property");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package ru.colibri.ui.settings.loaders;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SettingsLoaderConfig {

@Bean
ISettingsLoader loader() {
return new AbsSettingsLoaderFake();
}

}
2 changes: 2 additions & 0 deletions src/test/resources/planTestCycle/testCycle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
actual.property=hello,world
bad.property=

0 comments on commit 49304e0

Please sign in to comment.