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());
}
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();
}
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()));
}
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()));
}
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);
}
Aggregations