/** * Types text in an {@code EditText} * * @param index the index of the {@code EditText} * @param text the text that should be typed */ public void typeText(final EditText editText, final String text) { if (editText != null) { inst.runOnMainSync( new Runnable() { public void run() { editText.setInputType(InputType.TYPE_NULL); } }); clicker.clickOnScreen(editText, false, 0); activityUtils.hideSoftKeyboard(editText, true, true); boolean successfull = false; int retry = 0; while (!successfull && retry < 10) { try { inst.sendStringSync(text); successfull = true; } catch (SecurityException e) { activityUtils.hideSoftKeyboard(editText, true, true); retry++; } } if (!successfull) { Assert.assertTrue("Text can not be typed!", false); } } }
/** * Returns a Fragment with a given tag or id. * * @param tag the tag of the Fragment or null if no tag * @param id the id of the Fragment * @return a SupportFragment with a given tag or id */ private android.app.Fragment getFragment(String tag, int id) { try { if (tag == null) return activityUtils.getCurrentActivity().getFragmentManager().findFragmentById(id); else return activityUtils.getCurrentActivity().getFragmentManager().findFragmentByTag(tag); } catch (Throwable ignored) { } return null; }
/** * Asserts that an expected {@link Activity} is currently active one, with the possibility to * verify that the expected {@code Activity} is a new instance of the {@code Activity}. * * @param message the message that should be displayed if the assert fails * @param expectedClass the {@code Class} object that is expected to be active e.g. {@code * MyActivity.class} * @param isNewInstance {@code true} if the expected {@code Activity} is a new instance of the * {@code Activity} */ public void assertCurrentActivity( String message, Class<? extends Activity> expectedClass, boolean isNewInstance) { boolean found = false; assertCurrentActivity(message, expectedClass); Activity activity = activityUtils.getCurrentActivity(); for (int i = 0; i < activityUtils.getAllOpenedActivities().size() - 1; i++) { String instanceString = activityUtils.getAllOpenedActivities().get(i).toString(); if (instanceString.equals(activity.toString())) found = true; } Assert.assertNotSame(message + ", isNewInstance: actual and ", isNewInstance, found); }
/** * Waits for the given {@link Activity}. * * @param activityClass the class of the {@code Activity} to wait for * @param timeout the amount of time in milliseconds to wait * @return {@code true} if {@code Activity} appears before the timeout and {@code false} if it * does not */ public boolean waitForActivity(Class<? extends Activity> activityClass, int timeout) { Activity currentActivity = activityUtils.getCurrentActivity(false, false); final long endTime = SystemClock.uptimeMillis() + timeout; while (SystemClock.uptimeMillis() < endTime) { if (currentActivity != null && currentActivity.getClass().equals(activityClass)) { return true; } sleeper.sleep(MINISLEEP); currentActivity = activityUtils.getCurrentActivity(false, false); } return false; }
private void updateActivity(ExoSocialActivity activity, Question question) { Map<String, String> activityTemplateParams = updateTemplateParams( new HashMap<String, String>(), question.getId(), ActivityUtils.getQuestionRate(question), ActivityUtils.getNbOfAnswers(question), ActivityUtils.getNbOfComments(question), question.getLanguage(), question.getLink(), Utils.getQuestionPoint(question)); activity.setTemplateParams(activityTemplateParams); activity.setBody(null); activity.setTitle(null); }
private String getAnswerMessage(PropertyChangeEvent e, Answer answer, ExoSocialActivity comment) { String answerContent = ActivityUtils.processContent(answer.getResponses()); if ("answerEdit".equals(e.getPropertyName())) { I18NActivityUtils.addResourceKey(comment, "answer-update-content", answerContent); return "Answer has been edited to: " + answerContent; } else if ("answerPromoted".equals(e.getPropertyName())) { I18NActivityUtils.addResourceKey(comment, "answer-promoted", answerContent); return "Comment " + answerContent + " has been promoted as an answer"; } else if ("answerActivated".equals(e.getPropertyName())) { if (answer.getActivateAnswers()) { I18NActivityUtils.addResourceKey(comment, "answer-activated", answerContent); return "Answer has been activated: " + answerContent + "."; } else { I18NActivityUtils.addResourceKey(comment, "answer-unactivated", answerContent); return "Answer has been unactivated: " + answerContent + "."; } } else { if (answer.getApprovedAnswers()) { I18NActivityUtils.addResourceKey(comment, "answer-approved", answerContent); return "Answer has been approved: " + answerContent + "."; } else { I18NActivityUtils.addResourceKey(comment, "answer-disapproved", answerContent); return "Answer has been disapproved: " + answerContent + "."; } } }
private String getQuestionMessage( PropertyChangeEvent e, Question question, ExoSocialActivity comment) { String questionDetail = ActivityUtils.processContent(question.getDetail()); if ("questionName".equals(e.getPropertyName())) { String questionName = question.getQuestion(); I18NActivityUtils.addResourceKey( comment, "question-update-title", CommonUtils.decodeSpecialCharToHTMLnumberIgnore(questionName)); return "Title has been updated to: " + CommonUtils.decodeSpecialCharToHTMLnumber(questionName); } else if ("questionDetail".equals(e.getPropertyName())) { I18NActivityUtils.addResourceKey(comment, "question-update-detail", questionDetail); return "Details has been edited to: " + questionDetail; } else if ("questionActivated".equals(e.getPropertyName())) { if (question.isActivated()) { I18NActivityUtils.addResourceKey(comment, "question-activated", null); return "Question has been activated."; } else { I18NActivityUtils.addResourceKey(comment, "question-unactivated", null); return "Question has been unactivated."; } } else if ("questionAttachment".equals(e.getPropertyName())) { I18NActivityUtils.addResourceKey(comment, "question-add-attachment", null); return "Attachment(s) has been added."; } else { // case of add new language int length = question.getMultiLanguages().length; I18NActivityUtils.addResourceKey( comment, "question-add-language", question.getMultiLanguages()[length - 1].getLanguage()); return "Question has been added in " + question.getMultiLanguages()[length - 1].getLanguage(); } }
@Override protected void onPostExecute(List<Photoset> result) { if (result == null) ActivityUtils.showToast( UserActivity.this, getString(R.string.message_get_photosets_failed), error); updatePhotosetList(result); }
/** * Takes a screenshot and saves it in the {@link Config} objects save path. Requires write * permission (android.permission.WRITE_EXTERNAL_STORAGE) in AndroidManifest.xml of the * application under test. * * @param view the view to take screenshot of * @param name the name to give the screenshot image * @param quality the compression rate. From 0 (compress for lowest size) to 100 (compress for * maximum quality). */ public void takeScreenshot(final String name, final int quality) { View decorView = getScreenshotView(); if (decorView == null) return; initScreenShotSaver(); ScreenshotRunnable runnable = new ScreenshotRunnable(decorView, name, quality); activityUtils.getCurrentActivity(false).runOnUiThread(runnable); }
/** * Waits for the given {@link Activity}. * * @param name the name of the {@code Activity} to wait for e.g. {@code "MyActivity"} * @param timeout the amount of time in milliseconds to wait * @return {@code true} if {@code Activity} appears before the timeout and {@code false} if it * does not */ public boolean waitForActivity(String name, int timeout) { Activity currentActivity = activityUtils.getCurrentActivity(false, false); final long endTime = SystemClock.uptimeMillis() + timeout; while (SystemClock.uptimeMillis() < endTime) { if (currentActivity != null && currentActivity.getClass().getSimpleName().equals(name)) { return true; } if (activityUtils.getCurrentActivityName().contains(name)) { return true; } sleeper.sleep(MINISLEEP); currentActivity = activityUtils.getCurrentActivity(false, false); } return false; }
@Override protected void onPostExecute(Boolean result) { if (!result) { ActivityUtils.showToast( UserActivity.this, getString(R.string.message_finish_authentication_failed), error); return; } updateState(); }
@Override protected Dialog onCreateDialog(int id) { switch (id) { case DIALOG_ABOUT: return ActivityUtils.getAboutDialog(this); case DIALOG_NOT_MANAGED: String message = "This application was not created by this client.\n\nYou can manage it through the dashboard on the Touchatag website"; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder .setTitle("Info") // .setIcon(android.R.drawable.ic_dialog_info) // .setMessage(message) // .setCancelable(false) // .setPositiveButton( "Close", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); return builder.create(); case DIALOG_DELETE_APP: message = "Are you sure you want to delete application " + appToRemove.getId(); builder = new AlertDialog.Builder(this); builder .setTitle("Confirm") // .setIcon(android.R.drawable.ic_dialog_info) // .setMessage(message) // .setCancelable(false) // .setPositiveButton( "Delete", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { DeleteApplicationAsyncTask task = new DeleteApplicationAsyncTask( "Deleting Application...", "Failed to delete application.", AppsActivity.this); task.execute(appToRemove); appToRemove = null; } }) .setNegativeButton( "Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); return builder.create(); } return super.onCreateDialog(id); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ActivityUtils.setLayout(this, R.layout.activity_starting_point, R.layout.title_bar); mProgressBar = (ProgressBar) findViewById(R.id.dictionary_progressBar); mTopBarEditText = (TextView) findViewById(R.id.topbar_editText); mTopBarEditText.addTextChangedListener( new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {} @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {} @Override public void afterTextChanged(Editable editable) { mProgressBar.setVisibility(View.VISIBLE); mProgressBar.bringToFront(); new PopulateListView().execute(editable.toString()); } }); mProgressBar.setVisibility(View.VISIBLE); mProgressBar.bringToFront(); new PopulateListView().execute(); LinearLayout ll = (LinearLayout) findViewById(R.id.titlebar_linearlayout_tap_to_change_directions); ll.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { ImageView iv = (ImageView) findViewById(R.id.titlebar_arrow_tap_to_change_directions); TextView silesianTextView = (TextView) findViewById(R.id.titlebar_silesian_textView); TextView polishTextView = (TextView) findViewById(R.id.titlebar_polish_textView); if (isSilesianToPolish) { isSilesianToPolish = false; // // iv.setImageDrawable(getResources().getDrawable(R.drawable.left_arrow)); silesianTextView.setText(R.string.to_silesian); polishTextView.setText(R.string.from_polish); } else { isSilesianToPolish = true; // // iv.setImageDrawable(getResources().getDrawable(R.drawable.right_arrow)); silesianTextView.setText(R.string.from_silesian); polishTextView.setText(R.string.to_polish); } new PopulateListView().execute(); mTopBarEditText.setText(""); } }); }
@Override protected void onPostExecute(String result) { if (result == null) { ActivityUtils.showToast( UserActivity.this, getString(R.string.message_start_authentication_failed), error); return; } redirectUserTo(result); updateState(); }
/** * Returns a {@code View} with a given id. * * @param id the R.id of the {@code View} to be returned * @param index the index of the {@link View}. {@code 0} if only one is available * @param timeout the timeout in milliseconds * @return a {@code View} with a given id */ public View getView(int id, int index, int timeout) { final Activity activity = activityUtils.getCurrentActivity(false); View viewToReturn = null; if (index < 1) { index = 0; viewToReturn = activity.findViewById(id); } if (viewToReturn != null) { return viewToReturn; } return waiter.waitForView(id, index, timeout); }
private Identity getSpaceIdentity(String categoryId) { String spaceGroupId = ActivityUtils.getSpaceGroupId(categoryId); if ("".equals(spaceGroupId)) return null; IdentityManager identityM = (IdentityManager) ExoContainerContext.getCurrentContainer() .getComponentInstanceOfType(IdentityManager.class); SpaceService spaceService = (SpaceService) ExoContainerContext.getCurrentContainer() .getComponentInstanceOfType(SpaceService.class); Space space = spaceService.getSpaceByGroupId(spaceGroupId); if (space != null) return identityM.getOrCreateIdentity( SpaceIdentityProvider.NAME, space.getPrettyName(), false); else return null; }
/** * Returns a SupportFragment with a given tag or id. * * @param tag the tag of the SupportFragment or null if no tag * @param id the id of the SupportFragment * @return a SupportFragment with a given tag or id */ private Fragment getSupportFragment(String tag, int id) { FragmentActivity fragmentActivity = null; try { fragmentActivity = (FragmentActivity) activityUtils.getCurrentActivity(false); } catch (ClassCastException ignored) { } if (fragmentActivity != null) { try { if (tag == null) return fragmentActivity.getSupportFragmentManager().findFragmentById(id); else return fragmentActivity.getSupportFragmentManager().findFragmentByTag(tag); } catch (NoSuchMethodError ignored) { } } return null; }
/** * Takes a screenshot and saves it in "/sdcard/Robotium-Screenshots/". Requires write permission * (android.permission.WRITE_EXTERNAL_STORAGE) in AndroidManifest.xml of the application under * test. * * @param view the view to take screenshot of * @param name the name to give the screenshot image * @param quality the compression rate. From 0 (compress for lowest size) to 100 (compress for * maximum quality). */ public void takeScreenshot(final View view, final String name, final int quality) { activityUtils .getCurrentActivity(false) .runOnUiThread( new Runnable() { Bitmap b; public void run() { if (view != null) { if (view instanceof WebView) { b = getBitmapOfWebView((WebView) view); } else { b = getBitmapOfView(view); } saveFile(name, b, quality); view.destroyDrawingCache(); } } }); }
public static boolean isParametrizedConstraint(Constraint constraint) { Behavior toExecute = ActivityUtils.resolveBehaviorReference(constraint.getSpecification()); return toExecute.getOwnedParameters().size() > 1; }
/** * Returns a localized string * * @param id the resource ID for the string * @return the localized string */ public String getString(int id) { Activity activity = activityUtils.getCurrentActivity(false); return activity.getString(id); }
@Override public void moveQuestions(List<String> questions, String catId) { ActivityManager activityM = CommonsUtils.getService(ActivityManager.class); FAQService faqS = CommonsUtils.getService(FAQService.class); IdentityManager identityM = CommonsUtils.getService(IdentityManager.class); for (String questionId : questions) { try { Question question = faqS.getQuestionById(questionId); String activityId = faqS.getActivityIdForQuestion(question.getPath()); Identity streamOwner = null; Map<String, String> templateParams = updateTemplateParams( new HashMap<String, String>(), question.getId(), ActivityUtils.getQuestionRate(question), ActivityUtils.getNbOfAnswers(question), ActivityUtils.getNbOfComments(question), question.getLanguage(), question.getLink(), Utils.getQuestionPoint(question)); String questionDetail = ActivityUtils.processContent(question.getDetail()); Identity spaceIdentity = getSpaceIdentity(catId); if (spaceIdentity != null) { streamOwner = spaceIdentity; templateParams.put(SPACE_GROUP_ID, ActivityUtils.getSpaceGroupId(catId)); } if (activityId != null) { ExoSocialActivity oldActivity = activityM.getActivity(activityId); activityM.deleteActivity(oldActivity); Identity userIdentity = identityM.getOrCreateIdentity( OrganizationIdentityProvider.NAME, question.getAuthor(), false); ExoSocialActivity activity = newActivity(userIdentity, question.getQuestion(), questionDetail, templateParams); streamOwner = streamOwner != null ? streamOwner : userIdentity; activityM.saveActivityNoReturn(streamOwner, activity); faqS.saveActivityIdForQuestion(questionId, activity.getId()); for (Answer answer : question.getAnswers()) { ExoSocialActivity comment = createCommentForAnswer(userIdentity, answer); String answerContent = ActivityUtils.processContent(answer.getResponses()); comment.setTitle("Answer has been submitted: " + answerContent); I18NActivityUtils.addResourceKey(comment, "answer-add", answerContent); updateActivity(activity, question); activityM.updateActivity(activity); updateCommentTemplateParms(comment, answer.getId()); activityM.saveComment(activity, comment); faqS.saveActivityIdForAnswer(questionId, answer, comment.getId()); } for (Comment cm : question.getComments()) { String message = ActivityUtils.processContent(cm.getComments()); ExoSocialActivityImpl comment = new ExoSocialActivityImpl(); Map<String, String> commentTemplateParams = new HashMap<String, String>(); commentTemplateParams.put(LINK_KEY, cm.getId()); comment.setTemplateParams(commentTemplateParams); comment.setTitle(message); comment.setUserId(userIdentity.getId()); updateActivity(activity, question); activityM.updateActivity(activity); activityM.saveComment(activity, comment); faqS.saveActivityIdForComment( questionId, cm.getId(), question.getLanguage(), comment.getId()); } } } catch (Exception e) { LOG.error("Failed to move questions " + e.getMessage()); } } }
@Override public void saveAnswer(String questionId, Answer answer, boolean isNew) { try { ExoContainer exoContainer = ExoContainerContext.getCurrentContainer(); IdentityManager identityM = (IdentityManager) exoContainer.getComponentInstanceOfType(IdentityManager.class); ActivityManager activityM = (ActivityManager) exoContainer.getComponentInstanceOfType(ActivityManager.class); FAQService faqS = (FAQService) exoContainer.getComponentInstanceOfType(FAQService.class); Question question = faqS.getQuestionById(questionId); Identity userIdentity = identityM.getOrCreateIdentity( OrganizationIdentityProvider.NAME, answer.getResponseBy(), false); String activityId = faqS.getActivityIdForQuestion(questionId); // String answerContent = ActivityUtils.processContent(answer.getResponses()); if (activityId != null && answer.getApprovedAnswers()) { try { ExoSocialActivity activity = activityM.getActivity(activityId); ExoSocialActivity comment = createCommentForAnswer(userIdentity, answer); if (!comment.getTitle().equals("")) { // Case update answer or promote comment to answer String promotedAnswer = "Comment " + answerContent + " has been promoted as an answer"; if (promotedAnswer.equals(comment.getTitle())) { // promote a comment to an answer updateCommentTemplateParms(comment, answer.getId()); activityM.saveComment(activity, comment); faqS.saveActivityIdForAnswer(questionId, answer, comment.getId()); // update question activity content updateActivity(activity, question); activityM.updateActivity(activity); } else { // update answer activityM.saveComment(activity, comment); String answerActivityId = faqS.getActivityIdForAnswer(questionId, answer); faqS.saveActivityIdForAnswer( questionId, answer, answerActivityId + "," + comment.getId()); } } else { // Case submit new answer comment.setTitle("Answer has been submitted: " + answerContent); I18NActivityUtils.addResourceKey(comment, "answer-add", answerContent); updateActivity(activity, question); activityM.updateActivity(activity); updateCommentTemplateParms(comment, answer.getId()); activityM.saveComment(activity, comment); faqS.saveActivityIdForAnswer(questionId, answer, comment.getId()); } } catch (Exception e) { LOG.debug("Run in case of activity deleted and reupdate"); activityId = null; } } if (activityId == null) { saveQuestion(question, false); String newActivityId = faqS.getActivityIdForQuestion(question.getId()); ExoSocialActivity activity = activityM.getActivity(newActivityId); ExoSocialActivity comment = createCommentForAnswer(userIdentity, answer); if (comment.getTitle().equals("")) { comment.setTitle("Answer has been submitted: " + answerContent); I18NActivityUtils.addResourceKey(comment, "answer-add", answerContent); updateCommentTemplateParms(comment, answer.getId()); } activityM.saveComment(activity, comment); } } catch (Exception e) { // FQAService LOG.error("Can not record Activity for space when post answer ", e); } }
@Override public void saveComment(String questionId, Comment cm, String language) { try { ExoContainer exoContainer = ExoContainerContext.getCurrentContainer(); IdentityManager identityM = (IdentityManager) exoContainer.getComponentInstanceOfType(IdentityManager.class); ActivityManager activityM = (ActivityManager) exoContainer.getComponentInstanceOfType(ActivityManager.class); FAQService faqS = (FAQService) exoContainer.getComponentInstanceOfType(FAQService.class); Question question = faqS.getQuestionById(questionId); String message = ActivityUtils.processContent(cm.getComments()); Identity userIdentity = identityM.getOrCreateIdentity( OrganizationIdentityProvider.NAME, cm.getCommentBy(), false); String activityId = faqS.getActivityIdForQuestion(questionId); if (activityId != null) { try { ExoSocialActivity activity = activityM.getActivity(activityId); ExoSocialActivityImpl comment = new ExoSocialActivityImpl(); String commentActivityId = faqS.getActivityIdForComment(questionId, cm.getId(), language); Map<String, String> commentTemplateParams = new HashMap<String, String>(); commentTemplateParams.put(LINK_KEY, cm.getId()); if (commentActivityId != null) { // try to update activity's comment ExoSocialActivityImpl oldComment = (ExoSocialActivityImpl) activityM.getActivity(commentActivityId); if (oldComment != null) { comment = oldComment; comment.setTitle(message); comment.setTitleId("update-comment"); activityM.updateActivity(comment); } else { commentActivityId = null; } } if (commentActivityId == null) { // create new activity's comment comment.setTemplateParams(commentTemplateParams); comment.setTitle(message); comment.setTitleId("add-comment"); comment.setUserId(userIdentity.getId()); updateActivity(activity, question); activityM.updateActivity(activity); activityM.saveComment(activity, comment); faqS.saveActivityIdForComment(questionId, cm.getId(), language, comment.getId()); } } catch (Exception e) { LOG.debug("Run in case of activity deleted and reupdate"); activityId = null; } } if (activityId == null) { // Create new activity for the question and add new comment saveQuestion(question, false); String newActivityId = faqS.getActivityIdForQuestion(questionId); ExoSocialActivity activity = activityM.getActivity(newActivityId); ExoSocialActivity comment = new ExoSocialActivityImpl(); comment.setUserId(userIdentity.getId()); Map<String, String> commentTemplateParams = new HashMap<String, String>(); commentTemplateParams.put(LINK_KEY, cm.getId()); comment.setTitle(message); comment.setTemplateParams(commentTemplateParams); activityM.saveComment(activity, comment); } } catch (Exception e) { // FQAService LOG.error("Can not record Activity for space when post comment ", e); } }
@Override public void saveQuestion(Question question, boolean isNew) { try { ExoContainer exoContainer = ExoContainerContext.getCurrentContainer(); IdentityManager identityM = (IdentityManager) exoContainer.getComponentInstanceOfType(IdentityManager.class); ActivityManager activityM = (ActivityManager) exoContainer.getComponentInstanceOfType(ActivityManager.class); FAQService faqS = (FAQService) exoContainer.getComponentInstanceOfType(FAQService.class); Identity userIdentity = identityM.getOrCreateIdentity( OrganizationIdentityProvider.NAME, question.getAuthor(), false); Map<String, String> templateParams = updateTemplateParams( new HashMap<String, String>(), question.getId(), ActivityUtils.getQuestionRate(question), ActivityUtils.getNbOfAnswers(question), ActivityUtils.getNbOfComments(question), question.getLanguage(), question.getLink(), Utils.getQuestionPoint(question)); String activityId = faqS.getActivityIdForQuestion(question.getId()); String questionDetail = ActivityUtils.processContent(question.getDetail()); // in case deleted activity, if isUpdate, we will re-create new activity and add a comment // associated boolean isUpdate = false; // UserHelper.checkValueUser(values) if (activityId != null) { isUpdate = true; try { ExoSocialActivity activity = activityM.getActivity(activityId); if (UserHelper.getUserByUserId(question.getAuthor()) == null) { userIdentity = identityM.getIdentity(activity.getPosterId(), false); } activity.setTitle(CommonUtils.decodeSpecialCharToHTMLnumber(question.getQuestion())); activity.setBody(questionDetail); activity.setTemplateParams(templateParams); activityM.updateActivity(activity); ExoSocialActivity comment = createCommentWhenUpdateQuestion(userIdentity, question); if (!"".equals(comment.getTitle())) { activityM.saveComment(activity, comment); } } catch (Exception e) { LOG.debug("Run in case of activity deleted and reupdate"); activityId = null; } } if (activityId == null) { Identity streamOwner = null; String catId = (String) faqS.readQuestionProperty( question.getId(), FAQNodeTypes.EXO_CATEGORY_ID, String.class); Identity spaceIdentity = getSpaceIdentity(catId); if (spaceIdentity != null) { // publish the activity in the space stream. streamOwner = spaceIdentity; templateParams.put(SPACE_GROUP_ID, ActivityUtils.getSpaceGroupId(catId)); } List<String> categoryIds = faqS.getCategoryPath(catId); Collections.reverse(categoryIds); if (streamOwner == null) { streamOwner = userIdentity; } ExoSocialActivity activity = newActivity(userIdentity, question.getQuestion(), questionDetail, templateParams); activityM.saveActivityNoReturn(streamOwner, activity); faqS.saveActivityIdForQuestion(question.getId(), activity.getId()); if (isUpdate) { ExoSocialActivity comment = createCommentWhenUpdateQuestion(userIdentity, question); if (!"".equals(comment.getTitle())) { activityM.saveComment(activity, comment); } } } } catch (Exception e) { // FQAService LOG.error("Can not record Activity for space when add new question ", e); } }
/** * Asserts that an expected {@link Activity} is currently active one. * * @param message the message that should be displayed if the assert fails * @param name the name of the {@code Activity} that is expected to be active e.g. {@code * "MyActivity"} */ public void assertCurrentActivity(String message, String name) { sleeper.sleep(); Assert.assertEquals( message, name, activityUtils.getCurrentActivity().getClass().getSimpleName()); }
/** Asserts that the available memory in the system is not low. */ public void assertMemoryNotLow() { ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo(); ((ActivityManager) activityUtils.getCurrentActivity().getSystemService("activity")) .getMemoryInfo(mi); Assert.assertFalse("Low memory available: " + mi.availMem + " bytes", mi.lowMemory); }
/** * Asserts that an expected {@link Activity} is currently active one, with the possibility to * verify that the expected {@code Activity} is a new instance of the {@code Activity}. * * @param message the message that should be displayed if the assert fails * @param name the name of the {@code Activity} that is expected to be active e.g. {@code * "MyActivity"} * @param isNewInstance {@code true} if the expected {@code Activity} is a new instance of the * {@code Activity} */ public void assertCurrentActivity(String message, String name, boolean isNewInstance) { assertCurrentActivity(message, name); assertCurrentActivity(message, activityUtils.getCurrentActivity().getClass(), isNewInstance); }
/** * Asserts that an expected {@link Activity} is currently active one. * * @param message the message that should be displayed if the assert fails * @param expectedClass the {@code Class} object that is expected to be active e.g. {@code * MyActivity.class} */ public void assertCurrentActivity(String message, Class<? extends Activity> expectedClass) { sleeper.sleep(); Assert.assertEquals( message, expectedClass.getName(), activityUtils.getCurrentActivity().getClass().getName()); }