Skip to content

Commit ec26fa2

Browse files
committed
DX-2889 Add Media API Tests
1 parent d5706b9 commit ec26fa2

File tree

4 files changed

+155
-43
lines changed

4 files changed

+155
-43
lines changed

.github/workflows/test.yml

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,37 @@ jobs:
1212
strategy:
1313
matrix:
1414
os: [windows-2022, windows-2019, ubuntu-18.04, ubuntu-20.04]
15-
java-version: ['11',' 17', '19']
16-
distribution: ['zulu', 'temurin']
15+
java-version: ["11", " 17", "19"]
16+
distribution: ["zulu", "temurin"]
1717
steps:
18-
- name: Checkout
19-
uses: actions/checkout@v2
18+
- name: Checkout
19+
uses: actions/checkout@v2
2020

21-
- name: Set up JDK
22-
uses: actions/setup-java@v3
23-
with:
24-
distribution: ${{ matrix.distribution }}
25-
java-version: ${{ matrix.java-version }}
21+
- name: Set up JDK
22+
uses: actions/setup-java@v3
23+
with:
24+
distribution: ${{ matrix.distribution }}
25+
java-version: ${{ matrix.java-version }}
2626

27-
- name: Test
28-
env:
29-
BW_ACCOUNT_ID: ${{ secrets.BW_ACCOUNT_ID }}
30-
BW_PASSWORD: ${{ secrets.BW_PASSWORD }}
31-
BW_USERNAME: ${{ secrets.BW_USERNAME }}
32-
BW_VOICE_APPLICATION_ID: ${{ secrets.BW_VOICE_APPLICATION_ID }}
33-
BW_MESSAGING_APPLICATION_ID: ${{ secrets.BW_MESSAGING_APPLICATION_ID }}
34-
BW_NUMBER: ${{ secrets.BW_NUMBER }}
35-
USER_NUMBER: ${{ secrets.USER_NUMBER }}
36-
BASE_CALLBACK_URL: ${{ secrets.BASE_CALLBACK_URL }}
37-
run: mvn -B package --file pom.xml
27+
- name: Test
28+
env:
29+
BW_ACCOUNT_ID: ${{ secrets.BW_ACCOUNT_ID }}
30+
BW_PASSWORD: ${{ secrets.BW_PASSWORD }}
31+
BW_USERNAME: ${{ secrets.BW_USERNAME }}
32+
BW_VOICE_APPLICATION_ID: ${{ secrets.BW_VOICE_APPLICATION_ID }}
33+
BW_MESSAGING_APPLICATION_ID: ${{ secrets.BW_MESSAGING_APPLICATION_ID }}
34+
BW_NUMBER: ${{ secrets.BW_NUMBER }}
35+
USER_NUMBER: ${{ secrets.USER_NUMBER }}
36+
BASE_CALLBACK_URL: ${{ secrets.BASE_CALLBACK_URL }}
37+
JAVA_VERSION: ${{ matrix.java-version }}
38+
RUNNER_OS: ${{ matrix.os }}
39+
DISTRIBUTION: ${{ matrix.distribution }}
40+
run: mvn -B package --file pom.xml
3841

39-
- name: Notify Slack of Failures
40-
uses: Bandwidth/[email protected]
41-
if: failure() && !github.event.pull_request.draft
42-
with:
43-
job-status: ${{ job.status }}
44-
slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
45-
slack-channel: ${{ secrets.SLACK_CHANNEL }}
42+
- name: Notify Slack of Failures
43+
uses: Bandwidth/[email protected]
44+
if: failure() && !github.event.pull_request.draft
45+
with:
46+
job-status: ${{ job.status }}
47+
slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
48+
slack-channel: ${{ secrets.SLACK_CHANNEL }}

