mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-01-26 20:21:33 +01:00
Add test to ensure full mapping of types in AbstractStorageBasedProvider (#4318)
Signed-off-by: Jan N. Klug <github@klug.nrw>
This commit is contained in:
parent
0a5886c7e7
commit
8557666f0a
@ -19,9 +19,14 @@ import java.net.URI;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
|
import org.junit.jupiter.params.provider.Arguments;
|
||||||
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
|
import org.openhab.core.internal.types.StateDescriptionFragmentImpl;
|
||||||
import org.openhab.core.thing.ThingTypeUID;
|
import org.openhab.core.thing.ThingTypeUID;
|
||||||
import org.openhab.core.thing.type.AutoUpdatePolicy;
|
import org.openhab.core.thing.type.AutoUpdatePolicy;
|
||||||
import org.openhab.core.thing.type.ChannelDefinition;
|
import org.openhab.core.thing.type.ChannelDefinition;
|
||||||
@ -158,6 +163,37 @@ public class AbstractStorageBasedTypeProviderTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MethodSource
|
||||||
|
@ParameterizedTest
|
||||||
|
public void testMapToEntityIsComplete(Class<?> originalType, Class<?> mappedType, int allowedDelta) {
|
||||||
|
Class<?> clazz = originalType;
|
||||||
|
int originalTypeFieldCount = 0;
|
||||||
|
while (clazz != Object.class) {
|
||||||
|
originalTypeFieldCount += clazz.getDeclaredFields().length;
|
||||||
|
clazz = clazz.getSuperclass();
|
||||||
|
}
|
||||||
|
|
||||||
|
int mappedEntityFieldCount = mappedType.getDeclaredFields().length;
|
||||||
|
|
||||||
|
assertThat(originalType.getName() + " not properly mapped", mappedEntityFieldCount,
|
||||||
|
is(originalTypeFieldCount + allowedDelta));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Stream<Arguments> testMapToEntityIsComplete() {
|
||||||
|
return Stream.of( //
|
||||||
|
// isBridge is an extra field for storage and not present in ThingType
|
||||||
|
Arguments.of(ThingType.class, AbstractStorageBasedTypeProvider.ThingTypeEntity.class, 1),
|
||||||
|
Arguments.of(ChannelType.class, AbstractStorageBasedTypeProvider.ChannelTypeEntity.class, 0),
|
||||||
|
Arguments.of(ChannelDefinition.class, AbstractStorageBasedTypeProvider.ChannelDefinitionEntity.class,
|
||||||
|
0),
|
||||||
|
// configDescriptionURI is not available for ChannelGroupType
|
||||||
|
Arguments.of(ChannelGroupType.class, AbstractStorageBasedTypeProvider.ChannelGroupTypeEntity.class, -1),
|
||||||
|
Arguments.of(ChannelGroupDefinition.class,
|
||||||
|
AbstractStorageBasedTypeProvider.ChannelGroupDefinitionEntity.class, 0),
|
||||||
|
Arguments.of(StateDescriptionFragmentImpl.class,
|
||||||
|
AbstractStorageBasedTypeProvider.StateDescriptionFragmentEntity.class, 0));
|
||||||
|
}
|
||||||
|
|
||||||
private void assertChannelDefinition(ChannelDefinition actual, ChannelDefinition expected) {
|
private void assertChannelDefinition(ChannelDefinition actual, ChannelDefinition expected) {
|
||||||
assertThat(actual.getId(), is(expected.getId()));
|
assertThat(actual.getId(), is(expected.getId()));
|
||||||
assertThat(actual.getChannelTypeUID(), is(expected.getChannelTypeUID()));
|
assertThat(actual.getChannelTypeUID(), is(expected.getChannelTypeUID()));
|
||||||
|
Loading…
Reference in New Issue
Block a user