This repository has been archived by the owner on Feb 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Took 7 minutes
- Loading branch information
Showing
9 changed files
with
124 additions
and
49 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
14 changes: 14 additions & 0 deletions
14
src/main/java/ch/viascom/groundwork/foxhttp/cache/FoxHttpCacheStrategy.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 |
---|---|---|
@@ -1,8 +1,22 @@ | ||
package ch.viascom.groundwork.foxhttp.cache; | ||
|
||
import ch.viascom.groundwork.foxhttp.FoxHttpClient; | ||
import ch.viascom.groundwork.foxhttp.FoxHttpRequest; | ||
import ch.viascom.groundwork.foxhttp.FoxHttpResponse; | ||
|
||
/** | ||
* @author [email protected] | ||
*/ | ||
public interface FoxHttpCacheStrategy { | ||
|
||
boolean isCachingEnabled(); | ||
|
||
void setCachingEnabled(boolean enabled); | ||
|
||
boolean isCachingAvailable(FoxHttpRequest request, FoxHttpClient client); | ||
|
||
FoxHttpResponse loadDataFromCache(FoxHttpRequest request, FoxHttpClient client); | ||
|
||
void saveDataToCache(FoxHttpResponse response, FoxHttpRequest request, FoxHttpClient client); | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/ch/viascom/groundwork/foxhttp/cache/NoCacheStrategy.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,34 @@ | ||
package ch.viascom.groundwork.foxhttp.cache; | ||
|
||
import ch.viascom.groundwork.foxhttp.FoxHttpClient; | ||
import ch.viascom.groundwork.foxhttp.FoxHttpRequest; | ||
import ch.viascom.groundwork.foxhttp.FoxHttpResponse; | ||
import java.io.InputStream; | ||
|
||
public class NoCacheStrategy implements FoxHttpCacheStrategy { | ||
|
||
@Override | ||
public boolean isCachingEnabled() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public void setCachingEnabled(boolean enabled) { | ||
|
||
} | ||
|
||
@Override | ||
public boolean isCachingAvailable(FoxHttpRequest request, FoxHttpClient client) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public FoxHttpResponse loadDataFromCache(FoxHttpRequest request, FoxHttpClient client) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void saveDataToCache(FoxHttpResponse response, FoxHttpRequest request, FoxHttpClient client) { | ||
|
||
} | ||
} |
1 change: 1 addition & 0 deletions
1
src/test/java/ch/viascom/groundwork/foxhttp/FoxHttpParserTest.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
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 |
---|---|---|
@@ -1,29 +1,34 @@ | ||
package ch.viascom.groundwork.foxhttp; | ||
|
||
import ch.viascom.groundwork.foxhttp.body.request.*; | ||
import static org.fest.assertions.api.Assertions.assertThat; | ||
|
||
import ch.viascom.groundwork.foxhttp.body.request.FoxHttpRequestBody; | ||
import ch.viascom.groundwork.foxhttp.body.request.RequestByteArrayBody; | ||
import ch.viascom.groundwork.foxhttp.body.request.RequestMultipartBody; | ||
import ch.viascom.groundwork.foxhttp.body.request.RequestObjectBody; | ||
import ch.viascom.groundwork.foxhttp.body.request.RequestServiceResultBody; | ||
import ch.viascom.groundwork.foxhttp.body.request.RequestUrlEncodedFormBody; | ||
import ch.viascom.groundwork.foxhttp.builder.FoxHttpClientBuilder; | ||
import ch.viascom.groundwork.foxhttp.builder.FoxHttpRequestBuilder; | ||
import ch.viascom.groundwork.foxhttp.exception.FoxHttpRequestException; | ||
import ch.viascom.groundwork.foxhttp.log.FoxHttpLoggerLevel; | ||
import ch.viascom.groundwork.foxhttp.log.SystemOutFoxHttpLogger; | ||
import ch.viascom.groundwork.foxhttp.models.PostResponse; | ||
import ch.viascom.groundwork.foxhttp.models.User; | ||
import ch.viascom.groundwork.foxhttp.parser.GenericParser; | ||
import ch.viascom.groundwork.foxhttp.parser.GsonParser; | ||
import ch.viascom.groundwork.foxhttp.type.ContentType; | ||
import ch.viascom.groundwork.foxhttp.type.RequestType; | ||
import ch.viascom.groundwork.serviceresult.ServiceResult; | ||
import ch.viascom.groundwork.serviceresult.ServiceResultStatus; | ||
import ch.viascom.groundwork.serviceresult.util.Metadata; | ||
import com.google.gson.Gson; | ||
import com.google.gson.JsonElement; | ||
import org.junit.Test; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.FileInputStream; | ||
import java.io.InputStream; | ||
import java.io.Serializable; | ||
import java.nio.charset.Charset; | ||
|
||
import static org.fest.assertions.api.Assertions.assertThat; | ||
import org.junit.Test; | ||
|
||
/** | ||
* @author [email protected] | ||
|
@@ -65,7 +70,6 @@ public void postURLEncodedFormRequest() throws Exception { | |
requestBuilder.setRequestBody(requestBody); | ||
FoxHttpResponse foxHttpResponse = requestBuilder.build().execute(); | ||
|
||
|
||
assertThat(foxHttpResponse.getResponseCode()).isEqualTo(200); | ||
assertThat(foxHttpResponse.getByteArrayOutputStreamBody().size()).isGreaterThan(0); | ||
|
||
|
@@ -82,13 +86,13 @@ public void postMultiPartRequest() throws Exception { | |
|
||
RequestMultipartBody requestBody = new RequestMultipartBody(Charset.forName("UTF-8")); | ||
requestBody.addFormField("filename", "test.data"); | ||
requestBody.addInputStreamPart("file", "file.json", new ByteArrayInputStream("{\"name\":\"FoxHttp\"}".getBytes()), "QUOTED-PRINTABLE", ContentType.DEFAULT_TEXT.getMimeType()); | ||
requestBody.addInputStreamPart("file", "file.json", new ByteArrayInputStream("{\"name\":\"FoxHttp\"}".getBytes()), "QUOTED-PRINTABLE", | ||
ContentType.DEFAULT_TEXT.getMimeType()); | ||
|
||
FoxHttpRequestBuilder requestBuilder = new FoxHttpRequestBuilder(endpoint + "post", RequestType.POST, clientBuilder.build()); | ||
requestBuilder.setRequestBody(requestBody); | ||
FoxHttpResponse foxHttpResponse = requestBuilder.build().execute(); | ||
|
||
|
||
assertThat(foxHttpResponse.getResponseCode()).isEqualTo(200); | ||
assertThat(foxHttpResponse.getByteArrayOutputStreamBody().size()).isGreaterThan(0); | ||
|
||
|
@@ -116,7 +120,8 @@ public void postServiceResultRequest() throws Exception { | |
|
||
PostResponse postResponse = foxHttpResponse.getParsedBody(PostResponse.class); | ||
|
||
assertThat(postResponse.getData()).isEqualTo("{\"status\":\"failed\",\"type\":\"ch.viascom.app.models.AppUser\",\"content\":{\"username\":\"[email protected]\",\"firstname\":\"Fox\",\"lastname\":\"Http\"},\"hash\":\"FAKE-HASH\",\"destination\":\"\",\"metadata\":{\"isActive\":{\"type\":\"java.lang.Boolean\",\"content\":true}}}"); | ||
assertThat(postResponse.getData()).isEqualTo( | ||
"{\"status\":\"failed\",\"type\":\"ch.viascom.app.models.AppUser\",\"content\":{\"username\":\"[email protected]\",\"firstname\":\"Fox\",\"lastname\":\"Http\"},\"hash\":\"FAKE-HASH\",\"destination\":\"\",\"metadata\":{\"isActive\":{\"type\":\"java.lang.Boolean\",\"content\":true}}}"); | ||
} | ||
|
||
@Test | ||
|
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