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.library.LibraryPageRefreshingTest.java

public void testPullToRefresh() throws InterruptedException {
    FakeHttpLayerManager.addHttpResponseRule(ApiMatcher.RESOURCES, TestResponses.BIG_LOOKUP);
    startActivityUnderTest();/*from w  w w .  j a v  a  2 s.  co m*/

    onView(allOf(withId(R.id.refreshLayout), is(not(refreshing()))));

    ResourceLookupsList smallLookUp = TestResources.get().fromXML(ResourceLookupsList.class,
            TestResources.SMALL_LOOKUP);
    String lastResourceLabel = Queues.newArrayDeque(smallLookUp.getResourceLookups()).getLast().getLabel();

    FakeHttpLayerManager.addHttpResponseRule(ApiMatcher.RESOURCES, TestResponses.SMALL_LOOKUP);
    onView(withId(android.R.id.list)).perform(swipeDown());
    onView(withId(android.R.id.list)).check(matches(not(withAdaptedData(withItemContent(lastResourceLabel)))));
    onView(withId(android.R.id.empty)).check(matches(not(isDisplayed())));
}

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

public void testDashboardClick() {
    FakeHttpLayerManager.addHttpResponseRule(ApiMatcher.REPORTS_QUERY, TestResponses.ONLY_DASHBOARD);
    startActivityUnderTest();/*from   ww w. j  av a 2 s .co  m*/

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

From source file:com.jaspersoft.android.jaspermobile.test.acceptance.library.LibraryPageSortTest.java

@Override
protected void setUp() throws Exception {
    super.setUp();

    registerTestModule(new TestModule());
    setDefaultCurrentProfile();//from  w  w  w  .  java  2s .co  m

    // We don`t need to listen initial load of page
    FakeHttpLayerManager.clearHttpResponseRules();
    FakeHttpLayerManager.addHttpResponseRule(ApiMatcher.RESOURCES, TestResponses.ALL_RESOURCES);
}

From source file:com.jaspersoft.android.jaspermobile.test.acceptance.library.LibraryPageFilterTest.java

public void testDashboardAndAllFilterOption() throws InterruptedException {
    ResourceLookupsList onlyDashboardLookUp = TestResources.get().fromXML(ResourceLookupsList.class,
            TestResources.ONLY_DASHBOARD);
    ResourceLookupsList allLookUp = TestResources.get().fromXML(ResourceLookupsList.class,
            TestResources.ALL_RESOURCES);

    FakeHttpLayerManager.addHttpResponseRule(ApiMatcher.RESOURCES, TestResponses.get().noContent());
    startActivityUnderTest();//from   w  w w  . j  a v a  2s.  c  om

    FakeHttpLayerManager.addHttpResponseRule(ApiMatcher.RESOURCES, TestResponses.ONLY_DASHBOARD);
    clickFilterMenuItem();
    onOverflowView(getActivity(), withText(R.string.s_fd_option_dashboards)).perform(click());
    onView(withId(android.R.id.list)).check(hasTotalCount(onlyDashboardLookUp.getResourceLookups().size()));

    FakeHttpLayerManager.addHttpResponseRule(ApiMatcher.RESOURCES, TestResponses.ALL_RESOURCES);
    clickFilterMenuItem();
    onOverflowView(getActivity(), withText(R.string.s_fd_option_all)).perform(click());
    onView(withId(android.R.id.list)).check(hasTotalCount(allLookUp.getResourceLookups().size()));
}

From source file:com.jaspersoft.android.jaspermobile.test.acceptance.home.HomePageTest.java

public void testOverAllNavigationForDashboard() {
    startActivityUnderTest();//from   w  w w .  j  a v a2 s .c o m

    // Check ActionBar server name
    onView(withId(R.id.profile_name)).check(matches(withText("Mobile Demo")));

    FakeHttpLayerManager.addHttpResponseRule(ApiMatcher.RESOURCES, TestResponses.ONLY_FOLDER);
    onView(withId(R.id.home_item_library)).perform(click());
    Espresso.pressBack();

    FakeHttpLayerManager.clearHttpResponseRules();
    FakeHttpLayerManager.addHttpResponseRule(ApiMatcher.GET_ROOT_FOLDER, TestResponses.ROOT_FOLDER);
    onView(withId(R.id.home_item_repository)).perform(click());
    Espresso.pressBack();

    onView(withId(R.id.home_item_favorites)).perform(click());
    Espresso.pressBack();
    onView(withId(R.id.home_item_saved_reports)).perform(click());
    Espresso.pressBack();
    onView(withId(R.id.home_item_settings)).perform(click());
    Espresso.pressBack();
    onView(withId(R.id.home_item_servers)).perform(click());
}

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

public void testFolderClick() {
    FakeHttpLayerManager.addHttpResponseRule(ApiMatcher.REPORTS_QUERY, TestResponses.ONLY_FOLDER);
    RequestMatcher uriRegexMatcher = new GetUriRegexMatcher(".*(folderUri=/organizations/org_template).*");
    FakeHttpLayerManager.addHttpResponseRule(uriRegexMatcher, TestResponses.ROOT_REPOSITORIES);
    uriRegexMatcher = new GetUriRegexMatcher(".*(folderUri=/public).*");
    FakeHttpLayerManager.addHttpResponseRule(uriRegexMatcher, TestResponses.get().noContent());

    startActivityUnderTest();/*from  w  w w.j a va 2s  .com*/

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

    ResourceLookupsList levelRepositories = TestResources.get().fromXML(ResourceLookupsList.class,
            TestResources.ONLY_FOLDER);
    String firstLevelRepoLabel = levelRepositories.getResourceLookups().get(0).getLabel();
    onView(withId(android.R.id.list))
            .check(matches(not(withAdaptedData(withItemContent(firstLevelRepoLabel)))));

    // Bug related: To check whether we have only one switcher. Otherwise it will rise 'matches multiple views in the hierarchy.'
    onView(withId(R.id.switchLayout)).check(matches(isDisplayed()));

    onView(withText("Public")).perform(click());

    // Bug related: Check whether empty test displays correct message.
    onView(withId(android.R.id.empty)).check(matches(withText(R.string.r_browser_nothing_to_display)));
}

From source file:com.jaspersoft.android.jaspermobile.test.acceptance.library.LibraryPageRefreshingTest.java

public void testEmptyTextShouldBeInVisibleWhileContentExist() throws InterruptedException {
    FakeHttpLayerManager.addHttpResponseRule(ApiMatcher.RESOURCES, TestResponses.get().noContent());
    startActivityUnderTest();// w  ww  .jav a 2  s. c o m

    onView(allOf(withId(R.id.refreshLayout), is(not(refreshing()))));
    onView(withId(android.R.id.empty)).check(matches(isDisplayed()));
    onView(withId(android.R.id.empty)).check(matches(withText(R.string.r_browser_nothing_to_display)));
}

From source file:com.jaspersoft.android.jaspermobile.test.acceptance.library.LibraryPageTest.java

@Override
protected void setUp() throws Exception {
    super.setUp();

    smallLookUp = TestResources.get().fromXML(ResourceLookupsList.class, "library_reports_small");
    dashboardResource = smallLookUp.getResourceLookups().get(DASHBOARD_ITEM_POSITION);

    registerTestModule(new HackedTestModule());
    setDefaultCurrentProfile();//  w w w  .  ja  v  a2 s  .co m

    FakeHttpLayerManager.clearHttpResponseRules();
    FakeHttpLayerManager.addHttpResponseRule(ApiMatcher.RESOURCES, TestResponses.SMALL_LOOKUP);
}

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

@Override
protected void setUp() throws Exception {
    super.setUp();

    registerTestModule(new TestModule());
    setDefaultCurrentProfile();/*from  w  w w .j a  v a2 s.  c o  m*/

    FakeHttpLayerManager.addHttpResponseRule(ApiMatcher.GET_ROOT_FOLDER, TestResponses.ROOT_FOLDER);
}

From source file:com.jaspersoft.android.jaspermobile.test.real.RealReportViewerPageTest.java

public void testEmptyReport() {
    FakeHttpLayerManager.addHttpResponseRule(ApiMatcher.INPUT_CONTROLS, TestResponses.INPUT_CONTROLS);
    //        createReportIntent();
    startActivityUnderTest();/*from   w  ww. j a v a 2s . co  m*/

    FakeHttpLayerManager.addHttpResponseRule(ApiMatcher.REPORTS,
            TestResponses.get().xml("empty_inputcontrol_state"));
    FakeHttpLayerManager.addHttpResponseRule(ApiMatcher.REPORT_EXECUTIONS,
            TestResponses.get().xml("empty_report_execution"));
    onView(withId(R.id.saveAction)).perform(click());

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