Search in sources :

Example 1 with RegisteredServiceJsonSerializer

use of org.apereo.cas.services.util.RegisteredServiceJsonSerializer in project cas by apereo.

the class DeleteResourceBasedRegisteredServiceWatcherTests method verifyOperationFoundDeleted.

@Test
public void verifyOperationFoundDeleted() throws Exception {
    val result = new AtomicBoolean(false);
    val mockAppContext = mock(ConfigurableApplicationContext.class);
    doAnswer(args -> {
        val clazz = args.getArgument(0).getClass();
        result.set(clazz.equals(CasRegisteredServiceDeletedEvent.class));
        return null;
    }).when(mockAppContext).publishEvent(any());
    val registry = new AbstractResourceBasedServiceRegistry(new ClassPathResource("services"), List.of(new RegisteredServiceJsonSerializer()), mockAppContext, new ArrayList<>()) {

        @Override
        protected String[] getExtensions() {
            return new String[] { "json" };
        }
    };
    var results = registry.load();
    assertFalse(results.isEmpty());
    val watcher = new DeleteResourceBasedRegisteredServiceWatcher(registry);
    watcher.accept(new File("Sample-1.json"));
    assertTrue(result.get());
    assertEquals(0, registry.size());
}
Also used : lombok.val(lombok.val) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RegisteredServiceJsonSerializer(org.apereo.cas.services.util.RegisteredServiceJsonSerializer) CasRegisteredServiceDeletedEvent(org.apereo.cas.support.events.service.CasRegisteredServiceDeletedEvent) File(java.io.File) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 2 with RegisteredServiceJsonSerializer

use of org.apereo.cas.services.util.RegisteredServiceJsonSerializer in project cas by apereo.

the class GitServiceRegistryConfiguration method gitServiceRegistry.

@Bean
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
@ConditionalOnMissingBean(name = "gitServiceRegistry")
public ServiceRegistry gitServiceRegistry(final CasConfigurationProperties casProperties, final ObjectProvider<List<ServiceRegistryListener>> serviceRegistryListeners, final ConfigurableApplicationContext applicationContext, @Qualifier("gitServiceRegistryRepositoryInstance") final GitRepository gitServiceRegistryRepositoryInstance, @Qualifier("registeredServiceResourceNamingStrategy") final RegisteredServiceResourceNamingStrategy resourceNamingStrategy) {
    return BeanSupplier.of(ServiceRegistry.class).when(CONDITION.given(applicationContext.getEnvironment())).supply(() -> {
        val properties = casProperties.getServiceRegistry().getGit();
        val locators = new ArrayList<GitRepositoryRegisteredServiceLocator>();
        if (properties.isGroupByType()) {
            locators.add(new TypeAwareGitRepositoryRegisteredServiceLocator(resourceNamingStrategy, gitServiceRegistryRepositoryInstance.getRepositoryDirectory(), properties));
        }
        locators.add(new DefaultGitRepositoryRegisteredServiceLocator(resourceNamingStrategy, gitServiceRegistryRepositoryInstance.getRepositoryDirectory(), properties));
        return new GitServiceRegistry(applicationContext, gitServiceRegistryRepositoryInstance, CollectionUtils.wrapList(new RegisteredServiceJsonSerializer(), new RegisteredServiceYamlSerializer()), properties.isPushChanges(), properties.getRootDirectory(), Optional.ofNullable(serviceRegistryListeners.getIfAvailable()).orElseGet(ArrayList::new), locators);
    }).otherwiseProxy().get();
}
Also used : lombok.val(lombok.val) TypeAwareGitRepositoryRegisteredServiceLocator(org.apereo.cas.services.locator.TypeAwareGitRepositoryRegisteredServiceLocator) GitServiceRegistry(org.apereo.cas.services.GitServiceRegistry) RegisteredServiceJsonSerializer(org.apereo.cas.services.util.RegisteredServiceJsonSerializer) ArrayList(java.util.ArrayList) RegisteredServiceYamlSerializer(org.apereo.cas.services.util.RegisteredServiceYamlSerializer) DefaultGitRepositoryRegisteredServiceLocator(org.apereo.cas.services.locator.DefaultGitRepositoryRegisteredServiceLocator) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 3 with RegisteredServiceJsonSerializer

use of org.apereo.cas.services.util.RegisteredServiceJsonSerializer in project cas by apereo.

the class GenerateYamlRegisteredServiceCommandTests method verifyOperation.

