Search in sources :

Example 6 with Ticket

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));
}
Also used : PageableImpl(io.gravitee.rest.api.model.common.PageableImpl) Ticket(io.gravitee.repository.management.model.Ticket) SortableImpl(io.gravitee.rest.api.model.common.SortableImpl) Pageable(io.gravitee.repository.management.api.search.Pageable) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Sortable(io.gravitee.repository.management.api.search.Sortable) TicketCriteria(io.gravitee.repository.management.api.search.TicketCriteria) TicketQuery(io.gravitee.rest.api.model.api.TicketQuery) Test(org.junit.Test)

Example 7 with Ticket

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");
}
Also used : Ticket(io.gravitee.repository.management.model.Ticket) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Test(org.junit.Test)

Example 8 with Ticket

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());
}
Also used : Ticket(io.gravitee.repository.management.model.Ticket) EmailNotificationBuilder(io.gravitee.rest.api.service.builder.EmailNotificationBuilder) Test(org.junit.Test)

Aggregations

Ticket (io.gravitee.repository.management.model.Ticket)8 Test (org.junit.Test)5 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)4 TicketCriteria (io.gravitee.repository.management.api.search.TicketCriteria)3 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)3 Pageable (io.gravitee.repository.management.api.search.Pageable)2 Sortable (io.gravitee.repository.management.api.search.Sortable)2 TicketQuery (io.gravitee.rest.api.model.api.TicketQuery)2 PageableImpl (io.gravitee.rest.api.model.common.PageableImpl)2 SortableImpl (io.gravitee.rest.api.model.common.SortableImpl)2 EmailNotificationBuilder (io.gravitee.rest.api.service.builder.EmailNotificationBuilder)2 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)2 Page (io.gravitee.common.data.domain.Page)1 PageableBuilder (io.gravitee.repository.management.api.search.builder.PageableBuilder)1 UuidString (io.gravitee.rest.api.service.common.UuidString)1 EmailRequiredException (io.gravitee.rest.api.service.exceptions.EmailRequiredException)1 SupportUnavailableException (io.gravitee.rest.api.service.exceptions.SupportUnavailableException)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1