| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.configuration.internal; |
| 21 |
|
|
| 22 |
|
import java.util.Arrays; |
| 23 |
|
import java.util.List; |
| 24 |
|
import java.util.Properties; |
| 25 |
|
|
| 26 |
|
import org.apache.commons.configuration.BaseConfiguration; |
| 27 |
|
import org.apache.commons.configuration.Configuration; |
| 28 |
|
import org.junit.Assert; |
| 29 |
|
import org.junit.Before; |
| 30 |
|
import org.junit.Test; |
| 31 |
|
import org.xwiki.component.util.ReflectionUtils; |
| 32 |
|
import org.xwiki.configuration.ConversionException; |
| 33 |
|
import org.xwiki.properties.ConverterManager; |
| 34 |
|
import org.xwiki.test.jmock.AbstractComponentTestCase; |
| 35 |
|
|
| 36 |
|
|
| 37 |
|
@link |
| 38 |
|
|
| 39 |
|
@version |
| 40 |
|
@since |
| 41 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (58) |
Complexity: 11 |
Complexity Density: 0.23 |
|
| 42 |
|
public class CommonsConfigurationSourceTest extends AbstractComponentTestCase |
| 43 |
|
{ |
| 44 |
|
private Configuration configuration; |
| 45 |
|
|
| 46 |
|
private CommonsConfigurationSource source; |
| 47 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
| 48 |
10 |
@Override... |
| 49 |
|
@Before |
| 50 |
|
public void setUp() throws Exception |
| 51 |
|
{ |
| 52 |
10 |
super.setUp(); |
| 53 |
|
|
| 54 |
10 |
this.source = new CommonsConfigurationSource(); |
| 55 |
10 |
ConverterManager converterManager = getComponentManager().getInstance(ConverterManager.class); |
| 56 |
10 |
ReflectionUtils.setFieldValue(source, "converterManager", converterManager); |
| 57 |
10 |
this.configuration = new BaseConfiguration(); |
| 58 |
10 |
this.source.setConfiguration(this.configuration); |
| 59 |
|
} |
| 60 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
| 61 |
1 |
@Test... |
| 62 |
|
public void testDefaultValue() |
| 63 |
|
{ |
| 64 |
1 |
configuration.setProperty("string", "value"); |
| 65 |
|
|
| 66 |
1 |
Assert.assertEquals("default", source.getProperty("unknown", "default")); |
| 67 |
1 |
Assert.assertEquals("value", source.getProperty("string", "default")); |
| 68 |
1 |
Assert.assertEquals(null, source.getProperty("unknown", (String) null)); |
| 69 |
|
} |
| 70 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
| 71 |
1 |
@Test... |
| 72 |
|
public void testStringProperty() |
| 73 |
|
{ |
| 74 |
1 |
configuration.setProperty("string", "value"); |
| 75 |
|
|
| 76 |
1 |
Assert.assertEquals("value", source.getProperty("string")); |
| 77 |
1 |
Assert.assertEquals("value", source.getProperty("string", String.class)); |
| 78 |
|
|
| 79 |
1 |
Assert.assertNull(source.getProperty("unknown")); |
| 80 |
1 |
Assert.assertNull(source.getProperty("unknown", String.class)); |
| 81 |
|
} |
| 82 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
| 83 |
1 |
@Test(expected = ConversionException.class)... |
| 84 |
|
public void testStringPropertyWhenConversionError() |
| 85 |
|
{ |
| 86 |
1 |
configuration.setProperty("string", "value"); |
| 87 |
|
|
| 88 |
|
|
| 89 |
1 |
source.getProperty("string", Boolean.class); |
| 90 |
|
} |
| 91 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
| 92 |
1 |
@Test(expected = ConversionException.class)... |
| 93 |
|
public void testBooleanPropertyWhenConversionError() |
| 94 |
|
{ |
| 95 |
1 |
configuration.setProperty("boolean", true); |
| 96 |
|
|
| 97 |
|
|
| 98 |
1 |
source.getProperty("boolean", String.class); |
| 99 |
|
} |
| 100 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
| 101 |
1 |
@Test... |
| 102 |
|
public void testBooleanProperty() |
| 103 |
|
{ |
| 104 |
|
|
| 105 |
1 |
configuration.setProperty("boolean", true); |
| 106 |
|
|
| 107 |
1 |
Assert.assertEquals(true, source.getProperty("boolean")); |
| 108 |
1 |
Assert.assertEquals(true, source.getProperty("boolean", Boolean.class)); |
| 109 |
1 |
Assert.assertEquals(true, source.getProperty("unknown", true)); |
| 110 |
1 |
Assert.assertEquals(false, source.getProperty("unknown", false)); |
| 111 |
|
} |
| 112 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
| 113 |
1 |
@Test... |
| 114 |
|
public void testUnknownBooleanProperty() |
| 115 |
|
{ |
| 116 |
1 |
Assert.assertNull(source.getProperty("unknown", Boolean.class)); |
| 117 |
|
} |
| 118 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
| 119 |
1 |
@Test... |
| 120 |
|
public void testListProperty() |
| 121 |
|
{ |
| 122 |
1 |
configuration.setProperty("list", "value1"); |
| 123 |
1 |
configuration.addProperty("list", "value2"); |
| 124 |
1 |
List<String> expected = Arrays.asList("value1", "value2"); |
| 125 |
|
|
| 126 |
1 |
Assert.assertEquals(expected, source.getProperty("list")); |
| 127 |
1 |
Assert.assertEquals(expected, source.getProperty("list", List.class)); |
| 128 |
|
|
| 129 |
1 |
Assert.assertTrue(source.getProperty("unknown", List.class).isEmpty()); |
| 130 |
1 |
Assert.assertEquals(Arrays.asList("toto"), source.getProperty("unknown", Arrays.asList("toto"))); |
| 131 |
|
} |
| 132 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
| 133 |
1 |
@Test... |
| 134 |
|
public void testListPropertyWhenArrayList() |
| 135 |
|
{ |
| 136 |
1 |
configuration.setProperty("list", "value"); |
| 137 |
1 |
List<String> expected = Arrays.asList("value"); |
| 138 |
|
|
| 139 |
1 |
Assert.assertEquals(expected, source.getProperty("list", Arrays.asList("default"))); |
| 140 |
|
} |
| 141 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
| 142 |
1 |
@Test... |
| 143 |
|
public void testPropertiesProperty() |
| 144 |
|
{ |
| 145 |
1 |
configuration.setProperty("properties", "key1=value1"); |
| 146 |
1 |
configuration.addProperty("properties", "key2=value2"); |
| 147 |
1 |
List<String> expectedList = Arrays.asList("key1=value1", "key2=value2"); |
| 148 |
1 |
Properties expectedProperties = new Properties(); |
| 149 |
1 |
expectedProperties.put("key1", "value1"); |
| 150 |
1 |
expectedProperties.put("key2", "value2"); |
| 151 |
|
|
| 152 |
1 |
Assert.assertEquals(expectedList, source.getProperty("properties")); |
| 153 |
1 |
Assert.assertEquals(expectedProperties, source.getProperty("properties", Properties.class)); |
| 154 |
|
|
| 155 |
1 |
Assert.assertTrue(source.getProperty("unknown", Properties.class).isEmpty()); |
| 156 |
|
} |
| 157 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
| 158 |
1 |
@Test... |
| 159 |
|
public void testIsEmpty() |
| 160 |
|
{ |
| 161 |
1 |
Assert.assertTrue(configuration.isEmpty()); |
| 162 |
|
|
| 163 |
1 |
configuration.addProperty("properties", "key2=value2"); |
| 164 |
|
|
| 165 |
1 |
Assert.assertFalse(configuration.isEmpty()); |
| 166 |
|
} |
| 167 |
|
} |