|
19 | 19 | import java.util.List;
|
20 | 20 | import java.util.Map;
|
21 | 21 | import java.util.Objects;
|
| 22 | +import java.util.stream.Stream; |
22 | 23 |
|
23 | 24 | import org.eclipse.jdt.annotation.NonNullByDefault;
|
24 | 25 | 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; |
25 | 30 | import org.openhab.core.thing.ThingTypeUID;
|
26 | 31 | import org.openhab.core.thing.type.AutoUpdatePolicy;
|
27 | 32 | import org.openhab.core.thing.type.ChannelDefinition;
|
@@ -158,6 +163,37 @@ public void testThingTypeProperlyMappedToEntityAndBack() {
|
158 | 163 | }
|
159 | 164 | }
|
160 | 165 |
|
| 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 | + |
161 | 197 | private void assertChannelDefinition(ChannelDefinition actual, ChannelDefinition expected) {
|
162 | 198 | assertThat(actual.getId(), is(expected.getId()));
|
163 | 199 | assertThat(actual.getChannelTypeUID(), is(expected.getChannelTypeUID()));
|
|
0 commit comments