Search in sources :

Example 11 with PublisherIdentifier

use of org.apereo.cas.util.PublisherIdentifier in project cas by apereo.

the class CasServicesStreamingKafkaConfigurationTests method verifySerialization.

@Test
public void verifySerialization() throws Exception {
    val o = DistributedCacheObject.<RegisteredService>builder().value(RegisteredServiceTestUtils.getRegisteredService()).publisherIdentifier(new PublisherIdentifier()).build();
    val file = new File(FileUtils.getTempDirectoryPath(), UUID.randomUUID().toString() + ".json");
    val mapper = new RegisteredServiceJsonSerializer().getObjectMapper();
    mapper.writeValue(file, o);
    val readPolicy = mapper.readValue(file, DistributedCacheObject.class);
    assertEquals(o, readPolicy);
}
Also used : lombok.val(lombok.val) RegisteredServiceJsonSerializer(org.apereo.cas.services.util.RegisteredServiceJsonSerializer) PublisherIdentifier(org.apereo.cas.util.PublisherIdentifier) File(java.io.File) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 12 with PublisherIdentifier

use of org.apereo.cas.util.PublisherIdentifier in project cas by apereo.

the class CasServicesStreamingKafkaConfigurationTests method verifyAction.

@Test
public void verifyAction() throws Exception {
    val registeredService = RegisteredServiceTestUtils.getRegisteredService();
    var obj = registeredServiceDistributedCacheManager.get(registeredService);
    assertNull(obj);
    assertFalse(registeredServiceDistributedCacheManager.contains(registeredService));
    val cache = DistributedCacheObject.<RegisteredService>builder().value(registeredService).publisherIdentifier(casRegisteredServiceStreamPublisherIdentifier).build();
    registeredServiceDistributedCacheManager.set(registeredService, cache, true);
    Thread.sleep(2000);
    assertFalse(registeredServiceDistributedCacheManager.getAll().isEmpty());
    obj = registeredServiceDistributedCacheManager.get(registeredService);
    assertNotNull(obj);
    var c = registeredServiceDistributedCacheManager.findAll(obj1 -> obj1.getValue().equals(registeredService));
    assertFalse(c.isEmpty());
    registeredServiceDistributedCacheManager.remove(registeredService, cache, true);
    Thread.sleep(5000);
    c = registeredServiceDistributedCacheManager.findAll(obj1 -> obj1.getValue().equals(registeredService));
    assertTrue(c.isEmpty());
    registeredServiceDistributedCacheManager.clear();
    assertTrue(registeredServiceDistributedCacheManager.getAll().isEmpty());
}
Also used : lombok.val(lombok.val) lombok.val(lombok.val) Autowired(org.springframework.beans.factory.annotation.Autowired) FileUtils(org.apache.commons.io.FileUtils) CasRegisteredServiceLoadedEvent(org.apereo.cas.support.events.service.CasRegisteredServiceLoadedEvent) UUID(java.util.UUID) RegisteredServiceJsonSerializer(org.apereo.cas.services.util.RegisteredServiceJsonSerializer) DistributedCacheObject(org.apereo.cas.util.cache.DistributedCacheObject) RegisteredService(org.apereo.cas.services.RegisteredService) File(java.io.File) CasRegisteredServiceDeletedEvent(org.apereo.cas.support.events.service.CasRegisteredServiceDeletedEvent) Test(org.junit.jupiter.api.Test) DistributedCacheManager(org.apereo.cas.util.cache.DistributedCacheManager) EnabledIfPortOpen(org.apereo.cas.util.junit.EnabledIfPortOpen) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) RefreshAutoConfiguration(org.springframework.cloud.autoconfigure.RefreshAutoConfiguration) PublisherIdentifier(org.apereo.cas.util.PublisherIdentifier) RegisteredServiceTestUtils(org.apereo.cas.services.RegisteredServiceTestUtils) Qualifier(org.springframework.beans.factory.annotation.Qualifier) Assertions(org.junit.jupiter.api.Assertions) CasRegisteredServiceStreamPublisher(org.apereo.cas.services.publisher.CasRegisteredServiceStreamPublisher) CasRegisteredServiceSavedEvent(org.apereo.cas.support.events.service.CasRegisteredServiceSavedEvent) Tag(org.junit.jupiter.api.Tag) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 13 with PublisherIdentifier

use of org.apereo.cas.util.PublisherIdentifier in project cas by apereo.

the class RegisteredServiceKafkaDistributedCacheManagerTests method verifyOperation.