pom.xml

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<project xmlns="http://maven.apache.org/POM/4.0.0"
2-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
34
<modelVersion>4.0.0</modelVersion>
45
<groupId>com.bandwidth.sdk</groupId>
56
<artifactId>bandwidth-sdk</artifactId>
@@ -43,7 +44,8 @@
4344
<maxmem>512m</maxmem>
4445
<compilerArgs>
4546
<arg>-Xlint:all</arg>
46-
<arg>-J-Xss4m</arg> <!-- Compiling the generated JSON.java file may require larger stack size. -->
47+
<arg>-J-Xss4m</arg> <!-- Compiling the generated JSON.java file may require
48+
larger stack size. -->
4749
</compilerArgs>
4850
<forceJavacCompilerUse>true</forceJavacCompilerUse>
4951
<release>${java.version}</release>
@@ -87,7 +89,8 @@
8789
<threadCount>10</threadCount>
8890
</configuration>
8991
<dependencies>
90-
<!--Custom provider and engine for Junit 5 to surefire-->
92+
<!--Custom
93+
provider and engine for Junit 5 to surefire-->
9194
<dependency>
9295
<groupId>org.junit.jupiter</groupId>
9396
<artifactId>junit-jupiter-engine</artifactId>
@@ -208,8 +211,8 @@
208211
<include>.gitignore</include>
209212
</includes>
210213
<!-- define the steps to apply to those files -->
211-
<trimTrailingWhitespace/>
212-
<endWithNewline/>
214+
<trimTrailingWhitespace />
215+
<endWithNewline />
213216
<indent>
214217
<spaces>true</spaces> <!-- or <tabs>true</tabs> -->
215218
<spacesPerTab>4</spacesPerTab> <!-- optional, default is 4 -->
@@ -218,7 +221,8 @@
218221
</formats>
219222
<!-- define a language-specific format -->
220223
<java>
221-
<!-- no need to specify files, inferred automatically, but you can if you want -->
224+
<!-- no need to specify files, inferred automatically, but you can if you
225+
want -->
222226

223227
<!-- apply a specific flavor of google-java-format and reflow long strings -->
224228
<googleJavaFormat>
@@ -227,8 +231,8 @@
227231
<reflowLongStrings>true</reflowLongStrings>
228232
</googleJavaFormat>
229233

230-
<removeUnusedImports/>
231-
<importOrder/>
234+
<removeUnusedImports />
235+
<importOrder />
232236

