Search in sources :

Example 1 with PublisherIdentifier

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

the class DefaultRegisteredServiceReplicationStrategyTests method verifyUpdateWithNoMatch.

@Test
public void verifyUpdateWithNoMatch() {
    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");
    service.setId(500);
    val cachedService = newService("Test2");
    val object = DistributedCacheObject.<RegisteredService>builder().value(cachedService).publisherIdentifier(id).build();
    when(mgr.getAll()).thenReturn(CollectionUtils.wrapList(object));
    val strategy = new DefaultRegisteredServiceReplicationStrategy(mgr, stream, id);
    val results = strategy.updateLoadedRegisteredServicesFromCache(CollectionUtils.wrapList(service), serviceRegistry);
    assertFalse(results.isEmpty());
    assertEquals(2, results.size());
}
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 2 with PublisherIdentifier

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

the class DefaultRegisteredServiceReplicationStrategyTests method verifyGetInCacheAndUpdate.

@Test
public void verifyGetInCacheAndUpdate() {
    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 service2 = newService("Test1");
    val object = DistributedCacheObject.<RegisteredService>builder().value(service2).publisherIdentifier(id).build();
    when(mgr.find(any())).thenReturn(Optional.of(object));
    var svc = strategy.getRegisteredServiceFromCacheIfAny(service, 1000, serviceRegistry);
    assertNotNull(svc);
    assertEquals(serviceRegistry.size(), 1);
    svc = serviceRegistry.findServiceById(1000);
    assertEquals("Test1", svc.getName());
}
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 3 with PublisherIdentifier

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

the class DefaultRegisteredServiceReplicationStrategyTests method verifySetInCache.

@Test
public void verifySetInCache() {
    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);
    when(mgr.find(any())).thenReturn(Optional.empty());
    var svc = strategy.getRegisteredServiceFromCacheIfAny(newService("Test"), 1000, serviceRegistry);
    assertNotNull(svc);
    svc = strategy.getRegisteredServiceFromCacheIfAny(newService("Test"), "https://example.org", serviceRegistry);
    assertNotNull(svc);
    strategy.destroy();
}
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 4 with PublisherIdentifier

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

the class DefaultRegisteredServiceReplicationStrategyTests method verifyGetInCacheAndMatch.

@Test
public void verifyGetInCacheAndMatch() {
    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 service2 = newService("Test");
    val object = DistributedCacheObject.<RegisteredService>builder().value(service2).publisherIdentifier(id).build();
    when(mgr.find(any())).thenReturn(Optional.of(object));
    var svc = strategy.getRegisteredServiceFromCacheIfAny(service, 1000, serviceRegistry);
    assertNotNull(svc);
    assertEquals(serviceRegistry.size(), 0);
}
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 5 with PublisherIdentifier

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

the class DistributedCacheManagerTests method verifyDefaults.

@Test
public void verifyDefaults() {
    val mgr = DistributedCacheManager.noOp();
    assertNull(mgr.get("key"));
    assertNotNull(mgr.getAll());
    assertNotNull(mgr.findAll(distributedCacheObject -> true));
    assertNotNull(mgr.getName());
    assertFalse(mgr.contains("key"));
    assertFalse(mgr.find(distributedCacheObject -> true).isPresent());
    val id = new PublisherIdentifier();
    val object = DistributedCacheObject.<String>builder().value("value").publisherIdentifier(id).build();
    assertDoesNotThrow(() -> mgr.set("key", object, true));
    assertDoesNotThrow(mgr::clear);
    assertDoesNotThrow(() -> mgr.set("key", object, true));
    assertDoesNotThrow(() -> mgr.remove("key", object, true));
    assertNotNull(mgr.update("key", object, true));
    mgr.close();
}
Also used : lombok.val(lombok.val) Test(org.junit.jupiter.api.Test) PublisherIdentifier(org.apereo.cas.util.PublisherIdentifier) lombok.val(lombok.val) Assertions(org.junit.jupiter.api.Assertions) Tag(org.junit.jupiter.api.Tag) PublisherIdentifier(org.apereo.cas.util.PublisherIdentifier) Test(org.junit.jupiter.api.Test)

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