use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.
the class ExceptionMapperITCase method invalidRequests.
@Test
public void invalidRequests() {
try {
taskService.search(new TaskQuery.Builder(TaskType.NOTIFICATION).resource(RESOURCE_NAME_LDAP).build());
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.InvalidRequest, e.getType());
}
try {
taskService.search(new TaskQuery.Builder(TaskType.PULL).anyTypeKind(AnyTypeKind.ANY_OBJECT).build());
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.InvalidRequest, e.getType());
}
try {
taskService.search(new TaskQuery.Builder(TaskType.PULL).notification("e00945b5-1184-4d43-8e45-4318a8dcdfd4").build());
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.InvalidRequest, e.getType());
}
try {
anyTypeService.delete(AnyTypeKind.USER.name());
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.InvalidRequest, e.getType());
}
try {
clientFactory.create(ANONYMOUS_UNAME, ANONYMOUS_KEY).getService(AccessTokenService.class).login();
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.InvalidRequest, e.getType());
}
try {
ResourceTO ldap = resourceService.read(RESOURCE_NAME_LDAP);
ItemTO mapping = ldap.getProvisions().get(0).getMapping().getItems().get(0);
mapping.setIntAttrName("memberships.cn");
resourceService.update(ldap);
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.InvalidMapping, e.getType());
}
}
use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.
the class GroupITCase method selfRead.
@Test
public void selfRead() {
UserTO userTO = userService.read("1417acbe-cbf6-4277-9372-e75e04f97000");
assertNotNull(userTO);
assertTrue(userTO.getMembership("37d15e4c-cdc1-460b-a591-8505c8133806").isPresent());
assertFalse(userTO.getMembership("29f96485-729e-4d31-88a1-6fc60e4677f3").isPresent());
GroupService groupService2 = clientFactory.create("rossini", ADMIN_PWD).getService(GroupService.class);
try {
groupService2.read("29f96485-729e-4d31-88a1-6fc60e4677f3");
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.DelegatedAdministration, e.getType());
}
List<GroupTO> groups = groupService2.own();
assertNotNull(groups);
assertTrue(groups.stream().anyMatch(group -> "37d15e4c-cdc1-460b-a591-8505c8133806".equals(group.getKey())));
}
use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.
the class PullTaskITCase method issueSYNCOPE258.
@Test
public void issueSYNCOPE258() throws IOException {
// -----------------------------
// Add a custom correlation rule
// -----------------------------
ImplementationTO corrRule = null;
try {
corrRule = implementationService.read(ImplementationType.PULL_CORRELATION_RULE, "TestPullRule");
} catch (SyncopeClientException e) {
if (e.getType().getResponseStatus() == Response.Status.NOT_FOUND) {
corrRule = new ImplementationTO();
corrRule.setKey("TestPullRule");
corrRule.setEngine(ImplementationEngine.GROOVY);
corrRule.setType(ImplementationType.PULL_CORRELATION_RULE);
corrRule.setBody(IOUtils.toString(getClass().getResourceAsStream("/TestPullRule.groovy"), StandardCharsets.UTF_8));
Response response = implementationService.create(corrRule);
corrRule = implementationService.read(corrRule.getType(), response.getHeaderString(RESTHeaders.RESOURCE_KEY));
assertNotNull(corrRule);
}
}
assertNotNull(corrRule);
PullPolicyTO policyTO = policyService.read(PolicyType.PULL, "9454b0d7-2610-400a-be82-fc23cf553dd6");
policyTO.getCorrelationRules().put(AnyTypeKind.USER.name(), corrRule.getKey());
policyService.update(PolicyType.PULL, policyTO);
// -----------------------------
PullTaskTO task = new PullTaskTO();
task.setDestinationRealm(SyncopeConstants.ROOT_REALM);
task.setName("Test Pull Rule");
task.setActive(true);
task.setResource(RESOURCE_NAME_WS2);
task.setPullMode(PullMode.FULL_RECONCILIATION);
task.setPerformCreate(true);
task.setPerformDelete(true);
task.setPerformUpdate(true);
Response response = taskService.create(TaskType.PULL, task);
task = getObject(response.getLocation(), TaskService.class, PullTaskTO.class);
UserTO userTO = UserITCase.getUniqueSampleTO("s258_1@apache.org");
userTO.getResources().clear();
userTO.getResources().add(RESOURCE_NAME_WS2);
createUser(userTO);
userTO = UserITCase.getUniqueSampleTO("s258_2@apache.org");
userTO.getResources().clear();
userTO.getResources().add(RESOURCE_NAME_WS2);
userTO = createUser(userTO).getEntity();
// change email in order to unmatch the second user
UserPatch userPatch = new UserPatch();
userPatch.setKey(userTO.getKey());
userPatch.getPlainAttrs().add(attrAddReplacePatch("email", "s258@apache.org"));
userService.update(userPatch);
execProvisioningTask(taskService, TaskType.PULL, task.getKey(), 50, false);
PullTaskTO executed = taskService.read(TaskType.PULL, task.getKey(), true);
assertEquals(1, executed.getExecutions().size());
// asser for just one match
assertTrue(executed.getExecutions().get(0).getMessage().contains("[updated/failures]: 1/0"), executed.getExecutions().get(0).getMessage().substring(0, 55) + "...");
}
use of org.apache.syncope.common.lib.SyncopeClientException in project syncope by apache.
the class RealmITCase method createUpdate.
@Test
public void createUpdate() {
final RealmTO realm = new RealmTO();
realm.setName("last");
// 1. create
Response response = realmService.create("/even/two", realm);
RealmTO[] actuals = getObject(response.getLocation(), RealmService.class, RealmTO[].class);
assertNotNull(actuals);
assertTrue(actuals.length > 0);
RealmTO actual = actuals[0];
assertNotNull(actual.getKey());
assertEquals("last", actual.getName());
assertEquals("/even/two/last", actual.getFullPath());
assertEquals(actual.getParent(), getRealm("/even/two").get().getKey());
assertNull(realm.getAccountPolicy());
assertNull(realm.getPasswordPolicy());
// 2. update setting policies
actual.setAccountPolicy("06e2ed52-6966-44aa-a177-a0ca7434201f");
actual.setPasswordPolicy("986d1236-3ac5-4a19-810c-5ab21d79cba1");
realmService.update(actual);
actual = getRealm(actual.getFullPath()).get();
assertNotNull(actual.getAccountPolicy());
assertNotNull(actual.getPasswordPolicy());
// 3. update changing parent
actual.setParent(getRealm("/odd").get().getKey());
realmService.update(actual);
actual = getRealm("/odd/last").get();
assertNotNull(actual);
assertEquals("/odd/last", actual.getFullPath());
assertEquals(1, realmService.list().stream().filter(object -> realm.getName().equals(object.getName())).count());
// 4. create under invalid path
try {
realmService.create("a name", realm);
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.InvalidPath, e.getType());
}
// 5. attempt to create duplicate
try {
realmService.create("/odd", realm);
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 ReportITCase method executeAndExport.
@Test
public void executeAndExport() throws IOException {
ReportTO reportTO = reportService.read("0062ea9c-924d-4ecf-9961-4492a8cc6d1b");
reportTO.setKey(null);
reportTO.setName("executeAndExport" + getUUIDString());
reportTO.setActive(false);
reportTO.getExecutions().clear();
reportTO = createReport(reportTO);
assertNotNull(reportTO);
try {
execReport(reportTO.getKey());
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.Scheduling, e.getType());
assertTrue(e.getElements().iterator().next().contains("active"));
}
reportTO.setActive(true);
reportService.update(reportTO);
String execKey = execReport(reportTO.getKey());
checkExport(execKey, ReportExecExportFormat.XML);
checkExport(execKey, ReportExecExportFormat.HTML);
checkExport(execKey, ReportExecExportFormat.PDF);
checkExport(execKey, ReportExecExportFormat.RTF);
checkExport(execKey, ReportExecExportFormat.CSV);
}
Aggregations