/** * Setup and save feedback's info. * * @param feedback from the user. */ public void save(Feedback feedback) { IpInfo ipInfo = IpInfoService.getIpInfoMaxMind(feedback.getSendFromIp()); feedback.setCity(ipInfo.getCity()); feedback.setCountry(ipInfo.getCountry_code()); feedback.setLatitude(ipInfo.getLatitude()); feedback.setLongitude(ipInfo.getLongitude()); feedback.setCreatedDate(new Date(System.currentTimeMillis())); feedbackRepository.save(feedback); // gui vao email cua ca user va cua ca admin Mail mail = new Mail(); mail.setTo(feedback.getEmail()); mail.setBbc("*****@*****.**"); mail.setFrom("*****@*****.**"); mail.setSubject("Thanks for your feedback at bandoviet.net: " + feedback.getSubject()); mail.setText( "Xin chào " + feedback.getName() + "\n\nCảm ơn bạn đã viết cho chúng tôi với nội dung: \n\n" + feedback.getMessage() + "\n\nChúng tôi sẽ cố gắng có phản hồi cho bạn sớm nhất." + "\n\nThay mặt ban điều hành," + "\n Bản đồ Việt"); mailService.sendMail(mail); }
@Test public void testInvalidInsertNoMail() throws Exception { FeedbackPersistence persistence = mock(FeedbackPersistence.class); doThrow(new PersistenceException("", null)) .when(persistence) .insert( anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString()); Mailer mailer = mock(Mailer.class); feedback = new Feedback(persistence, mailer); try { feedback.insertNew( validGeometry, validComment, validEmail, validLayer, validDate, "ca", title, verificationMessage); fail(); } catch (Exception e) { } verify(mailer, never()) .sendVerificationMail(anyString(), anyString(), anyString(), anyString(), anyString()); }
private void testMandatoryParameter(String geom, String comment, String email, String layerName) throws CannotSendMailException, PersistenceException { try { feedback.insertNew( geom, comment, email, layerName, validDate, language, title, verificationMessage); fail(); } catch (MissingArgumentException e) { } }
@Test public void testVerifyComment() throws Exception { FeedbackPersistence persistence = mock(FeedbackPersistence.class); when(persistence.existsUnverified("100")).thenReturn(true); Mailer mailer = mock(Mailer.class); feedback = new Feedback(persistence, mailer); feedback.verify("100"); verify(persistence).verify("100"); verify(mailer).sendVerifiedMail("100"); }
@Test public void testVerifyVerifiedComment() throws Exception { FeedbackPersistence persistence = mock(FeedbackPersistence.class); when(persistence.existsUnverified("100")).thenReturn(false); feedback = new Feedback(persistence, mock(Mailer.class)); try { feedback.verify("100"); fail(); } catch (VerificationCodeNotFoundException e) { } }
@Test public void testDateCanBeNull() throws Exception { feedback = new Feedback(mock(FeedbackPersistence.class), mock(Mailer.class)); feedback.insertNew( validGeometry, validComment, validEmail, validDate, null, language, title, verificationMessage); }
@Test public void testNotifyAuthors() throws Exception { Config config = mockConfigMessages(); FeedbackPersistence persistence = mock(FeedbackPersistence.class); when(persistence.getValidatedToNotifyInfo()) .thenReturn(new CommentInfo[] {new CommentInfo(1, "*****@*****.**", "100", language)}); Mailer mailer = mock(Mailer.class); feedback = new Feedback(persistence, mailer); feedback.notifyValidated(config); verify(mailer).sendValidatedMail("*****@*****.**", "100", validationMessage, title); verify(persistence).setNotified(1); }
@Test public void testDifferentVerificationCodes() throws Exception { feedback = new Feedback(mock(FeedbackPersistence.class), mock(Mailer.class)); assertTrue( feedback.insertNew( validGeometry, validComment, validEmail, validLayer, validDate, language, title, verificationMessage) != feedback.insertNew( "POINT(1 1)", validComment, validEmail, validLayer, validDate, language, title, verificationMessage)); }
@Test public void testInsertCleansOutOfDate() throws Exception { FeedbackPersistence persistence = mock(FeedbackPersistence.class); feedback = new Feedback(persistence, mock(Mailer.class)); feedback.insertNew( validGeometry, validComment, validEmail, validLayer, validDate, language, title, verificationMessage); verify(persistence, times(1)).cleanOutOfDate(); }
/** Create a new feedback from given parameters. */ public void save(String name, String email, String subject, String message, String ip) { Feedback feedback = new Feedback(); feedback.setName(name); feedback.setEmail(email); feedback.setSubject(subject); feedback.setMessage(message); feedback.setSendFromIp(ip); try { save(feedback); } catch (Exception e) { System.out.println("Co loi: " + e.getMessage()); } }
@Test public void testInsert() throws Exception { FeedbackPersistence persistence = mock(FeedbackPersistence.class); feedback = new Feedback(persistence, mock(Mailer.class)); feedback.insertNew( validGeometry, validComment, validEmail, validLayer, validDate, language, title, verificationMessage); verify(persistence, times(1)) .insert( eq(validGeometry), eq("900913"), eq(validComment), eq(validEmail), eq(validLayer), eq(validDate), anyString(), anyString()); }
@Override public void bootstrap() { UserDetails userDetails = new UserDetails(); userDetails.setEmail("*****@*****.**"); userDetails.getRoles().addAll(ImmutableSet.of(ADMIN, CONTENT_MANAGER, VIDEO_MANAGER)); userRepository.save(userDetails); for (int i = 0; i < 15; i++) { Article article = new Article(); article.setAuthor("*****@*****.**"); article.setCreated(new Date()); article.setState(ArticleState.PUBLISHED); article.setToView(new Date()); article.setFeed("charity"); article.setContent("<h3> something </h3> <p><b> hey </b> you</p>"); article.setEditableContent("<h3> something </h3> <p><b> hey </b> you</p>"); article.setShortContent("<p><b>Short content</b> version<p>"); article.setLastUpdated(new Date()); article.setTitle("title" + i); article.setPermalink("super-title" + i); articleRepository.mergeArticle(article); searchRepository.submitToSearch(article); } Article article = new Article(); article.setAuthor(""); article.setCreated(new Date()); article.setState(ArticleState.PUBLISHED); article.setToView(new Date()); article.setFeed("main"); String content = "<p style=\"font-weight:bold; float:left; margin-left: 40%;margin-top: 10px;\">Шановні друзі!</p>" + " <p>Мені як народному депутатові України онлайн-спілкування видається " + " важливою ланкою вивчення проблем, які цікавлять людей.</p> " + " <p>Користуючись цим ресурсом, Ви зможете дізнатися про мою " + " депутатську, благодійну діяльність, участь у житті виборчого округу. Також ви " + " маєте можливість звернутися до моєї громадської приймальні, щоб отримати " + " відповіді на питання, які вас цікавлять.</p>" + " <p>Я завжди готовий до обміну думками і конструктивної дискусії. Буду " + " вдячний за ваші запитання і пропозиції.</p>" + " <div style=\"float: right; width: 60%; min-width: 360px;\">" + " <p style=\"float:right;font-weight:bold;\">З повагою,</p>" + " <p style=\"float:right;font-weight:bold;\">Народний депутат України Іван Куровський</p>" + " </div>"; article.setContent(content); article.setEditableContent(content); article.setShortContent(content); article.setLastUpdated(new Date()); article.setTitle("title" + "main"); article.setPermalink("Main_Page"); articleRepository.mergeArticle(article); searchRepository.submitToSearch(article); article = new Article(); article.setAuthor("*****@*****.**"); article.setCreated(new Date()); article.setState(ArticleState.PUBLISHED); article.setToView(new Date()); article.setFeed("visit"); article.setContent("<h3> something </h3> <p><b> hey </b> you</p>"); article.setEditableContent("<h3> something </h3> <p><b> hey </b> you</p>"); article.setShortContent("<p><b>Short content</b> version<p>"); article.setLastUpdated(new Date()); article.setTitle("title" + "any"); article.setPermalink("super-title" + "any"); articleRepository.mergeArticle(article); searchRepository.submitToSearch(article); Feedback feedback = new Feedback(); feedback.setFeed(FeedbackFeedType.QUESTION); StringBuffer strBuf = new StringBuffer(); for (int i = 0; i < 1000; i++) { strBuf.append(" ").append(i); } feedback.setAnswer("Question:" + strBuf); feedback.setId(1L); feedback.setAuthor("RoksanaSeletska@kjshdkf"); feedback.setCreated(new Date()); feedback.setQuestion("Answer:" + strBuf); feedback.setState(ArticleState.PUBLISHED); feedbackRepository.submitQuestion(feedback); feedbackRepository.submitQuestion(feedback); // article = new Article(); // article.setAuthor("*****@*****.**"); // article.setCreated(new Date()); // article.setState(ArticleState.PUBLISHED); // article.setFeed("news"); // article.setContent("<h3> Ololoev </h3> <p><b> hey </b> you</p>"); // article.setShortContent("<p><b>SHORT CONTENT</b> Кириллица<p>"); // article.setLastUpdated(new Date()); // article.setTitle("Another article"); // article.setPermalink("another-article"); // articleRepository.mergeArticle(article); // searchRepository.submitToSearch(article); }
void addFeedback(final Feedback fb) { m_allFeedback.add(fb); if (m_outputStream != null) m_outputStream.println(fb.getStandardFeedbackLine()); }