Example usage for org.apache.http.fake FakeHttpLayerManager addHttpResponseRule

List of usage examples for org.apache.http.fake FakeHttpLayerManager addHttpResponseRule

Introduction

In this page you can find the example usage for org.apache.http.fake FakeHttpLayerManager addHttpResponseRule.

Prototype

public static void addHttpResponseRule(RequestMatcher requestMatcher, List<? extends HttpResponse> responses) 

Source Link

Document

Adds an HTTP response rule.

Usage

From source file:com.jaspersoft.android.jaspermobile.test.acceptance.favorites.FavoritesPageTest.java

public void testPageShouldPreserveOriginalLabel() {
    ResourceLookupsList onlyFolder = TestResources.get().fromXML(ResourceLookupsList.class,
            TestResources.ONLY_FOLDER);/*from www .ja  v  a2s  .c om*/
    ResourceLookup resourceLookup = onlyFolder.getResourceLookups().get(0);
    favoritesHelper.addToFavorites(resourceLookup);

    FakeHttpLayerManager.addHttpResponseRule(ApiMatcher.RESOURCES, TestResponses.ONLY_FOLDER);

    startActivityUnderTest();

    onData(is(instanceOf(Cursor.class))).inAdapterView(withId(android.R.id.list)).atPosition(0)
            .perform(click());

    onView(withId(getActionBarTitleId())).check(matches(withText(resourceLookup.getLabel())));
    pressBack();
    onView(withId(getActionBarTitleId())).check(matches(withText(R.string.f_title)));
}

From source file:com.jaspersoft.android.jaspermobile.test.acceptance.favorites.FavoritesPageTest.java

private void startContextMenuInteractionTest() throws InterruptedException {
    FakeHttpLayerManager.addHttpResponseRule(ApiMatcher.INPUT_CONTROLS, TestResponses.get().noContent());
    FakeHttpLayerManager.addHttpResponseRule(ApiMatcher.REPORT_EXECUTIONS, TestResponses.get().noContent());

    Intent intent = LibraryActivity_.intent(mApplication).flags(Intent.FLAG_ACTIVITY_NEW_TASK).get();
    getInstrumentation().startActivitySync(intent);
    getInstrumentation().waitForIdleSync();

    onData(is(instanceOf(ResourceLookup.class))).inAdapterView(withId(android.R.id.list)).atPosition(0)
            .perform(longClick());//from ww w .  j av a2s  .  c o  m
    onView(withId(R.id.favoriteAction)).perform(click());
    pressBack();
    pressBack();

    onData(is(instanceOf(Cursor.class))).inAdapterView(withId(android.R.id.list)).atPosition(0)
            .perform(click());
    pressBack();

    intent = LibraryActivity_.intent(mApplication).flags(Intent.FLAG_ACTIVITY_NEW_TASK).get();
    getInstrumentation().startActivitySync(intent);
    getInstrumentation().waitForIdleSync();

    onData(is(instanceOf(ResourceLookup.class))).inAdapterView(withId(android.R.id.list)).atPosition(0)
            .perform(longClick());
    onView(withId(R.id.favoriteAction)).perform(click());
    pressBack();
    pressBack();

    Thread.sleep(200);
    onView(withId(android.R.id.list)).check(hasTotalCount(0));
    onView(withId(android.R.id.empty))
            .check(matches(allOf(withText(R.string.f_empty_list_msg), isDisplayed())));

    intent = LibraryActivity_.intent(mApplication).flags(Intent.FLAG_ACTIVITY_NEW_TASK).get();
    getInstrumentation().startActivitySync(intent);
    getInstrumentation().waitForIdleSync();

    onData(is(instanceOf(ResourceLookup.class))).inAdapterView(withId(android.R.id.list)).atPosition(0)
            .perform(longClick());
    onView(withId(R.id.favoriteAction)).perform(click());
    pressBack();
    pressBack();

    onData(is(instanceOf(Cursor.class))).inAdapterView(withId(android.R.id.list)).atPosition(0)
            .perform(longClick());
    onView(withId(R.id.removeFromFavorites)).perform(click());

    onView(withId(android.R.id.list)).check(hasTotalCount(0));
    onView(withId(android.R.id.empty))
            .check(matches(allOf(withText(R.string.f_empty_list_msg), isDisplayed())));
}

From source file:com.jaspersoft.android.jaspermobile.test.acceptance.profile.ActiveProfileTest.java