233237
</java>
234238
</configuration>
@@ -323,6 +327,11 @@
323327
<artifactId>commons-lang3</artifactId>
324328
<version>${commons-lang3-version}</version>
325329
</dependency>
330+
<dependency>
331+
<groupId>commons-io</groupId>
332+
<artifactId>commons-io</artifactId>
333+
<version>${version.commons-io}</version>
334+
</dependency>
326335
<dependency>
327336
<groupId>jakarta.annotation</groupId>
328337
<artifactId>jakarta.annotation-api</artifactId>
@@ -365,23 +374,30 @@
365374
</dependency>
366375
</dependencies>
367376
<properties>
368-
<java.version>11</java.version>
377+
<java.version>
378+
11</java.version>
369379
<maven.compiler.source>${java.version}</maven.compiler.source>
370380
<maven.compiler.target>${java.version}</maven.compiler.target>
371-
<gson-fire-version>1.8.5</gson-fire-version>
381+
<gson-fire-version>
382+
1.8.5</gson-fire-version>
372383
<swagger-core-version>1.6.5</swagger-core-version>
373384
<okhttp-version>4.9.3</okhttp-version>
374385
<gson-version>2.9.0</gson-version>
375-
<commons-lang3-version>3.12.0</commons-lang3-version>
386+
<version.commons-io>2.4</version.commons-io>
387+
<commons-lang3-version>
388+
3.12.0</commons-lang3-version>
376389
<jaxb.version>4.0.0</jaxb.version>
377390
<jackson-databind-nullable-version>0.2.3</jackson-databind-nullable-version>
378-
<jakarta-annotation-version>1.3.5</jakarta-annotation-version>
391+
<jakarta-annotation-version>
392+
1.3.5</jakarta-annotation-version>
379393
<junit-version>5.8.2</junit-version>
380394
<junit-platform-runner.version>1.6.2</junit-platform-runner.version>
381-
<mockito-core-version>3.12.4</mockito-core-version>
395+
<mockito-core-version>
396+
3.12.4</mockito-core-version>
382397
<javax.ws.rs-api-version>2.1.1</javax.ws.rs-api-version>
383398
<jsr311-api-version>1.1.1</jsr311-api-version>
384-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
399+
<project.build.sourceEncoding>
400+
UTF-8</project.build.sourceEncoding>
385401
<spotless.version>2.21.0</spotless.version>
386402
</properties>
387403
<dependencyManagement>
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package org.openapitools.client.api;
2+
3+
import org.openapitools.client.ApiException;
4+
import org.openapitools.client.ApiResponse;
5+
import org.openapitools.client.ApiClient;
6+
import org.openapitools.client.auth.HttpBasicAuth;
7+
import org.openapitools.client.model.Media;
8+
import org.openapitools.client.Configuration;
9+
import org.junit.BeforeClass;
10+
import org.junit.jupiter.api.Order;
11+
import org.junit.jupiter.api.Test;
12+
import org.junit.jupiter.api.TestMethodOrder;
13+
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
14+
import org.apache.commons.io.FileUtils;
15+
16+
import java.io.File;
17+
import java.io.IOException;
18+
import java.util.List;
19+
import java.util.UUID;
20+
21+
import static org.hamcrest.MatcherAssert.assertThat;
22+
import static org.hamcrest.Matchers.is;
23+
24+
import static org.openapitools.client.utils.TestingEnvironmentVariables.*;
25+
26+
@TestMethodOrder(OrderAnnotation.class)
27+
public class MediaApiTest {
28+
29+
@BeforeClass
30+
public void setupBeforeClass() {
31+
this.uuid = UUID.randomUUID();
32+
}
33+
34+
ApiClient defaultClient = Configuration.getDefaultApiClient();
35+
HttpBasicAuth Basic = (HttpBasicAuth) defaultClient.getAuthentication("Basic");
36+
private final MediaApi api = new MediaApi(defaultClient);
37+
38+
private String mediaPath = "src/test/java/org/openapitools/client/fixtures/";
39+
private String mediaFile = "java_cat.jpeg";
40+
private UUID uuid = null;
41+
private String mediaId = JAVA_VERSION + "_" + RUNNER_OS + "_" + this.uuid + "_" + mediaFile;
42+
private File media = new File(mediaPath + mediaFile);
43+
private String content_type = "image/jpeg";
44+
private String cache_control = "no-cache";
45+
46+
@Test
47+
@Order(1)
48+
public void uploadMedia() throws ApiException {
49+
Basic.setUsername(BW_USERNAME);
50+
Basic.setPassword(BW_PASSWORD);
51+
52+
ApiResponse<Void> response = api.uploadMediaWithHttpInfo(BW_ACCOUNT_ID, this.mediaId, this.media,
53+
this.content_type,
54+
this.cache_control);
55+
56+
assertThat(response.getStatusCode(), is(204));
57+
System.out.println(this.mediaId);
58+
}
59+
60+
@Test
61+
@Order(2)
62+
public void listMedia() throws ApiException {
63+
Basic.setUsername(BW_USERNAME);
64+
Basic.setPassword(BW_PASSWORD);
65+
ApiResponse<List<Media>> response = api.listMediaWithHttpInfo(BW_ACCOUNT_ID, null);
66+
67+
assertThat(response.getStatusCode(), is(200));
68+
System.out.println(this.mediaId);
69+
70+
}
71+
72+
@Test
73+
@Order(3)
74+
public void getMedia() throws ApiException, IOException {
75+
Basic.setUsername(BW_USERNAME);
76+
Basic.setPassword(BW_PASSWORD);
77+
System.out.println(this.mediaId);
78+
79+
ApiResponse<File> response = api.getMediaWithHttpInfo(BW_ACCOUNT_ID, this.mediaId);
80+
81+
assertThat(response.getStatusCode(), is(200));
82+
assertThat(FileUtils.readLines(response.getData(), "utf-8"), is(FileUtils.readLines(this.media, "utf-8")));
83+
}
84+
85+
@Test
86+
@Order(4)
87+
public void deleteMedia() throws ApiException {
88+
Basic.setUsername(BW_USERNAME);
89+
Basic.setPassword(BW_PASSWORD);
90+
91+
ApiResponse<Void> response = api.deleteMediaWithHttpInfo(BW_ACCOUNT_ID, this.mediaId);
92+
assertThat(response.getStatusCode(), is(204));
93+
}
94+
}

src/test/java/org/openapitools/client/utils/TestingEnvironmentVariables.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.openapitools.client.utils;
22

33
public final class TestingEnvironmentVariables {
4-
54
public static final String BW_USERNAME = System.getenv("BW_USERNAME");
65
public static final String BW_PASSWORD = System.getenv("BW_PASSWORD");
76
public static final String BW_ACCOUNT_ID = System.getenv("BW_ACCOUNT_ID");
@@ -24,5 +23,5 @@ public final class TestingEnvironmentVariables {
2423
public static final String JAVA_VERSION = System.getenv("JAVA_VERSION");
2524
public static final String OPERATING_SYSTEM = System.getenv("OPERATING_SYSTEM");
2625
public static final String RUNNER_OS = System.getenv("RUNNER_OS");
27-
26+
public static final String DISTRIBUTION = System.getenv("DISTRIBUTION");
2827
}

0 commit comments

Comments
 (0)