Skip to content

Commit a3b0f44

Browse files
tests and meven workflow
1 parent 027fe77 commit a3b0f44

File tree

7 files changed

+50
-23
lines changed

7 files changed

+50
-23
lines changed

.github/workflows/publish.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Publish to Docker
2+
on:
3+
push:
4+
branches:
5+
- main
6+
jobs:
7+
publish:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
# Add your test steps here if needed...
12+
- name: Build container
13+
uses: docker/build-push-action@v1
14+
with:
15+
username: ***REMOVED***
16+
password: ${{ secrets.GITHUB_TOKEN }}
17+
registry: docker.pkg.github.com
18+
repository: ***REMOVED***/publish-packages/game
19+
tag_with_sha: true

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@
6969
<id>ossrh</id>
7070
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
7171
</repository>
72+
<!-- <repository>-->
73+
<!-- <id>github</id>-->
74+
<!-- <name>GitHub Contentstack Apache Maven Packages</name>-->
75+
<!-- <url>https://maven.pkg.github.com/contentstack/contentstack-management-java</url>-->
76+
<!-- </repository>-->
7277
</distributionManagement>
7378

7479
<properties>

src/main/java/com/contentstack/cms/core/Util.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static void nullEmptyThrowsException(@NotNull String field) {
6868
try {
6969
throw new CMARuntimeException(field + " cannot take in an empty String or null value");
7070
} catch (CMARuntimeException e) {
71-
e.printStackTrace();
71+
System.out.println("Exception: "+e.getLocalizedMessage());
7272
}
7373
}
7474

src/main/java/com/contentstack/cms/stack/Asset.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import retrofit2.Retrofit;
1111

1212
import java.io.File;
13+
import java.io.IOException;
14+
import java.net.URLConnection;
1315
import java.util.HashMap;
1416
import java.util.Map;
1517

