use of io.gravitee.repository.management.model.Ticket in project gravitee-management-rest-api by gravitee-io.
the class TicketServiceTest method shouldNotSearchSearchIfRepositoryThrowException.
@Test(expected = TechnicalManagementException.class)
public void shouldNotSearchSearchIfRepositoryThrowException() throws TechnicalException {
Ticket ticket = new Ticket();
ticket.setId("generatedId");
ticket.setApi(API_ID);
ticket.setApplication(APPLICATION_ID);
ticket.setSubject(EMAIL_SUBJECT);
ticket.setContent(EMAIL_CONTENT);
ticket.setCreatedAt(new Date());
ticket.setFromUser(USERNAME);
List<Ticket> ticketList = new ArrayList<>();
for (int i = 0; i < 20; i++) {
Ticket t = new Ticket(ticket);
t.setId("ticket" + i);
ticketList.add(t);
}
when(ticketRepository.search(any(TicketCriteria.class), any(Sortable.class), any(Pageable.class))).thenThrow(new TechnicalException());
TicketQuery query = new TicketQuery();
query.setFromUser("fromUser");
ticketService.search(query, new SortableImpl("subject", true), new PageableImpl(1, Integer.MAX_VALUE));
}
use of io.gravitee.repository.management.model.Ticket in project gravitee-management-rest-api by gravitee-io.
the class TicketServiceTest method shouldNotFindByIdIfRepositoryThrowException.
@Test(expected = TechnicalManagementException.class)
public void shouldNotFindByIdIfRepositoryThrowException() throws TechnicalException {
Ticket ticket = new Ticket();
ticket.setId("ticket1");
ticket.setApi(API_ID);
ticket.setApplication(APPLICATION_ID);
ticket.setSubject(EMAIL_SUBJECT);
ticket.setContent(EMAIL_CONTENT);
ticket.setCreatedAt(new Date());
ticket.setFromUser(USERNAME);
ApiEntity apiEntity = new ApiEntity();
apiEntity.setName("apiName");
ApplicationEntity appEntity = new ApplicationEntity();
appEntity.setName("appName");
when(ticketRepository.findById("ticket1")).thenThrow(new TechnicalException());
ticketService.findById("ticket1");
}
use of io.gravitee.repository.management.model.Ticket in project gravitee-management-rest-api by gravitee-io.
the class TicketServiceTest method shouldCreateWithApi.
@Test
public void shouldCreateWithApi() throws TechnicalException {
when(mockParameterService.findAsBoolean(Key.CONSOLE_SUPPORT_ENABLED, REFERENCE_ID, REFERENCE_TYPE)).thenReturn(Boolean.TRUE);
when(newTicketEntity.getApi()).thenReturn(API_ID);
when(newTicketEntity.getApplication()).thenReturn(APPLICATION_ID);
when(newTicketEntity.getSubject()).thenReturn(EMAIL_SUBJECT);
when(newTicketEntity.isCopyToSender()).thenReturn(EMAIL_COPY_TO_SENDER);
when(newTicketEntity.getContent()).thenReturn(EMAIL_CONTENT);
when(userService.findById(USERNAME)).thenReturn(user);
when(user.getEmail()).thenReturn(USER_EMAIL);
when(user.getFirstname()).thenReturn(USER_FIRSTNAME);
when(user.getLastname()).thenReturn(USER_LASTNAME);
when(apiService.findByIdForTemplates(API_ID, true)).thenReturn(api);
when(applicationService.findById(APPLICATION_ID)).thenReturn(application);
Ticket ticketToCreate = new Ticket();
ticketToCreate.setId("generatedId");
ticketToCreate.setApi(API_ID);
ticketToCreate.setApplication(APPLICATION_ID);
ticketToCreate.setSubject(EMAIL_SUBJECT);
ticketToCreate.setContent(EMAIL_CONTENT);
ticketToCreate.setCreatedAt(new Date());
ticketToCreate.setFromUser(USERNAME);
when(ticketRepository.create(any(Ticket.class))).thenReturn(ticketToCreate);
final Map<String, String> metadata = new HashMap<>();
metadata.put(DefaultMetadataUpgrader.METADATA_EMAIL_SUPPORT_KEY, EMAIL_SUPPORT);
when(api.getMetadata()).thenReturn(metadata);
TicketEntity createdTicket = ticketService.create(USERNAME, newTicketEntity, REFERENCE_ID, REFERENCE_TYPE);
verify(emailService).sendEmailNotification(new EmailNotificationBuilder().replyTo(USER_EMAIL).fromName(USER_FIRSTNAME + ' ' + USER_LASTNAME).to(EMAIL_SUPPORT).copyToSender(EMAIL_COPY_TO_SENDER).template(TEMPLATES_FOR_ACTION_SUPPORT_TICKET).params(ImmutableMap.of("user", user, "api", api, "content", "Email<br />Content", "application", application, "ticketSubject", EMAIL_SUBJECT)).build());
verify(mockNotifierService, times(1)).trigger(eq(PortalHook.NEW_SUPPORT_TICKET), anyMap());
assertEquals("Invalid saved ticket id", createdTicket.getId(), ticketToCreate.getId());
assertEquals("Invalid saved ticket api", createdTicket.getApi(), ticketToCreate.getApi());
assertEquals("Invalid saved ticket application", createdTicket.getApplication(), ticketToCreate.getApplication());
assertEquals("Invalid saved ticket subject", createdTicket.getSubject(), ticketToCreate.getSubject());
assertEquals("Invalid saved ticket content", createdTicket.getContent(), ticketToCreate.getContent());
assertEquals("Invalid saved ticket from user", createdTicket.getFromUser(), ticketToCreate.getFromUser());
assertEquals("Invalid saved ticket created at", createdTicket.getCreatedAt(), ticketToCreate.getCreatedAt());
}
Aggregations