use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.
the class ReportTemplateITCase method issueSYNCOPE866.
@Test
public void issueSYNCOPE866() {
ReportTemplateTO reportTemplateTO = new ReportTemplateTO();
reportTemplateTO.setKey("empty");
try {
reportTemplateService.create(reportTemplateTO);
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.EntityExists, e.getType());
}
}
use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.
the class ReportTemplateITCase method crud.
@Test
public void crud() throws IOException {
final String key = getUUIDString();
// 1. create (empty) report template
ReportTemplateTO reportTemplateTO = new ReportTemplateTO();
reportTemplateTO.setKey(key);
Response response = reportTemplateService.create(reportTemplateTO);
assertEquals(201, response.getStatus());
// 2. attempt to read HTML and CSV -> fail
try {
reportTemplateService.getFormat(key, ReportTemplateFormat.HTML);
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.NotFound, e.getType());
}
try {
reportTemplateService.getFormat(key, ReportTemplateFormat.CSV);
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.NotFound, e.getType());
}
// 3. set CSV
String csvTemplate = "<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'></xsl:stylesheet>";
reportTemplateService.setFormat(key, ReportTemplateFormat.CSV, IOUtils.toInputStream(csvTemplate, StandardCharsets.UTF_8));
response = reportTemplateService.getFormat(key, ReportTemplateFormat.CSV);
assertEquals(200, response.getStatus());
assertTrue(response.getMediaType().toString().startsWith(MediaType.APPLICATION_XML));
assertTrue(response.getEntity() instanceof InputStream);
assertEquals(csvTemplate, IOUtils.toString((InputStream) response.getEntity(), StandardCharsets.UTF_8));
// 3. set HTML
String htmlTemplate = "<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'></xsl:stylesheet>";
reportTemplateService.setFormat(key, ReportTemplateFormat.HTML, IOUtils.toInputStream(htmlTemplate, StandardCharsets.UTF_8));
response = reportTemplateService.getFormat(key, ReportTemplateFormat.HTML);
assertEquals(200, response.getStatus());
assertTrue(response.getMediaType().toString().startsWith(MediaType.APPLICATION_XML));
assertTrue(response.getEntity() instanceof InputStream);
assertEquals(htmlTemplate, IOUtils.toString((InputStream) response.getEntity(), StandardCharsets.UTF_8));
// 4. remove HTML
reportTemplateService.removeFormat(key, ReportTemplateFormat.HTML);
try {
reportTemplateService.getFormat(key, ReportTemplateFormat.HTML);
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.NotFound, e.getType());
}
response = reportTemplateService.getFormat(key, ReportTemplateFormat.CSV);
assertEquals(200, response.getStatus());
assertTrue(response.getMediaType().toString().startsWith(MediaType.APPLICATION_XML));
assertTrue(response.getEntity() instanceof InputStream);
assertEquals(csvTemplate, IOUtils.toString((InputStream) response.getEntity(), StandardCharsets.UTF_8));
// 5. remove report template
reportTemplateService.delete(key);
try {
reportTemplateService.read(key);
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.NotFound, e.getType());
}
try {
reportTemplateService.getFormat(key, ReportTemplateFormat.HTML);
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.NotFound, e.getType());
}
try {
reportTemplateService.getFormat(key, ReportTemplateFormat.CSV);
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.NotFound, e.getType());
}
}
use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.
the class ResourceITCase method listConnObjects.
@Test
public void listConnObjects() {
List<String> groupKeys = new ArrayList<>();
for (int i = 0; i < 10; i++) {
GroupTO group = GroupITCase.getSampleTO("group");
group.getResources().add(RESOURCE_NAME_LDAP);
group = createGroup(group).getEntity();
groupKeys.add(group.getKey());
}
int totalRead = 0;
Set<String> read = new HashSet<>();
try {
ConnObjectTOListQuery.Builder builder = new ConnObjectTOListQuery.Builder().size(10);
PagedConnObjectTOResult list;
do {
list = null;
boolean succeeded = false;
// needed because ApacheDS seems to randomly fail when searching with cookie
for (int i = 0; i < 5 && !succeeded; i++) {
try {
list = resourceService.listConnObjects(RESOURCE_NAME_LDAP, AnyTypeKind.GROUP.name(), builder.build());
succeeded = true;
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.ConnectorException, e.getType());
}
}
assertNotNull(list);
totalRead += list.getResult().size();
read.addAll(list.getResult().stream().map(input -> input.getAttr(ConnIdSpecialName.NAME).get().getValues().get(0)).collect(Collectors.toList()));
if (list.getPagedResultsCookie() != null) {
builder.pagedResultsCookie(list.getPagedResultsCookie());
}
} while (list.getPagedResultsCookie() != null);
assertEquals(totalRead, read.size());
assertTrue(totalRead >= 10);
} finally {
groupKeys.forEach(key -> {
groupService.delete(key);
});
}
}
use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.
the class ResourceITCase method delete.
@Test
public void delete() {
String resourceKey = "tobedeleted";
ResourceTO resource = buildResourceTO(resourceKey);
Response response = resourceService.create(resource);
ResourceTO actual = getObject(response.getLocation(), ResourceService.class, ResourceTO.class);
assertNotNull(actual);
resourceService.delete(resourceKey);
try {
resourceService.read(resourceKey);
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(Response.Status.NOT_FOUND, e.getType().getResponseStatus());
}
}
use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.
the class ResourceITCase method createWithInvalidMapping.
@Test
public void createWithInvalidMapping() {
String resourceKey = RESOURCE_NAME_CREATE_WRONG;
ResourceTO resourceTO = new ResourceTO();
resourceTO.setKey(resourceKey);
resourceTO.setConnector("5ffbb4ac-a8c3-4b44-b699-11b398a1ba08");
ProvisionTO provisionTO = new ProvisionTO();
provisionTO.setAnyType(AnyTypeKind.USER.name());
provisionTO.setObjectClass(ObjectClass.ACCOUNT_NAME);
resourceTO.getProvisions().add(provisionTO);
MappingTO mapping = new MappingTO();
provisionTO.setMapping(mapping);
ItemTO item = new ItemTO();
item.setIntAttrName("key");
item.setExtAttrName("userId");
item.setConnObjectKey(true);
mapping.setConnObjectKeyItem(item);
item = new ItemTO();
item.setExtAttrName("email");
// missing intAttrName ...
mapping.add(item);
try {
createResource(resourceTO);
fail("Create should not have worked");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.RequiredValuesMissing, e.getType());
assertEquals("intAttrName", e.getElements().iterator().next());
}
}
Aggregations