Search in sources :

Example 1 with RequestDescription

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];
}
Also used : RequestExecutor(com.stanfy.enroscar.net.operation.executor.RequestExecutor) RequestDescription(com.stanfy.enroscar.net.operation.RequestDescription)

Example 2 with RequestDescription

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();
}
Also used : RequestDescription(com.stanfy.enroscar.net.operation.RequestDescription) Test(org.junit.Test) AbstractMockServerTest(com.stanfy.enroscar.net.test.AbstractMockServerTest)

Example 3 with RequestDescription

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();
}
Also used : Context(android.content.Context) EnroscarNetConfig(com.stanfy.enroscar.test.EnroscarNetConfig) RemoteServerApiConfiguration(com.stanfy.enroscar.rest.RemoteServerApiConfiguration) RequestMethod(com.stanfy.enroscar.rest.RequestMethod) Config(com.stanfy.enroscar.net.EnroscarConnectionsEngine.Config) EnroscarNetConfig(com.stanfy.enroscar.test.EnroscarNetConfig) RequestDescription(com.stanfy.enroscar.net.operation.RequestDescription)

Example 4 with RequestDescription

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"));
}
Also used : ParameterValue(com.stanfy.enroscar.net.operation.ParameterValue) ArrayList(java.util.ArrayList) RequestDescription(com.stanfy.enroscar.net.operation.RequestDescription) Parameter(com.stanfy.enroscar.net.operation.Parameter) AbstractNetTest(com.stanfy.enroscar.test.AbstractNetTest) Test(org.junit.Test)

Aggregations

RequestDescription (com.stanfy.enroscar.net.operation.RequestDescription)4 Test (org.junit.Test)2 Context (android.content.Context)1 Config (com.stanfy.enroscar.net.EnroscarConnectionsEngine.Config)1 Parameter (com.stanfy.enroscar.net.operation.Parameter)1 ParameterValue (com.stanfy.enroscar.net.operation.ParameterValue)1 RequestExecutor (com.stanfy.enroscar.net.operation.executor.RequestExecutor)1 AbstractMockServerTest (com.stanfy.enroscar.net.test.AbstractMockServerTest)1 RemoteServerApiConfiguration (com.stanfy.enroscar.rest.RemoteServerApiConfiguration)1 RequestMethod (com.stanfy.enroscar.rest.RequestMethod)1 AbstractNetTest (com.stanfy.enroscar.test.AbstractNetTest)1 EnroscarNetConfig (com.stanfy.enroscar.test.EnroscarNetConfig)1 ArrayList (java.util.ArrayList)1