Skip to content

Commit 8557666

Browse files
authored
Add test to ensure full mapping of types in AbstractStorageBasedProvider (#4318)
Signed-off-by: Jan N. Klug <[email protected]>
1 parent 0a5886c commit 8557666

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

Diff for: bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/binding/AbstractStorageBasedTypeProviderTest.java

+36
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,14 @@
1919
import java.util.List;
2020
import java.util.Map;
2121
import java.util.Objects;
22+
import java.util.stream.Stream;
2223

2324
import org.eclipse.jdt.annotation.NonNullByDefault;
2425
import org.junit.jupiter.api.Test;
26+
import org.junit.jupiter.params.ParameterizedTest;
27+
import org.junit.jupiter.params.provider.Arguments;
28+
import org.junit.jupiter.params.provider.MethodSource;
29+
import org.openhab.core.internal.types.StateDescriptionFragmentImpl;
2530
import org.openhab.core.thing.ThingTypeUID;
2631
import org.openhab.core.thing.type.AutoUpdatePolicy;
2732
import org.openhab.core.thing.type.ChannelDefinition;
@@ -158,6 +163,37 @@ public void testThingTypeProperlyMappedToEntityAndBack() {
158163
}
159164
}
160165

166+
@MethodSource
167+
@ParameterizedTest
168+
public void testMapToEntityIsComplete(Class<?> originalType, Class<?> mappedType, int allowedDelta) {
169+
Class<?> clazz = originalType;
170+
int originalTypeFieldCount = 0;
171+
while (clazz != Object.class) {
172+
originalTypeFieldCount += clazz.getDeclaredFields().length;
173+
clazz = clazz.getSuperclass();
174+
}
175+
176+
int mappedEntityFieldCount = mappedType.getDeclaredFields().length;
177+
178+
assertThat(originalType.getName() + " not properly mapped", mappedEntityFieldCount,
179+
is(originalTypeFieldCount + allowedDelta));
180+
}
181+
182+
private static Stream<Arguments> testMapToEntityIsComplete() {
183+
return Stream.of( //
184+
// isBridge is an extra field for storage and not present in ThingType
185+
Arguments.of(ThingType.class, AbstractStorageBasedTypeProvider.ThingTypeEntity.class, 1),
186+
Arguments.of(ChannelType.class, AbstractStorageBasedTypeProvider.ChannelTypeEntity.class, 0),
187+
Arguments.of(ChannelDefinition.class, AbstractStorageBasedTypeProvider.ChannelDefinitionEntity.class,
188+
0),
189+
// configDescriptionURI is not available for ChannelGroupType
190+
Arguments.of(ChannelGroupType.class, AbstractStorageBasedTypeProvider.ChannelGroupTypeEntity.class, -1),
191+
Arguments.of(ChannelGroupDefinition.class,
192+
AbstractStorageBasedTypeProvider.ChannelGroupDefinitionEntity.class, 0),
193+
Arguments.of(StateDescriptionFragmentImpl.class,
194+
AbstractStorageBasedTypeProvider.StateDescriptionFragmentEntity.class, 0));
195+
}
196+
161197
private void assertChannelDefinition(ChannelDefinition actual, ChannelDefinition expected) {
162198
assertThat(actual.getId(), is(expected.getId()));
163199
assertThat(actual.getChannelTypeUID(), is(expected.getChannelTypeUID()));

0 commit comments

Comments
 (0)