diff --git a/pom.xml b/pom.xml index dad5e55..5d6332d 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 com.testdroid testdroid-api - 3.16 + 3.17 jar Bitbar API v2 https://github.com/bitbar/testdroid-api @@ -23,6 +23,7 @@ 2.1.0 2.3.3 2.3.3 + 0.10.2 scm:git:git://github.com:bitbar/testdroid-api.git @@ -258,6 +259,11 @@ org.apache.logging.log4j log4j-slf4j-impl + + org.reflections + reflections + ${org.reflections.version} + org.junit.jupiter junit-jupiter-api diff --git a/src/main/java/com/testdroid/api/model/APIAdminDevice.java b/src/main/java/com/testdroid/api/model/APIAdminDevice.java index a3bd4d7..b824c37 100644 --- a/src/main/java/com/testdroid/api/model/APIAdminDevice.java +++ b/src/main/java/com/testdroid/api/model/APIAdminDevice.java @@ -80,7 +80,6 @@ public ComplexState compute(State state) { public ComplexState compute(SubState subState) { return MAP.get(Pair.of(state, subState)); } - } private APICluster cluster; diff --git a/src/main/java/com/testdroid/api/model/APIDeviceCleanupConfiguration.java b/src/main/java/com/testdroid/api/model/APIDeviceCleanupConfiguration.java index 1b51d5f..f00ba65 100644 --- a/src/main/java/com/testdroid/api/model/APIDeviceCleanupConfiguration.java +++ b/src/main/java/com/testdroid/api/model/APIDeviceCleanupConfiguration.java @@ -11,7 +11,7 @@ /** * @author Michał Szpruta */ -public class APIDeviceCleanupConfiguration extends APIEntity implements Cloneable { +public class APIDeviceCleanupConfiguration extends APIEntity { private String content; @@ -138,11 +138,6 @@ public void clone(T from) { this.discriminator = deviceCleanupConfiguration.discriminator; } - @Override - public APIDeviceCleanupConfiguration clone() throws CloneNotSupportedException { - return (APIDeviceCleanupConfiguration) super.clone(); - } - @Override public boolean equals(Object o) { if (this == o) { diff --git a/src/main/java/com/testdroid/api/util/TypeReferenceFactory.java b/src/main/java/com/testdroid/api/util/TypeReferenceFactory.java index 0b90e50..bb91a12 100644 --- a/src/main/java/com/testdroid/api/util/TypeReferenceFactory.java +++ b/src/main/java/com/testdroid/api/util/TypeReferenceFactory.java @@ -3,11 +3,15 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.testdroid.api.*; import com.testdroid.api.model.*; +import com.testdroid.api.model.capabilities.APIDesktopBrowser; import com.testdroid.api.model.capabilities.APIDesktopBrowserCapabilities; +import com.testdroid.api.model.capabilities.APIDesktopPlatform; import com.testdroid.api.model.devicetime.APIBasicDeviceTime; import com.testdroid.api.model.devicetime.APIDeviceTimeCountSessionReportEntry; +import com.testdroid.api.model.devicetime.APIDeviceTimeReportEntry; import com.testdroid.api.model.devicetime.APIDeviceTimeStepTimeReportEntry; import com.testdroid.api.model.notification.APINotification; +import com.testdroid.api.model.notification.APIVisualTestImage; import java.util.HashMap; import java.util.Map; @@ -28,60 +32,93 @@ private TypeReferenceFactory() { //@formatter:off LIST_MAP.put(APIAccessGroup.class, new TypeReference>() {}); LIST_MAP.put(APIAccount.class, new TypeReference>() {}); + LIST_MAP.put(APIAccountConcurrencyStatusMap.class, new TypeReference>() {}); + LIST_MAP.put(APIAccountPreference.class, new TypeReference>() {}); LIST_MAP.put(APIAccountService.class, new TypeReference>() {}); + LIST_MAP.put(APIAccountServicePayment.class, new TypeReference>() {}); LIST_MAP.put(APIActivity.class, new TypeReference>() {}); LIST_MAP.put(APIAdminDevice.class, new TypeReference>() {}); LIST_MAP.put(APIAdminDeviceModel.class, new TypeReference>() {}); LIST_MAP.put(APIAdminDeviceProblem.class, new TypeReference>() {}); + LIST_MAP.put(APIAdminDeviceProblemPair.class, new TypeReference>() {}); LIST_MAP.put(APIAdminDeviceSession.class, new TypeReference>() {}); + LIST_MAP.put(APIAdminDeviceSessionStatistics.class, new TypeReference>() {}); LIST_MAP.put(APIAdminDeviceType.class, new TypeReference>() {}); LIST_MAP.put(APIAdminEmail.class, new TypeReference>() {}); LIST_MAP.put(APIAdminError.class, new TypeReference>() {}); LIST_MAP.put(APIAdminFrameworkStatistics.class, new TypeReference>() {}); LIST_MAP.put(APIAdminInteractiveDeviceSession.class, new TypeReference>() {}); + LIST_MAP.put(APIAdminOverview.class, new TypeReference>() {}); LIST_MAP.put(APIAdminTestRun.class, new TypeReference>() {}); + LIST_MAP.put(APIBasicDeviceTime.class, new TypeReference>() {}); LIST_MAP.put(APIBillingPeriod.class, new TypeReference>() {}); LIST_MAP.put(APIBillingPeriodUsage.class, new TypeReference>() {}); + LIST_MAP.put(APIBrokerHub.class, new TypeReference>() {}); LIST_MAP.put(APIBrowser.class, new TypeReference>() {}); + LIST_MAP.put(APICloudInfo.class, new TypeReference>() {}); LIST_MAP.put(APICluster.class, new TypeReference>() {}); LIST_MAP.put(APICommand.class, new TypeReference>() {}); LIST_MAP.put(APIConnection.class, new TypeReference>() {}); + LIST_MAP.put(APIDesktopBrowser.class, new TypeReference>() {}); + LIST_MAP.put(APIDesktopBrowserCapabilities.class, new TypeReference>() {}); + LIST_MAP.put(APIDesktopPlatform.class, new TypeReference>() {}); LIST_MAP.put(APIDevice.class, new TypeReference>() {}); + LIST_MAP.put(APIDeviceAvailability.class, new TypeReference>() {}); LIST_MAP.put(APIDeviceCleanupConfiguration.class, new TypeReference>() {}); + LIST_MAP.put(APIDeviceFilter.class, new TypeReference>() {}); + LIST_MAP.put(APIDeviceFilterGroup.class, new TypeReference>() {}); LIST_MAP.put(APIDeviceGroup.class, new TypeReference>() {}); LIST_MAP.put(APIDeviceModelCriterion.class, new TypeReference>() {}); LIST_MAP.put(APIDeviceModelPool.class, new TypeReference>() {}); + LIST_MAP.put(APIDeviceModelPoolStatistics.class, new TypeReference>() {}); + LIST_MAP.put(APIDevicePicker.class, new TypeReference>() {}); LIST_MAP.put(APIDeviceProperty.class, new TypeReference>() {}); LIST_MAP.put(APIDeviceSession.class, new TypeReference>() {}); + LIST_MAP.put(APIDeviceSessionConfig.class, new TypeReference>() {}); + LIST_MAP.put(APIDeviceSessionDataAvailability.class, new TypeReference>() {}); LIST_MAP.put(APIDeviceSessionStep.class, new TypeReference>() {}); LIST_MAP.put(APIDeviceStatistic.class, new TypeReference>() {}); LIST_MAP.put(APIDeviceStatus.class, new TypeReference>() {}); LIST_MAP.put(APIDeviceTimeCountSessionReportEntry.class, new TypeReference>() {}); + LIST_MAP.put(APIDeviceTimeReportEntry.class, new TypeReference>() {}); LIST_MAP.put(APIDeviceTimeStepTimeReportEntry.class, new TypeReference>() {}); LIST_MAP.put(APIDeviceUsage.class, new TypeReference>() {}); LIST_MAP.put(APIEnum.class, new TypeReference>() {}); + LIST_MAP.put(APIFileConfig.class, new TypeReference>() {}); LIST_MAP.put(APIFramework.class, new TypeReference>() {}); + LIST_MAP.put(APIHealthCheck.class, new TypeReference>() {}); LIST_MAP.put(APILabelGroup.class, new TypeReference>() {}); LIST_MAP.put(APILicense.class, new TypeReference>() {}); + LIST_MAP.put(APIMaintenance.class, new TypeReference>() {}); LIST_MAP.put(APINotification.class, new TypeReference>() {}); LIST_MAP.put(APIProject.class, new TypeReference>() {}); LIST_MAP.put(APIProjectJobConfig.class, new TypeReference>() {}); LIST_MAP.put(APIProperty.class, new TypeReference>() {}); LIST_MAP.put(APIRole.class, new TypeReference>() {}); + LIST_MAP.put(APIS3Url.class, new TypeReference>() {}); LIST_MAP.put(APIScreenshot.class, new TypeReference>() {}); LIST_MAP.put(APIScreenshotExtended.class, new TypeReference>() {}); LIST_MAP.put(APIService.class, new TypeReference>() {}); LIST_MAP.put(APISharedResource.class, new TypeReference>() {}); + LIST_MAP.put(APISmartbearTunnel.class, new TypeReference>() {}); + LIST_MAP.put(APISoftwareVersion.class, new TypeReference>() {}); LIST_MAP.put(APITag.class, new TypeReference>() {}); LIST_MAP.put(APITestCaseRun.class, new TypeReference>() {}); + LIST_MAP.put(APITestCaseRunStep.class, new TypeReference>() {}); LIST_MAP.put(APITestRun.class, new TypeReference>() {}); + LIST_MAP.put(APITestRunConfig.class, new TypeReference>() {}); + LIST_MAP.put(APITestRunDataAvailability.class, new TypeReference>() {}); LIST_MAP.put(APITestRunParameter.class, new TypeReference>() {}); LIST_MAP.put(APIUser.class, new TypeReference>() {}); LIST_MAP.put(APIUserDeviceTime.class, new TypeReference>() {}); + LIST_MAP.put(APIUserDeviceTimeSummary.class, new TypeReference>() {}); LIST_MAP.put(APIUserFile.class, new TypeReference>() {}); LIST_MAP.put(APIUserFileProperty.class, new TypeReference>() {}); LIST_MAP.put(APIUserFileTag.class, new TypeReference>() {}); + LIST_MAP.put(APIUserPreference.class, new TypeReference>() {}); + LIST_MAP.put(APIUserStatistics.class, new TypeReference>() {}); LIST_MAP.put(APIVisualTestAccess.class, new TypeReference>() {}); + LIST_MAP.put(APIVisualTestImage.class, new TypeReference>() {}); //@formatter:on } @@ -117,6 +154,7 @@ private TypeReferenceFactory() { MAP.put(APICloudInfo.class, new TypeReference() {}); MAP.put(APICluster.class, new TypeReference() {}); MAP.put(APIConnection.class, new TypeReference() {}); + MAP.put(APIDesktopBrowser.class, new TypeReference() {}); MAP.put(APIDesktopBrowserCapabilities.class, new TypeReference() {}); MAP.put(APIDevice.class, new TypeReference() {}); MAP.put(APIDeviceCleanupConfiguration.class, new TypeReference() {}); diff --git a/src/test/java/com/testdroid/api/util/TypeReferenceFactoryTest.java b/src/test/java/com/testdroid/api/util/TypeReferenceFactoryTest.java new file mode 100644 index 0000000..a636c52 --- /dev/null +++ b/src/test/java/com/testdroid/api/util/TypeReferenceFactoryTest.java @@ -0,0 +1,158 @@ +package com.testdroid.api.util; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.testdroid.api.*; +import com.testdroid.api.model.*; +import com.testdroid.api.model.capabilities.APIDesktopBrowserCapabilities; +import com.testdroid.api.model.devicetime.APIBasicDeviceTime; +import com.testdroid.api.model.notification.APINotification; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.ArgumentsProvider; +import org.junit.jupiter.params.provider.ArgumentsSource; +import org.reflections.Reflections; + +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.stream.Stream; + +import static com.testdroid.cloud.test.categories.TestTags.UNIT; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + +/** + * @author Michał Szpruta + */ +@Tag(UNIT) +class TypeReferenceFactoryTest { + + static class ExplicitTypeProvider implements ArgumentsProvider { + + @Override + public Stream provideArguments(ExtensionContext context) { + Stream> stream = Stream.of(APIAccessGroup.class, + APIAccount.class, + APIAccountConcurrencyStatus.class, + APIAccountConcurrencyStatusMap.class, + APIAccountPreference.class, + APIAccountService.class, + APIAccountServicePayment.class, + APIAdminDevice.class, + APIAdminDeviceSessionStatistics.class, + APIAdminDeviceType.class, + APIAdminEmail.class, + APIAdminOverview.class, + APIAdminTestRun.class, + APIBasicDeviceTime.class, + APIBillingPeriod.class, + APIBillingPeriodUsage.class, + APIBrowser.class, + APICloudInfo.class, + APICluster.class, + APIConnection.class, + APIDesktopBrowserCapabilities.class, + APIDevice.class, + APIDeviceCleanupConfiguration.class, + APIDeviceGroup.class, + APIDeviceModelCriterion.class, + APIDeviceModelPool.class, + APIDeviceModelPoolStatistics.class, + APIDevicePicker.class, + APIDeviceProperty.class, + APIDeviceSession.class, + APIDeviceSessionStep.class, + APIExceptionMessage.class, + APIFramework.class, + APIHealthCheck.class, + APILabelGroup.class, + APILicense.class, + APIMaintenance.class, + APIMessage.class, + APINotification.class, + APIProject.class, + APIProjectJobConfig.class, + APIProperty.class, + APIRole.class, + APIS3Url.class, + APIService.class, + APIServicePaymentStatus.class, + APISharedResource.class, + APITag.class, + APITestRun.class, + APITestRunConfig.class, + APITestRunDataAvailability.class, + APITestRunParameter.class, + APIUser.class, + APIUserDeviceTimeSummary.class, + APIUserFile.class, + APIUserFileProperty.class, + APIUserPreference.class, + APIUserStatistics.class, + Properties.class, + String.class, + APIVisualTestAccess.class); + return stream.distinct().map(Arguments::of); + } + } + + static class APIEntitySubTypeProvider implements ArgumentsProvider { + + @Override + public Stream provideArguments(ExtensionContext context) { + Reflections reflections = new Reflections(APIEntity.class.getPackage().getName()); + Set> classes = reflections.getSubTypesOf(APIEntity.class); + return classes.stream() + .filter(c -> c != APIList.class) + .filter(c -> c != APISimpleList.class) + .map(Arguments::of); + } + } + + @Test + void testConstructor() { + assertThrows(IllegalAccessException.class, () -> TypeReferenceFactory.class.getDeclaredConstructor() + .newInstance()); + } + + @ArgumentsSource(ExplicitTypeProvider.class) + @ParameterizedTest + void testGetTypeRef(Class clazz) { + TypeReference result = TypeReferenceFactory.getTypeRef(clazz); + assertThat(result).isNotNull(); + assertThat(result.getType().getTypeName()).isEqualTo(clazz.getName()); + } + + @ArgumentsSource(APIEntitySubTypeProvider.class) + @ParameterizedTest + void testGetListTypeRef(Class clazz) { + TypeReference result = TypeReferenceFactory.getListTypeRef(clazz); + assertThat(result).withFailMessage(clazz.getSimpleName() + " not in the map").isNotNull(); + assertThat(result.getType().getTypeName()) + .isEqualTo(String.format("%s<%s>", APIList.class.getName(), clazz.getName())); + } + + @ArgumentsSource(APIEntitySubTypeProvider.class) + @ParameterizedTest + void testGetSimpleListTypeRef(Class clazz) { + TypeReference result = TypeReferenceFactory.getSimpleListTypeRef(clazz); + if (clazz == APIBrokerHub.class) { + assertThat(result).withFailMessage(clazz.getSimpleName() + " not in the map").isNotNull(); + assertThat(result.getType().getTypeName()) + .isEqualTo(String.format("%s<%s>", APISimpleList.class.getName(), clazz.getName())); + } else { + assertThat(result).isNull(); + } + } + + @Test + void testGetMapTypeReference() { + TypeReference result = TypeReferenceFactory.getMapTypeReference(); + assertThat(result).isNotNull(); + assertThat(result.getType().getTypeName()).isEqualTo( + String.format("%1$s<%2$s, %2$s>", Map.class.getName(), String.class.getName())); + } +}