Skip to content

Commit

Permalink
Merge pull request #471 from kasprzakalek/master
Browse files Browse the repository at this point in the history
Version 3.14
  • Loading branch information
szprutamich committed Feb 21, 2023
2 parents 3fdc015 + f72fb03 commit 449a8db
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 63 deletions.
2 changes: 1 addition & 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.13</version>
<version>3.14</version>
<packaging>jar</packaging>
<name>Bitbar API v2</name>
<url>https://github.com/bitbar/testdroid-api</url>
Expand Down
16 changes: 6 additions & 10 deletions src/main/java/com/testdroid/api/APIList.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,19 @@ public APIList() {
}

public APIList(String requestURL, List<T> data, Integer total, Context<T> ctx) {
int offset = ctx.getOffset();
int limit = ctx.getLimit();
String search = ctx.getSearch();
String sort = ctx.getSort().serialize();
this.total = total;
this.offset = offset;
this.limit = limit;
this.search = search;
this.sort = sort;
this.offset = ctx.getOffset();
this.limit = ctx.getLimit();
this.search = ctx.getSearch();
this.sort = ctx.getSort().serialize();
this.data = data;
this.context = ctx;
String filter = filterParam(ctx.getFilters());
if (offset + limit < total) {
this.next = getListURL(requestURL, offset + limit, limit, search, sort, filter);
this.next = getListURL(requestURL, offset.longValue() + limit, limit, search, sort, filter);
}
if (offset - limit >= 0) {
this.previous = getListURL(requestURL, offset - limit, limit, search, sort, filter);
this.previous = getListURL(requestURL, offset.longValue() - limit, limit, search, sort, filter);
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/main/java/com/testdroid/api/AbstractAPIClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,7 @@ protected <T extends APIEntity> T postOnce(
} catch (HttpResponseException ex) {
throw getAPIException(ex);
} catch (IOException ex) {
throw new APIException(String
.format("Failed to execute API call: %s. Reason: %s", uri, ex.getMessage()), ex);
throw new APIException(String.format(FAILED_TO_EXECUTE_API_CALL_WITH_REASON, uri, ex.getMessage()), ex);
} finally {
disconnectQuietly(response);
}
Expand Down Expand Up @@ -272,8 +271,7 @@ protected void deleteOnce(String uri) throws APIException {
} catch (HttpResponseException ex) {
throw getAPIException(ex);
} catch (IOException ex) {
throw new APIException(String
.format("Failed to execute API call: %s. Reason: %s", uri, ex.getMessage()), ex);
throw new APIException(String.format(FAILED_TO_EXECUTE_API_CALL_WITH_REASON, uri, ex.getMessage()), ex);
} finally {
disconnectQuietly(response);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/testdroid/api/DefaultAPIClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
*/
public class DefaultAPIClient extends AbstractAPIClient {

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

public static final int HTTP_CONNECT_TIMEOUT = 60000;

Expand Down
27 changes: 0 additions & 27 deletions src/main/java/com/testdroid/api/dto/Type.java

This file was deleted.

4 changes: 2 additions & 2 deletions src/main/java/com/testdroid/api/model/APIAccountService.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public Integer getPayUnitCount() {

@JsonIgnore
public String getVatPriceString() {
float vatPrice = (getPrice() * getVatRate()) / 100;
float vatPrice = (getPrice() * getVatRate()) / 100f;
return String.format(Locale.ENGLISH, "%.2f", vatPrice / 100);
}

Expand All @@ -346,7 +346,7 @@ public String getNetPriceString() {

@JsonIgnore
public String getTotalPriceString() {
float totalPrice = (getPrice() * (100 + getVatRate())) / 100;
float totalPrice = (getPrice() * (100 + getVatRate())) / 100f;
return String.format(Locale.ENGLISH, "%.2f", totalPrice / 100);
}

Expand Down
16 changes: 10 additions & 6 deletions src/main/java/com/testdroid/cloud/test/categories/TestTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
/**
* @author Krzysztof Fonał <krzysztof.fonal@bitbar.com>
*/
public interface TestTags {
public class TestTags {

String UNIT = "unit";
private TestTags() {
throw new IllegalStateException("Utility class");
}

String API = "api";
public static final String UNIT = "unit";

String INTEGRATION = "integration";
public static final String API = "api";

String API_CLIENT = "api_client";
public static final String INTEGRATION = "integration";

String PORT_FORWARDER_CLIENT = "port_forwarder_client";
public static final String API_CLIENT = "api_client";

public static final String PORT_FORWARDER_CLIENT = "port_forwarder_client";
}
5 changes: 3 additions & 2 deletions src/test/java/com/testdroid/api/APIClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ class APIClientTest extends BaseAPIClientTest {
@ArgumentsSource(APIClientProvider.class)
void td12086(APIClient apiClient) throws APIException {
APIUser user = apiClient.me();
Exception exception = assertThrows(APIException.class, () ->
user.getResource(user.selfURI + "/notifications/channels/SLACK+/scopes", APIEnum.class).getEntity());
APIResource<APIEnum> resource = user.getResource(user.selfURI + "/notifications/channels/SLACK+/scopes",
APIEnum.class);
Exception exception = assertThrows(APIException.class, resource::getEntity);
assertThat(exception.getMessage()).isEqualTo("Invalid Notification Channel: SLACK+");
}

Expand Down
5 changes: 3 additions & 2 deletions src/test/java/com/testdroid/api/APIDeviceGroupClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ void addDeviceTest(APIClient apiClient) throws APIException {
void addSelectorTest(APIClient apiClient) throws APIException {
APIList<APILabelGroup> labelGroups = apiClient.getLabelGroups(new Context<>(APILabelGroup.class)
.addFilter(new FilterEntry(DISPLAY_NAME, EQ, "Device groups"))).getEntity();
APILabelGroup deviceGroupLabelGroup = labelGroups.getData().stream().findFirst().get();
APILabelGroup deviceGroupLabelGroup = labelGroups.getData().stream().findFirst().orElseThrow(APIException::new);
APIList<APIDeviceProperty> apiDeviceProperties = deviceGroupLabelGroup.getDevicePropertiesResource(new
Context<>(APIDeviceProperty.class)
.addFilter(new FilterEntry(DISPLAY_NAME, EQ, "Android devices")))
.getEntity();
APIDeviceProperty androidDevicesLabel = apiDeviceProperties.getData().stream().findFirst().get();
APIDeviceProperty androidDevicesLabel = apiDeviceProperties.getData().stream().findFirst()
.orElseThrow(APIException::new);
APIDeviceGroup dynamicAndroidDeviceGroup = apiClient.me()
.createDeviceGroup("dynamicAndroidDeviceGroup", ANDROID);
dynamicAndroidDeviceGroup = dynamicAndroidDeviceGroup.addSelector(androidDevicesLabel);
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/com/testdroid/api/APIProjectAPIClientTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.testdroid.api;

import com.testdroid.api.model.APIProject;
import com.testdroid.api.model.APIUser;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ArgumentsSource;
Expand Down Expand Up @@ -38,11 +39,10 @@ void updateProjectTest(APIClient apiClient) throws APIException {
@ParameterizedTest
@ArgumentsSource(BaseAPIClientTest.APIClientProvider.class)
void deleteProjectTest(APIClient apiClient) throws APIException {
APIProject project = apiClient.me().createProject(generateUnique("testProject"));
APIUser me = apiClient.me();
APIProject project = me.createProject(generateUnique("testProject"));
project.delete();
assertThatThrownBy(() ->
apiClient.me().getProject(project.getId()))
.isInstanceOf(APIException.class)
assertThatThrownBy(() -> me.getProject(project.getId())).isInstanceOf(APIException.class)
.hasMessageContaining(String.format("Project with id %d does not exist", project.getId()));
}
}
9 changes: 5 additions & 4 deletions src/test/java/com/testdroid/api/BaseAPIClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ APIFramework getApiFramework(APIClient apiClient, String frameworkNameLike) thro

protected static APIUser create(APIKeyClient adminApiClient) throws APIException {
Map<String, Object> map = new HashMap<>();
map.put(EMAIL, generateUniqueEmail(EMAIL_PATTERN));
map.put(EMAIL, generateUniqueEmail());
APIUser userForTest = adminApiClient.post("/admin/users", map, APIUser.class);
map.clear();
map.put(EMAIL, userForTest.getEmail());
Expand All @@ -111,8 +111,8 @@ protected static APIUser create(APIKeyClient adminApiClient) throws APIException
return userForTest;
}

private static String generateUniqueEmail(String emailPattern) {
return String.format(emailPattern, System.currentTimeMillis());
private static String generateUniqueEmail() {
return String.format(EMAIL_PATTERN, System.currentTimeMillis());
}

static String generateUnique(String prefix) {
Expand All @@ -126,6 +126,7 @@ static DefaultAPIClient createDefaultApiClientWithProxy(HttpHost proxy) throws A
}

static File loadFile(String name) {
return new File(BaseAPIClientTest.class.getResource(name).getFile());
java.net.URL url = BaseAPIClientTest.class.getResource(name);
return new File(Objects.requireNonNull(url).getFile());
}
}

0 comments on commit 449a8db

Please sign in to comment.