Search in sources :

Example 16 with PublisherIdentifier

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

the class RegisteredServiceKafkaDistributedCacheListenerTests method verifyUpdate.

@Test
public void verifyUpdate() {
    val service = RegisteredServiceTestUtils.getRegisteredService();
    val item = new DistributedCacheObject<RegisteredService>(Map.of(), 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)

Example 17 with PublisherIdentifier

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

the class DefaultRegisteredServiceReplicationStrategyTests method verifyGetInCacheAndRemove.

@Test
public void verifyGetInCacheAndRemove() {
    val id = new PublisherIdentifier();
    val appCtx = new StaticApplicationContext();
    appCtx.refresh();
    val serviceRegistry = new InMemoryServiceRegistry(appCtx);
    val stream = casProperties.getServiceRegistry().getStream();
    val mgr = mock(DistributedCacheManager.class);
    val strategy = new DefaultRegisteredServiceReplicationStrategy(mgr, stream, id);
    val service = newService("Test");
    val object = DistributedCacheObject.<RegisteredService>builder().value(service).publisherIdentifier(id).properties(Map.of("event", CasRegisteredServiceDeletedEvent.class.getSimpleName())).build();
    when(mgr.find(any())).thenReturn(Optional.of(object));
    val svc = strategy.getRegisteredServiceFromCacheIfAny(service, 1000, serviceRegistry);
    assertNotNull(svc);
    assertEquals(serviceRegistry.size(), 0);
}
Also used : lombok.val(lombok.val) RegexRegisteredService(org.apereo.cas.services.RegexRegisteredService) RegisteredService(org.apereo.cas.services.RegisteredService) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) CasRegisteredServiceDeletedEvent(org.apereo.cas.support.events.service.CasRegisteredServiceDeletedEvent) PublisherIdentifier(org.apereo.cas.util.PublisherIdentifier) InMemoryServiceRegistry(org.apereo.cas.services.InMemoryServiceRegistry) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 18 with PublisherIdentifier

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

the class DefaultRegisteredServiceReplicationStrategyTests method verifyGetInCacheAndSave.

@Test
public void verifyGetInCacheAndSave() {
    val id = new PublisherIdentifier();
    val appCtx = new StaticApplicationContext();
    appCtx.refresh();
    val serviceRegistry = new InMemoryServiceRegistry(appCtx);
    val stream = casProperties.getServiceRegistry().getStream();
    val mgr = mock(DistributedCacheManager.class);
    val strategy = new DefaultRegisteredServiceReplicationStrategy(mgr, stream, id);
    val service = newService("Test");
    val object = DistributedCacheObject.<RegisteredService>builder().value(service).publisherIdentifier(id).build();
    when(mgr.find(any())).thenReturn(Optional.of(object));
    val svc = strategy.getRegisteredServiceFromCacheIfAny(null, 1000, serviceRegistry);
    assertNotNull(svc);
    assertEquals(serviceRegistry.size(), 1);
}
Also used : lombok.val(lombok.val) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) PublisherIdentifier(org.apereo.cas.util.PublisherIdentifier) InMemoryServiceRegistry(org.apereo.cas.services.InMemoryServiceRegistry) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 19 with PublisherIdentifier

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

the class DefaultRegisteredServiceReplicationStrategyTests method verifyUpdateWithMatch.

@Test
public void verifyUpdateWithMatch() {
    val id = new PublisherIdentifier();
    val appCtx = new StaticApplicationContext();
    appCtx.refresh();
    val serviceRegistry = new InMemoryServiceRegistry(appCtx);
    val stream = casProperties.getServiceRegistry().getStream();
    val mgr = mock(DistributedCacheManager.class);
    val service = newService("Test1");
    val service2 = newService("Test2");
    val obj1 = DistributedCacheObject.<RegisteredService>builder().value(service).publisherIdentifier(id).build();
    val object = DistributedCacheObject.<RegisteredService>builder().value(service).publisherIdentifier(id).properties(Map.of("event", CasRegisteredServiceDeletedEvent.class.getSimpleName())).build();
    when(mgr.getAll()).thenReturn(CollectionUtils.wrapList(obj1, object));
    val strategy = new DefaultRegisteredServiceReplicationStrategy(mgr, stream, id);
    val results = strategy.updateLoadedRegisteredServicesFromCache(CollectionUtils.wrapList(service, service2), serviceRegistry);
    assertFalse(results.isEmpty());
}
Also used : lombok.val(lombok.val) RegexRegisteredService(org.apereo.cas.services.RegexRegisteredService) RegisteredService(org.apereo.cas.services.RegisteredService) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) CasRegisteredServiceDeletedEvent(org.apereo.cas.support.events.service.CasRegisteredServiceDeletedEvent) PublisherIdentifier(org.apereo.cas.util.PublisherIdentifier) InMemoryServiceRegistry(org.apereo.cas.services.InMemoryServiceRegistry) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 20 with PublisherIdentifier

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

the class CasServicesStreamingKafkaConfigurationTests method verifyListener.

@Test
public void verifyListener() throws Exception {
    val registeredService = RegisteredServiceTestUtils.getRegisteredService();
    val publisherId = new PublisherIdentifier();
    casRegisteredServiceStreamPublisher.publish(registeredService, new CasRegisteredServiceSavedEvent(this, registeredService), publisherId);
    Thread.sleep(3000);
    assertFalse(registeredServiceDistributedCacheManager.getAll().isEmpty());
    casRegisteredServiceStreamPublisher.publish(registeredService, new CasRegisteredServiceDeletedEvent(this, registeredService), publisherId);
    Thread.sleep(2500);
    registeredServiceDistributedCacheManager.clear();
    assertTrue(registeredServiceDistributedCacheManager.getAll().isEmpty());
}
Also used : lombok.val(lombok.val) CasRegisteredServiceSavedEvent(org.apereo.cas.support.events.service.CasRegisteredServiceSavedEvent) CasRegisteredServiceDeletedEvent(org.apereo.cas.support.events.service.CasRegisteredServiceDeletedEvent) PublisherIdentifier(org.apereo.cas.util.PublisherIdentifier) 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