package org.apereo.cas.ticket;

import org.apereo.cas.authentication.CoreAuthenticationTestUtils;
import org.apereo.cas.config.CasCoreServicesConfiguration;
import org.apereo.cas.config.CasCoreTicketCatalogConfiguration;
import org.apereo.cas.config.CasCoreTicketIdGeneratorsConfiguration;
import org.apereo.cas.config.CasCoreTicketsConfiguration;
import org.apereo.cas.config.CasCoreUtilConfiguration;
import org.apereo.cas.config.support.CasWebApplicationServiceFactoryConfiguration;
import org.apereo.cas.mock.MockServiceTicket;
import org.apereo.cas.mock.MockTicketGrantingTicket;

import lombok.val;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.autoconfigure.RefreshAutoConfiguration;

import static org.junit.jupiter.api.Assertions.*;

/**
 * This is {@link DefaultTicketCatalogTests}.
 *
 * @author Misagh Moayyed
 * @since 6.1.0
 */
@SpringBootTest(classes = {
    RefreshAutoConfiguration.class,
    CasCoreServicesConfiguration.class,
    CasCoreTicketsConfiguration.class,
    CasCoreTicketCatalogConfiguration.class,
    CasCoreTicketIdGeneratorsConfiguration.class,
    CasCoreTicketCatalogConfiguration.class,
    CasWebApplicationServiceFactoryConfiguration.class,
    CasCoreUtilConfiguration.class
})
public class DefaultTicketCatalogTests {
    @Autowired
    @Qualifier("ticketCatalog")
    private TicketCatalog ticketCatalog;

    @Test
    public void verifyFindAll() {
        val tickets = ticketCatalog.findAll();
        assertFalse(tickets.isEmpty());
        assertEquals(5, tickets.size());
    }

    @Test
    public void verifyContains() {
        val tgt = new MockTicketGrantingTicket("casuser");
        assertTrue(ticketCatalog.contains(tgt.getPrefix()));
        assertNotNull(ticketCatalog.find(tgt));
        assertNotNull(ticketCatalog.find(tgt.getId()));
        assertNotNull(tgt.getClass());
        val st = tgt.grantServiceTicket(CoreAuthenticationTestUtils.getService());
        assertTrue(ticketCatalog.contains(st.getPrefix()));
        assertNotNull(ticketCatalog.find(st));
        assertNotNull(ticketCatalog.find(st.getId()));
        assertNotNull(st.getClass());
    }
}

@@ -483,54 +483,8 @@
 on;%0A
-import org.apereo.cas.mock.MockServiceTicket;%0A
 impo

fix checkstyle