@Test
public void verifyOperation() throws Exception {
    val file = File.createTempFile("service", ".json");
    val yaml = File.createTempFile("service", ".yaml");
    val svc = RegisteredServiceTestUtils.getRegisteredService("example");
    try (val writer = Files.newBufferedWriter(file.toPath(), StandardCharsets.UTF_8)) {
        new RegisteredServiceJsonSerializer().to(writer, svc);
        writer.flush();
    }
    assertTrue(file.exists() && file.length() > 0);
    assertNotNull(shell.evaluate(() -> "generate-yaml --file " + file.getPath() + " --destination " + yaml.getPath()));
    assertTrue(yaml.exists());
    val badFile = File.createTempFile("first", ".second");
    assertNotNull(shell.evaluate(() -> "generate-yaml --file " + badFile + " --destination " + yaml.getPath()));
    FileUtils.write(badFile, "data", StandardCharsets.UTF_8);
    assertNotNull(shell.evaluate(() -> "generate-yaml --file " + badFile + " --destination " + yaml.getPath()));
}
Also used : lombok.val(lombok.val) RegisteredServiceJsonSerializer(org.apereo.cas.services.util.RegisteredServiceJsonSerializer) Test(org.junit.jupiter.api.Test)

Example 4 with RegisteredServiceJsonSerializer

use of org.apereo.cas.services.util.RegisteredServiceJsonSerializer in project cas by apereo.

the class ValidateRegisteredServiceCommandTests method verifyOperation.

@Test
public void verifyOperation() throws Exception {
    val file = File.createTempFile("service", ".json");
    val yaml = File.createTempFile("service", ".yaml");
    val other = File.createTempFile("service-bad", ".json");
    FileUtils.write(other, "data{{}}", StandardCharsets.UTF_8);
    val svc = RegisteredServiceTestUtils.getRegisteredService("example");
    try (val writer = Files.newBufferedWriter(file.toPath(), StandardCharsets.UTF_8)) {
        new RegisteredServiceJsonSerializer().to(writer, svc);
        writer.flush();
    }
    assertTrue(file.exists() && file.length() > 0);
    assertNotNull(shell.evaluate(() -> "generate-yaml --file " + file.getPath() + " --destination " + yaml.getPath()));
    assertTrue(yaml.exists());
    assertDoesNotThrow(() -> shell.evaluate(() -> "validate-service --file " + file.getPath()));
    assertDoesNotThrow(() -> shell.evaluate(() -> "validate-service --file " + yaml.getPath()));
    assertDoesNotThrow(() -> shell.evaluate(() -> "validate-service --directory " + file.getParent()));
}
Also used : lombok.val(lombok.val) RegisteredServiceJsonSerializer(org.apereo.cas.services.util.RegisteredServiceJsonSerializer) Test(org.junit.jupiter.api.Test)

Example 5 with RegisteredServiceJsonSerializer

use of org.apereo.cas.services.util.RegisteredServiceJsonSerializer in project cas by apereo.

the class JsonServiceRegistryTests method verifyRequiredHandlersServiceDefinition.

@Test
public void verifyRequiredHandlersServiceDefinition() throws Exception {
    val resource = new ClassPathResource("RequiredHandlers-10000004.json");
    val serializer = new RegisteredServiceJsonSerializer();
    val service = serializer.from(resource.getInputStream());
    assertNotNull(service);
}
Also used : lombok.val(lombok.val) RegisteredServiceJsonSerializer(org.apereo.cas.services.util.RegisteredServiceJsonSerializer) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

lombok.val (lombok.val)31 RegisteredServiceJsonSerializer (org.apereo.cas.services.util.RegisteredServiceJsonSerializer)31 Test (org.junit.jupiter.api.Test)23 ClassPathResource (org.springframework.core.io.ClassPathResource)8 File (java.io.File)6 ChainingAttributeReleasePolicy (org.apereo.cas.services.ChainingAttributeReleasePolicy)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 RegisteredServiceYamlSerializer (org.apereo.cas.services.util.RegisteredServiceYamlSerializer)4 StringWriter (java.io.StringWriter)2 ArrayList (java.util.ArrayList)2 KafkaObjectFactory (org.apereo.cas.kafka.KafkaObjectFactory)2 RegisteredService (org.apereo.cas.services.RegisteredService)2 CasRegisteredServiceDeletedEvent (org.apereo.cas.support.events.service.CasRegisteredServiceDeletedEvent)2 CasRegisteredServiceSavedEvent (org.apereo.cas.support.events.service.CasRegisteredServiceSavedEvent)2 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)2 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)2 Bean (org.springframework.context.annotation.Bean)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1