A java implementation of the Binance API Specification
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.3 KiB

package com.sigmaflare.binancej.matchers;
import org.apache.commons.io.IOUtils;
import org.apache.http.client.methods.HttpPost;
import org.mockito.ArgumentMatcher;
import java.io.IOException;
public class PostMatcher implements ArgumentMatcher<HttpPost> {
private String url;
private String apiKey;
private String requestBody;
public PostMatcher(String url, String apiKey, String requestBody) {
this.url = url;
this.apiKey = apiKey;
this.requestBody = requestBody;
}
/**
* Matches HttpPost objects based on "loose matching". We really only care that the URL and associated
* headers we care about are correct.
* @param httpPost The HttpPost object under test
* @return True if they are equal by our definition, false otherwise
*/
public boolean matches(HttpPost httpPost) {
final String url = httpPost.getURI().toASCIIString();
final String apiKeyHeaderValue = httpPost.getFirstHeader("X-MBX-APIKEY").getValue();
try {
String testBody = IOUtils.toString(httpPost.getEntity().getContent(), "UTF-8");
return this.url.equals(url) && apiKey.equals(apiKeyHeaderValue) && requestBody.equals(testBody);
} catch(IOException e) {
return false;
}
}
}