http://git-wip-us.apache.org/repos/asf/syncope/blob/d30c8526/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/NotificationITCase.java ---------------------------------------------------------------------- diff --git a/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/NotificationITCase.java b/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/NotificationITCase.java new file mode 100644 index 0000000..03a557f --- /dev/null +++ b/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/NotificationITCase.java @@ -0,0 +1,172 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.fit.core.reference; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +import java.util.List; +import javax.ws.rs.core.Response; +import org.apache.syncope.client.lib.SyncopeClient; +import org.apache.syncope.common.lib.SyncopeClientException; +import org.apache.syncope.common.lib.to.NotificationTO; +import org.apache.syncope.common.lib.types.ClientExceptionType; +import org.apache.syncope.common.lib.types.IntMappingType; +import org.apache.syncope.common.lib.types.TraceLevel; +import org.apache.syncope.common.rest.api.service.NotificationService; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +@FixMethodOrder(MethodSorters.JVM) +public class NotificationITCase extends AbstractITCase { + + private NotificationTO buildNotificationTO() { + NotificationTO notificationTO = new NotificationTO(); + notificationTO.setTraceLevel(TraceLevel.SUMMARY); + notificationTO.getEvents().add("create"); + + notificationTO.setUserAbout(SyncopeClient.getUserSearchConditionBuilder(). + is("fullname").equalTo("*o*").and("fullname").equalTo("*i*").query()); + + notificationTO.setRecipientAttrName("email"); + notificationTO.setRecipientAttrType(IntMappingType.UserPlainSchema); + + notificationTO.setSender("[email protected]"); + notificationTO.setSubject("Test notification"); + notificationTO.setTemplate("test"); + return notificationTO; + } + + @Test + public void read() { + NotificationTO notificationTO = notificationService.read(10L); + assertNotNull(notificationTO); + } + + @Test + public void list() { + List<NotificationTO> notificationTOs = notificationService.list(); + assertNotNull(notificationTOs); + assertFalse(notificationTOs.isEmpty()); + for (NotificationTO instance : notificationTOs) { + assertNotNull(instance); + } + } + + @Test + public void create() { + NotificationTO notificationTO = buildNotificationTO(); + notificationTO.setRecipients(SyncopeClient.getUserSearchConditionBuilder().hasRoles(7L).query()); + + Response response = notificationService.create(notificationTO); + NotificationTO actual = getObject(response.getLocation(), NotificationService.class, + NotificationTO.class); + + assertNotNull(actual); + assertNotNull(actual.getKey()); + notificationTO.setKey(actual.getKey()); + assertEquals(actual, notificationTO); + } + + @Test + public void update() { + NotificationTO notificationTO = notificationService.read(10L); + notificationTO.setRecipients(SyncopeClient.getUserSearchConditionBuilder().hasRoles(7L).query()); + + notificationService.update(notificationTO.getKey(), notificationTO); + NotificationTO actual = notificationService.read(notificationTO.getKey()); + assertNotNull(actual); + assertEquals(actual, notificationTO); + } + + @Test + public void delete() { + NotificationTO notification = buildNotificationTO(); + notification.setSelfAsRecipient(true); + Response response = notificationService.create(notification); + notification = getObject(response.getLocation(), NotificationService.class, NotificationTO.class); + + notificationService.delete(notification.getKey()); + + try { + notificationService.read(notification.getKey()); + fail(); + } catch (SyncopeClientException e) { + assertEquals(ClientExceptionType.NotFound, e.getType()); + } + } + + @Test + public void issueSYNCOPE83() { + NotificationTO notificationTO = buildNotificationTO(); + notificationTO.setSelfAsRecipient(true); + + NotificationTO actual = null; + try { + Response response = notificationService.create(notificationTO); + actual = getObject(response.getLocation(), NotificationService.class, NotificationTO.class); + } catch (SyncopeClientException e) { + assertNotNull(e); + } + assertNotNull(actual); + assertNotNull(actual.getKey()); + notificationTO.setKey(actual.getKey()); + assertEquals(actual, notificationTO); + } + + @Test + public void issueSYNCOPE445() { + NotificationTO notificationTO = buildNotificationTO(); + notificationTO.getStaticRecipients().add("[email protected]"); + + NotificationTO actual = null; + try { + Response response = notificationService.create(notificationTO); + actual = getObject(response.getLocation(), NotificationService.class, NotificationTO.class); + } catch (SyncopeClientException e) { + assertNotNull(e); + } + assertNotNull(actual); + assertNotNull(actual.getKey()); + notificationTO.setKey(actual.getKey()); + assertEquals(actual, notificationTO); + } + + @Test + public void issueSYNCOPE446() { + NotificationTO notificationTO = buildNotificationTO(); + notificationTO.getStaticRecipients().add("[email protected]"); + notificationTO.setRoleAbout(SyncopeClient.getRoleSearchConditionBuilder().hasEntitlements("ROLE_READ").query()); + + NotificationTO actual = null; + try { + Response response = notificationService.create(notificationTO); + actual = getObject(response.getLocation(), NotificationService.class, NotificationTO.class); + } catch (SyncopeClientException e) { + assertNotNull(e); + } + assertNotNull(actual); + assertNotNull(actual.getKey()); + notificationTO.setKey(actual.getKey()); + assertEquals(actual, notificationTO); + } +}
http://git-wip-us.apache.org/repos/asf/syncope/blob/d30c8526/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/NotificationTaskITCase.java ---------------------------------------------------------------------- diff --git a/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/NotificationTaskITCase.java b/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/NotificationTaskITCase.java new file mode 100644 index 0000000..87a49fb --- /dev/null +++ b/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/NotificationTaskITCase.java @@ -0,0 +1,155 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.fit.core.reference; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import javax.ws.rs.core.Response; +import org.apache.syncope.client.lib.SyncopeClient; +import org.apache.syncope.common.lib.to.MembershipTO; +import org.apache.syncope.common.lib.to.NotificationTO; +import org.apache.syncope.common.lib.to.NotificationTaskTO; +import org.apache.syncope.common.lib.to.PagedResult; +import org.apache.syncope.common.lib.to.TaskExecTO; +import org.apache.syncope.common.lib.to.UserTO; +import org.apache.syncope.common.lib.types.IntMappingType; +import org.apache.syncope.common.lib.types.TaskType; +import org.apache.syncope.common.lib.types.TraceLevel; +import org.apache.syncope.common.rest.api.service.NotificationService; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +@FixMethodOrder(MethodSorters.JVM) +public class NotificationTaskITCase extends AbstractTaskITCase { + + @Test + public void issueSYNCOPE81() { + String sender = "[email protected]"; + createNotificationTask(sender); + NotificationTaskTO taskTO = findNotificationTaskBySender(sender); + assertNotNull(taskTO); + + assertTrue(taskTO.getExecutions().isEmpty()); + + // generate an execution in order to verify the deletion of a notification task with one or more executions + TaskExecTO execution = taskService.execute(taskTO.getKey(), false); + assertEquals("NOT_SENT", execution.getStatus()); + + int i = 0; + int maxit = 50; + int executions = 0; + + // wait for task exec completion (executions incremented) + do { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + } + + taskTO = taskService.read(taskTO.getKey()); + + assertNotNull(taskTO); + assertNotNull(taskTO.getExecutions()); + + i++; + } while (executions == taskTO.getExecutions().size() && i < maxit); + + assertFalse(taskTO.getExecutions().isEmpty()); + + taskService.delete(taskTO.getKey()); + } + + @Test + public void issueSYNCOPE86() { + // 1. create notification task + String sender = "[email protected]"; + createNotificationTask(sender); + + // 2. get NotificationTaskTO for user just created + NotificationTaskTO taskTO = findNotificationTaskBySender(sender); + assertNotNull(taskTO); + assertTrue(taskTO.getExecutions().isEmpty()); + + try { + // 3. execute the generated NotificationTask + TaskExecTO execution = taskService.execute(taskTO.getKey(), false); + assertNotNull(execution); + + // 4. verify + taskTO = taskService.read(taskTO.getKey()); + assertNotNull(taskTO); + assertEquals(1, taskTO.getExecutions().size()); + } finally { + // Remove execution to make test re-runnable + taskService.deleteExecution(taskTO.getExecutions().get(0).getKey()); + } + } + + private NotificationTaskTO findNotificationTaskBySender(final String sender) { + PagedResult<NotificationTaskTO> tasks = taskService.list(TaskType.NOTIFICATION); + assertNotNull(tasks); + assertFalse(tasks.getResult().isEmpty()); + NotificationTaskTO taskTO = null; + for (NotificationTaskTO task : tasks.getResult()) { + if (sender.equals(task.getSender())) { + taskTO = task; + } + } + return taskTO; + } + + private void createNotificationTask(final String sender) { + // 1. Create notification + NotificationTO notification = new NotificationTO(); + notification.setTraceLevel(TraceLevel.FAILURES); + notification.getEvents().add("[REST]:[UserLogic]:[]:[create]:[SUCCESS]"); + + notification.setUserAbout(SyncopeClient.getUserSearchConditionBuilder().hasRoles(7L).query()); + + notification.setRecipients(SyncopeClient.getUserSearchConditionBuilder().hasRoles(8L).query()); + notification.setSelfAsRecipient(true); + + notification.setRecipientAttrName("email"); + notification.setRecipientAttrType(IntMappingType.UserPlainSchema); + + notification.setSender(sender); + String subject = "Test notification"; + notification.setSubject(subject); + notification.setTemplate("optin"); + notification.setActive(true); + + Response response = notificationService.create(notification); + notification = getObject(response.getLocation(), NotificationService.class, NotificationTO.class); + assertNotNull(notification); + + // 2. create user + UserTO userTO = UserITCase.getUniqueSampleTO("[email protected]"); + MembershipTO membershipTO = new MembershipTO(); + membershipTO.setRoleId(7); + userTO.getMemberships().add(membershipTO); + + userTO = createUser(userTO); + assertNotNull(userTO); + } + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/d30c8526/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/PlainSchemaITCase.java ---------------------------------------------------------------------- diff --git a/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/PlainSchemaITCase.java b/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/PlainSchemaITCase.java new file mode 100644 index 0000000..b9d8239 --- /dev/null +++ b/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/PlainSchemaITCase.java @@ -0,0 +1,317 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.fit.core.reference; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.security.AccessControlException; +import java.util.List; +import javax.ws.rs.core.Response; +import org.apache.commons.lang3.SerializationUtils; +import org.apache.syncope.common.lib.AttributableOperations; +import org.apache.syncope.common.lib.SyncopeClientException; +import org.apache.syncope.common.lib.mod.UserMod; +import org.apache.syncope.common.lib.to.MembershipTO; +import org.apache.syncope.common.lib.to.PlainSchemaTO; +import org.apache.syncope.common.lib.to.UserTO; +import org.apache.syncope.common.lib.types.AttrSchemaType; +import org.apache.syncope.common.lib.types.AttributableType; +import org.apache.syncope.common.lib.types.CipherAlgorithm; +import org.apache.syncope.common.lib.types.ClientExceptionType; +import org.apache.syncope.common.lib.types.EntityViolationType; +import org.apache.syncope.common.lib.types.SchemaType; +import org.apache.syncope.common.rest.api.service.SchemaService; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +@FixMethodOrder(MethodSorters.JVM) +public class PlainSchemaITCase extends AbstractITCase { + + private PlainSchemaTO buildPlainSchemaTO(final String name, final AttrSchemaType type) { + PlainSchemaTO schemaTO = new PlainSchemaTO(); + schemaTO.setKey(name + getUUIDString()); + schemaTO.setType(type); + return schemaTO; + } + + @Test + public void create() { + PlainSchemaTO schemaTO = buildPlainSchemaTO("testAttribute", AttrSchemaType.String); + schemaTO.setMandatoryCondition("false"); + + PlainSchemaTO newPlainSchemaTO = createSchema(AttributableType.USER, SchemaType.PLAIN, schemaTO); + assertEquals(schemaTO, newPlainSchemaTO); + + newPlainSchemaTO = createSchema(AttributableType.MEMBERSHIP, SchemaType.PLAIN, schemaTO); + assertEquals(schemaTO, newPlainSchemaTO); + } + + @Test + public void createWithNotPermittedName() { + PlainSchemaTO schemaTO = new PlainSchemaTO(); + schemaTO.setKey("failedLogins"); + schemaTO.setType(AttrSchemaType.String); + + try { + createSchema(AttributableType.USER, SchemaType.PLAIN, schemaTO); + fail("This should not be reacheable"); + } catch (SyncopeClientException e) { + assertEquals(ClientExceptionType.InvalidPlainSchema, e.getType()); + + assertTrue(e.getElements().iterator().next().toString(). + contains(EntityViolationType.InvalidName.name())); + } + } + + @Test + public void createREnumWithoutEnumeration() { + PlainSchemaTO schemaTO = new PlainSchemaTO(); + schemaTO.setKey("enumcheck"); + schemaTO.setType(AttrSchemaType.Enum); + + try { + createSchema(AttributableType.ROLE, SchemaType.PLAIN, schemaTO); + fail("This should not be reacheable"); + } catch (SyncopeClientException e) { + assertEquals(ClientExceptionType.InvalidPlainSchema, e.getType()); + + assertTrue(e.getElements().iterator().next().toString(). + contains(EntityViolationType.InvalidSchemaEnum.name())); + } + } + + @Test + public void createUEnumWithoutEnumeration() { + PlainSchemaTO schemaTO = new PlainSchemaTO(); + schemaTO.setKey("enumcheck"); + schemaTO.setType(AttrSchemaType.Enum); + + try { + createSchema(AttributableType.USER, SchemaType.PLAIN, schemaTO); + fail("This should not be reacheable"); + } catch (SyncopeClientException e) { + assertEquals(ClientExceptionType.InvalidPlainSchema, e.getType()); + + assertTrue(e.getElements().iterator().next().contains(EntityViolationType.InvalidSchemaEnum.name())); + } + } + + @Test + public void createEncrypted() { + PlainSchemaTO schemaTO = new PlainSchemaTO(); + schemaTO.setKey("encrypted"); + schemaTO.setType(AttrSchemaType.Encrypted); + schemaTO.setCipherAlgorithm(CipherAlgorithm.AES); + schemaTO.setSecretKey("huhadfhsjfsfsdkj!####"); + + createSchema(AttributableType.MEMBERSHIP, SchemaType.PLAIN, schemaTO); + } + + @Test + public void createBinary() { + PlainSchemaTO schemaTO = new PlainSchemaTO(); + schemaTO.setKey("x509certificate"); + schemaTO.setType(AttrSchemaType.Binary); + schemaTO.setMimeType("application/x-x509-ca-cert"); + + createSchema(AttributableType.ROLE, SchemaType.PLAIN, schemaTO); + } + + @Test + public void delete() { + PlainSchemaTO schemaTO = buildPlainSchemaTO("todelete", AttrSchemaType.String); + schemaTO.setMandatoryCondition("false"); + createSchema(AttributableType.USER, SchemaType.PLAIN, schemaTO); + + schemaService.delete(AttributableType.USER, SchemaType.PLAIN, schemaTO.getKey()); + PlainSchemaTO firstname = null; + try { + firstname = schemaService.read(AttributableType.USER, SchemaType.PLAIN, schemaTO.getKey()); + } catch (SyncopeClientException e) { + assertEquals(Response.Status.NOT_FOUND, e.getType().getResponseStatus()); + } + assertNull(firstname); + } + + @Test + public void list() { + List<PlainSchemaTO> userSchemas = schemaService.list(AttributableType.USER, SchemaType.PLAIN); + assertFalse(userSchemas.isEmpty()); + for (PlainSchemaTO schemaTO : userSchemas) { + assertNotNull(schemaTO); + } + + List<PlainSchemaTO> roleSchemas = schemaService.list(AttributableType.ROLE, SchemaType.PLAIN); + assertFalse(roleSchemas.isEmpty()); + for (PlainSchemaTO schemaTO : roleSchemas) { + assertNotNull(schemaTO); + } + + List<PlainSchemaTO> membershipSchemas = schemaService.list(AttributableType.MEMBERSHIP, SchemaType.PLAIN); + assertFalse(membershipSchemas.isEmpty()); + for (PlainSchemaTO schemaTO : membershipSchemas) { + assertNotNull(schemaTO); + } + } + + @Test + public void update() { + PlainSchemaTO schemaTO = schemaService.read(AttributableType.ROLE, SchemaType.PLAIN, "icon"); + assertNotNull(schemaTO); + + schemaService.update(AttributableType.ROLE, SchemaType.PLAIN, schemaTO.getKey(), schemaTO); + PlainSchemaTO updatedTO = schemaService.read(AttributableType.ROLE, SchemaType.PLAIN, "icon"); + assertEquals(schemaTO, updatedTO); + + updatedTO.setType(AttrSchemaType.Date); + try { + schemaService.update(AttributableType.ROLE, SchemaType.PLAIN, schemaTO.getKey(), updatedTO); + fail("This should not be reacheable"); + } catch (SyncopeClientException e) { + assertEquals(ClientExceptionType.InvalidPlainSchema, e.getType()); + } + } + + @Test + public void issue258() { + PlainSchemaTO schemaTO = new PlainSchemaTO(); + schemaTO.setKey("schema_issue258"); + schemaTO.setType(AttrSchemaType.Double); + + schemaTO = createSchema(AttributableType.USER, SchemaType.PLAIN, schemaTO); + assertNotNull(schemaTO); + + UserTO userTO = UserITCase.getUniqueSampleTO("[email protected]"); + userTO.getPlainAttrs().add(attrTO(schemaTO.getKey(), "1.2")); + + userTO = createUser(userTO); + assertNotNull(userTO); + + schemaTO.setType(AttrSchemaType.Long); + try { + schemaService.update(AttributableType.USER, SchemaType.PLAIN, schemaTO.getKey(), schemaTO); + fail("This should not be reacheable"); + } catch (SyncopeClientException e) { + assertEquals(ClientExceptionType.InvalidPlainSchema, e.getType()); + } + } + + @Test + public void issue259() { + PlainSchemaTO schemaTO = buildPlainSchemaTO("schema_issue259", AttrSchemaType.Double); + schemaTO.setUniqueConstraint(true); + + schemaTO = createSchema(AttributableType.USER, SchemaType.PLAIN, schemaTO); + assertNotNull(schemaTO); + + UserTO userTO = UserITCase.getUniqueSampleTO("[email protected]"); + userTO.getPlainAttrs().add(attrTO(schemaTO.getKey(), "1")); + userTO = createUser(userTO); + assertNotNull(userTO); + + UserTO newUserTO = SerializationUtils.clone(userTO); + MembershipTO membership = new MembershipTO(); + membership.setRoleId(2L); + newUserTO.getMemberships().add(membership); + + UserMod userMod = AttributableOperations.diff(newUserTO, userTO); + + userTO = userService.update(userMod.getKey(), userMod).readEntity(UserTO.class); + assertNotNull(userTO); + } + + @Test + public void issue260() { + PlainSchemaTO schemaTO = buildPlainSchemaTO("schema_issue260", AttrSchemaType.Double); + schemaTO.setUniqueConstraint(true); + + schemaTO = createSchema(AttributableType.USER, SchemaType.PLAIN, schemaTO); + assertNotNull(schemaTO); + + UserTO userTO = UserITCase.getUniqueSampleTO("[email protected]"); + userTO.getPlainAttrs().add(attrTO(schemaTO.getKey(), "1.2")); + userTO = createUser(userTO); + assertNotNull(userTO); + + schemaTO.setUniqueConstraint(false); + try { + schemaService.update(AttributableType.USER, SchemaType.PLAIN, schemaTO.getKey(), schemaTO); + fail("This should not be reacheable"); + } catch (SyncopeClientException e) { + assertEquals(ClientExceptionType.InvalidPlainSchema, e.getType()); + } + } + + @Test + public void issueSYNCOPE323() { + PlainSchemaTO actual = schemaService.read(AttributableType.ROLE, SchemaType.PLAIN, "icon"); + assertNotNull(actual); + + try { + createSchema(AttributableType.ROLE, SchemaType.PLAIN, actual); + fail(); + } catch (SyncopeClientException e) { + assertEquals(Response.Status.CONFLICT, e.getType().getResponseStatus()); + assertEquals(ClientExceptionType.EntityExists, e.getType()); + } + + actual.setKey(null); + try { + createSchema(AttributableType.ROLE, SchemaType.PLAIN, actual); + fail(); + } catch (SyncopeClientException e) { + assertEquals(Response.Status.BAD_REQUEST, e.getType().getResponseStatus()); + assertEquals(ClientExceptionType.RequiredValuesMissing, e.getType()); + } + } + + @Test + public void issueSYNCOPE418() { + PlainSchemaTO schema = buildPlainSchemaTO("http://schemas.examples.org/security/authorization/organizationUnit", + AttrSchemaType.Double); + + try { + createSchema(AttributableType.ROLE, SchemaType.PLAIN, schema); + fail(); + } catch (SyncopeClientException e) { + assertEquals(ClientExceptionType.InvalidPlainSchema, e.getType()); + assertTrue(e.getElements().iterator().next().contains(EntityViolationType.InvalidName.name())); + } + } + + @Test + public void anonymous() { + SchemaService unauthenticated = clientFactory.createAnonymous().getService(SchemaService.class); + try { + unauthenticated.list(AttributableType.USER, SchemaType.VIRTUAL); + fail(); + } catch (AccessControlException e) { + assertNotNull(e); + } + + SchemaService anonymous = clientFactory.create(ANONYMOUS_UNAME, ANONYMOUS_KEY).getService(SchemaService.class); + assertFalse(anonymous.list(AttributableType.USER, SchemaType.VIRTUAL).isEmpty()); + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/d30c8526/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/PolicyITCase.java ---------------------------------------------------------------------- diff --git a/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/PolicyITCase.java b/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/PolicyITCase.java new file mode 100644 index 0000000..409f29d --- /dev/null +++ b/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/PolicyITCase.java @@ -0,0 +1,238 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.fit.core.reference; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.Arrays; +import java.util.List; +import org.apache.syncope.common.lib.SyncopeClientException; +import org.apache.syncope.common.lib.to.AccountPolicyTO; +import org.apache.syncope.common.lib.to.PasswordPolicyTO; +import org.apache.syncope.common.lib.to.SyncPolicyTO; +import org.apache.syncope.common.lib.types.AccountPolicySpec; +import org.apache.syncope.common.lib.types.ClientExceptionType; +import org.apache.syncope.common.lib.types.PasswordPolicySpec; +import org.apache.syncope.common.lib.types.PolicyType; +import org.apache.syncope.common.lib.types.SyncPolicySpec; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +@FixMethodOrder(MethodSorters.JVM) +public class PolicyITCase extends AbstractITCase { + + private SyncPolicyTO buildSyncPolicyTO() { + SyncPolicyTO policy = new SyncPolicyTO(); + + SyncPolicySpec spec = new SyncPolicySpec(); + spec.setUserJavaRule(TestSyncRule.class.getName()); + + policy.setSpecification(spec); + policy.setDescription("Sync policy"); + + return policy; + } + + @Test + public void listByType() { + List<SyncPolicyTO> policyTOs = policyService.list(PolicyType.SYNC); + + assertNotNull(policyTOs); + assertFalse(policyTOs.isEmpty()); + } + + @Test + public void getAccountPolicy() { + AccountPolicyTO policyTO = policyService.read(6L); + + assertNotNull(policyTO); + assertTrue(policyTO.getUsedByResources().isEmpty()); + assertEquals(Arrays.asList(6L, 7L, 10L, 14L), policyTO.getUsedByRoles()); + } + + @Test + public void getPasswordPolicy() { + PasswordPolicyTO policyTO = policyService.read(4L); + + assertNotNull(policyTO); + assertTrue(policyTO.getUsedByResources().contains(RESOURCE_NAME_NOPROPAGATION)); + assertEquals(Arrays.asList(6L, 7L, 10L, 8L), policyTO.getUsedByRoles()); + } + + @Test + public void getSyncPolicy() { + SyncPolicyTO policyTO = policyService.read(1L); + + assertNotNull(policyTO); + assertTrue(policyTO.getUsedByRoles().isEmpty()); + } + + @Test + public void getGlobalAccountPolicy() { + AccountPolicyTO policyTO = policyService.readGlobal(PolicyType.ACCOUNT); + + assertNotNull(policyTO); + assertEquals(PolicyType.GLOBAL_ACCOUNT, policyTO.getType()); + } + + @Test + public void getGlobalPasswordPolicy() { + PasswordPolicyTO policyTO = policyService.readGlobal(PolicyType.PASSWORD); + + assertNotNull(policyTO); + assertEquals(PolicyType.GLOBAL_PASSWORD, policyTO.getType()); + assertEquals(8, policyTO.getSpecification().getMinLength()); + assertFalse(policyTO.getUsedByResources().contains(RESOURCE_NAME_NOPROPAGATION)); + } + + @Test + public void getGlobalSyncPolicy() { + SyncPolicyTO policyTO = policyService.readGlobal(PolicyType.SYNC); + + assertNotNull(policyTO); + assertEquals(PolicyType.GLOBAL_SYNC, policyTO.getType()); + assertFalse(policyTO.getUsedByResources().contains(RESOURCE_NAME_CSV)); + assertFalse(policyTO.getUsedByResources().contains(RESOURCE_NAME_WS2)); + assertTrue(policyTO.getUsedByRoles().isEmpty()); + } + + @Test + public void createWithException() { + PasswordPolicyTO policy = new PasswordPolicyTO(true); + policy.setSpecification(new PasswordPolicySpec()); + policy.setDescription("global password policy"); + + try { + createPolicy(policy); + fail(); + } catch (SyncopeClientException e) { + assertEquals(ClientExceptionType.InvalidPolicy, e.getType()); + } + } + + @Test + public void createMissingDescription() { + SyncPolicyTO policy = new SyncPolicyTO(); + policy.setSpecification(new SyncPolicySpec()); + + try { + createPolicy(policy); + fail(); + } catch (SyncopeClientException e) { + assertEquals(ClientExceptionType.InvalidPolicy, e.getType()); + } + } + + @Test + public void create() { + SyncPolicyTO policy = buildSyncPolicyTO(); + + SyncPolicyTO policyTO = createPolicy(policy); + + assertNotNull(policyTO); + assertEquals(PolicyType.SYNC, policyTO.getType()); + assertEquals(TestSyncRule.class.getName(), policyTO.getSpecification().getUserJavaRule()); + } + + @Test + public void update() { + // get global password + PasswordPolicyTO globalPolicy = policyService.read(2L); + + PasswordPolicyTO policy = new PasswordPolicyTO(); + policy.setDescription("A simple password policy"); + policy.setSpecification(globalPolicy.getSpecification()); + + // create a new password policy using global password as a template + policy = createPolicy(policy); + + // read new password policy + policy = policyService.read(policy.getKey()); + + assertNotNull("find to update did not work", policy); + + PasswordPolicySpec policySpec = policy.getSpecification(); + policySpec.setMaxLength(22); + policy.setSpecification(policySpec); + + // update new password policy + policyService.update(policy.getKey(), policy); + policy = policyService.read(policy.getKey()); + + assertNotNull(policy); + assertEquals(PolicyType.PASSWORD, policy.getType()); + assertEquals(22, policy.getSpecification().getMaxLength()); + assertEquals(8, policy.getSpecification().getMinLength()); + } + + @Test + public void delete() { + SyncPolicyTO policy = buildSyncPolicyTO(); + + SyncPolicyTO policyTO = createPolicy(policy); + assertNotNull(policyTO); + + policyService.delete(policyTO.getKey()); + + try { + policyService.read(policyTO.getKey()); + fail(); + } catch (SyncopeClientException e) { + assertNotNull(e); + } + } + + @Test + public void getCorrelationRules() { + assertEquals(1, syncopeService.info().getSyncCorrelationRules().size()); + } + + @Test + public void issueSYNCOPE466() { + PasswordPolicyTO policy = policyService.read(4L); + assertEquals(PolicyType.PASSWORD, policy.getType()); + + policy.setType(PolicyType.GLOBAL_PASSWORD); + try { + policyService.update(policy.getKey(), policy); + fail(); + } catch (SyncopeClientException e) { + assertEquals(ClientExceptionType.InvalidPolicy, e.getType()); + } + } + + @Test + public void issueSYNCOPE553() { + AccountPolicyTO policy = new AccountPolicyTO(false); + policy.setDescription("SYNCOPE553"); + + final AccountPolicySpec accountPolicySpec = new AccountPolicySpec(); + accountPolicySpec.setMinLength(3); + accountPolicySpec.setMaxLength(8); + policy.setSpecification(accountPolicySpec); + + policy = createPolicy(policy); + assertNotNull(policy); + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/d30c8526/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/PropagationTaskITCase.java ---------------------------------------------------------------------- diff --git a/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/PropagationTaskITCase.java b/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/PropagationTaskITCase.java new file mode 100644 index 0000000..a4598b2 --- /dev/null +++ b/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/PropagationTaskITCase.java @@ -0,0 +1,150 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.fit.core.reference; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.List; +import javax.ws.rs.core.Response; +import org.apache.syncope.common.lib.SyncopeClientException; +import org.apache.syncope.common.lib.to.AbstractTaskTO; +import org.apache.syncope.common.lib.to.BulkAction; +import org.apache.syncope.common.lib.to.PagedResult; +import org.apache.syncope.common.lib.to.PropagationTaskTO; +import org.apache.syncope.common.lib.to.ReportExecTO; +import org.apache.syncope.common.lib.to.TaskExecTO; +import org.apache.syncope.common.lib.to.UserTO; +import org.apache.syncope.common.lib.types.PropagationTaskExecStatus; +import org.apache.syncope.common.lib.types.TaskType; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +@FixMethodOrder(MethodSorters.JVM) +public class PropagationTaskITCase extends AbstractTaskITCase { + + @Test + public void paginatedList() { + PagedResult<PropagationTaskTO> tasks = taskService.list(TaskType.PROPAGATION, 1, 2); + + assertNotNull(tasks); + assertFalse(tasks.getResult().isEmpty()); + assertEquals(2, tasks.getResult().size()); + + for (AbstractTaskTO task : tasks.getResult()) { + assertNotNull(task); + } + + tasks = taskService.list(TaskType.PROPAGATION, 2, 2); + + assertNotNull(tasks); + assertFalse(tasks.getResult().isEmpty()); + + for (AbstractTaskTO task : tasks.getResult()) { + assertNotNull(task); + } + + tasks = taskService.list(TaskType.PROPAGATION, 1000, 2); + + assertNotNull(tasks); + assertTrue(tasks.getResult().isEmpty()); + } + + @Test + public void read() { + final PropagationTaskTO taskTO = taskService.read(3L); + assertNotNull(taskTO); + assertNotNull(taskTO.getExecutions()); + assertTrue(taskTO.getExecutions().isEmpty()); + } + + @Test + public void readExecution() { + TaskExecTO taskTO = taskService.readExecution(6L); + assertNotNull(taskTO); + } + + @Test + public void deal() { + // Currently test is not re-runnable. + // To successfully run test second time it is necessary to restart cargo + try { + taskService.delete(0L); + } catch (SyncopeClientException e) { + assertEquals(Response.Status.NOT_FOUND, e.getType().getResponseStatus()); + } + TaskExecTO exec = taskService.execute(1L, false); + assertEquals(PropagationTaskExecStatus.SUBMITTED.name(), exec.getStatus()); + + ReportExecTO report = new ReportExecTO(); + report.setStatus(PropagationTaskExecStatus.SUCCESS.name()); + report.setMessage("OK"); + taskService.report(exec.getKey(), report); + exec = taskService.readExecution(exec.getKey()); + assertEquals(PropagationTaskExecStatus.SUCCESS.name(), exec.getStatus()); + assertEquals("OK", exec.getMessage()); + + taskService.delete(1L); + try { + taskService.readExecution(exec.getKey()); + } catch (SyncopeClientException e) { + assertEquals(Response.Status.NOT_FOUND, e.getType().getResponseStatus()); + } + } + + @Test + public void issue196() { + TaskExecTO exec = taskService.execute(6L, false); + assertNotNull(exec); + assertEquals(0, exec.getKey()); + assertNotNull(exec.getTask()); + } + + @Test + public void bulkAction() { + final PagedResult<PropagationTaskTO> before = taskService.list(TaskType.PROPAGATION); + + // create user with testdb resource + final UserTO userTO = UserITCase.getUniqueSampleTO("[email protected]"); + userTO.getResources().add(RESOURCE_NAME_TESTDB); + createUser(userTO); + + final List<PropagationTaskTO> after = new ArrayList<>( + taskService.<PropagationTaskTO>list(TaskType.PROPAGATION).getResult()); + + after.removeAll(before.getResult()); + + assertFalse(after.isEmpty()); + + final BulkAction bulkAction = new BulkAction(); + bulkAction.setOperation(BulkAction.Type.DELETE); + + for (AbstractTaskTO taskTO : after) { + bulkAction.getTargets().add(String.valueOf(taskTO.getKey())); + } + + taskService.bulk(bulkAction); + + assertFalse(taskService.list(TaskType.PROPAGATION).getResult().containsAll(after)); + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/d30c8526/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/PushTaskITCase.java ---------------------------------------------------------------------- diff --git a/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/PushTaskITCase.java b/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/PushTaskITCase.java new file mode 100644 index 0000000..d7d354f --- /dev/null +++ b/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/PushTaskITCase.java @@ -0,0 +1,353 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.fit.core.reference; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import javax.ws.rs.core.Response; +import org.apache.syncope.client.lib.SyncopeClient; +import org.apache.syncope.common.lib.to.AbstractTaskTO; +import org.apache.syncope.common.lib.to.MappingItemTO; +import org.apache.syncope.common.lib.to.MappingTO; +import org.apache.syncope.common.lib.to.PagedResult; +import org.apache.syncope.common.lib.to.PlainSchemaTO; +import org.apache.syncope.common.lib.to.PushTaskTO; +import org.apache.syncope.common.lib.to.ResourceTO; +import org.apache.syncope.common.lib.to.RoleTO; +import org.apache.syncope.common.lib.to.TaskExecTO; +import org.apache.syncope.common.lib.types.AttrSchemaType; +import org.apache.syncope.common.lib.types.AttributableType; +import org.apache.syncope.common.lib.types.IntMappingType; +import org.apache.syncope.common.lib.types.MappingPurpose; +import org.apache.syncope.common.lib.types.MatchingRule; +import org.apache.syncope.common.lib.types.PropagationTaskExecStatus; +import org.apache.syncope.common.lib.types.SchemaType; +import org.apache.syncope.common.lib.types.SubjectType; +import org.apache.syncope.common.lib.types.TaskType; +import org.apache.syncope.common.lib.types.UnmatchingRule; +import org.apache.syncope.common.rest.api.service.ResourceService; +import org.apache.syncope.common.rest.api.service.TaskService; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; +import org.springframework.jdbc.core.JdbcTemplate; + +@FixMethodOrder(MethodSorters.JVM) +public class PushTaskITCase extends AbstractTaskITCase { + + @Test + public void getPushActionsClasses() { + List<String> actions = syncopeService.info().getPushActions(); + assertNotNull(actions); + } + + @Test + public void read() { + PushTaskTO pushTaskTO = taskService.<PushTaskTO>read(17L); + assertEquals(UnmatchingRule.ASSIGN, pushTaskTO.getUnmatchingRule()); + assertEquals(MatchingRule.UPDATE, pushTaskTO.getMatchingRule()); + } + + @Test + public void list() { + final PagedResult<PushTaskTO> tasks = taskService.list(TaskType.PUSH); + assertFalse(tasks.getResult().isEmpty()); + for (AbstractTaskTO task : tasks.getResult()) { + if (!(task instanceof PushTaskTO)) { + fail(); + } + } + } + + @Test + public void createPushTask() { + PushTaskTO task = new PushTaskTO(); + task.setName("Test create Push"); + task.setResource(RESOURCE_NAME_WS2); + task.setUserFilter( + SyncopeClient.getUserSearchConditionBuilder().hasNotResources(RESOURCE_NAME_TESTDB2).query()); + task.setRoleFilter( + SyncopeClient.getRoleSearchConditionBuilder().isNotNull("cool").query()); + task.setMatchingRule(MatchingRule.LINK); + + final Response response = taskService.create(task); + final PushTaskTO actual = getObject(response.getLocation(), TaskService.class, PushTaskTO.class); + assertNotNull(actual); + + task = taskService.read(actual.getKey()); + assertNotNull(task); + assertEquals(task.getKey(), actual.getKey()); + assertEquals(task.getJobClassName(), actual.getJobClassName()); + assertEquals(task.getUserFilter(), actual.getUserFilter()); + assertEquals(task.getRoleFilter(), actual.getRoleFilter()); + assertEquals(UnmatchingRule.ASSIGN, actual.getUnmatchingRule()); + assertEquals(MatchingRule.LINK, actual.getMatchingRule()); + } + + @Test + public void pushMatchingUnmatchingRoles() { + assertFalse(roleService.read(3L).getResources().contains(RESOURCE_NAME_LDAP)); + + execSyncTask(23L, 50, false); + + assertNotNull(resourceService.getConnectorObject(RESOURCE_NAME_LDAP, SubjectType.ROLE, 3L)); + assertTrue(roleService.read(3L).getResources().contains(RESOURCE_NAME_LDAP)); + + execSyncTask(23L, 50, false); + + assertNotNull(resourceService.getConnectorObject(RESOURCE_NAME_LDAP, SubjectType.ROLE, 3L)); + assertFalse(roleService.read(3L).getResources().contains(RESOURCE_NAME_LDAP)); + } + + @Test + public void pushUnmatchingUsers() throws Exception { + assertFalse(userService.read(2L).getResources().contains(RESOURCE_NAME_TESTDB2)); + assertFalse(userService.read(3L).getResources().contains(RESOURCE_NAME_TESTDB2)); + assertFalse(userService.read(4L).getResources().contains(RESOURCE_NAME_TESTDB2)); + assertTrue(userService.read(5L).getResources().contains(RESOURCE_NAME_TESTDB2)); + + final JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource); + assertEquals(0, jdbcTemplate.queryForList("SELECT ID FROM test2 WHERE ID='puccini'").size()); + + // ------------------------------------------ + // Unmatching --> Assign --> dryRuyn + // ------------------------------------------ + execSyncTask(13L, 50, true); + assertEquals(0, jdbcTemplate.queryForList("SELECT ID FROM test2 WHERE ID='vivaldi'").size()); + assertFalse(userService.read(3L).getResources().contains(RESOURCE_NAME_TESTDB2)); + // ------------------------------------------ + + final Set<Long> pushTaskIds = new HashSet<>(); + pushTaskIds.add(13L); + pushTaskIds.add(14L); + pushTaskIds.add(15L); + pushTaskIds.add(16L); + execSyncTasks(pushTaskIds, 50, false); + + // ------------------------------------------ + // Unatching --> Ignore + // ------------------------------------------ + assertEquals(1, jdbcTemplate.queryForList("SELECT ID FROM test2 WHERE ID='verdi'").size()); + assertFalse(userService.read(2L).getResources().contains(RESOURCE_NAME_TESTDB2)); + // ------------------------------------------ + + // ------------------------------------------ + // Unmatching --> Assign + // ------------------------------------------ + assertEquals(1, jdbcTemplate.queryForList("SELECT ID FROM test2 WHERE ID='vivaldi'").size()); + assertTrue(userService.read(3L).getResources().contains(RESOURCE_NAME_TESTDB2)); + jdbcTemplate.execute("DELETE FROM test2 WHERE ID='vivaldi'"); + // ------------------------------------------ + + // ------------------------------------------ + // Unmatching --> Provision + // ------------------------------------------ + assertEquals(1, jdbcTemplate.queryForList("SELECT ID FROM test2 WHERE ID='bellini'").size()); + assertFalse(userService.read(4L).getResources().contains(RESOURCE_NAME_TESTDB2)); + jdbcTemplate.execute("DELETE FROM test2 WHERE ID='bellini'"); + // ------------------------------------------ + + // ------------------------------------------ + // Unmatching --> Unlink + // ------------------------------------------ + assertEquals(0, jdbcTemplate.queryForList("SELECT ID FROM test2 WHERE ID='puccini'").size()); + assertFalse(userService.read(5L).getResources().contains(RESOURCE_NAME_TESTDB2)); + // ------------------------------------------ + } + + @Test + public void pushMatchingUser() throws Exception { + assertTrue(userService.read(1L).getResources().contains(RESOURCE_NAME_TESTDB2)); + assertFalse(userService.read(2L).getResources().contains(RESOURCE_NAME_TESTDB2)); + + final JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource); + assertEquals(1, jdbcTemplate.queryForList("SELECT ID FROM test2 WHERE ID='verdi'").size()); + assertEquals(1, jdbcTemplate.queryForList("SELECT ID FROM test2 WHERE ID='rossini'").size()); + + // ------------------------------------------ + // Matching --> Deprovision --> dryRuyn + // ------------------------------------------ + execSyncTask(19L, 50, true); + assertTrue(userService.read(1L).getResources().contains(RESOURCE_NAME_TESTDB2)); + assertEquals(1, jdbcTemplate.queryForList("SELECT ID FROM test2 WHERE ID='rossini'").size()); + // ------------------------------------------ + + final Set<Long> pushTaskIds = new HashSet<>(); + pushTaskIds.add(18L); + pushTaskIds.add(19L); + pushTaskIds.add(16L); + + execSyncTasks(pushTaskIds, 50, false); + + // ------------------------------------------ + // Matching --> Deprovision && Ignore + // ------------------------------------------ + assertFalse(userService.read(2L).getResources().contains(RESOURCE_NAME_TESTDB2)); + // DELETE Capability not available .... + assertEquals(1, jdbcTemplate.queryForList("SELECT ID FROM test2 WHERE ID='verdi'").size()); + // ------------------------------------------ + + // ------------------------------------------ + // Matching --> Unassign + // ------------------------------------------ + assertFalse(userService.read(1L).getResources().contains(RESOURCE_NAME_TESTDB2)); + // DELETE Capability not available .... + assertEquals(1, jdbcTemplate.queryForList("SELECT ID FROM test2 WHERE ID='rossini'").size()); + // ------------------------------------------ + + // ------------------------------------------ + // Matching --> Link + // ------------------------------------------ + execSyncTask(20L, 50, false); + assertTrue(userService.read(2L).getResources().contains(RESOURCE_NAME_TESTDB2)); + assertEquals(1, jdbcTemplate.queryForList("SELECT ID FROM test2 WHERE ID='verdi'").size()); + // ------------------------------------------ + + pushTaskIds.clear(); + pushTaskIds.add(21L); + pushTaskIds.add(22L); + + execSyncTasks(pushTaskIds, 50, false); + + // ------------------------------------------ + // Matching --> Unlink && Update + // ------------------------------------------ + assertFalse(userService.read(2L).getResources().contains(RESOURCE_NAME_TESTDB2)); + assertEquals(1, jdbcTemplate.queryForList("SELECT ID FROM test2 WHERE ID='verdi'").size()); + // ------------------------------------------ + } + + @Test + public void issueSYNCOPE598() { + // create a new role schema + final PlainSchemaTO schemaTO = new PlainSchemaTO(); + schemaTO.setKey("LDAPGroupName" + getUUIDString()); + schemaTO.setType(AttrSchemaType.String); + schemaTO.setMandatoryCondition("true"); + + final PlainSchemaTO newPlainSchemaTO = createSchema(AttributableType.ROLE, SchemaType.PLAIN, schemaTO); + assertEquals(schemaTO, newPlainSchemaTO); + + // create a new sample role + RoleTO roleTO = new RoleTO(); + roleTO.setName("all" + getUUIDString()); + roleTO.setParent(8L); + + roleTO.getRPlainAttrTemplates().add(newPlainSchemaTO.getKey()); + roleTO.getPlainAttrs().add(attrTO(newPlainSchemaTO.getKey(), "all")); + + roleTO = createRole(roleTO); + assertNotNull(roleTO); + + String resourceName = "resource-ldap-roleonly"; + ResourceTO newResourceTO = null; + + try { + // Create resource ad-hoc + ResourceTO resourceTO = new ResourceTO(); + resourceTO.setKey(resourceName); + resourceTO.setConnectorId(105L); + + final MappingTO umapping = new MappingTO(); + MappingItemTO item = new MappingItemTO(); + item.setIntMappingType(IntMappingType.Username); + item.setExtAttrName("cn"); + item.setAccountid(true); + item.setPurpose(MappingPurpose.PROPAGATION); + item.setMandatoryCondition("true"); + umapping.setAccountIdItem(item); + + item = new MappingItemTO(); + item.setIntMappingType(IntMappingType.UserPlainSchema); + item.setExtAttrName("surname"); + item.setIntAttrName("sn"); + item.setPurpose(MappingPurpose.BOTH); + umapping.addItem(item); + + item = new MappingItemTO(); + item.setIntMappingType(IntMappingType.UserPlainSchema); + item.setExtAttrName("email"); + item.setIntAttrName("mail"); + item.setPurpose(MappingPurpose.BOTH); + umapping.addItem(item); + + item = new MappingItemTO(); + item.setIntMappingType(IntMappingType.Password); + item.setPassword(true); + item.setPurpose(MappingPurpose.BOTH); + item.setMandatoryCondition("true"); + umapping.addItem(item); + + umapping.setAccountLink("'cn=' + username + ',ou=people,o=isp'"); + + final MappingTO rmapping = new MappingTO(); + + item = new MappingItemTO(); + item.setIntMappingType(IntMappingType.RolePlainSchema); + item.setExtAttrName("cn"); + item.setIntAttrName(newPlainSchemaTO.getKey()); + item.setAccountid(true); + item.setPurpose(MappingPurpose.BOTH); + rmapping.setAccountIdItem(item); + + rmapping.setAccountLink("'cn=' + " + newPlainSchemaTO.getKey() + " + ',ou=groups,o=isp'"); + + resourceTO.setRmapping(rmapping); + + Response response = resourceService.create(resourceTO); + newResourceTO = getObject(response.getLocation(), ResourceService.class, ResourceTO.class); + + assertNotNull(newResourceTO); + assertNull(newResourceTO.getUmapping()); + assertNotNull(newResourceTO.getRmapping()); + + // create push task ad-hoc + final PushTaskTO task = new PushTaskTO(); + task.setName("issueSYNCOPE598"); + task.setResource(resourceName); + task.setPerformCreate(true); + task.setPerformDelete(true); + task.setPerformUpdate(true); + task.setUnmatchingRule(UnmatchingRule.ASSIGN); + task.setMatchingRule(MatchingRule.UPDATE); + + response = taskService.create(task); + final PushTaskTO push = getObject(response.getLocation(), TaskService.class, PushTaskTO.class); + + assertNotNull(push); + + // execute the new task + final TaskExecTO pushExec = execSyncTask(push.getKey(), 50, false); + assertTrue(PropagationTaskExecStatus.valueOf(pushExec.getStatus()).isSuccessful()); + } finally { + roleService.delete(roleTO.getKey()); + if (newResourceTO != null) { + resourceService.delete(resourceName); + } + } + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/d30c8526/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/ReportITCase.java ---------------------------------------------------------------------- diff --git a/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/ReportITCase.java b/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/ReportITCase.java new file mode 100644 index 0000000..78ab74f --- /dev/null +++ b/syncope620/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/ReportITCase.java @@ -0,0 +1,252 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.fit.core.reference; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.Response; +import org.apache.commons.io.IOUtils; +import org.apache.syncope.common.lib.SyncopeClientException; +import org.apache.syncope.common.lib.SyncopeConstants; +import org.apache.syncope.common.lib.report.UserReportletConf; +import org.apache.syncope.common.lib.to.PagedResult; +import org.apache.syncope.common.lib.to.ReportExecTO; +import org.apache.syncope.common.lib.to.ReportTO; +import org.apache.syncope.common.lib.types.ReportExecExportFormat; +import org.apache.syncope.common.lib.types.ReportExecStatus; +import org.apache.syncope.common.lib.wrap.ReportletConfClass; +import org.apache.syncope.common.rest.api.service.ReportService; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +@FixMethodOrder(MethodSorters.JVM) +public class ReportITCase extends AbstractITCase { + + private ReportTO createReport(final ReportTO report) { + Response response = reportService.create(report); + assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode()); + return getObject(response.getLocation(), ReportService.class, ReportTO.class); + } + + @Test + public void getReportletClasses() { + List<ReportletConfClass> reportletClasses = reportService.getReportletConfClasses(); + assertNotNull(reportletClasses); + assertFalse(reportletClasses.isEmpty()); + } + + @Test + public void list() { + PagedResult<ReportTO> reports = reportService.list(); + assertNotNull(reports); + assertFalse(reports.getResult().isEmpty()); + for (ReportTO report : reports.getResult()) { + assertNotNull(report); + } + } + + @Test + public void read() { + ReportTO reportTO = reportService.read(1L); + + assertNotNull(reportTO); + assertNotNull(reportTO.getExecutions()); + assertFalse(reportTO.getExecutions().isEmpty()); + } + + @Test + public void readExecution() { + ReportExecTO reportExecTO = reportService.readExecution(1L); + assertNotNull(reportExecTO); + } + + @Test + public void create() { + ReportTO report = new ReportTO(); + report.setName("testReportForCreate" + getUUIDString()); + report.getReportletConfs().add(new UserReportletConf("first")); + report.getReportletConfs().add(new UserReportletConf("second")); + + report = createReport(report); + assertNotNull(report); + + ReportTO actual = reportService.read(report.getKey()); + assertNotNull(actual); + + assertEquals(actual, report); + } + + @Test + public void update() { + ReportTO report = new ReportTO(); + report.setName("testReportForUpdate" + getUUIDString()); + + report.getReportletConfs().add(new UserReportletConf("first")); + report.getReportletConfs().add(new UserReportletConf("second")); + + report = createReport(report); + assertNotNull(report); + assertEquals(2, report.getReportletConfs().size()); + + report.getReportletConfs().add(new UserReportletConf("last")); + + reportService.update(report.getKey(), report); + ReportTO updated = reportService.read(report.getKey()); + assertNotNull(updated); + assertEquals(3, updated.getReportletConfs().size()); + } + + @Test + public void delete() { + ReportTO report = new ReportTO(); + report.setName("testReportForDelete" + getUUIDString()); + report.getReportletConfs().add(new UserReportletConf("first")); + report.getReportletConfs().add(new UserReportletConf("second")); + + report = createReport(report); + assertNotNull(report); + + reportService.delete(report.getKey()); + + try { + reportService.read(report.getKey()); + fail(); + } catch (SyncopeClientException e) { + assertEquals(Response.Status.NOT_FOUND, e.getType().getResponseStatus()); + } + } + + private void checkExport(final Long execId, final ReportExecExportFormat fmt) throws IOException { + final Response response = reportService.exportExecutionResult(execId, fmt); + assertNotNull(response); + assertEquals(Response.Status.OK.getStatusCode(), response.getStatusInfo().getStatusCode()); + assertNotNull(response.getHeaderString(HttpHeaders.CONTENT_DISPOSITION)); + assertTrue(response.getHeaderString(HttpHeaders.CONTENT_DISPOSITION). + endsWith("." + fmt.name().toLowerCase())); + + Object entity = response.getEntity(); + assertTrue(entity instanceof InputStream); + assertFalse(IOUtils.toString((InputStream) entity, SyncopeConstants.DEFAULT_ENCODING).isEmpty()); + } + + @Test + public void executeAndExport() throws IOException { + ReportTO reportTO = reportService.read(1L); + reportTO.setKey(0); + reportTO.setName("executeAndExport" + getUUIDString()); + reportTO.getExecutions().clear(); + reportTO = createReport(reportTO); + assertNotNull(reportTO); + + ReportExecTO execution = reportService.execute(reportTO.getKey()); + assertNotNull(execution); + + int i = 0; + int maxit = 50; + + // wait for report execution completion (executions incremented) + do { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + } + + reportTO = reportService.read(reportTO.getKey()); + + assertNotNull(reportTO); + assertNotNull(reportTO.getExecutions()); + + i++; + } while (reportTO.getExecutions().isEmpty() + || (!ReportExecStatus.SUCCESS.name().equals(reportTO.getExecutions().get(0).getStatus()) && i < maxit)); + assertEquals(ReportExecStatus.SUCCESS.name(), reportTO.getExecutions().get(0).getStatus()); + + long execId = reportTO.getExecutions().get(0).getKey(); + + checkExport(execId, ReportExecExportFormat.XML); + checkExport(execId, ReportExecExportFormat.HTML); + checkExport(execId, ReportExecExportFormat.PDF); + checkExport(execId, ReportExecExportFormat.RTF); + checkExport(execId, ReportExecExportFormat.CSV); + } + + @Test + public void issueSYNCOPE43() { + ReportTO reportTO = new ReportTO(); + reportTO.setName("issueSYNCOPE43" + getUUIDString()); + reportTO = createReport(reportTO); + assertNotNull(reportTO); + + ReportExecTO execution = reportService.execute(reportTO.getKey()); + assertNotNull(execution); + + int maxit = 50; + do { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + } + + reportTO = reportService.read(reportTO.getKey()); + + maxit--; + } while (reportTO.getExecutions().isEmpty() && maxit > 0); + + assertEquals(1, reportTO.getExecutions().size()); + } + + @Test + public void issueSYNCOPE102() throws IOException { + // Create + ReportTO reportTO = reportService.read(1L); + reportTO.setKey(0); + reportTO.setName("issueSYNCOPE102" + getUUIDString()); + reportTO = createReport(reportTO); + assertNotNull(reportTO); + + // Execute (multiple requests) + for (int i = 0; i < 10; i++) { + ReportExecTO execution = reportService.execute(reportTO.getKey()); + assertNotNull(execution); + } + + // Wait for one execution + int maxit = 50; + do { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + } + + reportTO = reportService.read(reportTO.getKey()); + + maxit--; + } while (reportTO.getExecutions().isEmpty() && maxit > 0); + assertFalse(reportTO.getExecutions().isEmpty()); + } +}