public void testProfilePasswordResetShouldBePersistent() {
    FakeHttpLayerManager.addHttpResponseRule(ApiMatcher.SERVER_INFO, TestResponses.SERVER_INFO);
    onData(Matchers.is(instanceOf(Cursor.class))).inAdapterView(withId(android.R.id.list)).atPosition(0)
            .perform(longClick());/*from   w  w w.  j a  va2s . co  m*/
    onView(withId(R.id.editItem)).perform(click());

    onView(withId(R.id.organizationEdit)).perform(clearText());
    onView(withId(R.id.askPasswordCheckBox)).perform(click());
    onView(withId(R.id.saveAction)).perform(click());

    onData(Matchers.is(instanceOf(Cursor.class))).inAdapterView(withId(android.R.id.list)).atPosition(0)
            .perform(longClick());
    onView(withId(R.id.editItem)).perform(click());
    onView(withId(R.id.askPasswordCheckBox)).perform(click());
    onView(withId(R.id.passwordEdit)).perform(typeText("1234"));
    onView(withId(R.id.saveAction)).perform(click());

    onData(Matchers.is(instanceOf(Cursor.class))).inAdapterView(withId(android.R.id.list)).atPosition(0)
            .perform(longClick());
    onView(withId(R.id.editItem)).perform(click());
    onView(withId(R.id.passwordEdit)).check(matches(isEnabled()));
    onView(withId(R.id.passwordEdit)).check(matches(hasText("1234")));
}

From source file:com.jaspersoft.android.jaspermobile.test.acceptance.profile.ServersManagerPageTest.java

public void testPageShouldProperlyHandleUnAuthorized() {
    registerTestModule(new CommonTestModule() {
        @Override//from   w w w.ja v  a2 s.c o  m
        protected void semanticConfigure() {
            bind(JsSpiceManager.class).toInstance(new JsSpiceManager() {
                @Override
                public <T> void execute(CachedSpiceRequest<T> cachedSpiceRequest,
                        final RequestListener<T> requestListener) {
                    HttpClientErrorException httpClientErrorException = new HttpClientErrorException(
                            HttpStatus.UNAUTHORIZED);
                    requestListener.onRequestFailure(new NetworkException(
                            "Exception occurred during invocation of web service.", httpClientErrorException));
                }
            });
        }
    });
    startActivityUnderTest();

    onView(withId(R.id.addProfile)).perform(click());

    onView(withId(R.id.aliasEdit)).perform(typeText(TEST_ALIAS));
    onView(withId(R.id.serverUrlEdit)).perform(typeText(TEST_SERVER_URL));
    onView(withId(R.id.organizationEdit)).perform(typeText("some invalid organization"));
    onView(withId(R.id.usernameEdit)).perform(typeText("some invalid username"));
    onView(withId(R.id.passwordEdit)).perform(typeText("some invalid password"));
    onView(withId(R.id.saveAction)).perform(click());

    FakeHttpLayerManager.clearHttpResponseRules();
    FakeHttpLayerManager.addHttpResponseRule(ApiMatcher.SERVER_INFO, TestResponses.get().notAuthorized());
    onView(withText(TEST_ALIAS)).perform(click());

    onOverflowView(getActivity(), withId(R.id.sdl__title)).check(matches(withText(R.string.error_msg)));
    onOverflowView(getActivity(), withId(R.id.sdl__message))
            .check(matches(withText(ExceptionRule.UNAUTHORIZED.getMessage())));
    onOverflowView(getActivity(), withId(R.id.sdl__negative_button)).perform(click());
}

From source file:com.jaspersoft.android.jaspermobile.test.acceptance.profile.ServersManagerPageTest.java

public void testServerLowerThanEmeraldNotAcceptable() {
    registerTestModule(new CommonTestModule() {
        @Override//from   w  w w. j  ava  2s .  co m
        protected void semanticConfigure() {
            bind(JsSpiceManager.class).toInstance(new JsSpiceManager() {
                @Override
                public <T> void execute(CachedSpiceRequest<T> cachedSpiceRequest,
                        final RequestListener<T> requestListener) {
                    ServerInfo serverInfo = TestResources.get().fromXML(ServerInfo.class,
                            TestResources.EMERALD_MR1_SERVER_INFO);
                    requestListener.onRequestSuccess((T) serverInfo);
                }
            });
        }
    });
    startActivityUnderTest();
    onView(withId(R.id.addProfile)).perform(click());

    onView(withId(R.id.aliasEdit)).perform(typeText(DatabaseUtils.TEST_ALIAS));
    onView(withId(R.id.serverUrlEdit)).perform(typeText(DatabaseUtils.TEST_SERVER_URL));
    onView(withId(R.id.organizationEdit)).perform(typeText(DatabaseUtils.TEST_ORGANIZATION));
    onView(withId(R.id.usernameEdit)).perform(typeText(DatabaseUtils.TEST_USERNAME));
    onView(withId(R.id.passwordEdit)).perform(typeText(DatabaseUtils.TEST_PASS));
    onView(withId(R.id.saveAction)).perform(click());

    FakeHttpLayerManager.clearHttpResponseRules();
    FakeHttpLayerManager.addHttpResponseRule(ApiMatcher.SERVER_INFO, TestResponses.EMERALD_MR1_SERVER_INFO);
    onView(withText(TEST_ALIAS)).perform(click());

    onOverflowView(getActivity(), withId(R.id.sdl__title)).check(matches(withText(R.string.error_msg)));
    onOverflowView(getActivity(), withId(R.id.sdl__message))
            .check(matches(withText(R.string.r_error_server_not_supported)));
}