Search in sources :

Example 1 with Feedback

use of edu.hawaii.its.groupings.type.Feedback in project uhgroupings by uhawaii-system-its-ti-iam.

the class HomeController method feedbackError.

@PreAuthorize("isAuthenticated()")
@GetMapping("/feedback/{error}")
public String feedbackError(RedirectAttributes redirectAttributes, @PathVariable String error) {
    Feedback feedback = new Feedback(error);
    redirectAttributes.addFlashAttribute("feedback", feedback);
    return "redirect:/feedback";
}
Also used : Feedback(edu.hawaii.its.groupings.type.Feedback) GetMapping(org.springframework.web.bind.annotation.GetMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 2 with Feedback

use of edu.hawaii.its.groupings.type.Feedback in project uhgroupings by uhawaii-system-its-ti-iam.

the class HomeControllerTest method feedbackSubmit.

@Test
@WithMockUhUser
public void feedbackSubmit() throws Exception {
    MvcResult mvcResult = mockMvc.perform(post("/feedback").with(csrf()).flashAttr("feedback", new Feedback())).andExpect(status().is3xxRedirection()).andExpect(redirectedUrl("/feedback")).andExpect(flash().attribute("success", equalTo(true))).andReturn();
    assertNotNull(mvcResult);
}
Also used : Feedback(edu.hawaii.its.groupings.type.Feedback) MvcResult(org.springframework.test.web.servlet.MvcResult) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with Feedback

use of edu.hawaii.its.groupings.type.Feedback in project uhgroupings by uhawaii-system-its-ti-iam.

the class EmailServiceTest method sendFeedbackWithMailExceptionThrown.

@Test
public void sendFeedbackWithMailExceptionThrown() {
    JavaMailSender senderWithException = new MockJavaMailSender() {

        @Override
        public void send(SimpleMailMessage mailMessage) throws MailException {
            wasSent = false;
            throw new MailSendException("Exception");
        }
    };
    EmailService emailServiceWithException = new EmailService(senderWithException);
    emailServiceWithException.setEnabled(true);
    Feedback feedback = createBaseFeedback();
    emailServiceWithException.send(feedback);
    assertThat(wasSent, is(false));
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage) MailSendException(org.springframework.mail.MailSendException) Feedback(edu.hawaii.its.groupings.type.Feedback) JavaMailSender(org.springframework.mail.javamail.JavaMailSender) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with Feedback

use of edu.hawaii.its.groupings.type.Feedback in project uhgroupings by uhawaii-system-its-ti-iam.

the class EmailServiceTest method sendFeedbackWithNoExceptionMessage.

@Test
public void sendFeedbackWithNoExceptionMessage() {
    Feedback feedback = createBaseFeedback();
    emailService.send(feedback);
    assertThat(wasSent, is(true));
    assertThat(messageSent.getSubject(), containsString("problem"));
    assertThat(messageSent.getText(), containsString("John Doe"));
    assertThat(messageSent.getText(), containsString("jdoe@hawaii.edu"));
    assertThat(messageSent.getText(), containsString("Some problem happened."));
    assertThat(messageSent.getText(), not(containsString("Stack Trace:")));
}
Also used : Feedback(edu.hawaii.its.groupings.type.Feedback) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with Feedback

use of edu.hawaii.its.groupings.type.Feedback in project uhgroupings by uhawaii-system-its-ti-iam.

the class ErrorRestControllerTest method httpPostFeedbackError.

@Test
public void httpPostFeedbackError() throws Exception {
    HttpSession session = mockMvc.perform(post("/feedback/error").contentType(MediaType.APPLICATION_JSON).content("{\"exceptionMessage\":\"exception\"}")).andExpect(status().isNoContent()).andReturn().getRequest().getSession();
    assertNotNull(session.getAttribute("feedback"));
    Feedback feedback = (Feedback) session.getAttribute("feedback");
    assertThat(feedback.getExceptionMessage(), equalTo("exception"));
}
Also used : Feedback(edu.hawaii.its.groupings.type.Feedback) HttpSession(javax.servlet.http.HttpSession) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Feedback (edu.hawaii.its.groupings.type.Feedback)11 Test (org.junit.Test)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 HttpSession (javax.servlet.http.HttpSession)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 ResponseEntity (org.springframework.http.ResponseEntity)1 MailSendException (org.springframework.mail.MailSendException)1 SimpleMailMessage (org.springframework.mail.SimpleMailMessage)1 JavaMailSender (org.springframework.mail.javamail.JavaMailSender)1 MvcResult (org.springframework.test.web.servlet.MvcResult)1