Skip to content

Commit

Permalink
Merge pull request #336 from szprutamich/master
Browse files Browse the repository at this point in the history
Version 2.59
  • Loading branch information
szprutamich authored May 23, 2018
2 parents 4dc5755 + f431866 commit a784510
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 193 deletions.
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.testdroid</groupId>
<artifactId>testdroid-api</artifactId>
<version>2.58</version>
<version>2.59</version>
<packaging>jar</packaging>
<name>Testdroid API v2</name>
<url>https://github.com/bitbar/testdroid-api</url>
Expand Down Expand Up @@ -122,5 +122,10 @@
<artifactId>jackson-databind</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.13</version>
</dependency>
</dependencies>
</project>
9 changes: 1 addition & 8 deletions src/main/java/com/testdroid/api/APIEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* @author Łukasz Kajda <[email protected]>
Expand Down Expand Up @@ -206,12 +204,7 @@ private void checkClient(APIClient client) throws APIException {

@JsonIgnore
public String toJson() throws JsonProcessingException {
try {
return new ObjectMapper().writeValueAsString(this);
} catch (JsonProcessingException ex) {
Logger.getLogger(APIEntity.class.getName()).log(Level.SEVERE, null, ex);
}
return "";
return new ObjectMapper().writeValueAsString(this);
}

@JsonIgnore
Expand Down
16 changes: 6 additions & 10 deletions src/main/java/com/testdroid/api/APIKeyClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.apache.ApacheHttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.testdroid.api.dto.Context;
import com.testdroid.api.model.APIDevice;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
Expand All @@ -16,16 +14,18 @@
import org.apache.http.impl.auth.BasicScheme;
import org.apache.http.impl.client.BasicAuthCache;
import org.apache.http.impl.client.DefaultHttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.security.GeneralSecurityException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* @author Michał Szpruta <[email protected]>
*/
public class APIKeyClient extends AbstractAPIClient {

private static final Logger LOGGER = LoggerFactory.getLogger(APIKeyClient.class);

private String apiKey;

public APIKeyClient(String cloudURL, String apiKey) {
Expand All @@ -38,9 +38,7 @@ public APIKeyClient(String cloudURL, String apiKey, boolean skipCheckCertificate
try {
netHttpBuilder = new NetHttpTransport.Builder().doNotValidateCertificate();
} catch (GeneralSecurityException ex) {
Logger.getLogger(APIKeyClient.class.getName())
.log(Level.WARNING, "Cannot set not-validating certificate. Certificate will be validating.",
ex);
LOGGER.warn("Cannot set not-validating certificate. Certificate will be validating.", ex);
netHttpBuilder = new NetHttpTransport.Builder();
}
} else {
Expand All @@ -57,9 +55,7 @@ public APIKeyClient(String cloudURL, String username, HttpHost proxy, boolean sk
try {
apacheBuilder = new ApacheHttpTransport.Builder().setProxy(proxy).doNotValidateCertificate();
} catch (GeneralSecurityException ex) {
Logger.getLogger(APIKeyClient.class.getName())
.log(Level.WARNING, "Cannot set not-validating certificate. Certificate will be validating.",
ex);
LOGGER.warn("Cannot set not-validating certificate. Certificate will be validating.", ex);
apacheBuilder = new ApacheHttpTransport.Builder().setProxy(proxy);
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/testdroid/api/APISort.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public String serialize() {
return sorts.stream().map(SortItem::toString).collect(Collectors.joining(":"));
}

public String toString(){
public String toString() {
return serialize();
}

Expand Down
29 changes: 6 additions & 23 deletions src/main/java/com/testdroid/api/DefaultAPIClient.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
package com.testdroid.api;

import com.fasterxml.jackson.core.type.TypeReference;
import com.google.api.client.auth.oauth2.BearerToken;
import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.http.*;
import com.google.api.client.http.apache.ApacheHttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.testdroid.api.dto.Context;
import com.testdroid.api.http.MultipartFormDataContent;
import com.testdroid.api.model.APIDevice;
import com.testdroid.api.model.APILabelGroup;
import com.testdroid.api.model.APIUser;
import net.sf.json.JSONObject;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
Expand All @@ -21,27 +15,18 @@
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.AuthCache;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.impl.auth.BasicScheme;
import org.apache.http.impl.client.BasicAuthCache;
import org.apache.http.impl.client.DefaultHttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.net.URISyntaxException;
import java.security.GeneralSecurityException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import static java.nio.charset.StandardCharsets.UTF_8;

Expand All @@ -52,6 +37,8 @@
*/
public class DefaultAPIClient extends AbstractAPIClient {

private static final Logger LOGGER = LoggerFactory.getLogger(APIKeyClient.class);

public static final int HTTP_CONNECT_TIMEOUT = 60000;

public static final int HTTP_READ_TIMEOUT = 60000;
Expand All @@ -78,9 +65,7 @@ public DefaultAPIClient(String cloudURL, String username, String password, boole
try {
netHttpBuilder = new NetHttpTransport.Builder().doNotValidateCertificate();
} catch (GeneralSecurityException ex) {
Logger.getLogger(DefaultAPIClient.class.getName())
.log(Level.WARNING, "Cannot set not-validating certificate. Certificate will be validating.",
ex);
LOGGER.warn("Cannot set not-validating certificate. Certificate will be validating.", ex);
netHttpBuilder = new NetHttpTransport.Builder();
}
} else {
Expand All @@ -99,9 +84,7 @@ public DefaultAPIClient(
try {
apacheBuilder = new ApacheHttpTransport.Builder().setProxy(proxy).doNotValidateCertificate();
} catch (GeneralSecurityException ex) {
Logger.getLogger(DefaultAPIClient.class.getName())
.log(Level.WARNING, "Cannot set not-validating certificate. Certificate will be validating.",
ex);
LOGGER.warn("Cannot set not-validating certificate. Certificate will be validating.", ex);
apacheBuilder = new ApacheHttpTransport.Builder().setProxy(proxy);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* @author Damian Sniezek <[email protected]>
*/
public enum APIBillingPeriodType {

BUY,
CHARGE,
CANCEL
Expand Down
20 changes: 17 additions & 3 deletions src/main/java/com/testdroid/api/model/APIDeviceSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ public class APIDeviceSession extends APIEntity {

@XmlType(namespace = "APIDeviceSession")
public enum Type {
MANUAL,
AUTOMATIC
ADB,
AUTOMATIC,
MANUAL
}

@XmlType(namespace = "APIDeviceSession")
Expand Down Expand Up @@ -92,6 +93,8 @@ public boolean isFinished() {

private Long deviceTime;

private Long duration;

public APIDeviceSession() {
}

Expand Down Expand Up @@ -125,7 +128,8 @@ public APIDeviceSession(Long id, Type type, Date createTime, Date startTime, Dat
APIDevice device, Long timeLimit, Long launchAppDuration, State state, Long deviceRunId,
Integer testCaseAllCount, Integer testCaseSuccessCount, Integer testCasePassedCount,
Integer testCaseFailedCount, Integer testCaseSkippedCount, Boolean billable, String excludeReason,
Long deviceInstanceId, RetryState retryState, Integer autoRetriesLeftCount, Long deviceTime) {
Long deviceInstanceId, RetryState retryState, Integer autoRetriesLeftCount, Long deviceTime,
Long duration) {
this(id, type, createTime, startTime, installTime, endTime, device, timeLimit, launchAppDuration, state,
deviceRunId, billable, excludeReason, deviceTime);
this.testCaseAllCount = testCaseAllCount;
Expand All @@ -136,6 +140,7 @@ public APIDeviceSession(Long id, Type type, Date createTime, Date startTime, Dat
this.deviceInstanceId = deviceInstanceId;
this.retryState = retryState;
this.autoRetriesLeftCount = autoRetriesLeftCount;
this.duration = duration;
}

public Type getType() {
Expand Down Expand Up @@ -306,6 +311,14 @@ public void setDeviceTime(Long deviceTime) {
this.deviceTime = deviceTime;
}

public Long getDuration() {
return duration;
}

public void setDuration(Long duration) {
this.duration = duration;
}

@JsonIgnore
public APIListResource<APIDeviceSessionStep> getDeviceSessionStepsResource() throws APIException {
return getListResource(createUri(selfURI, "/steps"), APIDeviceSessionStep.class);
Expand Down Expand Up @@ -361,5 +374,6 @@ protected <T extends APIEntity> void clone(T from) {
this.retryState = apiDeviceSession.retryState;
this.autoRetriesLeftCount = apiDeviceSession.autoRetriesLeftCount;
this.deviceTime = apiDeviceSession.deviceTime;
this.duration = apiDeviceSession.duration;
}
}
2 changes: 0 additions & 2 deletions src/main/java/com/testdroid/api/model/APIProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,6 @@ public APITestRun runWithConfig(
Map<String, Object> body = new HashMap<>();
body.put("scheduler", config.getScheduler() != null ? config.getScheduler().name() : null);
body.put("appCrawlerRun", config.isAppCrawlerRun());
body.put("autoScreenshots", config.isAutoScreenshots());
body.put("screenshotDir", config.getScreenshotDir());
body.put("limitationType", config.getLimitationType() != null ? config.getLimitationType().name() : null);
body.put("limitationValue", config.getLimitationValue());
Expand All @@ -449,7 +448,6 @@ public APITestRun runWithConfig(
body.put("uiAutomatorTestClasses", config.getUiAutomatorTestClasses());
body.put("launchApp", config.isLaunchApp());
body.put("instrumentationRunner", config.getInstrumentationRunner());
body.put("appRequired", config.isAppRequired());
body.put("timeout", config.getTimeout());
body.put("name", testRunName);
body.put("usedDeviceIds[]", StringUtils.join(deviceIds, ","));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class APIProjectJobConfig extends APIEntity {

@XmlType(namespace = "APIProjectJobConfig")
public enum Type {
ADB(APIDevice.OsType.ANDROID, "Remote ADB"),
DEFAULT(APIDevice.OsType.ANDROID, "Android instrumentation"),
INSTATEST(APIDevice.OsType.ANDROID, "Android App Crawler"),
INTERACTIVE(APIDevice.OsType.ANDROID, "Testdroid Interactive"),
Expand Down
Loading

0 comments on commit a784510

Please sign in to comment.