@Test
public void verifyOperation() {
    val service = RegisteredServiceTestUtils.getRegisteredService();
    assertFalse(registeredServiceDistributedCacheManager.contains(service));
    assertTrue(registeredServiceDistributedCacheManager.getAll().isEmpty());
    assertTrue(registeredServiceDistributedCacheManager.findAll(Objects::nonNull).isEmpty());
    val item = new DistributedCacheObject<RegisteredService>(Map.of(), System.currentTimeMillis(), service, new PublisherIdentifier());
    assertNotNull(registeredServiceDistributedCacheManager.set(service, item, true));
    assertNotNull(registeredServiceDistributedCacheManager.set(service, item, false));
    assertNotNull(registeredServiceDistributedCacheManager.update(service, item, true));
    assertNotNull(registeredServiceDistributedCacheManager.update(service, item, false));
}
Also used : lombok.val(lombok.val) DistributedCacheObject(org.apereo.cas.util.cache.DistributedCacheObject) Objects(java.util.Objects) PublisherIdentifier(org.apereo.cas.util.PublisherIdentifier) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 14 with PublisherIdentifier

use of org.apereo.cas.util.PublisherIdentifier in project cas by apereo.

the class RegisteredServiceHazelcastDistributedCacheManagerTests method verifyPublisher.

@Test
public void verifyPublisher() {
    val registeredService = RegisteredServiceTestUtils.getRegisteredService();
    val casRegisteredServiceStreamPublisherIdentifier = new PublisherIdentifier("123456");
    val publisher = new DefaultCasRegisteredServiceStreamPublisher(mgr);
    publisher.publish(registeredService, new CasRegisteredServiceDeletedEvent(this, registeredService), casRegisteredServiceStreamPublisherIdentifier);
    publisher.publish(registeredService, new CasRegisteredServiceSavedEvent(this, registeredService), casRegisteredServiceStreamPublisherIdentifier);
    publisher.publish(registeredService, new CasRegisteredServiceLoadedEvent(this, registeredService), casRegisteredServiceStreamPublisherIdentifier);
    assertFalse(mgr.getAll().isEmpty());
}
Also used : lombok.val(lombok.val) CasRegisteredServiceSavedEvent(org.apereo.cas.support.events.service.CasRegisteredServiceSavedEvent) CasRegisteredServiceDeletedEvent(org.apereo.cas.support.events.service.CasRegisteredServiceDeletedEvent) CasRegisteredServiceLoadedEvent(org.apereo.cas.support.events.service.CasRegisteredServiceLoadedEvent) PublisherIdentifier(org.apereo.cas.util.PublisherIdentifier) DefaultCasRegisteredServiceStreamPublisher(org.apereo.cas.services.publisher.DefaultCasRegisteredServiceStreamPublisher) Test(org.junit.jupiter.api.Test)

Example 15 with PublisherIdentifier

use of org.apereo.cas.util.PublisherIdentifier in project cas by apereo.

the class RegisteredServiceKafkaDistributedCacheListenerTests method verifyRemoval.

@Test
public void verifyRemoval() {
    val service = RegisteredServiceTestUtils.getRegisteredService();
    val item = new DistributedCacheObject<RegisteredService>(Map.of("event", CasRegisteredServiceDeletedEvent.class.getSimpleName()), System.currentTimeMillis(), service, new PublisherIdentifier());
    assertDoesNotThrow(new Executable() {

        @Override
        public void execute() throws Throwable {
            listener.registeredServiceDistributedCacheKafkaListener(item);
        }
    });
}
Also used : lombok.val(lombok.val) DistributedCacheObject(org.apereo.cas.util.cache.DistributedCacheObject) PublisherIdentifier(org.apereo.cas.util.PublisherIdentifier) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

lombok.val (lombok.val)24 PublisherIdentifier (org.apereo.cas.util.PublisherIdentifier)24 Test (org.junit.jupiter.api.Test)23 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)13 InMemoryServiceRegistry (org.apereo.cas.services.InMemoryServiceRegistry)7 StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)7 CasRegisteredServiceDeletedEvent (org.apereo.cas.support.events.service.CasRegisteredServiceDeletedEvent)5 TicketGrantingTicketImpl (org.apereo.cas.ticket.TicketGrantingTicketImpl)4 DistributedCacheObject (org.apereo.cas.util.cache.DistributedCacheObject)4 File (java.io.File)3 RegisteredService (org.apereo.cas.services.RegisteredService)3 CasRegisteredServiceSavedEvent (org.apereo.cas.support.events.service.CasRegisteredServiceSavedEvent)3 RegexRegisteredService (org.apereo.cas.services.RegexRegisteredService)2 RegisteredServiceJsonSerializer (org.apereo.cas.services.util.RegisteredServiceJsonSerializer)2 CasRegisteredServiceLoadedEvent (org.apereo.cas.support.events.service.CasRegisteredServiceLoadedEvent)2 Assertions (org.junit.jupiter.api.Assertions)2 Tag (org.junit.jupiter.api.Tag)2 Executable (org.junit.jupiter.api.function.Executable)2 Objects (java.util.Objects)1 UUID (java.util.UUID)1