@@ -237,8 +239,8 @@ public Call<ResponseBody> subfolder(
237239
*
238240
* @param filePath
239241
* the file path
240-
* @param requestBody
241-
* Request body for the asset file
242+
* @param description
243+
* The description of the asset file
242244
* <ul>
243245
* <li>asset[upload] (mandatory) Select the input type as 'File'. Then, browse and select the asset file that
244246
* you want to import. Supported file types include JPG, GIF, PNG, XML, WebP, BMP, TIFF, SVG, and PSD</li>
@@ -269,8 +271,14 @@ public Call<ResponseBody> uploadAsset(@NotNull String filePath, String descripti
269271
private MultipartBody.Part uploadFile(@NotNull String filePath) {
270272
if (!filePath.isEmpty()) {
271273
File file = new File(filePath);
274+
URLConnection connection = null;
275+
try {
276+
connection = file.toURL().openConnection();
277+
} catch (IOException e) {
278+
throw new RuntimeException(e);
279+
}
272280
if (file.exists()) {
273-
RequestBody body = RequestBody.create(MediaType.parse("multipart/form-data"), file);
281+
RequestBody body = RequestBody.create(MediaType.parse(connection.getContentType()), file);
274282
return MultipartBody.Part.createFormData("asset[upload]", file.getName(), body);
275283
}
276284
}
@@ -297,11 +305,6 @@ private MultipartBody.Part uploadFile(@NotNull String filePath) {
297305
public Call<ResponseBody> replace(@NotNull String filePath, @NotNull String description) {
298306
this.validate();
299307
MultipartBody.Part assetPath = uploadFile(filePath);
300-
// if (this.headers.containsKey(Util.CONTENT_TYPE)) {
301-
// this.headers.remove(Util.CONTENT_TYPE);
302-
// this.headers.put(Util.CONTENT_TYPE, "multipart/form-data");
303-
// }
304-
305308
RequestBody body = RequestBody.create(MediaType.parse(String.valueOf(MultipartBody.FORM)), description);
306309
return this.service.replace(this.headers, this.assetUid, assetPath, body, this.params);
307310
}

src/test/java/com/contentstack/cms/stack/AssetAPITest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,17 @@ void testAssetUpload() throws IOException {
151151
asset.addHeader("api_key", API_KEY);
152152
asset.addHeader("authorization", MANAGEMENT_TOKEN);
153153
// Create Asset Instance to find all assets
154-
String filePath = "/Users/shaileshmishra/Downloads/calendar.png";
154+
String filePath = "/Users/shaileshmishra/Desktop/pexels.jpeg";
155155
String description =
156156
"The calender has been placed to assets by ***REMOVED***";
157157
Response<ResponseBody> resp = asset.uploadAsset(filePath, description).execute();
158158

159159
// The assertions
160-
Assertions.assertEquals(5, resp.raw().request().headers().size());
160+
Assertions.assertEquals(6, resp.raw().request().headers().size());
161161
Assertions.assertTrue(resp.raw().request().headers().names().contains("api_key"));
162162
Assertions.assertTrue(resp.raw().request().headers().names().contains("authtoken"));
163163
Assertions.assertTrue(resp.raw().request().isHttps(), "always works on https");
164-
Assertions.assertEquals("GET", resp.raw().request().method(), "works with GET call");
164+
Assertions.assertEquals("POST", resp.raw().request().method(), "works with GET call");
165165
Assertions.assertEquals("https", resp.raw().request().url().scheme(), "the scheme should be https");
166166
Assertions.assertEquals("api.contentstack.io", resp.raw().request().url().host(), "host should be anything but not null");
167167
Assertions.assertEquals(443, resp.raw().request().url().port(), "port should be 443");

src/test/java/com/contentstack/cms/stack/EnvironmentAPITest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void fetchLocales() {
4040
Assertions.assertFalse(response.isSuccessful());
4141
}
4242
} catch (IOException e) {
43-
e.printStackTrace();
43+
System.out.println("Exception: "+e.getLocalizedMessage());
4444
}
4545

4646
}
@@ -56,7 +56,7 @@ void addLocale() {
5656
Assertions.assertFalse(response.isSuccessful());
5757
}
5858
} catch (IOException e) {
59-
e.printStackTrace();
59+
System.out.println("Exception: "+e.getLocalizedMessage());
6060
}
6161
}
6262

@@ -68,12 +68,12 @@ void getLocale() {
6868
try {
6969
Response<ResponseBody> response = environment.create(requestBody).execute();
7070
if (response.isSuccessful()){
71-
Assertions.assertTrue(response.isSuccessful());
71+
Assertions.assertTrue(true);
7272
}else{
73-
Assertions.assertFalse(response.isSuccessful());
73+
Assertions.assertFalse(false);
7474
}
7575
} catch (IOException e) {
76-
e.printStackTrace();
76+
System.out.println("Exception: "+e.getLocalizedMessage());
7777
}
7878
}
7979

@@ -89,7 +89,7 @@ void updateLocale() {
8989
Assertions.assertFalse(response.isSuccessful());
9090
}
9191
} catch (IOException e) {
92-
e.printStackTrace();
92+
System.out.println("Exception: "+e.getLocalizedMessage());
9393
}
9494
}
9595

@@ -99,12 +99,12 @@ void deleteLocale() {
9999
try {
100100
Response<ResponseBody> response = environment.delete().execute();
101101
if (response.isSuccessful()){
102-
Assertions.assertTrue(response.isSuccessful());
102+
Assertions.assertTrue(true);
103103
}else{
104-
Assertions.assertFalse(response.isSuccessful());
104+
Assertions.assertFalse(false);
105105
}
106106
} catch (IOException e) {
107-
e.printStackTrace();
107+
System.out.println("Exception: "+e.getLocalizedMessage());
108108
}
109109
}
110110

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"stack": {
3-
"name": "My New Stack",
4-
"description": "My new test stack",
3+
"name": "Content Management Stack",
4+
"description": "The New way to sun testcases",
55
"master_locale": "en-us"
66
}
77
}

0 commit comments

Comments
 (0)