Skip to content

Commit

Permalink
Update the logging properties to opt-out of the prefix events ESAPI#844
Browse files Browse the repository at this point in the history
… seventh iteration
  • Loading branch information
mickeyz07 committed Jul 31, 2024
1 parent c9d5b78 commit 54a7463
Show file tree
Hide file tree
Showing 4 changed files with 454 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,7 @@ public Boolean getBooleanProp(String propertyName) throws ConfigurationException
@Override
public Boolean getBooleanProp(String propertyName, Boolean defaultValue) {
for (AbstractPrioritizedPropertyLoader loader : loaders) {
try {
return loader.getBooleanProp(propertyName);
} catch (ConfigurationException e) {
return defaultValue;
}
return loader.getBooleanProp(propertyName, defaultValue);
}
return defaultValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,46 @@ public void testBooleanPropFoundInLoader() {
assertEquals(expectedPropertyValue, propertyValue);
}


@Test
public void testBooleanPropFoundInLoaderWithDefaultValueTrue() {
// given
System.setProperty(EsapiConfiguration.DEVTEAM_ESAPI_CFG.getConfigName(), xmlFilename1);
String propertyKey = "boolean_property";
boolean expectedPropertyValue = true;

// when
try {
testPropertyManager = new EsapiPropertyManager();
} catch (IOException e) {
fail(e.getMessage());
}
boolean propertyValue = testPropertyManager.getBooleanProp(propertyKey, true);

// then
assertEquals(expectedPropertyValue, propertyValue);
}

@Test
public void testBooleanPropFoundInLoaderWithDefaultValueFalse() {
// given
System.setProperty(EsapiConfiguration.DEVTEAM_ESAPI_CFG.getConfigName(), xmlFilename1);
String propertyKey = "boolean_property";
boolean expectedPropertyValue = true;

// when
try {
testPropertyManager = new EsapiPropertyManager();
} catch (IOException e) {
fail(e.getMessage());
}
boolean propertyValue = testPropertyManager.getBooleanProp(propertyKey, false);

// then
assertEquals(expectedPropertyValue, propertyValue);
}


@Test(expected = ConfigurationException.class)
public void testBooleanPropertyNotFoundByLoaderAndThrowException() {
// given
Expand All @@ -304,6 +344,44 @@ public void testBooleanPropertyNotFoundByLoaderAndThrowException() {
// then expect exception
}

@Test
public void testBooleanPropertyNotFoundByLoaderWithDefaultValueTrue() {
// given
String propertyKey = "non.existing.property";
boolean expectedPropertyValue = true;

// when
try {
testPropertyManager = new EsapiPropertyManager();
} catch (IOException e) {
fail(e.getMessage());
}

boolean propertyValue = testPropertyManager.getBooleanProp(propertyKey, true);

// then
assertEquals(expectedPropertyValue, propertyValue);
}

@Test
public void testBooleanPropertyNotFoundByLoaderWithDefaultValueFalse() {
// given
String propertyKey = "non.existing.property";
boolean expectedPropertyValue = false;

// when
try {
testPropertyManager = new EsapiPropertyManager();
} catch (IOException e) {
fail(e.getMessage());
}

boolean propertyValue = testPropertyManager.getBooleanProp(propertyKey, false);

// then
assertEquals(expectedPropertyValue, propertyValue);
}

@Test
public void testByteArrayPropFoundInLoader() {
// given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,48 @@ public void testGetBooleanProp() {
assertEquals(expectedValue, value);
}

@Test
public void testGetBooleanPropWithDefaultValueTrue() {
// given
String filename = "src" + File.separator + "test" + File.separator + "resources" + File.separator +
"esapi" + File.separator + "ESAPI-test.properties";
int priority = 1;
String propertyKey = "boolean_property";
boolean expectedValue = true;

// when
try {
testPropertyLoader = new StandardEsapiPropertyLoader(filename, priority);
} catch ( IOException e ) {
fail( e.getMessage() );
}
boolean value = testPropertyLoader.getBooleanProp(propertyKey,true);

// then
assertEquals(expectedValue, value);
}

@Test
public void testGetBooleanPropWithDefaultValueFalse() {
// given
String filename = "src" + File.separator + "test" + File.separator + "resources" + File.separator +
"esapi" + File.separator + "ESAPI-test.properties";
int priority = 1;
String propertyKey = "boolean_property";
boolean expectedValue = true;

// when
try {
testPropertyLoader = new StandardEsapiPropertyLoader(filename, priority);
} catch ( IOException e ) {
fail( e.getMessage() );
}
boolean value = testPropertyLoader.getBooleanProp(propertyKey,false);

// then
assertEquals(expectedValue, value);
}

@Test
public void testGetBooleanYesProperty() {
// given
Expand All @@ -257,6 +299,42 @@ public void testGetBooleanYesProperty() {
assertEquals(expectedValue, value);
}

@Test
public void testGetBooleanYesPropertyWithDefaultValueTrue() {
// given
String key = "boolean_yes_property";
boolean expectedValue = true;

// when
try {
testPropertyLoader = new StandardEsapiPropertyLoader(filename, priority);
} catch ( IOException e ) {
fail( e.getMessage() );
}
boolean value = testPropertyLoader.getBooleanProp(key,true);

// then
assertEquals(expectedValue, value);
}

@Test
public void testGetBooleanYesPropertyWithDefaultValueFalse() {
// given
String key = "boolean_yes_property";
boolean expectedValue = true;

// when
try {
testPropertyLoader = new StandardEsapiPropertyLoader(filename, priority);
} catch ( IOException e ) {
fail( e.getMessage() );
}
boolean value = testPropertyLoader.getBooleanProp(key,false);

// then
assertEquals(expectedValue, value);
}

@Test
public void testGetBooleanNoProperty() {
// given
Expand All @@ -275,6 +353,42 @@ public void testGetBooleanNoProperty() {
assertEquals(expectedValue, value);
}

@Test
public void testGetBooleanNoPropertyWithDefaultValueTrue() {
// given
String key = "boolean_no_property";
boolean expectedValue = false;

// when
try {
testPropertyLoader = new StandardEsapiPropertyLoader(filename, priority);
} catch ( IOException e ) {
fail( e.getMessage() );
}
boolean value = testPropertyLoader.getBooleanProp(key, true);

// then
assertEquals(expectedValue, value);
}

@Test
public void testGetBooleanNoPropertyWithDefaultValueFalse() {
// given
String key = "boolean_no_property";
boolean expectedValue = false;

// when
try {
testPropertyLoader = new StandardEsapiPropertyLoader(filename, priority);
} catch ( IOException e ) {
fail( e.getMessage() );
}
boolean value = testPropertyLoader.getBooleanProp(key, false);

// then
assertEquals(expectedValue, value);
}

@Test(expected = ConfigurationException.class)
public void testBooleanPropertyNotFound() throws ConfigurationException {
// given
Expand All @@ -294,6 +408,48 @@ public void testBooleanPropertyNotFound() throws ConfigurationException {
// then expect exception
}

@Test
public void testBooleanPropertyNotFoundWithDefaultValueTrue() {
// given
String filename = "src" + File.separator + "test" + File.separator + "resources" + File.separator +
"esapi" + File.separator + "ESAPI-test.properties";
int priority = 1;
String propertyKey = "non-existing-key";
boolean expectedValue = true;

// when
try {
testPropertyLoader = new StandardEsapiPropertyLoader(filename, priority);
} catch ( IOException e ) {
fail( e.getMessage() );
}
boolean value = testPropertyLoader.getBooleanProp(propertyKey, true);

// then
assertEquals(expectedValue, value);
}

@Test
public void testBooleanPropertyNotFoundWithDefaultValueFalse() {
// given
String filename = "src" + File.separator + "test" + File.separator + "resources" + File.separator +
"esapi" + File.separator + "ESAPI-test.properties";
int priority = 1;
String propertyKey = "non-existing-key";
boolean expectedValue = false;

// when
try {
testPropertyLoader = new StandardEsapiPropertyLoader(filename, priority);
} catch ( IOException e ) {
fail( e.getMessage() );
}
boolean value = testPropertyLoader.getBooleanProp(propertyKey, false);

// then
assertEquals(expectedValue, value);
}

@Test(expected = ConfigurationException.class)
public void testIncorrectBooleanPropertyType() throws ConfigurationException {
// given
Expand All @@ -310,6 +466,42 @@ public void testIncorrectBooleanPropertyType() throws ConfigurationException {
// then expect exception
}

@Test
public void testIncorrectBooleanPropertyTypeWithDefaultValueTrue() {
// given
String key = "invalid_boolean_property";
boolean expectedValue = true;

// when
try {
testPropertyLoader = new StandardEsapiPropertyLoader(filename, priority);
} catch ( IOException e ) {
fail( e.getMessage() );
}
boolean value = testPropertyLoader.getBooleanProp(key, true);

// then
assertEquals(expectedValue, value);
}

@Test
public void testIncorrectBooleanPropertyTypeWithDefaultValueFalse() {
// given
String key = "invalid_boolean_property";
boolean expectedValue = false;

// when
try {
testPropertyLoader = new StandardEsapiPropertyLoader(filename, priority);
} catch ( IOException e ) {
fail( e.getMessage() );
}
boolean value = testPropertyLoader.getBooleanProp(key, false);

// then
assertEquals(expectedValue, value);
}

@Test
public void testGetByteArrayProp() {
// given
Expand Down
Loading

0 comments on commit 54a7463

Please sign in to comment.