|
4 | 4 |
|
5 | 5 | import org.firebirdsql.common.FBTestProperties; |
6 | 6 | import org.firebirdsql.gds.impl.GDSServerVersion; |
| 7 | +import org.firebirdsql.gds.ng.WireCrypt; |
7 | 8 | import org.firebirdsql.jaybird.props.PropertyConstants; |
8 | 9 | import org.firebirdsql.jaybird.props.PropertyNames; |
9 | 10 | import org.firebirdsql.util.FirebirdSupportInfo; |
10 | 11 | import org.junit.jupiter.params.ParameterizedTest; |
11 | 12 | import org.junit.jupiter.params.provider.Arguments; |
12 | 13 | import org.junit.jupiter.params.provider.MethodSource; |
13 | 14 |
|
| 15 | +import java.beans.BeanInfo; |
| 16 | +import java.beans.IntrospectionException; |
| 17 | +import java.beans.Introspector; |
| 18 | +import java.beans.PropertyDescriptor; |
| 19 | +import java.lang.reflect.Method; |
14 | 20 | import java.util.ArrayList; |
15 | 21 | import java.util.List; |
16 | 22 | import java.util.Locale; |
| 23 | +import java.util.Set; |
17 | 24 | import java.util.stream.Stream; |
18 | 25 |
|
19 | 26 | import static org.firebirdsql.common.FBTestProperties.DB_SERVER_PORT; |
20 | 27 | import static org.firebirdsql.common.FBTestProperties.DB_SERVER_URL; |
21 | | -import static org.firebirdsql.common.FBTestProperties.ENABLE_PROTOCOL; |
22 | 28 | import static org.firebirdsql.common.FBTestProperties.GDS_TYPE; |
23 | 29 | import static org.firebirdsql.common.FBTestProperties.configureServiceManager; |
24 | 30 | import static org.firebirdsql.common.FBTestProperties.getDefaultSupportInfo; |
|
31 | 37 | import static org.hamcrest.core.IsEqual.equalTo; |
32 | 38 | import static org.hamcrest.core.IsNot.not; |
33 | 39 | import static org.hamcrest.core.IsNull.notNullValue; |
| 40 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
34 | 41 |
|
35 | 42 | /** |
36 | 43 | * Tests for {@link org.firebirdsql.management.FBServiceManager}. |
@@ -139,4 +146,44 @@ static Stream<Arguments> testGetServerVersion() { |
139 | 146 | private static boolean isWindowsSystem() { |
140 | 147 | return System.getProperty("os.name").toLowerCase(Locale.ROOT).contains("win"); |
141 | 148 | } |
| 149 | + |
| 150 | + @ParameterizedTest |
| 151 | + @MethodSource |
| 152 | + void testBeanProperties(PropertyDescriptor beanProperty) throws Exception { |
| 153 | + var serviceManager = new FBServiceManager(FBTestProperties.getGdsType()); |
| 154 | + Method readMethod = beanProperty.getReadMethod(); |
| 155 | + final Object originalValue = readMethod.invoke(serviceManager); |
| 156 | + |
| 157 | + final Object testValue = generateTestValue(beanProperty, originalValue); |
| 158 | + Method writeMethod = beanProperty.getWriteMethod(); |
| 159 | + writeMethod.invoke(serviceManager, testValue); |
| 160 | + |
| 161 | + assertEquals(testValue, readMethod.invoke(serviceManager), |
| 162 | + "Unexpected value read back from property " + beanProperty.getName()); |
| 163 | + } |
| 164 | + |
| 165 | + static Stream<Arguments> testBeanProperties() throws IntrospectionException { |
| 166 | + final var excludedProperties = Set.of("type", "logger", "serverVersion"); |
| 167 | + BeanInfo serviceManagerBeanInfo = Introspector.getBeanInfo(FBServiceManager.class, Object.class); |
| 168 | + return Stream.of(serviceManagerBeanInfo.getPropertyDescriptors()) |
| 169 | + .filter(property -> !excludedProperties.contains(property.getName())) |
| 170 | + .map(Arguments::of); |
| 171 | + } |
| 172 | + |
| 173 | + private static Object generateTestValue(PropertyDescriptor beanProperty, Object originalValue) { |
| 174 | + String propertyName = beanProperty.getName(); |
| 175 | + if ("wireCrypt".equals(propertyName)) { |
| 176 | + return "ENABLED".equals(originalValue) ? "DISABLED" : "ENABLED"; |
| 177 | + } |
| 178 | + return switch (beanProperty.getPropertyType().getName()) { |
| 179 | + case "java.lang.String" -> "testValue " + propertyName; |
| 180 | + case "boolean", "java.lang.Boolean" -> originalValue == null || !((boolean) originalValue); |
| 181 | + case "int", "java.lang.Integer" -> originalValue == null ? 1 : ((int) originalValue) + 1; |
| 182 | + case "org.firebirdsql.gds.ng.WireCrypt" -> |
| 183 | + originalValue == WireCrypt.ENABLED ? WireCrypt.DISABLED : WireCrypt.ENABLED; |
| 184 | + default -> throw new IllegalStateException("Property: %s has unsupported type: %s" |
| 185 | + .formatted(propertyName, beanProperty.getPropertyType())); |
| 186 | + }; |
| 187 | + } |
| 188 | + |
142 | 189 | } |
0 commit comments