From b20b24d6deb6e48770b56124ee1df18d4cf27ef6 Mon Sep 17 00:00:00 2001 From: "michal.szpruta" Date: Tue, 25 Sep 2018 18:14:10 +0200 Subject: [PATCH] Version 2.65 --- pom.xml | 2 +- .../java/com/testdroid/api/APIEntity.java | 2 +- src/main/java/com/testdroid/api/APIList.java | 21 +-- .../com/testdroid/api/APIListResource.java | 4 +- .../java/com/testdroid/api/dto/Context.java | 9 +- .../testdroid/api/model/APIAdminDevice.java | 88 +++++++++--- .../api/model/APIAdminDeviceEvent.java | 20 +-- .../api/model/APIAdminDeviceProblemPair.java | 1 + .../testdroid/api/model/APIDeviceStatus.java | 8 +- .../api/model/APIDeviceTimeEntry.java | 125 ------------------ .../testdroid/api/model/APILabelGroup.java | 4 +- .../api/model/APIUserDeviceTime.java | 124 +++++++++-------- .../api/model/APIUserDeviceTimeSummary.java | 100 ++++++++++++++ .../api/model/build/APIBuildResultConfig.java | 2 +- .../api/model/build/APIPipelineBuild.java | 15 ++- .../api/util/TypeReferenceFactory.java | 4 +- .../cloud/test/categories/TestTags.java | 1 + .../dao/repository/dto/MappingKey.java | 2 - .../java/com/testdroid/api/APIListTest.java | 118 +++++++++++++++++ 19 files changed, 408 insertions(+), 242 deletions(-) delete mode 100644 src/main/java/com/testdroid/api/model/APIDeviceTimeEntry.java create mode 100644 src/main/java/com/testdroid/api/model/APIUserDeviceTimeSummary.java create mode 100644 src/test/java/com/testdroid/api/APIListTest.java diff --git a/pom.xml b/pom.xml index 411f65d4..abd17742 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.testdroid testdroid-api - 2.64 + 2.65 jar Testdroid API v2 https://github.com/bitbar/testdroid-api diff --git a/src/main/java/com/testdroid/api/APIEntity.java b/src/main/java/com/testdroid/api/APIEntity.java index 727a0636..5ebba807 100644 --- a/src/main/java/com/testdroid/api/APIEntity.java +++ b/src/main/java/com/testdroid/api/APIEntity.java @@ -69,7 +69,6 @@ APIDeviceSessionStep.class, APIDeviceStatus.class, APIDeviceTimeCountSessionReportEntry.class, - APIDeviceTimeEntry.class, APIDeviceUsage.class, APIEnum.class, APIExceptionMessage.class, @@ -108,6 +107,7 @@ APITestRunParameter.class, APIUser.class, APIUserDeviceTime.class, + APIUserDeviceTimeSummary.class, APIUserFile.class, APIUserFileProperty.class, APIUserFileTag.class, diff --git a/src/main/java/com/testdroid/api/APIList.java b/src/main/java/com/testdroid/api/APIList.java index 21c69dd7..cd981cee 100644 --- a/src/main/java/com/testdroid/api/APIList.java +++ b/src/main/java/com/testdroid/api/APIList.java @@ -1,9 +1,10 @@ package com.testdroid.api; - import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; import com.testdroid.api.dto.Context; +import com.testdroid.api.filter.FilterEntry; import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; @@ -12,6 +13,7 @@ import java.util.List; import static com.testdroid.api.dto.Context.*; +import static java.util.stream.Collectors.joining; /** * @author Łukasz Kajda @@ -58,17 +60,19 @@ public APIList(String requestURL, List data, Integer total, Context ctx) { this.sort = sort; this.data = data; this.context = ctx; + String filter = ctx.getFilters().stream().map(FilterEntry::toString).collect(joining(FILTER_DELIMITER)); if (offset + limit < total) { - this.next = getListURL(requestURL, offset + limit, limit, search, sort); + this.next = getListURL(requestURL, offset + limit, limit, search, sort, filter); } if (offset - limit >= 0) { - this.previous = getListURL(requestURL, offset - limit, limit, search, sort); + this.previous = getListURL(requestURL, offset - limit, limit, search, sort, filter); } } - private String getListURL(String requestURL, long offset, long limit, String search, String sort) { - return String.format("%s?%s=%s&%s=%s&%s=%s&%s=%s", requestURL, OFFSET_REQUEST_PARAM, offset, - LIMIT_REQUEST_PARAM, limit, SEARCH_REQUEST_PARAM, search, SORT_REQUEST_PARAM, sort); + private String getListURL(String requestURL, long offset, long limit, String search, String sort, String filter) { + return String.format("%s?%s=%s&%s=%s&%s=%s&%s=%s&%s=%s", requestURL, OFFSET_REQUEST_PARAM, offset, + LIMIT_REQUEST_PARAM, limit, SEARCH_REQUEST_PARAM, search, SORT_REQUEST_PARAM, sort, + FILTER_REQUEST_PARAM, filter); } /** @@ -96,7 +100,7 @@ public APIList getNextItems() throws APIException { if (!isNextAvailable()) { return null; } - return new APIListResource(client, selfURI, context.setOffset(offset + limit)).getEntity(); + return new APIListResource<>(client, selfURI, context.setOffset(offset + limit)).getEntity(); } /** @@ -112,7 +116,7 @@ public APIList getPreviousItems() throws APIException { if (!isPreviousAvailable()) { return null; } - return new APIListResource(client, selfURI, context.setOffset(offset - limit)).getEntity(); + return new APIListResource<>(client, selfURI, context.setOffset(offset - limit)).getEntity(); } /** @@ -145,6 +149,7 @@ public T get(int index) { return this.data.get(index); } + @JsonProperty(access = JsonProperty.Access.READ_ONLY) public boolean isEmpty() { return this.data.isEmpty(); } diff --git a/src/main/java/com/testdroid/api/APIListResource.java b/src/main/java/com/testdroid/api/APIListResource.java index deef0fb9..ea8cc413 100644 --- a/src/main/java/com/testdroid/api/APIListResource.java +++ b/src/main/java/com/testdroid/api/APIListResource.java @@ -70,7 +70,7 @@ public APIListResource getNext() throws APIException { return null; } APIList list = getEntity(); - return new APIListResource(client, resourceURI, context.setOffset(list.getOffset() + list.getLimit())); + return new APIListResource<>(client, resourceURI, context.setOffset(list.getOffset() + list.getLimit())); } /** @@ -96,6 +96,6 @@ public APIListResource getPrevious() throws APIException { return null; } APIList list = getEntity(); - return new APIListResource(client, resourceURI, context.setOffset(list.getOffset() - list.getLimit())); + return new APIListResource<>(client, resourceURI, context.setOffset(list.getOffset() - list.getLimit())); } } diff --git a/src/main/java/com/testdroid/api/dto/Context.java b/src/main/java/com/testdroid/api/dto/Context.java index 2ec69f7b..45994f54 100644 --- a/src/main/java/com/testdroid/api/dto/Context.java +++ b/src/main/java/com/testdroid/api/dto/Context.java @@ -4,10 +4,7 @@ import com.testdroid.api.APISort; import com.testdroid.api.filter.FilterEntry; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; /** @@ -122,6 +119,10 @@ public List getFilters() { return filters; } + public Optional findFilter(String field, Operand operand) { + return filters.stream().filter(f -> f.getField().equals(field) && f.getOperand().equals(operand)).findAny(); + } + public Context setFilters(List filters) { this.filters = filters; return this; diff --git a/src/main/java/com/testdroid/api/model/APIAdminDevice.java b/src/main/java/com/testdroid/api/model/APIAdminDevice.java index b9edda3a..24d33de8 100644 --- a/src/main/java/com/testdroid/api/model/APIAdminDevice.java +++ b/src/main/java/com/testdroid/api/model/APIAdminDevice.java @@ -2,10 +2,11 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.testdroid.api.APIEntity; +import org.apache.commons.lang3.tuple.Pair; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; -import java.util.Date; +import java.util.*; /** * @author Łukasz Kajda @@ -27,6 +28,60 @@ public enum State { OFFLINE } + @XmlType(namespace = "APIAdminDevice") + public enum SubState { + CLEANING, + DIRTY, + FREE, + TESTING + } + + @XmlType(namespace = "APIAdminDevice") + public enum ComplexState { + OFFLINE(State.OFFLINE, SubState.DIRTY), // for backward compatibility + ONLINE(State.ONLINE, SubState.FREE), // for backward compatibility + OFFLINE_CLEANING(State.OFFLINE, SubState.CLEANING), + OFFLINE_DIRTY(State.OFFLINE, SubState.DIRTY), + OFFLINE_FREE(State.OFFLINE, SubState.FREE), + OFFLINE_TESTING(State.OFFLINE, SubState.TESTING), + ONLINE_CLEANING(State.ONLINE, SubState.CLEANING), + ONLINE_DIRTY(State.ONLINE, SubState.DIRTY), + ONLINE_FREE(State.ONLINE, SubState.FREE), + ONLINE_TESTING(State.ONLINE, SubState.TESTING); + + private State state; + + private SubState subState; + + private static final Map, ComplexState> MAP = new HashMap<>(values().length, 1); + + static { + Arrays.stream(values()).forEach(c -> MAP.put(Pair.of(c.state, c.subState), c)); + } + + ComplexState(State state, SubState subState) { + this.state = state; + this.subState = subState; + } + + public State getState() { + return state; + } + + public SubState getSubState() { + return subState; + } + + public ComplexState compute(State state) { + return MAP.get(Pair.of(state, subState)); + } + + public ComplexState compute(SubState subState) { + return MAP.get(Pair.of(state, subState)); + } + + } + private APICluster cluster; private Long deviceModelId; @@ -45,7 +100,7 @@ public enum State { private APISoftwareVersion softwareVersion; - private State state; + private ComplexState state; private Date stateTime; @@ -63,8 +118,6 @@ public enum State { private APIDevice.OsType osType; - private boolean dirty; - public APIAdminDevice() { } @@ -75,29 +128,31 @@ public APIAdminDevice(Long id) { public APIAdminDevice( Long id, String name, boolean enabled, String serialId, String fingerprint, String unlockGesture, - APISoftwareVersion softwareVersion, Long deviceModelId, String deviceModelName, State state, - Date stateTime, InitStep initStep, String ipAddress, APICluster cluster, Date lastOnlineTime, - Long accountId, String mainUserEmail, Boolean locked, APIDevice.OsType osType, Boolean dirty) { + Long softwareVersionId, String releaseVersion, Integer apiLevel, Long deviceModelId, String deviceModelName, + ComplexState state, Date stateTime, InitStep initStep, String ipAddress, Long clusterId, String clusterName, + String clusterUrl, APICluster.State clusterState, Date clusterStateTime, Date clusterStateChangeTime, + Boolean clusterEnabled, Date lastOnlineTime, Long accountId, String mainUserEmail, Boolean locked, + APIDevice.OsType osType) { super(id); this.name = name; this.enabled = enabled; this.serialId = serialId; this.fingerprint = fingerprint; this.unlockGesture = unlockGesture; - this.softwareVersion = softwareVersion; + this.softwareVersion = new APISoftwareVersion(softwareVersionId, releaseVersion, apiLevel); this.deviceModelId = deviceModelId; this.deviceModelName = deviceModelName; this.state = state; this.stateTime = stateTime; this.initStep = initStep; this.ipAddress = ipAddress; - this.cluster = cluster; + this.cluster = new APICluster(clusterId, clusterName, clusterUrl, clusterState, + clusterStateTime, clusterStateChangeTime, clusterEnabled); this.lastOnlineTime = lastOnlineTime; this.accountId = accountId; this.mainUserEmail = mainUserEmail; this.locked = locked; this.osType = osType; - this.dirty = dirty; } public String getName() { @@ -156,11 +211,11 @@ public void setDeviceModelId(Long deviceModelId) { this.deviceModelId = deviceModelId; } - public State getState() { + public ComplexState getState() { return state; } - public void setState(State state) { + public void setState(ComplexState state) { this.state = state; } @@ -244,14 +299,6 @@ public void setOsType(APIDevice.OsType osType) { this.osType = osType; } - public boolean isDirty() { - return dirty; - } - - public void setDirty(boolean dirty) { - this.dirty = dirty; - } - @Override @JsonIgnore protected void clone(T from) { @@ -275,6 +322,5 @@ protected void clone(T from) { this.mainUserEmail = adminDevice.mainUserEmail; this.locked = adminDevice.locked; this.osType = adminDevice.osType; - this.dirty = adminDevice.dirty; } } diff --git a/src/main/java/com/testdroid/api/model/APIAdminDeviceEvent.java b/src/main/java/com/testdroid/api/model/APIAdminDeviceEvent.java index 3ecbc2a0..d5d7141c 100644 --- a/src/main/java/com/testdroid/api/model/APIAdminDeviceEvent.java +++ b/src/main/java/com/testdroid/api/model/APIAdminDeviceEvent.java @@ -25,9 +25,7 @@ public enum DeviceEventType { private DeviceEventType type; - private APIAdminDevice.State state; - - private Boolean dirty; + private APIAdminDevice.ComplexState state; private APIAdminDevice device; @@ -40,7 +38,7 @@ public APIAdminDeviceEvent() { } public APIAdminDeviceEvent(Long id, LocalDateTime time, APIAdminDeviceEvent.DeviceEventType type, - APIAdminDevice.State state, Boolean dirty, Long deviceId, + APIAdminDevice.ComplexState state, Long deviceId, Long clusterId, String name, String url, APICluster.State clusterState, Date stateTime, Date stateChangeTime, Boolean enabled, Long deviceSessionId, Date createTime, Date startTime, Date endTime, String startedByDisplayName, @@ -51,7 +49,6 @@ public APIAdminDeviceEvent(Long id, LocalDateTime time, APIAdminDeviceEvent.Devi this.time = TimeConverter.toDate(time); this.type = type; this.state = state; - this.dirty = dirty; this.device = new APIAdminDevice(deviceId); this.cluster = new APICluster(clusterId, name, url, clusterState, stateTime, stateChangeTime, enabled); this.deviceSession = new APIAdminDeviceSession(deviceSessionId, createTime, startTime, endTime, @@ -99,29 +96,20 @@ public void setDeviceSession(APIAdminDeviceSession deviceSession) { this.deviceSession = deviceSession; } - public APIAdminDevice.State getState() { + public APIAdminDevice.ComplexState getState() { return state; } - public void setState(APIAdminDevice.State state) { + public void setState(APIAdminDevice.ComplexState state) { this.state = state; } - public Boolean getDirty() { - return dirty; - } - - public void setDirty(Boolean dirty) { - this.dirty = dirty; - } - @Override protected void clone(T from) { APIAdminDeviceEvent deviceEvent = (APIAdminDeviceEvent) from; cloneBase(from); this.time = deviceEvent.time; this.state = deviceEvent.state; - this.dirty = deviceEvent.dirty; this.device = deviceEvent.device; this.cluster = deviceEvent.cluster; this.deviceSession = deviceEvent.deviceSession; diff --git a/src/main/java/com/testdroid/api/model/APIAdminDeviceProblemPair.java b/src/main/java/com/testdroid/api/model/APIAdminDeviceProblemPair.java index 0253a4a1..de1936ec 100644 --- a/src/main/java/com/testdroid/api/model/APIAdminDeviceProblemPair.java +++ b/src/main/java/com/testdroid/api/model/APIAdminDeviceProblemPair.java @@ -14,6 +14,7 @@ public class APIAdminDeviceProblemPair extends APIEntity { @XmlType(namespace = "APIAdminDeviceProblemPair", name = "APIAdminDeviceProblemPairType") public enum Type { + CLEANING, DIRTY, OFFLINE, LOW_BATTERY, diff --git a/src/main/java/com/testdroid/api/model/APIDeviceStatus.java b/src/main/java/com/testdroid/api/model/APIDeviceStatus.java index ee1e31ad..a4747315 100644 --- a/src/main/java/com/testdroid/api/model/APIDeviceStatus.java +++ b/src/main/java/com/testdroid/api/model/APIDeviceStatus.java @@ -55,7 +55,7 @@ public class APIDeviceStatus extends APIEntity { private String ssid; - private APIAdminDevice.State state; + private APIAdminDevice.ComplexState state; private String tdsVersion; @@ -69,7 +69,7 @@ public APIDeviceStatus() { } public APIDeviceStatus( - Long id, Long deviceId, String deviceName, APIAdminDevice.State state, Long clusterId, + Long id, Long deviceId, String deviceName, APIAdminDevice.ComplexState state, Long clusterId, String clusterName, Date updateTime, Boolean internetAccess, Boolean monitoringOn, Boolean testExecuting, String ssid, Boolean flashOn, Boolean alarmOn, Boolean aslOn, Integer batteryLevel, Long deviceTime, String deviceTimeZone, Boolean screenLocked, Boolean mockLocationOn, Boolean locationServiceOn, @@ -304,11 +304,11 @@ public void setClusterId(Long clusterId) { this.clusterId = clusterId; } - public APIAdminDevice.State getState() { + public APIAdminDevice.ComplexState getState() { return state; } - public void setState(APIAdminDevice.State state) { + public void setState(APIAdminDevice.ComplexState state) { this.state = state; } diff --git a/src/main/java/com/testdroid/api/model/APIDeviceTimeEntry.java b/src/main/java/com/testdroid/api/model/APIDeviceTimeEntry.java deleted file mode 100644 index 2551207d..00000000 --- a/src/main/java/com/testdroid/api/model/APIDeviceTimeEntry.java +++ /dev/null @@ -1,125 +0,0 @@ -package com.testdroid.api.model; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.testdroid.api.APIEntity; - -import javax.xml.bind.annotation.XmlRootElement; -import java.util.Date; - -/** - * @author Adrian Zybala - */ -@XmlRootElement -public class APIDeviceTimeEntry extends APIEntity { - - private Date createTime; - - private Date endTime; - - private String userName; - - private Long userId; - - private Long freeTime; - - private Long billableTime; - - private Long deviceTime; - - private APIDeviceSession.Type type; - - public APIDeviceTimeEntry() { - - } - - public APIDeviceTimeEntry( - Date createTime, Date endTime, String userName, Long userId, Long freeTime, Long billableTime, - APIDeviceSession.Type type) { - this.createTime = createTime; - this.endTime = endTime; - this.userName = userName; - this.userId = userId; - this.freeTime = freeTime; - this.billableTime = billableTime; - this.deviceTime = freeTime + billableTime; - this.type = type; - } - - @Override - @JsonIgnore - protected void clone(T from) { - APIDeviceTimeEntry apiDeviceTimeEntry = (APIDeviceTimeEntry) from; - cloneBase(from); - this.createTime = apiDeviceTimeEntry.createTime; - this.endTime = apiDeviceTimeEntry.endTime; - this.userName = apiDeviceTimeEntry.userName; - this.userId = apiDeviceTimeEntry.userId; - this.deviceTime = apiDeviceTimeEntry.deviceTime; - this.type = apiDeviceTimeEntry.type; - this.freeTime = apiDeviceTimeEntry.freeTime; - } - - public Date getCreateTime() { - return createTime; - } - - public void setCreateTime(Date createTime) { - this.createTime = createTime; - } - - public Date getEndTime() { - return endTime; - } - - public void setEndTime(Date endTime) { - this.endTime = endTime; - } - - public String getUserName() { - return userName; - } - - public void setUserName(String userName) { - this.userName = userName; - } - - public Long getUserId() { - return userId; - } - - public void setUserId(Long userId) { - this.userId = userId; - } - - public Long getDeviceTime() { - return deviceTime; - } - - public void setDeviceTime(Long deviceTime) { - this.deviceTime = deviceTime; - } - - public APIDeviceSession.Type getType() { - return type; - } - - public void setType(APIDeviceSession.Type type) { - this.type = type; - } - - public Long getFreeTime() { - return freeTime; - } - - public void setFreeTime(Long freeTime) { - this.freeTime = freeTime; - } - - public Long getBillableTime() { - return billableTime; - } - - public void setBillableTime(Long billableTime) { - this.billableTime = billableTime; - } -} diff --git a/src/main/java/com/testdroid/api/model/APILabelGroup.java b/src/main/java/com/testdroid/api/model/APILabelGroup.java index a47ddb62..4a1785b6 100644 --- a/src/main/java/com/testdroid/api/model/APILabelGroup.java +++ b/src/main/java/com/testdroid/api/model/APILabelGroup.java @@ -49,12 +49,12 @@ private String getDevicePropertiesURI() { @JsonIgnore public APIListResource getDevicePropertiesResource() { - return new APIListResource(client, getDevicePropertiesURI(), APIDeviceProperty.class); + return new APIListResource<>(client, getDevicePropertiesURI(), APIDeviceProperty.class); } @JsonIgnore public APIListResource getDevicePropertiesResource(Context context) { - return new APIListResource(client, getDevicePropertiesURI(), context); + return new APIListResource<>(client, getDevicePropertiesURI(), context); } @Override diff --git a/src/main/java/com/testdroid/api/model/APIUserDeviceTime.java b/src/main/java/com/testdroid/api/model/APIUserDeviceTime.java index 4270d861..60c2f169 100644 --- a/src/main/java/com/testdroid/api/model/APIUserDeviceTime.java +++ b/src/main/java/com/testdroid/api/model/APIUserDeviceTime.java @@ -4,6 +4,7 @@ import com.testdroid.api.APIEntity; import javax.xml.bind.annotation.XmlRootElement; +import java.util.Date; /** * @author Adrian Zybala @@ -11,95 +12,114 @@ @XmlRootElement public class APIUserDeviceTime extends APIEntity { - private Long totalDeviceTime; + private Date createTime; - private Long inspectorDeviceTime; + private Date endTime; - private Long automaticDeviceTime; + private String userName; - private Long freeDeviceTime; + private Long userId; - private Long periodStart; + private Long freeTime; - private Long periodEnd; + private Long billableTime; - private APIDeviceTimeEntry[] deviceTimeEntries; + private Long deviceTime; + + private APIDeviceSession.Type type; public APIUserDeviceTime() { } public APIUserDeviceTime( - Long inspectorDeviceTime, Long automaticDeviceTime, Long freeDeviceTime, Long periodStart, - Long periodEnd, APIDeviceTimeEntry... deviceTimeEntries) { - this.totalDeviceTime = inspectorDeviceTime + automaticDeviceTime + freeDeviceTime; - this.inspectorDeviceTime = inspectorDeviceTime; - this.automaticDeviceTime = automaticDeviceTime; - this.freeDeviceTime = freeDeviceTime; - this.deviceTimeEntries = deviceTimeEntries; - this.periodStart = periodStart; - this.periodEnd = periodEnd; + Date createTime, Date endTime, String userName, Long userId, Long freeTime, Long billableTime, + APIDeviceSession.Type type) { + this.createTime = createTime; + this.endTime = endTime; + this.userName = userName; + this.userId = userId; + this.freeTime = freeTime; + this.billableTime = billableTime; + this.deviceTime = freeTime + billableTime; + this.type = type; } - public Long getTotalDeviceTime() { - return totalDeviceTime; + @Override + @JsonIgnore + protected void clone(T from) { + APIUserDeviceTime apiUserDeviceTime = (APIUserDeviceTime) from; + cloneBase(from); + this.createTime = apiUserDeviceTime.createTime; + this.endTime = apiUserDeviceTime.endTime; + this.userName = apiUserDeviceTime.userName; + this.userId = apiUserDeviceTime.userId; + this.deviceTime = apiUserDeviceTime.deviceTime; + this.type = apiUserDeviceTime.type; + this.freeTime = apiUserDeviceTime.freeTime; } - public void setTotalDeviceTime(Long totalDeviceTime) { - this.totalDeviceTime = totalDeviceTime; + public Date getCreateTime() { + return createTime; } - public Long getInspectorDeviceTime() { - return inspectorDeviceTime; + public void setCreateTime(Date createTime) { + this.createTime = createTime; } - public void setInspectorDeviceTime(Long inspectorDeviceTime) { - this.inspectorDeviceTime = inspectorDeviceTime; + public Date getEndTime() { + return endTime; } - public Long getAutomaticDeviceTime() { - return automaticDeviceTime; + public void setEndTime(Date endTime) { + this.endTime = endTime; } - public void setAutomaticDeviceTime(Long automaticDeviceTime) { - this.automaticDeviceTime = automaticDeviceTime; + public String getUserName() { + return userName; } - public APIDeviceTimeEntry[] getDeviceTimeEntries() { - return deviceTimeEntries; + public void setUserName(String userName) { + this.userName = userName; } - public Long getPeriodStart() { - return periodStart; + public Long getUserId() { + return userId; } - public Long getPeriodEnd() { - return periodEnd; + public void setUserId(Long userId) { + this.userId = userId; } - public void setDeviceTimeEntries(APIDeviceTimeEntry[] deviceTimeEntries) { - this.deviceTimeEntries = deviceTimeEntries; + public Long getDeviceTime() { + return deviceTime; } - public Long getFreeDeviceTime() { - return freeDeviceTime; + public void setDeviceTime(Long deviceTime) { + this.deviceTime = deviceTime; } - public void setFreeDeviceTime(Long freeDeviceTime) { - this.freeDeviceTime = freeDeviceTime; + public APIDeviceSession.Type getType() { + return type; } - @Override - @JsonIgnore - protected void clone(T from) { - APIUserDeviceTime apiUserDeviceTime = (APIUserDeviceTime) from; - cloneBase(from); - this.totalDeviceTime = apiUserDeviceTime.totalDeviceTime; - this.inspectorDeviceTime = apiUserDeviceTime.inspectorDeviceTime; - this.automaticDeviceTime = apiUserDeviceTime.automaticDeviceTime; - this.freeDeviceTime = apiUserDeviceTime.freeDeviceTime; - this.deviceTimeEntries = apiUserDeviceTime.deviceTimeEntries; - this.periodStart = apiUserDeviceTime.periodStart; - this.periodEnd = apiUserDeviceTime.periodEnd; + public void setType(APIDeviceSession.Type type) { + this.type = type; + } + + public Long getFreeTime() { + return freeTime; + } + + public void setFreeTime(Long freeTime) { + this.freeTime = freeTime; + } + + public Long getBillableTime() { + return billableTime; + } + + public void setBillableTime(Long billableTime) { + this.billableTime = billableTime; } } diff --git a/src/main/java/com/testdroid/api/model/APIUserDeviceTimeSummary.java b/src/main/java/com/testdroid/api/model/APIUserDeviceTimeSummary.java new file mode 100644 index 00000000..0978b2b0 --- /dev/null +++ b/src/main/java/com/testdroid/api/model/APIUserDeviceTimeSummary.java @@ -0,0 +1,100 @@ +package com.testdroid.api.model; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.testdroid.api.APIEntity; + +import javax.xml.bind.annotation.XmlRootElement; + +/** + * @author Adrian Zybala + */ +@JsonIgnoreProperties("id") +@XmlRootElement +public class APIUserDeviceTimeSummary extends APIEntity { + + private Long totalDeviceTime; + + private Long inspectorDeviceTime; + + private Long automaticDeviceTime; + + private Long freeDeviceTime; + + private Long periodStart; + + private Long periodEnd; + + public APIUserDeviceTimeSummary() { + + } + + public APIUserDeviceTimeSummary( + Long inspectorDeviceTime, Long automaticDeviceTime, Long freeDeviceTime) { + this.totalDeviceTime = inspectorDeviceTime + automaticDeviceTime + freeDeviceTime; + this.inspectorDeviceTime = inspectorDeviceTime; + this.automaticDeviceTime = automaticDeviceTime; + this.freeDeviceTime = freeDeviceTime; + } + + public Long getTotalDeviceTime() { + return totalDeviceTime; + } + + public void setTotalDeviceTime(Long totalDeviceTime) { + this.totalDeviceTime = totalDeviceTime; + } + + public Long getInspectorDeviceTime() { + return inspectorDeviceTime; + } + + public void setInspectorDeviceTime(Long inspectorDeviceTime) { + this.inspectorDeviceTime = inspectorDeviceTime; + } + + public Long getAutomaticDeviceTime() { + return automaticDeviceTime; + } + + public void setAutomaticDeviceTime(Long automaticDeviceTime) { + this.automaticDeviceTime = automaticDeviceTime; + } + + public Long getPeriodStart() { + return periodStart; + } + + public Long getPeriodEnd() { + return periodEnd; + } + + public void setPeriodEnd(Long periodEnd) { + this.periodEnd = periodEnd; + } + + public void setPeriodStart(Long periodStart) { + this.periodStart = periodStart; + } + + public Long getFreeDeviceTime() { + return freeDeviceTime; + } + + public void setFreeDeviceTime(Long freeDeviceTime) { + this.freeDeviceTime = freeDeviceTime; + } + + @Override + @JsonIgnore + protected void clone(T from) { + APIUserDeviceTimeSummary apiUserDeviceTimeSummary = (APIUserDeviceTimeSummary) from; + cloneBase(from); + this.totalDeviceTime = apiUserDeviceTimeSummary.totalDeviceTime; + this.inspectorDeviceTime = apiUserDeviceTimeSummary.inspectorDeviceTime; + this.automaticDeviceTime = apiUserDeviceTimeSummary.automaticDeviceTime; + this.freeDeviceTime = apiUserDeviceTimeSummary.freeDeviceTime; + this.periodStart = apiUserDeviceTimeSummary.periodStart; + this.periodEnd = apiUserDeviceTimeSummary.periodEnd; + } +} diff --git a/src/main/java/com/testdroid/api/model/build/APIBuildResultConfig.java b/src/main/java/com/testdroid/api/model/build/APIBuildResultConfig.java index 744150e7..dc59111a 100644 --- a/src/main/java/com/testdroid/api/model/build/APIBuildResultConfig.java +++ b/src/main/java/com/testdroid/api/model/build/APIBuildResultConfig.java @@ -18,7 +18,7 @@ public class APIBuildResultConfig extends APIEntity implements Serializable { private boolean isDirectory; private String fileUrlEnvVariable; - + private String storage; public APIBuildResultConfig() { diff --git a/src/main/java/com/testdroid/api/model/build/APIPipelineBuild.java b/src/main/java/com/testdroid/api/model/build/APIPipelineBuild.java index 3c7d42df..4d27d421 100644 --- a/src/main/java/com/testdroid/api/model/build/APIPipelineBuild.java +++ b/src/main/java/com/testdroid/api/model/build/APIPipelineBuild.java @@ -25,13 +25,14 @@ public class APIPipelineBuild extends APIEntity { private Long pipelineJobId; - public APIPipelineBuild() { + private Long userId; + public APIPipelineBuild() { } public APIPipelineBuild( Long id, Long buildNumber, LocalDateTime createTime, Long duration, APIPipelineBuildStatus status, - APIPipelineBuildState state, Long pipelineJobId) { + APIPipelineBuildState state, Long pipelineJobId, Long userId) { super(id); this.buildNumber = buildNumber; this.pipelineJobId = pipelineJobId; @@ -39,6 +40,7 @@ public APIPipelineBuild( this.duration = duration; this.status = status; this.state = state; + this.userId = userId; } public Long getBuildNumber() { @@ -89,6 +91,14 @@ public void setState(APIPipelineBuildState state) { this.state = state; } + public Long getUserId() { + return userId; + } + + public void setUserId(Long userId) { + this.userId = userId; + } + @Override protected void clone(T from) { APIPipelineBuild apiBuild = (APIPipelineBuild) from; @@ -99,5 +109,6 @@ protected void clone(T from) { this.duration = apiBuild.duration; this.status = apiBuild.status; this.state = apiBuild.state; + this.userId = apiBuild.userId; } } diff --git a/src/main/java/com/testdroid/api/util/TypeReferenceFactory.java b/src/main/java/com/testdroid/api/util/TypeReferenceFactory.java index 12798132..41fb6df0 100644 --- a/src/main/java/com/testdroid/api/util/TypeReferenceFactory.java +++ b/src/main/java/com/testdroid/api/util/TypeReferenceFactory.java @@ -89,6 +89,8 @@ public class TypeReferenceFactory { }); TYPE_REFERENCE_LIST_MAP.put(APIUserFileTag.class, new TypeReference>() { }); + TYPE_REFERENCE_LIST_MAP.put(APIUserDeviceTime.class, new TypeReference>() { + }); TYPE_REFERENCE_LIST_MAP.put(APITestRunParameter.class, new TypeReference>() { }); TYPE_REFERENCE_LIST_MAP.put(APIProjectTypeExtended.class, new TypeReference>() { @@ -225,7 +227,7 @@ public class TypeReferenceFactory { }); TYPE_REFERENCE_MAP.put(APIUser.class, new TypeReference() { }); - TYPE_REFERENCE_MAP.put(APIUserDeviceTime.class, new TypeReference() { + TYPE_REFERENCE_MAP.put(APIUserDeviceTimeSummary.class, new TypeReference() { }); TYPE_REFERENCE_MAP.put(APIBasicDeviceTime.class, new TypeReference() { }); diff --git a/src/main/java/com/testdroid/cloud/test/categories/TestTags.java b/src/main/java/com/testdroid/cloud/test/categories/TestTags.java index 2587d287..2da7fc68 100644 --- a/src/main/java/com/testdroid/cloud/test/categories/TestTags.java +++ b/src/main/java/com/testdroid/cloud/test/categories/TestTags.java @@ -13,4 +13,5 @@ public interface TestTags { String API_CLIENT = "api_client"; + String PORT_FORWARDER_CLIENT = "port_forwarder_client"; } diff --git a/src/main/java/com/testdroid/dao/repository/dto/MappingKey.java b/src/main/java/com/testdroid/dao/repository/dto/MappingKey.java index 3544759f..e5c81c98 100644 --- a/src/main/java/com/testdroid/dao/repository/dto/MappingKey.java +++ b/src/main/java/com/testdroid/dao/repository/dto/MappingKey.java @@ -185,8 +185,6 @@ public class MappingKey { public static final String DIRECTION = "direction"; - public static final String DIRTY = "dirty"; - public static final String DISPLAY_NAME = "displayName"; public static final String DURATION = "duration"; diff --git a/src/test/java/com/testdroid/api/APIListTest.java b/src/test/java/com/testdroid/api/APIListTest.java new file mode 100644 index 00000000..208414db --- /dev/null +++ b/src/test/java/com/testdroid/api/APIListTest.java @@ -0,0 +1,118 @@ +package com.testdroid.api; + +import com.testdroid.api.dto.Context; +import com.testdroid.api.filter.ListStringFilterEntry; +import com.testdroid.api.filter.NumberFilterEntry; +import com.testdroid.api.model.APIUser; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +import java.util.Arrays; +import java.util.Collection; + +import static com.testdroid.api.dto.Operand.EQ; +import static com.testdroid.api.dto.Operand.IN; +import static com.testdroid.cloud.test.categories.TestTags.UNIT; +import static com.testdroid.dao.repository.dto.MappingKey.ID; +import static com.testdroid.dao.repository.dto.MappingKey.NAME; +import static org.apache.commons.lang3.StringUtils.EMPTY; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * @author Michał Szpruta + */ +@Tag(UNIT) +public class APIListTest { + + private static final String URL = "https://cloud.bitbar.com/api/v2/users"; + + private static final APISort SORT_EMPTY = APISort.deserialize(EMPTY); + + public static Collection data() { + Object[][] data = new Object[][]{ + { + 0, + new Context<>(APIUser.class).setSort(SORT_EMPTY).setSearch(EMPTY), + null, + null + }, + { + 20, + new Context<>(APIUser.class).setSort(SORT_EMPTY).setSearch(EMPTY), + null, + null, + }, + { + 20, + new Context<>(APIUser.class).setSort(SORT_EMPTY).setSearch(EMPTY).setLimit(10), + null, + String.format("%s?offset=10&limit=10&search=&sort=&filter=", URL) + }, + { + 100, + new Context<>(APIUser.class).setSort(SORT_EMPTY).setSearch(EMPTY), + null, + String.format("%s?offset=20&limit=20&search=&sort=&filter=", URL) + }, + { + 100, + new Context<>(APIUser.class).setSort(SORT_EMPTY).setSearch("text"), + null, + String.format("%s?offset=20&limit=20&search=text&sort=&filter=", URL) + }, + { + 100, + new Context<>(APIUser.class).setOffset(25).setSort(SORT_EMPTY).setSearch("text"), + String.format("%s?offset=5&limit=20&search=text&sort=&filter=", URL), + String.format("%s?offset=45&limit=20&search=text&sort=&filter=", URL) + }, + { + 100, + new Context<>(APIUser.class).setOffset(25).setLimit(5).setSort(SORT_EMPTY).setSearch("text"), + String.format("%s?offset=20&limit=5&search=text&sort=&filter=", URL), + String.format("%s?offset=30&limit=5&search=text&sort=&filter=", URL) + }, + { + 100, + new Context<>(APIUser.class).setOffset(25).setLimit(5).setSort(APISort.deserialize("email_a")) + .setSearch("text"), + String.format("%s?offset=20&limit=5&search=text&sort=email_a&filter=", URL), + String.format("%s?offset=30&limit=5&search=text&sort=email_a&filter=", URL) + }, + { + 100, + new Context<>(APIUser.class).setOffset(25).setLimit(5).setSort(APISort.deserialize("state_d")) + .setSearch("text"), + String.format("%s?offset=20&limit=5&search=text&sort=state_d&filter=", URL), + String.format("%s?offset=30&limit=5&search=text&sort=state_d&filter=", URL) + }, + { + 100, + new Context<>(APIUser.class).setOffset(25).setLimit(5).setSort(APISort.deserialize("state_d")) + .setSearch("text").addFilter(new NumberFilterEntry(ID, EQ, 10)), + String.format("%s?offset=20&limit=5&search=text&sort=state_d&filter=n_id_EQ_10", URL), + String.format("%s?offset=30&limit=5&search=text&sort=state_d&filter=n_id_EQ_10", URL) + }, + { + 100, + new Context<>(APIUser.class).setOffset(25).setLimit(5).setSort(APISort.deserialize("state_d")) + .setSearch(EMPTY) + .addFilter(new ListStringFilterEntry(NAME, IN, Arrays.asList("Nowak", "Skrobak"))), + String.format("%s?offset=20&limit=5&search=&sort=state_d&filter=name_IN_Nowak|Skrobak", URL), + String.format("%s?offset=30&limit=5&search=&sort=state_d&filter=name_IN_Nowak|Skrobak", URL) + }, + }; + return Arrays.asList(data); + } + + @ParameterizedTest + @MethodSource("data") + public void testLinks(int total, Context ctx, String expectedPrevious, String expectedNext) { + APIList apiList = new APIList<>(URL, null, total, ctx); + assertThat(apiList.getPrevious(), is(expectedPrevious)); + assertThat(apiList.getNext(), is(expectedNext)); + } + +}