-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add Unit Tests to core package (#243)
- Loading branch information
1 parent
acb303e
commit 049b9ff
Showing
16 changed files
with
736 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/test/java/com/crowdin/client/core/http/CrowdinApiConstructorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.crowdin.client.core.http; | ||
|
||
import com.crowdin.client.Client; | ||
import com.crowdin.client.core.model.ClientConfig; | ||
import com.crowdin.client.core.model.Credentials; | ||
|
||
public class CrowdinApiConstructorTest extends Client { | ||
|
||
public CrowdinApiConstructorTest(Credentials credentials, ClientConfig clientConfig) { | ||
super(credentials, clientConfig); | ||
} | ||
|
||
public CrowdinApiConstructorTest(Credentials credentials) { | ||
super(credentials); | ||
} | ||
|
||
public HttpClient getHttpClient() { | ||
return this.httpClient; | ||
} | ||
|
||
public String geturl() { | ||
return this.url; | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
src/test/java/com/crowdin/client/core/http/CrowdinApiTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.crowdin.client.core.http; | ||
|
||
import com.crowdin.client.core.http.impl.http.ApacheHttpClient; | ||
import com.crowdin.client.core.http.impl.json.JacksonJsonTransformer; | ||
import com.crowdin.client.core.model.ClientConfig; | ||
import com.crowdin.client.core.model.Credentials; | ||
import com.crowdin.client.framework.TestHttpClient; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestInstance; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
public class CrowdinApiTest { | ||
|
||
private final String organization = "testOrganization"; | ||
private final String token = "testToken"; | ||
private final String regularUrl = "https://api.crowdin.com/api/v2"; | ||
private final String organizationUrl = "https://testOrganization.api.crowdin.com/api/v2"; | ||
|
||
@Test | ||
public void testCrowdinApiWithNullInputs() { | ||
CrowdinApiConstructorTest client = new CrowdinApiConstructorTest(new Credentials(null, null, null), ClientConfig.builder() | ||
.userAgent("User-Agent") | ||
.build()); | ||
assertNotNull(client); | ||
assertInstanceOf(ApacheHttpClient.class, client.getHttpClient()); | ||
} | ||
|
||
@Test | ||
public void testCrowdinApiWithAgent() { | ||
CrowdinApiConstructorTest client = new CrowdinApiConstructorTest(new Credentials(null, null, null), ClientConfig.builder() | ||
.integrationUserAgent("X-Crowdin-Integrations-User-Agent") | ||
.jsonTransformer(new JacksonJsonTransformer()) | ||
.build()); | ||
assertNotNull(client); | ||
assertInstanceOf(ApacheHttpClient.class, client.getHttpClient()); | ||
assertEquals(client.geturl(), regularUrl); | ||
} | ||
|
||
@Test | ||
public void testCrowdinApiWithBaseUrl() { | ||
CrowdinApiConstructorTest client = new CrowdinApiConstructorTest(new Credentials(token, organization, "/"), ClientConfig.builder() | ||
.httpClient(new TestHttpClient()).build()); | ||
assertEquals(client.geturl(), "/api/v2"); | ||
} | ||
|
||
@Test | ||
public void testCrowdinApiWithBaseUrlEmpty() { | ||
CrowdinApiConstructorTest client = new CrowdinApiConstructorTest(new Credentials(token, organization, ""), ClientConfig.builder() | ||
.userAgent("User-Agent") | ||
.httpClient(new TestHttpClient()).build()); | ||
assertEquals(client.geturl(), "/api/v2"); | ||
} | ||
|
||
@Test | ||
public void testCrowdinApiForRegularUrl() { | ||
CrowdinApiConstructorTest client = new CrowdinApiConstructorTest(new Credentials(token, null, null), ClientConfig.builder() | ||
.userAgent("User-Agent") | ||
.httpClient(new TestHttpClient()).build()); | ||
assertEquals(client.geturl(), regularUrl); | ||
} | ||
|
||
@Test | ||
public void testCrowdinApiForOrganizationUrl() { | ||
CrowdinApiConstructorTest client = new CrowdinApiConstructorTest(new Credentials(token, organization, null), ClientConfig.builder() | ||
.userAgent("User-Agent") | ||
.httpClient(new TestHttpClient()).build()); | ||
assertEquals(client.geturl(), organizationUrl); | ||
} | ||
|
||
@Test | ||
public void testCrowdinApiConstructor() { | ||
CrowdinApiConstructorTest client = new CrowdinApiConstructorTest(new Credentials(token, organization, null)); | ||
assertInstanceOf(ApacheHttpClient.class, client.getHttpClient()); | ||
assertEquals(client.geturl(), organizationUrl); | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
src/test/java/com/crowdin/client/core/http/exception/HttpExceptionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.crowdin.client.core.http.exception; | ||
|
||
import com.crowdin.client.core.http.exceptions.HttpException; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class HttpExceptionTest { | ||
|
||
@Test | ||
public void httpExceptionFromTest() { | ||
HttpException message = HttpException.fromMessage("Exception message!"); | ||
assertEquals(message.getError().getMessage(), "Exception message!"); | ||
} | ||
} |
Oops, something went wrong.