List of usage examples for org.apache.http.fake FakeHttpLayerManager addHttpResponseRule
public static void addHttpResponseRule(RequestMatcher requestMatcher, List<? extends HttpResponse> responses)
From source file:com.jaspersoft.android.jaspermobile.test.acceptance.favorites.FavoritesPageTest.java
public void testAddToFavoriteFromDashboardView() { FakeHttpLayerManager.addHttpResponseRule(ApiMatcher.RESOURCES, TestResponses.ONLY_DASHBOARD); startActivityUnderTest();/*from www .ja v a 2 s. c o m*/ // Force only dashboards Intent intent = LibraryActivity_.intent(mApplication).flags(Intent.FLAG_ACTIVITY_NEW_TASK).get(); getInstrumentation().startActivitySync(intent); getInstrumentation().waitForIdleSync(); // Select dashboard onData(is(instanceOf(ResourceLookup.class))).inAdapterView(withId(android.R.id.list)).atPosition(1) .perform(click()); // Add to favorite onView(withId(R.id.favoriteAction)).perform(click()); pressBack(); pressBack(); onData(is(instanceOf(Cursor.class))).inAdapterView(withId(android.R.id.list)).atPosition(0) .perform(click()); // Remove from favorite onView(withId(R.id.favoriteAction)).perform(click()); pressBack(); 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 testInValidChangesToProfileWillBeIgnored() { onData(Matchers.is(instanceOf(Cursor.class))).inAdapterView(withId(android.R.id.list)).atPosition(0) .perform(longClick());// ww w .j a v a 2 s. com onView(withId(R.id.editItem)).perform(click()); onView(withId(R.id.organizationEdit)).perform(clearText()); onView(withId(R.id.usernameEdit)).perform(clearText()); onView(withId(R.id.usernameEdit)).perform(typeText("invalid_user")); onView(withId(R.id.passwordEdit)).perform(clearText()); onView(withId(R.id.passwordEdit)).perform(typeText("1234")); // We test invalid creation case. FakeHttpLayerManager.addHttpResponseRule(ApiMatcher.SERVER_INFO, TestResponses.get().notAuthorized()); onView(withId(R.id.saveAction)).perform(click()); // Assert out profile still the same JsServerProfile jsServerProfile = jsRestClient.getServerProfile(); assertThat(jsServerProfile.getOrganization(), is(not(""))); assertThat(jsServerProfile.getUsername(), is(not("invalid_user"))); assertThat(jsServerProfile.getPassword(), is(not("1234"))); // We also should see 401 error dialog 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)) .check(matches(withText(android.R.string.ok))); onOverflowView(getActivity(), withId(R.id.sdl__negative_button)).perform(click()); }
From source file:com.jaspersoft.android.jaspermobile.test.acceptance.SearchableActivityTest.java
public void testSearchResultsWithNoResults() { FakeHttpLayerManager.addHttpResponseRule(ApiMatcher.REPORTS_QUERY, TestResponses.get().noContent()); startActivityUnderTest();//from w w w . java 2 s . c o m onView(withId(android.R.id.empty)).check(matches(withText(R.string.r_search_nothing_to_display))); rotate(); onView(withId(android.R.id.empty)).check(matches(withText(R.string.r_search_nothing_to_display))); }
From source file:com.jaspersoft.android.jaspermobile.test.acceptance.library.LibraryPageFilterTest.java
public void testCurrentPositionResetAfterNewFilterSelected() { FakeHttpLayerManager.addHttpResponseRule(ApiMatcher.RESOURCES, TestResponses.BIG_LOOKUP); startActivityUnderTest();//ww w . j av a2 s . c o m onData(Matchers.is(instanceOf(ResourceLookup.class))).inAdapterView(withId(android.R.id.list)).atPosition(5) .perform(longClick()); pressBack(); FakeHttpLayerManager.addHttpResponseRule(ApiMatcher.RESOURCES, TestResponses.ONLY_DASHBOARD); clickFilterMenuItem(); onOverflowView(getActivity(), withText(R.string.s_fd_option_dashboards)).perform(click()); }
From source file:com.jaspersoft.android.jaspermobile.test.acceptance.home.InitialHomePageTest.java
public void testProfileIncorrectSetupWithNoPassword() throws Throwable { startActivityUnderTest();//from ww w .j ava 2 s . co m FakeHttpLayerManager.addHttpResponseRule(ApiMatcher.SERVER_INFO, TestResponses.SERVER_INFO); onData(is(instanceOf(Cursor.class))).inAdapterView(withId(android.R.id.list)).atPosition(0) .perform(click()); FakeHttpLayerManager.addHttpResponseRule(ApiMatcher.RESOURCES, TestResponses.get().notAuthorized()); onView(withId(R.id.home_item_library)).perform(click()); onOverflowView(getCurrentActivity(), withText(android.R.string.ok)).perform(click()); onView(withId(getActionBarTitleId())).check(matches(withText(R.string.sp_bc_edit_profile))); onView(withId(getActionBarSubTitleId())).check(matches(withText(ProfileHelper.DEFAULT_ALIAS))); onView(withId(R.id.askPasswordCheckBox)).perform(click()); FakeHttpLayerManager.addHttpResponseRule(ApiMatcher.SERVER_INFO, TestResponses.SERVER_INFO); onView(withId(R.id.saveAction)).perform(click()); // Check whether our dialog is shown with Appropriate info onOverflowView(getActivity(), withId(R.id.dialogUsernameText)) .check(matches(withText(ProfileHelper.DEFAULT_USERNAME))); onOverflowView(getActivity(), withId(R.id.dialogOrganizationText)) .check(matches(withText(ProfileHelper.DEFAULT_ORGANIZATION))); onOverflowView(getActivity(), withId(R.id.dialogOrganizationTableRow)).check(matches(isDisplayed())); // Lets type some invalid password and check validation onOverflowView(getActivity(), withId(R.id.dialogPasswordEdit)).perform(clearText()); onOverflowView(getActivity(), withText(android.R.string.ok)).perform(click()); onOverflowView(getActivity(), withId(R.id.dialogPasswordEdit)) .check(matches(hasErrorText(getActivity().getString(R.string.sp_error_field_required)))); // Lets type some password and check if it set onOverflowView(getActivity(), withId(R.id.dialogPasswordEdit)).perform(typeText(PASSWORD)); onOverflowView(getActivity(), withText(android.R.string.ok)).perform(click()); assertThat(getServerProfile().getPassword(), is(PASSWORD)); }
From source file:com.jaspersoft.android.jaspermobile.test.acceptance.RepositoryPageTest.java
public void testRepoBackstackPersistance() throws InterruptedException { FolderDataResponse rootFolder = TestResources.get().fromXML(FolderDataResponse.class, TestResources.ROOT_FOLDER);//from w ww. j a v a2s . com String rootLevelRepoLabel = rootFolder.getLabel(); ResourceLookupsList levelRepositories = TestResources.get().fromXML(ResourceLookupsList.class, TestResources.ONLY_FOLDER); String firstLevelRepoLabel = levelRepositories.getResourceLookups().get(0).getLabel(); FakeHttpLayerManager.addHttpResponseRule(ApiMatcher.ROOT_FOLDER_CONTENT, TestResponses.ONLY_FOLDER); forcePreview(ViewType.LIST); startActivityUnderTest(); // Force this test not to be fluky Thread.sleep(200); onData(is(instanceOf(ResourceLookup.class))).inAdapterView(withId(android.R.id.list)).atPosition(0) .perform(click()); onView(withId(android.R.id.list)) .check(matches(not(withAdaptedData(withItemContent(firstLevelRepoLabel))))); rotate(); onView(withId(android.R.id.list)) .check(matches(not(withAdaptedData(withItemContent(firstLevelRepoLabel))))); pressBack(); onView(withId(android.R.id.list)).check(matches(not(withAdaptedData(withItemContent(rootLevelRepoLabel))))); rotate(); onView(withId(android.R.id.list)).check(matches(not(withAdaptedData(withItemContent(rootLevelRepoLabel))))); }
From source file:com.jaspersoft.android.jaspermobile.test.acceptance.favorites.FavoritesPageTest.java
public void testAddToFavoriteFromReportView() { FakeHttpLayerManager.addHttpResponseRule(ApiMatcher.RESOURCES, TestResponses.ONLY_REPORT); startActivityUnderTest();/* www.ja v a2 s . c o m*/ // Force only reports Intent intent = LibraryActivity_.intent(mApplication).flags(Intent.FLAG_ACTIVITY_NEW_TASK).get(); getInstrumentation().startActivitySync(intent); getInstrumentation().waitForIdleSync(); // Select report FakeHttpLayerManager.setDefaultHttpResponse(TestResponses.get().noContent()); onData(is(instanceOf(ResourceLookup.class))).inAdapterView(withId(android.R.id.list)).atPosition(0) .perform(click()); // Add to favorite onView(withId(R.id.favoriteAction)).perform(click()); pressBack(); pressBack(); onData(is(instanceOf(Cursor.class))).inAdapterView(withId(android.R.id.list)).atPosition(0) .perform(click()); // Remove from favorite onView(withId(R.id.favoriteAction)).perform(click()); pressBack(); 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 testOldServerInstanceShouldBeIgnored() { onData(Matchers.is(instanceOf(Cursor.class))).inAdapterView(withId(android.R.id.list)).atPosition(0) .perform(longClick());/* w w w.j a v a 2s.co m*/ onView(withId(R.id.editItem)).perform(click()); onView(withId(R.id.organizationEdit)).perform(clearText()); onView(withId(R.id.usernameEdit)).perform(clearText()); onView(withId(R.id.usernameEdit)).perform(typeText("another_user")); onView(withId(R.id.passwordEdit)).perform(clearText()); onView(withId(R.id.passwordEdit)).perform(typeText("1234")); // We will send server info with unsupported server version FakeHttpLayerManager.addHttpResponseRule(ApiMatcher.SERVER_INFO, TestResponses.EMERALD_MR1_SERVER_INFO); onView(withId(R.id.saveAction)).perform(click()); // Assert out profile still the same JsServerProfile jsServerProfile = jsRestClient.getServerProfile(); assertThat(jsServerProfile.getOrganization(), is(not(""))); assertThat(jsServerProfile.getUsername(), is(not("invalid_user"))); assertThat(jsServerProfile.getPassword(), is(not("1234"))); // We also should see info dialog about old JRS usage 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))); }
From source file:com.jaspersoft.android.jaspermobile.test.acceptance.RepositoryPageTest.java
public void testSearchInRepository() { FakeHttpLayerManager.addHttpResponseRule(ApiMatcher.REPORTS_QUERY, TestResponses.ONLY_FOLDER); startActivityUnderTest();/* w w w . j a v a 2 s . c o m*/ try { onView(withId(R.id.search)).perform(click()); } catch (NoMatchingViewException ex) { openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext()); onOverflowView(getActivity(), withText(android.R.string.search_go)).perform(click()); } onView(withId(getSearcFieldId())).perform(typeText(REPORTS_QUERY)); onView(withId(getSearcFieldId())).perform(pressImeActionButton()); onView(withText(getActivity().getString(R.string.search_result_format, REPORTS_QUERY))) .check(matches(isDisplayed())); }
From source file:com.jaspersoft.android.jaspermobile.test.acceptance.home.AskPasswordHomePageTest.java
private void setAskForPasswordOption() throws Throwable { onData(is(instanceOf(Cursor.class))).inAdapterView(withId(android.R.id.list)).atPosition(0) .perform(click());//from w w w . j a v a2 s .c om FakeHttpLayerManager.addHttpResponseRule(ApiMatcher.ROOT_FOLDER_CONTENT, TestResponses.get().notAuthorized()); onView(withId(R.id.home_item_library)).perform(click()); onOverflowView(getCurrentActivity(), withText(android.R.string.ok)).perform(click()); onView(withId(getActionBarTitleId())).check(matches(withText(R.string.sp_bc_edit_profile))); onView(withId(getActionBarSubTitleId())).check(matches(withText(ProfileHelper.DEFAULT_ALIAS))); onView(withId(R.id.askPasswordCheckBox)).perform(click()); onView(withId(R.id.saveAction)).perform(click()); }