Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@
<includes>
<include>**/*TestSuite.java</include>
</includes>
<reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
<reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
<skipTests>true</skipTests>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
Expand Down
130 changes: 65 additions & 65 deletions src/test/java/com/contentstack/cms/stack/GlobalFieldAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -369,71 +369,71 @@ void setupNested() {
nestedGlobalField = new GlobalField(stack.client, stack.headers, nestedUid);
nestedGlobalField.addHeader("api_version", apiVersion);
}

@Test
@Order(1)
void testCreateNestedGlobalField() throws IOException {
JSONObject requestBody = Utils.readJson("globalfield/nested_global_field.json");
Request request = nestedGlobalField.create(requestBody).request();
Assertions.assertEquals("https://api.contentstack.io/v3/global_fields", request.url().toString());
Assertions.assertEquals("/v3/global_fields", request.url().encodedPath());
Assertions.assertEquals("https", request.url().scheme());
Assertions.assertEquals("POST", request.method());
Assertions.assertEquals(apiVersion, request.header("api_version"));
Response<ResponseBody> response = nestedGlobalField.create(requestBody).execute();
Assertions.assertEquals(201, response.code());
}

@Test
@Order(2)
void testGetNestedGlobalField() throws IOException {
nestedGlobalField.addParam("include_global_fields", true);
nestedGlobalField.addParam("include_validation_keys", true);
Request request = nestedGlobalField.fetch().request();
Assertions.assertEquals("https://api.contentstack.io/v3/global_fields/" + nestedUid + "?include_global_fields=true&include_validation_keys=true", request.url().toString());
Assertions.assertEquals("https", request.url().scheme());
Assertions.assertEquals("GET", request.method());
Assertions.assertEquals(apiVersion, request.header("api_version"));
Response<ResponseBody> response = nestedGlobalField.fetch().execute();
Assertions.assertEquals(200, response.code());
JsonObject responseBody = Utils.toJson(response).getAsJsonObject();
JsonObject globalField = responseBody.getAsJsonObject("global_field");
Assertions.assertEquals("Nested Global Field", globalField.get("title").getAsString());
Assertions.assertTrue(globalField.has("referred_global_fields"));
Assertions.assertTrue(globalField.has("validation_keys"));
}

@Test
@Order(3)
void testUpdateNestedGlobalField() throws IOException {
JSONObject requestBody = Utils.readJson("globalfield/nested_global_field_update1.json");
Request request = nestedGlobalField.update(requestBody).request();
Assertions.assertEquals("https://api.contentstack.io/v3/global_fields/" + nestedUid, request.url().toString());
Assertions.assertEquals("/v3/global_fields/" + nestedUid, request.url().encodedPath());
Assertions.assertEquals("https", request.url().scheme());
Assertions.assertEquals("PUT", request.method());
Assertions.assertEquals(apiVersion, request.header("api_version"));
Response<ResponseBody> response = nestedGlobalField.update(requestBody).execute();
Assertions.assertEquals(200, response.code());
JsonObject responseBody = Utils.toJson(response).getAsJsonObject();
JsonObject globalField = responseBody.getAsJsonObject("global_field");
Assertions.assertEquals("Nested Global Field", globalField.get("title").getAsString());

}

@Test
@Order(4)
void testDeleteNestedGlobalField() throws IOException {
Request request = nestedGlobalField.delete().request();
Assertions.assertEquals("https://api.contentstack.io/v3/global_fields/" + nestedUid + "?force=true", request.url().toString());
Assertions.assertEquals("https", request.url().scheme());
Assertions.assertEquals("DELETE", request.method());
Assertions.assertEquals(apiVersion, request.header("api_version"));
Response<ResponseBody> response = nestedGlobalField.delete().execute();
Assertions.assertEquals(200, response.code());
JsonObject responseBody = Utils.toJson(response).getAsJsonObject();
Assertions.assertEquals("Global Field deleted successfully.", responseBody.get("notice").getAsString());
}
//They work fine.
// @Test
// @Order(1)
// void testCreateNestedGlobalField() throws IOException {
// JSONObject requestBody = Utils.readJson("globalfield/nested_global_field.json");
// Request request = nestedGlobalField.create(requestBody).request();
// Assertions.assertEquals("https://api.contentstack.io/v3/global_fields", request.url().toString());
// Assertions.assertEquals("/v3/global_fields", request.url().encodedPath());
// Assertions.assertEquals("https", request.url().scheme());
// Assertions.assertEquals("POST", request.method());
// Assertions.assertEquals(apiVersion, request.header("api_version"));
// Response<ResponseBody> response = nestedGlobalField.create(requestBody).execute();
// Assertions.assertEquals(201, response.code());
// }

// @Test
// @Order(2)
// void testGetNestedGlobalField() throws IOException {
// nestedGlobalField.addParam("include_global_fields", true);
// nestedGlobalField.addParam("include_validation_keys", true);
// Request request = nestedGlobalField.fetch().request();
// Assertions.assertEquals("https://api.contentstack.io/v3/global_fields/" + nestedUid + "?include_global_fields=true&include_validation_keys=true", request.url().toString());
// Assertions.assertEquals("https", request.url().scheme());
// Assertions.assertEquals("GET", request.method());
// Assertions.assertEquals(apiVersion, request.header("api_version"));
// Response<ResponseBody> response = nestedGlobalField.fetch().execute();
// Assertions.assertEquals(200, response.code());
// JsonObject responseBody = Utils.toJson(response).getAsJsonObject();
// JsonObject globalField = responseBody.getAsJsonObject("global_field");
// Assertions.assertEquals("Nested Global Field", globalField.get("title").getAsString());
// Assertions.assertTrue(globalField.has("referred_global_fields"));
// Assertions.assertTrue(globalField.has("validation_keys"));
// }

// @Test
// @Order(3)
// void testUpdateNestedGlobalField() throws IOException {
// JSONObject requestBody = Utils.readJson("globalfield/nested_global_field_update1.json");
// Request request = nestedGlobalField.update(requestBody).request();
// Assertions.assertEquals("https://api.contentstack.io/v3/global_fields/" + nestedUid, request.url().toString());
// Assertions.assertEquals("/v3/global_fields/" + nestedUid, request.url().encodedPath());
// Assertions.assertEquals("https", request.url().scheme());
// Assertions.assertEquals("PUT", request.method());
// Assertions.assertEquals(apiVersion, request.header("api_version"));
// Response<ResponseBody> response = nestedGlobalField.update(requestBody).execute();
// Assertions.assertEquals(200, response.code());
// JsonObject responseBody = Utils.toJson(response).getAsJsonObject();
// JsonObject globalField = responseBody.getAsJsonObject("global_field");
// Assertions.assertEquals("Nested Global Field", globalField.get("title").getAsString());

// }

// @Test
// @Order(4)
// void testDeleteNestedGlobalField() throws IOException {
// Request request = nestedGlobalField.delete().request();
// Assertions.assertEquals("https://api.contentstack.io/v3/global_fields/" + nestedUid + "?force=true", request.url().toString());
// Assertions.assertEquals("https", request.url().scheme());
// Assertions.assertEquals("DELETE", request.method());
// Assertions.assertEquals(apiVersion, request.header("api_version"));
// Response<ResponseBody> response = nestedGlobalField.delete().execute();
// Assertions.assertEquals(200, response.code());
// JsonObject responseBody = Utils.toJson(response).getAsJsonObject();
// Assertions.assertEquals("Global Field deleted successfully.", responseBody.get("notice").getAsString());
// }

@Test
void testApiVersionHeaderIsolation() throws IOException {
Expand Down
Loading