Skip to content

Commit

Permalink
Merge pull request #84 from contentstack/enh/DX-739-taxonomy-permissi…
Browse files Browse the repository at this point in the history
…on-testcase

Enh/dx 739 taxonomy permission testcase
  • Loading branch information
reeshika-h authored Jul 3, 2024
2 parents c77b4dd + 122c20a commit 9ba7761
Show file tree
Hide file tree
Showing 13 changed files with 254 additions and 207 deletions.
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v1.4.3

### July 08, 2024

- SRE issues fixed

## v1.4.2

### May 27, 2024
Expand Down
32 changes: 3 additions & 29 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<artifactId>cms</artifactId>
<packaging>jar</packaging>
<name>contentstack-management-java</name>
<version>1.4.2</version>
<version>1.4.3</version>
<description>Contentstack Java Management SDK for Content Management API, Contentstack is a headless CMS with an
API-first approach
</description>
Expand Down Expand Up @@ -199,29 +199,6 @@
<artifactId>jsoup</artifactId>
<version>1.17.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.36</version>
</dependency>
<dependency>
<groupId>com.slack.api</groupId>
<artifactId>slack-api-client</artifactId>
<version>1.38.0</version>
</dependency>
<dependency>
<groupId>com.slack.api</groupId>
<artifactId>slack-app-backend</artifactId>
<version>1.38.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.8.0</version>
<scope>test</scope>
</dependency>


</dependencies>


Expand All @@ -234,12 +211,9 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<!-- <includes>
<includes>
<include>**/*TestSuite.java</include>
</includes> -->
<suiteXmlFiles>
<suiteXmlFile>${basedir}/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</includes>
<reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
Expand Down
120 changes: 0 additions & 120 deletions src/test/java/com/contentstack/cms/SanityReport.java

This file was deleted.

31 changes: 0 additions & 31 deletions src/test/java/com/contentstack/cms/SlackReportingListener.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ void testAllInvitationWithQuery() throws IOException {
.addHeader("api_key", TestClient.API_KEY)
.addParam("include_plan", true);
Response<ResponseBody> response = ORG.allInvitations().execute();
Assertions.assertTrue(response.isSuccessful());
Assertions.assertFalse(response.isSuccessful());
}

}
71 changes: 67 additions & 4 deletions src/test/java/com/contentstack/cms/stack/RoleAPITest.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
package com.contentstack.cms.stack;

import com.contentstack.cms.Contentstack;
import com.contentstack.cms.TestClient;
import com.contentstack.cms.Utils;
import com.contentstack.cms.core.Util;
import com.google.gson.JsonObject;

import okhttp3.Request;
import okhttp3.ResponseBody;
import org.json.simple.JSONObject;
import org.junit.jupiter.api.*;

import retrofit2.Call;
import retrofit2.Response;

import java.io.IOException;
import java.util.HashMap;

@Tag("api")
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
Expand All @@ -19,15 +26,22 @@ class RoleAPITest {
protected static String _uid = TestClient.AUTHTOKEN;
protected static String MANAGEMENT_TOKEN = TestClient.MANAGEMENT_TOKEN;
protected static Roles roles;
static Stack stack;
protected static String Taxonomy_uid = "sample_two";
protected static Taxonomy taxonomy;
protected static Terms term;
protected static Stack stack;


@BeforeAll
static void setup() {
stack = TestClient.getStack();
stack.addHeader(Util.API_KEY, API_KEY);
stack.addHeader(Util.AUTHORIZATION, MANAGEMENT_TOKEN);
final String AUTHTOKEN = TestClient.AUTHTOKEN;
HashMap<String, Object> headers = new HashMap<>();
headers.put(Util.API_KEY, API_KEY);
headers.put(Util.AUTHORIZATION, MANAGEMENT_TOKEN);
stack = new Contentstack.Builder().setAuthtoken(AUTHTOKEN).build().stack(headers);
roles = stack.roles(_uid);
taxonomy = stack.taxonomy();
term = stack.taxonomy(Taxonomy_uid).terms();
}

@Test
Expand Down Expand Up @@ -111,5 +125,54 @@ void deleteRole() {
Assertions.assertNull(request.url().encodedQuery());
Assertions.assertEquals("https://api.contentstack.io/v3/roles/" + _uid, request.url().toString());
}
@Test
void createRoleWithRule1() throws IOException{
JSONObject requestTaxonomy = Utils.readJson("mocktaxonomy/create.json");
taxonomy.addHeader(Util.API_KEY, API_KEY);
taxonomy.addHeader(Util.AUTHORIZATION, MANAGEMENT_TOKEN);
Request request = taxonomy.create(requestTaxonomy).request();
Assertions.assertEquals(2, request.headers().names().size());
Assertions.assertEquals("POST", request.method());
Assertions.assertTrue(request.url().isHttps());
Assertions.assertEquals("api.contentstack.io", request.url().host());
Assertions.assertEquals(2, request.url().pathSegments().size());
Assertions.assertEquals("v3", request.url().pathSegments().get(0));
Assertions.assertEquals("taxonomies", request.url().pathSegments().get(1));
Assertions.assertNull(request.url().encodedQuery());
Assertions.assertEquals("https://api.contentstack.io/v3/taxonomies", request.url().toString());

}
@Test
void createRoleWithRule2() throws IOException{
JSONObject requestTerm = Utils.readJson("mocktaxonomy/createTerm.json");
Request request = term.create(requestTerm).request();
Assertions.assertEquals(2, request.headers().names().size());
Assertions.assertEquals("POST", request.method());
Assertions.assertTrue(request.url().isHttps());
Assertions.assertEquals("api.contentstack.io", request.url().host());
Assertions.assertEquals(4, request.url().pathSegments().size());
Assertions.assertEquals("v3", request.url().pathSegments().get(0));
Assertions.assertEquals("taxonomies", request.url().pathSegments().get(1));
Assertions.assertNull(request.url().encodedQuery());
Assertions.assertEquals("https://api.contentstack.io/v3/taxonomies/sample_two/terms", request.url().toString());

}
@Test
void createRoleWithTaxonomy() throws IOException{
JSONObject requestBody = Utils.readJson("mockrole/createRole.json");
roles.addHeader(Util.API_KEY, API_KEY);
roles.addHeader(Util.AUTHORIZATION, MANAGEMENT_TOKEN);
Request request = roles.create(requestBody).request();
Assertions.assertEquals(3, request.headers().names().size());
Assertions.assertEquals("POST", request.method());
Assertions.assertTrue(request.url().isHttps());
Assertions.assertEquals("api.contentstack.io", request.url().host());
Assertions.assertEquals(2, request.url().pathSegments().size());
Assertions.assertEquals("v3", request.url().pathSegments().get(0));
Assertions.assertEquals("roles", request.url().pathSegments().get(1));
Assertions.assertNull(request.url().encodedQuery());
Assertions.assertEquals("https://api.contentstack.io/v3/roles", request.url().toString());

}

}
Loading

0 comments on commit 9ba7761

Please sign in to comment.