use of com.stanfy.enroscar.net.operation.RequestDescription in project enroscar by stanfy.
the class RemoteServerApiConfigurationTest method createRequestDescription.
private RequestDescription createRequestDescription() {
RequestBuilder<?> rb = new SimpleRequestBuilder<String>(Robolectric.application) {
}.setUrl("http://example.com");
final RequestDescription[] rd = new RequestDescription[1];
rb.setExecutor(new RequestExecutor() {
@Override
public void performRequest(final RequestDescription d) {
rd[0] = d;
}
});
rb.execute();
return rd[0];
}
use of com.stanfy.enroscar.net.operation.RequestDescription in project enroscar by stanfy.
the class RequestDescriptionTest method shouldManageHeaders.
@Test
public void shouldManageHeaders() {
RequestDescription rd = new RequestDescription();
assertThat(rd.getHeader("h1")).isNull();
rd.addHeader("h1", "v1");
assertThat(rd.getHeader("h1")).isEqualTo("v1");
rd.removeHeader("h1");
assertThat(rd.getHeader("h1")).isNull();
rd.addHeader("h1", "v1");
rd.addHeader("h2", "v2");
assertThat(rd.getHeader("h2")).isEqualTo("v2");
rd.clearHeaders();
assertThat(rd.getHeader("h1")).isNull();
assertThat(rd.getHeader("h2")).isNull();
}
use of com.stanfy.enroscar.net.operation.RequestDescription in project enroscar by stanfy.
the class AbstractMockServerTest method whenBeansConfigured.
@Override
protected void whenBeansConfigured() {
super.whenBeansConfigured();
BeansManager.get(getApplication()).getContainer().getBean(RemoteServerApiConfiguration.class).setDefaultRequestMethod(new RequestMethod() {
@Override
protected void before(final Context systemContext, final RequestDescription description) {
// do not use TrafficStats
}
@Override
protected void after(final Context systemContext, final RequestDescription description) {
// do not use TrafficStats
}
});
if (config == null) {
config = BeanUtils.getAnnotationFromHierarchy(getClass(), EnroscarNetConfig.class);
}
if (config != null && config.connectionEngineRequired()) {
final Config config = EnroscarConnectionsEngine.config();
configureConnectionsEngine(config);
config.treatFileScheme(false);
config.setup(Robolectric.application);
}
configureServiceBind();
}
use of com.stanfy.enroscar.net.operation.RequestDescription in project enroscar by stanfy.
the class BaseRequestBuilderTest method testAddSimpleParameters.
@Test
public void testAddSimpleParameters() {
final MyBuilder b = new MyBuilder();
final int count = 5;
b.addSimpleParameter("boolean1", true);
b.addSimpleParameter("boolean2", false);
b.addSimpleParameter("string", "abc");
b.addSimpleParameter("int", 1);
b.addSimpleParameter("long", 2L);
final RequestDescription d = b.getResult();
assertThat(d.getSimpleParameters().getChildren().size()).isEqualTo(count);
final ArrayList<String> names = new ArrayList<String>(), values = new ArrayList<String>();
for (final Parameter p : d.getSimpleParameters().getChildren()) {
final ParameterValue pv = (ParameterValue) p;
names.add(pv.getName());
values.add(pv.getValue());
}
assertThat(names).isEqualTo(Arrays.asList("boolean1", "boolean2", "string", "int", "long"));
assertThat(values).isEqualTo(Arrays.asList("1", "0", "abc", "1", "2"));
}
Aggregations