Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed dev host #41

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dev-host=dev18-app.csnonprod.com
dev-host=api.contentstack.io // use developer host here
12 changes: 6 additions & 6 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.1.0-SNAPSHOT</version>
<version>1.1.0</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 @@ -67,11 +67,11 @@
<name>Apache Maven Packages Snapshot</name>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<!-- <snapshotRepository>
<id>github</id>
<name>GitHub Apache Maven Packages</name>
<url>https://maven.pkg.github.com/contentstack/contentstack-management-java</url>
</snapshotRepository> -->
<!-- <snapshotRepository>-->
<!-- <id>github</id>-->
<!-- <name>GitHub Apache Maven Packages</name>-->
<!-- <url>https://maven.pkg.github.com/contentstack/contentstack-management-java</url>-->
<!-- </snapshotRepository> -->
<repository>
<id>ossrh</id>
<name>Apache Maven Packages Release</name>
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/contentstack/cms/BaseImplementation.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public interface BaseImplementation<T> {
* object as its value.
* @return The method is returning an object of type T.
*/
T addParam(@NotNull String key, @NotNull Object value);
T addParam(@NotNull String key, @NotNull Object value);

/**
* The function adds a header with a key-value pair to a request.
Expand All @@ -45,7 +45,7 @@ public interface BaseImplementation<T> {
* annotated with @NotNull, indicating that it cannot be null.
* @return The method is returning an object of type T.
*/
T addParams(@NotNull HashMap<String, Object> params);
T addParams(@NotNull HashMap<String, Object> params);

/**
* The function adds headers to a HashMap.
Expand All @@ -56,5 +56,5 @@ public interface BaseImplementation<T> {
* representing the header value.
* @return The method is returning an object of type T.
*/
T addHeaders(@NotNull HashMap<String, String> headers);
T addHeaders(@NotNull HashMap<String, String> headers);
}
54 changes: 30 additions & 24 deletions src/main/java/com/contentstack/cms/Contentstack.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public class Contentstack {
* @return User
* @author ishaileshmishra
* @see <a href=
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#users">User
* </a>
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#users">User
* </a>
* @since 2022-05-19
*/
public User user() {
Expand Down Expand Up @@ -130,8 +130,8 @@ public User user() {
* @throws IOException the IOException
* @author ishaileshmishra
* @see <a href=
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#users">User
* </a>
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#users">User
* </a>
*/
public Response<LoginDetails> login(String emailId, String password) throws IOException {
if (this.authtoken != null)
Expand Down Expand Up @@ -183,10 +183,10 @@ public Response<LoginDetails> login(String emailId, String password) throws IOEx
* @throws IOException the IOException
* @author ishaileshmishra
* @see <a
* href=
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#log-in-to-your-account">Login
* your account
* </a>
* href=
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#log-in-to-your-account">Login
* your account
* </a>
*/
public Response<LoginDetails> login(String emailId, String password, String tfaToken) throws IOException {
if (this.authtoken != null)
Expand All @@ -201,7 +201,7 @@ public Response<LoginDetails> login(String emailId, String password, String tfaT
private void setupLoginCredentials(Response<LoginDetails> loginResponse) throws IOException {
if (loginResponse.isSuccessful()) {
assert loginResponse.body() != null;
//logger.info(loginResponse.body().getNotice());
// logger.info(loginResponse.body().getNotice());
this.authtoken = loginResponse.body().getUser().getAuthtoken();
this.interceptor.setAuthtoken(this.authtoken);
} else {
Expand Down Expand Up @@ -287,10 +287,10 @@ public Organization organization() {
*
* @param organizationUid The UID of the organization that you want to retrieve
* @return the organization
* <br>
* <b>Example</b>
* <br>
* <b>Example</b>
*
* <pre>
* <pre>
* Contentstack contentstack = new Contentstack.Builder().build();
* Organization org = contentstack.organization();
* </pre>
Expand Down Expand Up @@ -398,13 +398,12 @@ public Stack stack(@NotNull String key) {
// When API_Key is available
headers.put(API_KEY, key);
} else {
//When branch is available
// When branch is available
headers.put(BRANCH, key);
}
return new Stack(this.instance, headers);
}


/**
* <a href=
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#stacks">stack</a>
Expand Down Expand Up @@ -489,11 +488,14 @@ public Builder() {
* <br>
* <p>
* {@code
* <p>
*
<p>
* Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("hostname", 433));
* Contentstack contentstack = new Contentstack.Builder().setProxy(proxy).build();
* <p>
*
<p>
* }
*
* @param proxy the proxy
* @return the Builder instance
*/
Expand Down Expand Up @@ -557,11 +559,13 @@ public Builder setTimeout(int timeout) {
return this;
}


/**
* Create a new connection pool with tuning parameters appropriate for a single-user application.
* The tuning parameters in this pool are subject to change in future OkHttp releases. Currently,
* this pool holds up to 5 idle connections which will be evicted after 5 minutes of inactivity.
* Create a new connection pool with tuning parameters appropriate for a
* single-user application.
* The tuning parameters in this pool are subject to change in future OkHttp
* releases. Currently,
* this pool holds up to 5 idle connections which will be evicted after 5
* minutes of inactivity.
* <p>
* <p>
* public ConnectionPool() {
Expand All @@ -570,11 +574,13 @@ public Builder setTimeout(int timeout) {
*
* @param maxIdleConnections Maximum number of idle connections
* @param keepAliveDuration The Keep Alive Duration
* @param timeUnit A TimeUnit represents time durations at a given unit of granularity and provides utility methods to convert across units
* @param timeUnit A TimeUnit represents time durations at a given
* unit of granularity and provides utility methods to
* convert across units
* @return instance of Builder
* <p>
* Example:
* {@code
* <p>
* Example:
* {@code
* Contentstack cs = new Contentstack.Builder()
* .setAuthtoken(AUTHTOKEN)
* .setConnectionPool(5, 400, TimeUnit.MILLISECONDS)
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/contentstack/cms/package-info.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* This is topmost package that is used to contains all the sub-packages in itself
* This is topmost package that is used to contains all the sub-packages in
* itself
* like core, models, organisations, stacks, users and contentstack
*/
package com.contentstack.cms;
14 changes: 8 additions & 6 deletions src/test/java/com/contentstack/cms/TestClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@ public class TestClient {

final static Dotenv env = Dotenv.load();

public final static String ORGANIZATION_UID = (env.get("organizationUid") != null) ? env.get("organizationUid") : "orgId999999999";
public final static String ORGANIZATION_UID = (env.get("organizationUid") != null) ? env.get("organizationUid")
: "orgId999999999";
public final static String AUTHTOKEN = (env.get("authToken") != null) ? env.get("authToken") : "auth999999999";
public final static String USER_ID = (env.get("userId") != null) ? env.get("userId") : "c11e668e0295477f";
public final static String OWNERSHIP = (env.get("ownershipToken") != null) ? env.get("ownershipToken") : "ownershipTokenId";
public final static String OWNERSHIP = (env.get("ownershipToken") != null) ? env.get("ownershipToken")
: "ownershipTokenId";
public final static String API_KEY = (env.get("apiKey") != null) ? env.get("apiKey") : "apiKey99999999";
public final static String MANAGEMENT_TOKEN = (env.get("managementToken") != null) ? env.get("managementToken") : "managementToken99999999";
public final static String MANAGEMENT_TOKEN = (env.get("managementToken") != null) ? env.get("managementToken")
: "managementToken99999999";

public final static String DEV_HOST = (env.get("dev_host") != null) ? env.get("dev_host") : "dev18-app.csnonprod.com";
public final static String DEV_HOST = "api.contentstack.io";
// (env.get("dev_host") != null) ? env.get("dev_host") : "api.contentstack.io";
private static Contentstack instance;
private static Stack stackInstance;

Expand All @@ -37,7 +41,6 @@ public static Contentstack getClient() {
return instance;
}


public static Contentstack getCustomClient() {
if (instance == null) {
synchronized (Contentstack.class) {
Expand Down Expand Up @@ -71,4 +74,3 @@ public static Stack getStack() {
}

}

33 changes: 21 additions & 12 deletions src/test/java/com/contentstack/cms/stack/TaxonomyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ void fetchTest() {
Assertions.assertEquals("taxonomies", request.url().pathSegments().get(1));
Assertions.assertEquals("v3", request.url().pathSegments().get(0));
Assertions.assertNotNull(request.url().encodedQuery());
Assertions.assertEquals("https://api.contentstack.io/v3/taxonomies/taxonomyId?limit=2&skip=2&include_count=false", request.url().toString());
Assertions.assertEquals(
"https://api.contentstack.io/v3/taxonomies/taxonomyId?limit=2&skip=2&include_count=false",
request.url().toString());
}

@Test
Expand Down Expand Up @@ -149,7 +151,6 @@ void deleteTest() {
Assertions.assertEquals("https://api.contentstack.io/v3/taxonomies/taxonomyId", request.url().toString());
}


@Test
void deleteTestWithHeaders() {
taxonomy.clearParams();
Expand All @@ -174,7 +175,6 @@ void deleteTestWithHeaders() {
Assertions.assertEquals("https://api.contentstack.io/v3/taxonomies/taxonomyId", request.url().toString());
}


@Test
void createTest() {
JSONObject obj = new JSONObject();
Expand Down Expand Up @@ -212,7 +212,8 @@ void testCreateTerm() {
Assertions.assertEquals("terms", request.url().pathSegments().get(3));
Assertions.assertNotNull(request.body());
Assertions.assertNull(request.url().encodedQuery());
Assertions.assertEquals("https://api.contentstack.io/v3/taxonomies/auth999999999/terms", request.url().toString());
Assertions.assertEquals("https://api.contentstack.io/v3/taxonomies/auth999999999/terms",
request.url().toString());
}

@Test
Expand All @@ -231,7 +232,8 @@ void testFindTerm() {
Assertions.assertEquals("terms", request.url().pathSegments().get(3));
Assertions.assertNull(request.body());
Assertions.assertEquals("limit=3", request.url().encodedQuery());
Assertions.assertEquals("https://api.contentstack.io/v3/taxonomies/" + _uid + "/terms?limit=3", request.url().toString());
Assertions.assertEquals("https://api.contentstack.io/v3/taxonomies/" + _uid + "/terms?limit=3",
request.url().toString());
}

@Test
Expand All @@ -250,11 +252,13 @@ void testFetchTerm() {
Assertions.assertEquals(_uid, request.url().pathSegments().get(2));
Assertions.assertEquals("terms", request.url().pathSegments().get(3));
Assertions.assertNull(request.body());
Assertions.assertEquals("include_children_count=false&include_referenced_entries_count=true", request.url().encodedQuery());
Assertions.assertEquals("https://api.contentstack.io/v3/taxonomies/auth999999999/terms/auth999999999?include_children_count=false&include_referenced_entries_count=true", request.url().toString());
Assertions.assertEquals("include_children_count=false&include_referenced_entries_count=true",
request.url().encodedQuery());
Assertions.assertEquals(
"https://api.contentstack.io/v3/taxonomies/auth999999999/terms/auth999999999?include_children_count=false&include_referenced_entries_count=true",
request.url().toString());
}


@Test
void testTermUpdate() {
terms.clearParams();
Expand Down Expand Up @@ -302,7 +306,9 @@ void testDescendantsTerm() {
Assertions.assertEquals("terms", request.url().pathSegments().get(3));
Assertions.assertNull(request.body());
Assertions.assertEquals("include_count=true", request.url().encodedQuery());
Assertions.assertEquals("https://api.contentstack.io/v3/taxonomies/auth999999999/terms/termId45/descendants?include_count=true", request.url().toString());
Assertions.assertEquals(
"https://api.contentstack.io/v3/taxonomies/auth999999999/terms/termId45/descendants?include_count=true",
request.url().toString());
}

@Test
Expand All @@ -321,15 +327,18 @@ void testAncestorsTerm() {
Assertions.assertEquals(_uid, request.url().pathSegments().get(2));
Assertions.assertEquals("terms", request.url().pathSegments().get(3));
Assertions.assertNull(request.body());
Assertions.assertEquals("include_children_count=false&include_referenced_entries_count=true", request.url().encodedQuery());
Assertions.assertEquals("https://api.contentstack.io/v3/taxonomies/auth999999999/terms/termId45/ancestors?include_children_count=false&include_referenced_entries_count=true", request.url().toString());
Assertions.assertEquals("include_children_count=false&include_referenced_entries_count=true",
request.url().encodedQuery());
Assertions.assertEquals(
"https://api.contentstack.io/v3/taxonomies/auth999999999/terms/termId45/ancestors?include_children_count=false&include_referenced_entries_count=true",
request.url().toString());
}

@Test
void findTestAPI() throws IOException {
Taxonomy taxonomy = new Contentstack.Builder()
.setAuthtoken(TestClient.AUTHTOKEN)
.setHost("dev18-app.csnonprod.com")
.setHost("api.contentstack.io")
.build()
.stack("blt12c1ba95c1b11e88", "")
.taxonomy();
Expand Down
Loading