Skip to content

Commit

Permalink
Merge pull request #474 from szprutamich/master
Browse files Browse the repository at this point in the history
Version 3.17
  • Loading branch information
szprutamich authored Apr 4, 2023
2 parents 0b5a990 + e0a5b78 commit 781702e
Show file tree
Hide file tree
Showing 5 changed files with 204 additions and 8 deletions.
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.testdroid</groupId>
<artifactId>testdroid-api</artifactId>
<version>3.16</version>
<version>3.17</version>
<packaging>jar</packaging>
<name>Bitbar API v2</name>
<url>https://github.com/bitbar/testdroid-api</url>
Expand All @@ -23,6 +23,7 @@
<jakarta.activation.version>2.1.0</jakarta.activation.version>
<jakarta.bind.version>2.3.3</jakarta.bind.version>
<jaxb.version>2.3.3</jaxb.version>
<org.reflections.version>0.10.2</org.reflections.version>
</properties>
<scm>
<connection>scm:git:git://github.com:bitbar/testdroid-api.git</connection>
Expand Down Expand Up @@ -258,6 +259,11 @@
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
</dependency>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>${org.reflections.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/testdroid/api/model/APIAdminDevice.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public ComplexState compute(State state) {
public ComplexState compute(SubState subState) {
return MAP.get(Pair.of(state, subState));
}

}

private APICluster cluster;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* @author Michał Szpruta <[email protected]>
*/
public class APIDeviceCleanupConfiguration extends APIEntity implements Cloneable {
public class APIDeviceCleanupConfiguration extends APIEntity {

private String content;

Expand Down Expand Up @@ -138,11 +138,6 @@ public <T extends APIEntity> 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) {
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/com/testdroid/api/util/TypeReferenceFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,60 +32,93 @@ private TypeReferenceFactory() {
//@formatter:off
LIST_MAP.put(APIAccessGroup.class, new TypeReference<APIList<APIAccessGroup>>() {});
LIST_MAP.put(APIAccount.class, new TypeReference<APIList<APIAccount>>() {});
LIST_MAP.put(APIAccountConcurrencyStatusMap.class, new TypeReference<APIList<APIAccountConcurrencyStatusMap>>() {});
LIST_MAP.put(APIAccountPreference.class, new TypeReference<APIList<APIAccountPreference>>() {});
LIST_MAP.put(APIAccountService.class, new TypeReference<APIList<APIAccountService>>() {});
LIST_MAP.put(APIAccountServicePayment.class, new TypeReference<APIList<APIAccountServicePayment>>() {});
LIST_MAP.put(APIActivity.class, new TypeReference<APIList<APIActivity>>() {});
LIST_MAP.put(APIAdminDevice.class, new TypeReference<APIList<APIAdminDevice>>() {});
LIST_MAP.put(APIAdminDeviceModel.class, new TypeReference<APIList<APIAdminDeviceModel>>() {});
LIST_MAP.put(APIAdminDeviceProblem.class, new TypeReference<APIList<APIAdminDeviceProblem>>() {});
LIST_MAP.put(APIAdminDeviceProblemPair.class, new TypeReference<APIList<APIAdminDeviceProblemPair>>() {});
LIST_MAP.put(APIAdminDeviceSession.class, new TypeReference<APIList<APIAdminDeviceSession>>() {});
LIST_MAP.put(APIAdminDeviceSessionStatistics.class, new TypeReference<APIList<APIAdminDeviceSessionStatistics>>() {});
LIST_MAP.put(APIAdminDeviceType.class, new TypeReference<APIList<APIAdminDeviceType>>() {});
LIST_MAP.put(APIAdminEmail.class, new TypeReference<APIList<APIAdminEmail>>() {});
LIST_MAP.put(APIAdminError.class, new TypeReference<APIList<APIAdminError>>() {});
LIST_MAP.put(APIAdminFrameworkStatistics.class, new TypeReference<APIList<APIAdminFrameworkStatistics>>() {});
LIST_MAP.put(APIAdminInteractiveDeviceSession.class, new TypeReference<APIList<APIAdminInteractiveDeviceSession>>() {});
LIST_MAP.put(APIAdminOverview.class, new TypeReference<APIList<APIAdminOverview>>() {});
LIST_MAP.put(APIAdminTestRun.class, new TypeReference<APIList<APIAdminTestRun>>() {});
LIST_MAP.put(APIBasicDeviceTime.class, new TypeReference<APIList<APIBasicDeviceTime>>() {});
LIST_MAP.put(APIBillingPeriod.class, new TypeReference<APIList<APIBillingPeriod>>() {});
LIST_MAP.put(APIBillingPeriodUsage.class, new TypeReference<APIList<APIBillingPeriodUsage>>() {});
LIST_MAP.put(APIBrokerHub.class, new TypeReference<APIList<APIBrokerHub>>() {});
LIST_MAP.put(APIBrowser.class, new TypeReference<APIList<APIBrowser>>() {});
LIST_MAP.put(APICloudInfo.class, new TypeReference<APIList<APICloudInfo>>() {});
LIST_MAP.put(APICluster.class, new TypeReference<APIList<APICluster>>() {});
LIST_MAP.put(APICommand.class, new TypeReference<APIList<APICommand>>() {});
LIST_MAP.put(APIConnection.class, new TypeReference<APIList<APIConnection>>() {});
LIST_MAP.put(APIDesktopBrowser.class, new TypeReference<APIList<APIDesktopBrowser>>() {});
LIST_MAP.put(APIDesktopBrowserCapabilities.class, new TypeReference<APIList<APIDesktopBrowserCapabilities>>() {});
LIST_MAP.put(APIDesktopPlatform.class, new TypeReference<APIList<APIDesktopPlatform>>() {});
LIST_MAP.put(APIDevice.class, new TypeReference<APIList<APIDevice>>() {});
LIST_MAP.put(APIDeviceAvailability.class, new TypeReference<APIList<APIDeviceAvailability>>() {});
LIST_MAP.put(APIDeviceCleanupConfiguration.class, new TypeReference<APIList<APIDeviceCleanupConfiguration>>() {});
LIST_MAP.put(APIDeviceFilter.class, new TypeReference<APIList<APIDeviceFilter>>() {});
LIST_MAP.put(APIDeviceFilterGroup.class, new TypeReference<APIList<APIDeviceFilterGroup>>() {});
LIST_MAP.put(APIDeviceGroup.class, new TypeReference<APIList<APIDeviceGroup>>() {});
LIST_MAP.put(APIDeviceModelCriterion.class, new TypeReference<APIList<APIDeviceModelCriterion>>() {});
LIST_MAP.put(APIDeviceModelPool.class, new TypeReference<APIList<APIDeviceModelPool>>() {});
LIST_MAP.put(APIDeviceModelPoolStatistics.class, new TypeReference<APIList<APIDeviceModelPoolStatistics>>() {});
LIST_MAP.put(APIDevicePicker.class, new TypeReference<APIList<APIDevicePicker>>() {});
LIST_MAP.put(APIDeviceProperty.class, new TypeReference<APIList<APIDeviceProperty>>() {});
LIST_MAP.put(APIDeviceSession.class, new TypeReference<APIList<APIDeviceSession>>() {});
LIST_MAP.put(APIDeviceSessionConfig.class, new TypeReference<APIList<APIDeviceSessionConfig>>() {});
LIST_MAP.put(APIDeviceSessionDataAvailability.class, new TypeReference<APIList<APIDeviceSessionDataAvailability>>() {});
LIST_MAP.put(APIDeviceSessionStep.class, new TypeReference<APIList<APIDeviceSessionStep>>() {});
LIST_MAP.put(APIDeviceStatistic.class, new TypeReference<APIList<APIDeviceStatistic>>() {});
LIST_MAP.put(APIDeviceStatus.class, new TypeReference<APIList<APIDeviceStatus>>() {});
LIST_MAP.put(APIDeviceTimeCountSessionReportEntry.class, new TypeReference<APIList<APIDeviceTimeCountSessionReportEntry>>() {});
LIST_MAP.put(APIDeviceTimeReportEntry.class, new TypeReference<APIList<APIDeviceTimeReportEntry>>() {});
LIST_MAP.put(APIDeviceTimeStepTimeReportEntry.class, new TypeReference<APIList<APIDeviceTimeStepTimeReportEntry>>() {});
LIST_MAP.put(APIDeviceUsage.class, new TypeReference<APIList<APIDeviceUsage>>() {});
LIST_MAP.put(APIEnum.class, new TypeReference<APIList<APIEnum>>() {});
LIST_MAP.put(APIFileConfig.class, new TypeReference<APIList<APIFileConfig>>() {});
LIST_MAP.put(APIFramework.class, new TypeReference<APIList<APIFramework>>() {});
LIST_MAP.put(APIHealthCheck.class, new TypeReference<APIList<APIHealthCheck>>() {});
LIST_MAP.put(APILabelGroup.class, new TypeReference<APIList<APILabelGroup>>() {});
LIST_MAP.put(APILicense.class, new TypeReference<APIList<APILicense>>() {});
LIST_MAP.put(APIMaintenance.class, new TypeReference<APIList<APIMaintenance>>() {});
LIST_MAP.put(APINotification.class, new TypeReference<APIList<APINotification>>() {});
LIST_MAP.put(APIProject.class, new TypeReference<APIList<APIProject>>() {});
LIST_MAP.put(APIProjectJobConfig.class, new TypeReference<APIList<APIProjectJobConfig>>() {});
LIST_MAP.put(APIProperty.class, new TypeReference<APIList<APIProperty>>() {});
LIST_MAP.put(APIRole.class, new TypeReference<APIList<APIRole>>() {});
LIST_MAP.put(APIS3Url.class, new TypeReference<APIList<APIS3Url>>() {});
LIST_MAP.put(APIScreenshot.class, new TypeReference<APIList<APIScreenshot>>() {});
LIST_MAP.put(APIScreenshotExtended.class, new TypeReference<APIList<APIScreenshotExtended>>() {});
LIST_MAP.put(APIService.class, new TypeReference<APIList<APIService>>() {});
LIST_MAP.put(APISharedResource.class, new TypeReference<APIList<APISharedResource>>() {});
LIST_MAP.put(APISmartbearTunnel.class, new TypeReference<APIList<APISmartbearTunnel>>() {});
LIST_MAP.put(APISoftwareVersion.class, new TypeReference<APIList<APISoftwareVersion>>() {});
LIST_MAP.put(APITag.class, new TypeReference<APIList<APITag>>() {});
LIST_MAP.put(APITestCaseRun.class, new TypeReference<APIList<APITestCaseRun>>() {});
LIST_MAP.put(APITestCaseRunStep.class, new TypeReference<APIList<APITestCaseRunStep>>() {});
LIST_MAP.put(APITestRun.class, new TypeReference<APIList<APITestRun>>() {});
LIST_MAP.put(APITestRunConfig.class, new TypeReference<APIList<APITestRunConfig>>() {});
LIST_MAP.put(APITestRunDataAvailability.class, new TypeReference<APIList<APITestRunDataAvailability>>() {});
LIST_MAP.put(APITestRunParameter.class, new TypeReference<APIList<APITestRunParameter>>() {});
LIST_MAP.put(APIUser.class, new TypeReference<APIList<APIUser>>() {});
LIST_MAP.put(APIUserDeviceTime.class, new TypeReference<APIList<APIUserDeviceTime>>() {});
LIST_MAP.put(APIUserDeviceTimeSummary.class, new TypeReference<APIList<APIUserDeviceTimeSummary>>() {});
LIST_MAP.put(APIUserFile.class, new TypeReference<APIList<APIUserFile>>() {});
LIST_MAP.put(APIUserFileProperty.class, new TypeReference<APIList<APIUserFileProperty>>() {});
LIST_MAP.put(APIUserFileTag.class, new TypeReference<APIList<APIUserFileTag>>() {});
LIST_MAP.put(APIUserPreference.class, new TypeReference<APIList<APIUserPreference>>() {});
LIST_MAP.put(APIUserStatistics.class, new TypeReference<APIList<APIUserStatistics>>() {});
LIST_MAP.put(APIVisualTestAccess.class, new TypeReference<APIList<APIVisualTestAccess>>() {});
LIST_MAP.put(APIVisualTestImage.class, new TypeReference<APIList<APIVisualTestImage>>() {});
//@formatter:on
}

Expand Down Expand Up @@ -117,6 +154,7 @@ private TypeReferenceFactory() {
MAP.put(APICloudInfo.class, new TypeReference<APICloudInfo>() {});
MAP.put(APICluster.class, new TypeReference<APICluster>() {});
MAP.put(APIConnection.class, new TypeReference<APIConnection>() {});
MAP.put(APIDesktopBrowser.class, new TypeReference<APIDesktopBrowser>() {});
MAP.put(APIDesktopBrowserCapabilities.class, new TypeReference<APIDesktopBrowserCapabilities>() {});
MAP.put(APIDevice.class, new TypeReference<APIDevice>() {});
MAP.put(APIDeviceCleanupConfiguration.class, new TypeReference<APIDeviceCleanupConfiguration>() {});
Expand Down
158 changes: 158 additions & 0 deletions src/test/java/com/testdroid/api/util/TypeReferenceFactoryTest.java
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
*/
@Tag(UNIT)
class TypeReferenceFactoryTest {

static class ExplicitTypeProvider implements ArgumentsProvider {

@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
Stream<Class<?>> 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<? extends Arguments> provideArguments(ExtensionContext context) {
Reflections reflections = new Reflections(APIEntity.class.getPackage().getName());
Set<Class<? extends APIEntity>> 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
<T extends APIEntity> void testGetListTypeRef(Class<T> 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
<T extends APIEntity> void testGetSimpleListTypeRef(Class<T> 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()));
}
}

0 comments on commit 781702e

Please sign in to comment.