use of org.apereo.cas.services.util.RegisteredServiceJsonSerializer in project cas by apereo.
the class RegisteredServicesEndpoint method export.
/**
* Export.
*
* @return the response entity
*/
@GetMapping(path = "/export", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
@ResponseBody
@Operation(summary = "Export registered services as a zip file")
public ResponseEntity<Resource> export() {
val serializer = new RegisteredServiceJsonSerializer();
val resource = CompressionUtils.toZipFile(servicesManager.stream(), Unchecked.function(entry -> {
val service = (RegisteredService) entry;
val fileName = String.format("%s-%s", service.getName(), service.getId());
val sourceFile = File.createTempFile(fileName, ".json");
serializer.to(sourceFile, service);
return sourceFile;
}), "services");
val headers = new HttpHeaders();
headers.setContentDisposition(ContentDisposition.attachment().filename(Objects.requireNonNull(resource.getFilename())).build());
return new ResponseEntity<>(resource, headers, HttpStatus.OK);
}
use of org.apereo.cas.services.util.RegisteredServiceJsonSerializer in project cas by apereo.
the class RegisteredServicesEndpointTests method verifyBulkImportAsZip.
@Test
public void verifyBulkImportAsZip() throws Exception {
val request = new MockHttpServletRequest();
request.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
try (val out = new ByteArrayOutputStream(2048);
val zipStream = new ZipOutputStream(out)) {
var registeredService = RegisteredServiceTestUtils.getRegisteredService();
val content = new RegisteredServiceJsonSerializer().toString(registeredService);
var name = registeredService.getName() + ".json";
val e = new ZipEntry(name);
zipStream.putNextEntry(e);
val data = content.getBytes(StandardCharsets.UTF_8);
zipStream.write(data, 0, data.length);
zipStream.closeEntry();
request.setContent(out.toByteArray());
}
assertEquals(HttpStatus.OK, endpoint.importService(request).getStatusCode());
}
use of org.apereo.cas.services.util.RegisteredServiceJsonSerializer in project cas by apereo.
the class RegisteredServicesEndpointTests method verifyImportOperationAsJson.
@Test
public void verifyImportOperationAsJson() throws Exception {
val request = new MockHttpServletRequest();
val content = new RegisteredServiceJsonSerializer().toString(RegisteredServiceTestUtils.getRegisteredService());
request.setContent(content.getBytes(StandardCharsets.UTF_8));
assertEquals(HttpStatus.CREATED, endpoint.importService(request).getStatusCode());
}
use of org.apereo.cas.services.util.RegisteredServiceJsonSerializer in project cas by apereo.
the class RegisteredServiceResourceTests method runTest.
private void runTest(final String attrName, final String attrValue, final String credentials, final ResultMatcher result) throws Exception {
val registeredServiceResource = getRegisteredServiceResource(attrName, attrValue);
val service = RegisteredServiceTestUtils.getRegisteredService();
val sz = new RegisteredServiceJsonSerializer();
try (val writer = new StringWriter()) {
sz.to(writer, service);
configureMockMvcFor(registeredServiceResource).perform(post("/cas/v1/services").contentType(MediaType.APPLICATION_JSON).header("Authorization", "Basic " + EncodingUtils.encodeBase64(credentials)).content(writer.toString())).andExpect(result);
}
}
use of org.apereo.cas.services.util.RegisteredServiceJsonSerializer in project cas by apereo.
the class GitServiceRegistryTests method verifyPullFails.
@Test
public void verifyPullFails() throws Exception {
val gitRepository = mock(GitRepository.class);
when(gitRepository.getObjectsInRepository()).thenThrow(new JGitInternalException("error"));
when(gitRepository.getObjectsInRepository(any())).thenThrow(new JGitInternalException("error"));
when(gitRepository.getRepositoryDirectory()).thenReturn(gitRepositoryInstance.getRepositoryDirectory());
val svc = buildRegisteredServiceInstance(RandomUtils.nextLong(), RegexRegisteredService.class);
svc.setId(RegisteredService.INITIAL_IDENTIFIER_VALUE);
newServiceRegistry.save(svc);
val size = newServiceRegistry.load().size();
val registry = new GitServiceRegistry(applicationContext, gitRepository, CollectionUtils.wrapList(new RegisteredServiceJsonSerializer(), new RegisteredServiceYamlSerializer()), false, null, List.of(), List.of());
assertEquals(size, registry.load().size());
}
Aggregations