Skip to content

Commit 0a0955c

Browse files
authored
Merge pull request #81 from Bandwidth/DX-2889
DX-2889 Add Media API Integration Tests
2 parents 1adb195 + b2c703d commit 0a0955c

File tree

4 files changed

+123
-16
lines changed

4 files changed

+123
-16
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ jobs:
3434
BW_NUMBER: ${{ secrets.BW_NUMBER }}
3535
USER_NUMBER: ${{ secrets.USER_NUMBER }}
3636
BASE_CALLBACK_URL: ${{ secrets.BASE_CALLBACK_URL }}
37+
JAVA_VERSION: ${{ matrix.java-version }}
38+
RUNNER_OS: ${{ matrix.os }}
3739
BW_USERNAME_FORBIDDEN: ${{ secrets.BW_USERNAME_FORBIDDEN }}
3840
BW_PASSWORD_FORBIDDEN: ${{ secrets.BW_PASSWORD_FORBIDDEN }}
3941
MANTECA_IDLE_NUMBER: ${{ secrets.MANTECA_IDLE_NUMBER }}

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.11.0</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: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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.jupiter.api.BeforeAll;
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+
ApiClient defaultClient = Configuration.getDefaultApiClient();
29+
HttpBasicAuth Basic = (HttpBasicAuth) defaultClient.getAuthentication("Basic");
30+
private final MediaApi api = new MediaApi(defaultClient);
31+
32+
private static String mediaPath = "src/test/java/org/openapitools/client/fixtures/";
33+
private static String mediaFile = "java_cat.jpeg";
34+
private static String mediaId;
35+
private static UUID uuid;
36+
private static File media = new File(mediaPath + mediaFile);
37+
private static String contentType = "image/jpeg";
38+
private static String cacheControl = "no-cache";
39+
40+
@BeforeAll
41+
public static void setupBeforeClass() {
42+
uuid = UUID.randomUUID();
43+
mediaId = JAVA_VERSION + "_" + RUNNER_OS + "_" + uuid + "_" + mediaFile;
44+
}
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, mediaId, media,
53+
contentType,
54+
cacheControl);
55+
56+
assertThat(response.getStatusCode(), is(204));
57+
}
58+
59+
@Test
60+
@Order(2)
61+
public void listMedia() throws ApiException {
62+
Basic.setUsername(BW_USERNAME);
63+
Basic.setPassword(BW_PASSWORD);
64+
ApiResponse<List<Media>> response = api.listMediaWithHttpInfo(BW_ACCOUNT_ID, null);
65+
66+
assertThat(response.getStatusCode(), is(200));
67+
}
68+
69+
@Test
70+
@Order(3)
71+
public void getMedia() throws ApiException, IOException {
72+
Basic.setUsername(BW_USERNAME);
73+
Basic.setPassword(BW_PASSWORD);
74+
75+
ApiResponse<File> response = api.getMediaWithHttpInfo(BW_ACCOUNT_ID, mediaId);
76+
77+
assertThat(response.getStatusCode(), is(200));
78+
assertThat(FileUtils.readLines(response.getData(), "utf-8"), is(FileUtils.readLines(media, "utf-8")));
79+
}
80+
81+
@Test
82+
@Order(4)
83+
public void deleteMedia() throws ApiException {
84+
Basic.setUsername(BW_USERNAME);
85+
Basic.setPassword(BW_PASSWORD);
86+
87+
ApiResponse<Void> response = api.deleteMediaWithHttpInfo(BW_ACCOUNT_ID, mediaId);
88+
assertThat(response.getStatusCode(), is(204));
89+
}
90+
}

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");
@@ -25,5 +24,5 @@ public final class TestingEnvironmentVariables {
2524
public static final String OPERATING_SYSTEM = System.getenv("OPERATING_SYSTEM");
2625
public static final String DISTRIBUTION = System.getenv("DISTRIBUTION");
2726
public static final String RUNNER_OS = System.getenv("RUNNER_OS");
28-
27+
public static final String DISTRIBUTION = System.getenv("DISTRIBUTION");
2928
}

0 commit comments

Comments
 (0)