Skip to content

Commit

Permalink
(jcabi#254) Add more intergration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andreoss committed Jun 28, 2021
1 parent aaa2e1d commit 5e30bf0
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions src/test/java/com/jcabi/http/RequestITCaseTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
package com.jcabi.http;

import com.jcabi.aspects.Tv;
import com.jcabi.http.request.ApacheRequest;
import com.jcabi.http.request.JdkRequest;
import com.jcabi.http.response.JsonResponse;
import com.jcabi.http.response.RestResponse;
Expand All @@ -41,6 +42,7 @@
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URI;
import java.util.Collections;
import java.util.Locale;
import javax.json.Json;
import javax.json.JsonObject;
Expand Down Expand Up @@ -177,6 +179,63 @@ final void readsJsonResponse() throws Exception {
);
}

@Test
final void sendsQueryParams() throws Exception {
MatcherAssert.assertThat(
"Must parse Json response",
this.request("/anything")
.uri()
.queryParams(Collections.singletonMap("foo", "bar"))
.queryParams(Collections.singletonMap("fee", "baz"))
.back()
.fetch()
.as(JsonResponse.class)
.json()
.readObject()
.getJsonObject("args"),
Matchers.allOf(
Matchers.hasEntry(
Matchers.is("foo"),
Matchers.is(Json.createValue("bar"))
),
Matchers.hasEntry(
Matchers.is("fee"),
Matchers.is(Json.createValue("baz"))
)
)
);
}


@Test
@DisabledIf("isApacheRequest")
final void sendsFormParams() throws Exception {
MatcherAssert.assertThat(
"Must parse Json response",
this.request("/anything")
.method(Request.POST)
.body()
.formParam("a", Tv.THREE)
.formParam("b", Tv.FOUR)
.back()
.fetch()
.as(JsonResponse.class)
.json()
.readObject()
.getJsonObject("form"),
Matchers.allOf(
Matchers.hasEntry(
Matchers.is("a"),
Matchers.is(Json.createValue(String.valueOf(Tv.THREE)))
),
Matchers.hasEntry(
Matchers.is("b"),
Matchers.is(Json.createValue(String.valueOf(Tv.FOUR)))
)
)
);
}

@Test
@DisabledIf("isJdkRequest")
final void readsDeflatedJsonResponse() throws Exception {
Expand Down Expand Up @@ -241,6 +300,15 @@ final void readsXmlResponse() throws Exception {
);
}

/**
* Is ApacheRequest being tested?
* @return True if so.
*/
@SuppressWarnings("PMD.UnusedPrivateMethod")
private boolean isApacheRequest() {
return ApacheRequest.class.equals(this.type);
}

/**
* Is JdkRequest being tested?
* @return True if so.
Expand Down

0 comments on commit 5e30bf0

Please sign in to comment.