Skip to content

Commit

Permalink
added bit more tests coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ibalosh committed Nov 23, 2017
1 parent 8942df8 commit b4f5676
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 1 deletion.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<organization>Wildbit</organization>
<organizationUrl>https://wildbit.com/</organizationUrl>
<url>https://twitter.com/ibalosh/</url>
<email>[email protected]</email>
</developer>
</developers>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
public class BaseApiClient extends HttpClientHandler {

public final String baseUrl;
protected final String baseUrl;
public String getEndpointUrl(String endpoint) {
return baseUrl + endpoint;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ public void setReadTimeoutSeconds(int readTimeoutSeconds) {
client.property(ClientProperties.READ_TIMEOUT, readTimeoutSeconds * 1000);
}

/**
* Access to original HTTP client used for requests
*
* @return original HTTP client
*/
public Client getClient() {
return client;
}

/**
* Gets simplified HTTP request response that will contain only response and status.
*
Expand Down
37 changes: 37 additions & 0 deletions src/test/java/integration/TriggersTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package integration;

import base.BaseTest;
import com.wildbit.java.postmark.client.ApiClient;
import com.wildbit.java.postmark.client.Parameters;
import com.wildbit.java.postmark.client.data.model.templates.*;
import com.wildbit.java.postmark.client.data.model.triggers.InboundRules;
import com.wildbit.java.postmark.client.data.model.triggers.TagMatchers;
import com.wildbit.java.postmark.client.exception.PostmarkException;
import org.junit.jupiter.api.Test;

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

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

/**
* Created by bash on 11/14/17.
*/
public class TriggersTest extends BaseTest {

ApiClient client = getDefaultApiClient();

@Test
void listTagTriggers() throws PostmarkException, IOException {
TagMatchers matchers = client.getTriggerTags(Parameters.init().build("count",5).build("offset",0));
assertNotNull(matchers.getTotalCount());
}

@Test
void listInboundRuleTriggers() throws PostmarkException, IOException {
InboundRules inboundRules = client.getInboundRules(Parameters.init().build("count",5).build("offset",0));
assertNotNull(inboundRules.getTotalCount());
}

}
38 changes: 38 additions & 0 deletions src/test/java/unit/client/BaseApiClientTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package unit.client;

import com.wildbit.java.postmark.Postmark;
import com.wildbit.java.postmark.client.ApiClient;
import com.wildbit.java.postmark.client.BaseApiClient;
import com.wildbit.java.postmark.client.HttpClient;
import org.junit.jupiter.api.Test;

import javax.ws.rs.core.MultivaluedHashMap;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

/**
* Created by bash on 11/13/17.
*/
public class BaseApiClientTest {

MultivaluedHashMap headers = Postmark.DefaultHeaders.headers();
BaseApiClient client = new BaseApiClient(Postmark.DEFAULTS.API_URL.value, headers);

@Test
void getBaseUrl() {
assertEquals(client.getBaseUrl(), Postmark.DEFAULTS.API_URL.value);
client.getEndpointUrl("/test");
}

@Test
void getEndpointUrl() {
String endpoint = "/test";
assertEquals(client.getEndpointUrl(endpoint), Postmark.DEFAULTS.API_URL.value + endpoint);
}

@Test
void getHttpClient() {
assertEquals(client.getHttpClient().getClass(), HttpClient.class);
}
}
13 changes: 13 additions & 0 deletions src/test/java/unit/client/HttpClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ void execute() throws IOException, PostmarkException {

assertEquals(response.getCode(),302);
assertNotNull(response.getMessage());
}

@Test
void executeIncorrectLink() throws IOException, PostmarkException {
HttpClient client = new HttpClient(new MultivaluedHashMap<>());
HttpClient.ClientResponse response = client.execute(HttpClient.REQUEST_TYPES.GET, "https://" + Postmark.DEFAULTS.API_URL.value + "/someweirdlink");

assertEquals(response.getCode(),404);
}

@Test
void getClient() throws IOException, PostmarkException {
HttpClient client = new HttpClient(new MultivaluedHashMap<>());
assertNotNull(client.getClient());
}
}

0 comments on commit b4f5676

Please sign in to comment.