You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2016/01/26 13:04:50 UTC
[19/21] syncope git commit: [SYNCOPE-152] Moving console IT under
fit/core-reference in order to speed-up the total build time
http://git-wip-us.apache.org/repos/asf/syncope/blob/17d5d892/fit/core-reference/src/test/java/org/apache/syncope/fit/console/TestPage.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/console/TestPage.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/console/TestPage.java
new file mode 100644
index 0000000..9dc19ea
--- /dev/null
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/console/TestPage.java
@@ -0,0 +1,88 @@
+/*
+ * 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.console;
+
+import java.io.Serializable;
+import org.apache.wicket.MarkupContainer;
+import org.apache.wicket.markup.IMarkupResourceStreamProvider;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.markup.html.panel.Panel;
+import org.apache.wicket.util.resource.IResourceStream;
+import org.apache.wicket.util.resource.StringResourceStream;
+
+public class TestPage<T extends Serializable, S extends Panel>
+ extends WebPage implements IMarkupResourceStreamProvider {
+
+ private static final long serialVersionUID = 483736530078975170L;
+
+ public static String FIELD = "field";
+
+ private final Form<T> form;
+
+ private final S fieldPanel;
+
+ private TestPage(S field, final Builder<T, S> builder) {
+
+ this.form = builder.form;
+ this.fieldPanel = field;
+
+ field.setOutputMarkupId(builder.outputMarkupId);
+ add(form);
+ form.add(field);
+ }
+
+ public Form<T> getForm() {
+ return form;
+ }
+
+ public S getFieldPanel() {
+ return fieldPanel;
+ }
+
+ public static class Builder<T extends Serializable, S extends Panel> implements Serializable {
+
+ private static final long serialVersionUID = 4882978420728876617L;
+
+ private final Form<T> form;
+
+ private boolean outputMarkupId;
+
+ public Builder() {
+ this.form = new Form<>("form");
+
+ }
+
+ public Builder<T, S> setOutputMarkupId(final boolean outputMarkupId) {
+ this.outputMarkupId = outputMarkupId;
+ return this;
+ }
+
+ public TestPage<T, S> build(final S field) {
+ return new TestPage<>(field, this);
+ }
+ }
+
+ @Override
+ public IResourceStream getMarkupResourceStream(final MarkupContainer container,
+ final Class<?> containerClass) {
+ return new StringResourceStream("<html><body>"
+ + "<form wicket:id=\"form\"><span wicket:id=\"field\"></span></form></body></html>");
+ }
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/17d5d892/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AbstractTaskITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AbstractTaskITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AbstractTaskITCase.java
new file mode 100644
index 0000000..b9ec955
--- /dev/null
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AbstractTaskITCase.java
@@ -0,0 +1,184 @@
+/*
+ * 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;
+
+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.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import org.apache.commons.collections4.IterableUtils;
+import org.apache.commons.collections4.Predicate;
+import org.apache.syncope.common.lib.to.AbstractTaskTO;
+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.TaskType;
+import org.apache.syncope.common.rest.api.beans.ExecuteQuery;
+import org.apache.syncope.common.rest.api.beans.TaskQuery;
+import org.apache.syncope.common.rest.api.service.TaskService;
+import org.apache.syncope.core.logic.notification.NotificationJob;
+import org.apache.syncope.fit.AbstractITCase;
+
+public abstract class AbstractTaskITCase extends AbstractITCase {
+
+ protected static final Long SYNC_TASK_ID = 4L;
+
+ protected static final Long SCHED_TASK_ID = 5L;
+
+ protected static class ThreadExec implements Callable<TaskExecTO> {
+
+ private final TaskService taskService;
+
+ private final Long taskKey;
+
+ private final int maxWaitSeconds;
+
+ private final boolean dryRun;
+
+ public ThreadExec(
+ final TaskService taskService, final Long taskKey, final int maxWaitSeconds, final boolean dryRun) {
+
+ this.taskService = taskService;
+ this.taskKey = taskKey;
+ this.maxWaitSeconds = maxWaitSeconds;
+ this.dryRun = dryRun;
+ }
+
+ @Override
+ public TaskExecTO call() throws Exception {
+ return execProvisioningTask(taskService, taskKey, maxWaitSeconds, dryRun);
+ }
+ }
+
+ /**
+ * Remove initial and synchronized users to make test re-runnable.
+ */
+ protected void removeTestUsers() {
+ for (int i = 0; i < 10; i++) {
+ String cUserName = "test" + i;
+ try {
+ UserTO cUserTO = readUser(cUserName);
+ userService.delete(cUserTO.getKey());
+ } catch (Exception e) {
+ // Ignore
+ }
+ }
+ }
+
+ protected static TaskExecTO execTask(final TaskService taskService, final Long taskKey, final String initialStatus,
+ final int maxWaitSeconds, final boolean dryRun) {
+
+ AbstractTaskTO taskTO = taskService.read(taskKey, true);
+ assertNotNull(taskTO);
+ assertNotNull(taskTO.getExecutions());
+
+ int preSyncSize = taskTO.getExecutions().size();
+ TaskExecTO execution = taskService.execute(
+ new ExecuteQuery.Builder().key(taskTO.getKey()).dryRun(dryRun).build());
+ assertEquals(initialStatus, execution.getStatus());
+
+ int i = 0;
+ int maxit = maxWaitSeconds;
+
+ // wait for completion (executions incremented)
+ do {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ }
+
+ taskTO = taskService.read(taskTO.getKey(), true);
+
+ assertNotNull(taskTO);
+ assertNotNull(taskTO.getExecutions());
+
+ i++;
+ } while (preSyncSize == taskTO.getExecutions().size() && i < maxit);
+ if (i == maxit) {
+ fail("Timeout when executing task " + taskKey);
+ }
+ return taskTO.getExecutions().get(taskTO.getExecutions().size() - 1);
+ }
+
+ public static TaskExecTO execProvisioningTask(
+ final TaskService taskService, final Long taskKey, final int maxWaitSeconds, final boolean dryRun) {
+
+ return execTask(taskService, taskKey, "JOB_FIRED", maxWaitSeconds, dryRun);
+ }
+
+ protected static TaskExecTO execNotificationTask(
+ final TaskService taskService, final Long taskKey, final int maxWaitSeconds) {
+
+ return execTask(taskService, taskKey, NotificationJob.Status.SENT.name(), maxWaitSeconds, false);
+ }
+
+ protected Map<Long, TaskExecTO> execProvisioningTasks(final TaskService taskService,
+ final Set<Long> taskKeys, final int maxWaitSeconds, final boolean dryRun) throws Exception {
+
+ ExecutorService service = Executors.newFixedThreadPool(taskKeys.size());
+ List<Future<TaskExecTO>> futures = new ArrayList<>();
+
+ for (Long key : taskKeys) {
+ futures.add(service.submit(new ThreadExec(taskService, key, maxWaitSeconds, dryRun)));
+ // avoid flooding the test server
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ }
+ }
+
+ Map<Long, TaskExecTO> res = new HashMap<>();
+
+ for (Future<TaskExecTO> future : futures) {
+ TaskExecTO taskExecTO = future.get(100, TimeUnit.SECONDS);
+ res.put(taskExecTO.getTask(), taskExecTO);
+ }
+
+ service.shutdownNow();
+
+ return res;
+ }
+
+ protected NotificationTaskTO findNotificationTaskBySender(final String sender) {
+ PagedResult<NotificationTaskTO> tasks =
+ taskService.list(new TaskQuery.Builder().type(TaskType.NOTIFICATION).build());
+ assertNotNull(tasks);
+ assertFalse(tasks.getResult().isEmpty());
+
+ return IterableUtils.find(tasks.getResult(), new Predicate<NotificationTaskTO>() {
+
+ @Override
+ public boolean evaluate(final NotificationTaskTO task) {
+ return sender.equals(task.getSender());
+ }
+ });
+ }
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/17d5d892/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AnyObjectITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AnyObjectITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AnyObjectITCase.java
new file mode 100644
index 0000000..35521e2
--- /dev/null
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AnyObjectITCase.java
@@ -0,0 +1,210 @@
+/*
+ * 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;
+
+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.Set;
+import javax.ws.rs.core.Response;
+import org.apache.syncope.common.lib.SyncopeClientException;
+import org.apache.syncope.common.lib.SyncopeConstants;
+import org.apache.syncope.common.lib.patch.AnyObjectPatch;
+import org.apache.syncope.common.lib.to.ConnObjectTO;
+import org.apache.syncope.common.lib.to.AnyObjectTO;
+import org.apache.syncope.common.lib.to.AttrTO;
+import org.apache.syncope.common.lib.to.MembershipTO;
+import org.apache.syncope.common.lib.to.PagedResult;
+import org.apache.syncope.common.lib.to.RelationshipTO;
+import org.apache.syncope.common.lib.types.AnyTypeKind;
+import org.apache.syncope.common.lib.types.ClientExceptionType;
+import org.apache.syncope.common.lib.types.SchemaType;
+import org.apache.syncope.common.rest.api.beans.AnyListQuery;
+import org.apache.syncope.fit.AbstractITCase;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
+@FixMethodOrder(MethodSorters.JVM)
+public class AnyObjectITCase extends AbstractITCase {
+
+ public static AnyObjectTO getSampleTO(final String location) {
+ AnyObjectTO anyObjectTO = new AnyObjectTO();
+ anyObjectTO.setRealm(SyncopeConstants.ROOT_REALM);
+ anyObjectTO.setType("PRINTER");
+ anyObjectTO.getPlainAttrs().add(attrTO("location", location + getUUIDString()));
+
+ anyObjectTO.getResources().add(RESOURCE_NAME_DBSCRIPTED);
+ return anyObjectTO;
+ }
+
+ @Test
+ public void create() {
+ AnyObjectTO anyObjectTO = getSampleTO("create");
+
+ anyObjectTO = createAnyObject(anyObjectTO).getAny();
+ assertNotNull(anyObjectTO);
+
+ ConnObjectTO connObjectTO =
+ resourceService.readConnObject(RESOURCE_NAME_DBSCRIPTED, anyObjectTO.getType(), anyObjectTO.getKey());
+ assertNotNull(connObjectTO);
+ assertNotNull(connObjectTO.getPlainAttrMap().get("location"));
+ assertEquals(anyObjectTO.getPlainAttrMap().get("location"), connObjectTO.getPlainAttrMap().get("location"));
+ }
+
+ @Test
+ public void createInvalidMembership() {
+ // 1. create anyObject in realm /odd and attempt to assign group 15, from realm /even => exception
+ AnyObjectTO anyObjectTO = getSampleTO("createInvalidMembership");
+ anyObjectTO.setRealm("/odd");
+ anyObjectTO.getMemberships().add(new MembershipTO.Builder().group(15L).build());
+
+ try {
+ createAnyObject(anyObjectTO);
+ fail();
+ } catch (SyncopeClientException e) {
+ assertEquals(ClientExceptionType.InvalidMembership, e.getType());
+ }
+
+ // 2. change anyObject's realm to /even/two, now it works
+ anyObjectTO.setRealm("/even/two");
+
+ anyObjectTO = createAnyObject(anyObjectTO).getAny();
+ assertTrue(anyObjectTO.getMembershipMap().containsKey(15L));
+ }
+
+ @Test
+ public void delete() {
+ try {
+ anyObjectService.delete(0L);
+ } catch (SyncopeClientException e) {
+ assertEquals(Response.Status.NOT_FOUND, e.getType().getResponseStatus());
+ }
+
+ AnyObjectTO anyObjectTO = getSampleTO("deletable");
+ anyObjectTO.setRealm("/even");
+
+ anyObjectTO = createAnyObject(anyObjectTO).getAny();
+ assertNotNull(anyObjectTO);
+
+ AnyObjectTO deletedAnyObject = deleteAnyObject(anyObjectTO.getKey()).getAny();
+ assertNotNull(deletedAnyObject);
+
+ try {
+ anyObjectService.read(deletedAnyObject.getKey());
+ } catch (SyncopeClientException e) {
+ assertEquals(Response.Status.NOT_FOUND, e.getType().getResponseStatus());
+ }
+ }
+
+ @Test
+ public void list() {
+ PagedResult<AnyObjectTO> anyObjectTOs = anyObjectService.list(
+ "PRINTER", new AnyListQuery.Builder().realm(SyncopeConstants.ROOT_REALM).build());
+ assertNotNull(anyObjectTOs);
+ assertTrue(anyObjectTOs.getResult().size() >= 2);
+ for (AnyObjectTO anyObjectTO : anyObjectTOs.getResult()) {
+ assertNotNull(anyObjectTO);
+ }
+ }
+
+ @Test
+ public void read() {
+ AnyObjectTO anyObjectTO = anyObjectService.read(1L);
+ assertNotNull(anyObjectTO);
+ assertNotNull(anyObjectTO.getPlainAttrs());
+ assertFalse(anyObjectTO.getPlainAttrs().isEmpty());
+ }
+
+ @Test
+ public void update() {
+ AnyObjectTO anyObjectTO = getSampleTO("update");
+ anyObjectTO = createAnyObject(anyObjectTO).getAny();
+
+ assertEquals(1, anyObjectTO.getPlainAttrs().size());
+
+ AnyObjectPatch anyObjectPatch = new AnyObjectPatch();
+ anyObjectPatch.setKey(anyObjectTO.getKey());
+ String newLocation = "new" + getUUIDString();
+ anyObjectPatch.getPlainAttrs().add(attrAddReplacePatch("location", newLocation));
+
+ anyObjectTO = updateAnyObject(anyObjectPatch).getAny();
+
+ assertEquals(newLocation, anyObjectTO.getPlainAttrMap().get("location").getValues().get(0));
+ }
+
+ @Test
+ public void readAttrs() {
+ AnyObjectTO anyObjectTO = getSampleTO("readAttrs");
+ anyObjectTO = createAnyObject(anyObjectTO).getAny();
+ assertNotNull(anyObjectTO);
+
+ Set<AttrTO> attrs = anyObjectService.read(anyObjectTO.getKey(), SchemaType.PLAIN);
+ assertEquals(anyObjectTO.getPlainAttrs(), attrs);
+
+ AttrTO location = anyObjectService.read(anyObjectTO.getKey(), SchemaType.PLAIN, "location");
+ assertEquals(anyObjectTO.getPlainAttrMap().get("location"), location);
+ }
+
+ @Test
+ public void updateAttr() {
+ AnyObjectTO anyObjectTO = getSampleTO("updateAttr");
+ anyObjectTO = createAnyObject(anyObjectTO).getAny();
+ assertNotNull(anyObjectTO);
+
+ AttrTO updated = attrTO("location", "newlocation");
+ anyObjectService.update(anyObjectTO.getKey(), SchemaType.PLAIN, updated);
+
+ AttrTO location = anyObjectService.read(anyObjectTO.getKey(), SchemaType.PLAIN, "location");
+ assertEquals(updated, location);
+ }
+
+ @Test
+ public void deleteAttr() {
+ AnyObjectTO anyObjectTO = getSampleTO("deleteAttr");
+ anyObjectTO = createAnyObject(anyObjectTO).getAny();
+ assertNotNull(anyObjectTO);
+ assertNotNull(anyObjectTO.getPlainAttrMap().get("location"));
+
+ anyObjectService.delete(anyObjectTO.getKey(), SchemaType.PLAIN, "location");
+
+ try {
+ anyObjectService.read(anyObjectTO.getKey(), SchemaType.PLAIN, "location");
+ fail();
+ } catch (SyncopeClientException e) {
+ assertEquals(ClientExceptionType.NotFound, e.getType());
+ }
+ }
+
+ @Test
+ public void issueSYNCOPE756() {
+ AnyObjectTO anyObjectTO = getSampleTO("issueSYNCOPE756");
+ anyObjectTO.getRelationships().add(new RelationshipTO.Builder().right(AnyTypeKind.USER.name(), 1).build());
+
+ try {
+ createAnyObject(anyObjectTO).getAny();
+ fail();
+ } catch (SyncopeClientException e) {
+ assertEquals(ClientExceptionType.InvalidAnyType, e.getType());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/17d5d892/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AnyTypeClassITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AnyTypeClassITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AnyTypeClassITCase.java
new file mode 100644
index 0000000..bdce865
--- /dev/null
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AnyTypeClassITCase.java
@@ -0,0 +1,154 @@
+/*
+ * 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;
+
+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.List;
+import javax.ws.rs.core.Response;
+import org.apache.syncope.common.lib.SyncopeClientException;
+import org.apache.syncope.common.lib.to.AnyTypeClassTO;
+import org.apache.syncope.common.lib.to.DerSchemaTO;
+import org.apache.syncope.common.lib.to.PlainSchemaTO;
+import org.apache.syncope.common.lib.types.AttrSchemaType;
+import org.apache.syncope.common.lib.types.ClientExceptionType;
+import org.apache.syncope.common.lib.types.SchemaType;
+import org.apache.syncope.common.rest.api.service.AnyTypeClassService;
+import org.apache.syncope.fit.AbstractITCase;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
+@FixMethodOrder(MethodSorters.JVM)
+public class AnyTypeClassITCase extends AbstractITCase {
+
+ @Test
+ public void read() {
+ AnyTypeClassTO minimalGroup = anyTypeClassService.read("minimal group");
+ assertNotNull(minimalGroup);
+
+ assertFalse(minimalGroup.getPlainSchemas().isEmpty());
+ assertFalse(minimalGroup.getDerSchemas().isEmpty());
+ assertFalse(minimalGroup.getVirSchemas().isEmpty());
+ }
+
+ @Test
+ public void list() {
+ List<AnyTypeClassTO> list = anyTypeClassService.list();
+ assertFalse(list.isEmpty());
+ }
+
+ @Test
+ public void crud() {
+ // 1. create sample schemas
+ PlainSchemaTO plainSchema = new PlainSchemaTO();
+ plainSchema.setKey("new_plain_schema" + getUUIDString());
+ plainSchema.setType(AttrSchemaType.String);
+ plainSchema = createSchema(SchemaType.PLAIN, plainSchema);
+
+ DerSchemaTO derSchema = new DerSchemaTO();
+ derSchema.setKey("new_der_schema" + getUUIDString());
+ derSchema.setExpression(plainSchema.getKey() + " + '_' + derived_dx");
+ derSchema = createSchema(SchemaType.DERIVED, derSchema);
+
+ // 2. actual CRUD
+ AnyTypeClassTO newClass = new AnyTypeClassTO();
+ newClass.setKey("new class" + getUUIDString());
+ newClass.getPlainSchemas().add(plainSchema.getKey());
+
+ Response response = anyTypeClassService.create(newClass);
+ assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode());
+
+ newClass = getObject(response.getLocation(), AnyTypeClassService.class, AnyTypeClassTO.class);
+ assertNotNull(newClass);
+ assertFalse(newClass.getPlainSchemas().isEmpty());
+ assertTrue(newClass.getDerSchemas().isEmpty());
+ assertTrue(newClass.getVirSchemas().isEmpty());
+
+ newClass.getDerSchemas().add(derSchema.getKey());
+ anyTypeClassService.update(newClass);
+
+ newClass = anyTypeClassService.read(newClass.getKey());
+ assertNotNull(newClass);
+ assertFalse(newClass.getPlainSchemas().isEmpty());
+ assertFalse(newClass.getDerSchemas().isEmpty());
+ assertTrue(newClass.getVirSchemas().isEmpty());
+
+ assertEquals(newClass.getKey(), schemaService.read(SchemaType.PLAIN, plainSchema.getKey()).getAnyTypeClass());
+ assertEquals(newClass.getKey(), schemaService.read(SchemaType.DERIVED, derSchema.getKey()).getAnyTypeClass());
+
+ anyTypeClassService.delete(newClass.getKey());
+
+ try {
+ anyTypeClassService.read(newClass.getKey());
+ fail();
+ } catch (SyncopeClientException e) {
+ assertEquals(ClientExceptionType.NotFound, e.getType());
+ }
+
+ assertNull(schemaService.read(SchemaType.PLAIN, plainSchema.getKey()).getAnyTypeClass());
+ assertNull(schemaService.read(SchemaType.DERIVED, derSchema.getKey()).getAnyTypeClass());
+ }
+
+ @Test
+ public void deleteSchema() {
+ PlainSchemaTO newSchema = new PlainSchemaTO();
+ newSchema.setKey("newSchema" + getUUIDString());
+ newSchema.setType(AttrSchemaType.Date);
+ createSchema(SchemaType.PLAIN, newSchema);
+
+ AnyTypeClassTO newClass = new AnyTypeClassTO();
+ newClass.setKey("new class" + getUUIDString());
+ newClass.getPlainSchemas().add(newSchema.getKey());
+
+ Response response = anyTypeClassService.create(newClass);
+ assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode());
+
+ newClass = getObject(response.getLocation(), AnyTypeClassService.class, AnyTypeClassTO.class);
+ assertNotNull(newClass);
+ assertTrue(newClass.getPlainSchemas().contains(newSchema.getKey()));
+
+ schemaService.delete(SchemaType.PLAIN, newSchema.getKey());
+
+ newClass = anyTypeClassService.read(newClass.getKey());
+ assertNotNull(newClass);
+ assertFalse(newClass.getPlainSchemas().contains(newSchema.getKey()));
+ }
+
+ @Test
+ public void issueSYNCOPE759() {
+ AnyTypeClassTO minimalGroup = anyTypeClassService.read("minimal group");
+ assertNotNull(minimalGroup);
+
+ AnyTypeClassTO newAnyTypeClass = new AnyTypeClassTO();
+ newAnyTypeClass.setKey(minimalGroup.getKey());
+
+ try {
+ anyTypeClassService.create(newAnyTypeClass);
+ fail();
+ } catch (SyncopeClientException e) {
+ assertEquals(ClientExceptionType.EntityExists, e.getType());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/17d5d892/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AnyTypeITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AnyTypeITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AnyTypeITCase.java
new file mode 100644
index 0000000..f89e9a0
--- /dev/null
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AnyTypeITCase.java
@@ -0,0 +1,194 @@
+/*
+ * 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;
+
+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.List;
+import javax.ws.rs.core.Response;
+import org.apache.syncope.common.lib.SyncopeClientException;
+import org.apache.syncope.common.lib.to.AnyTypeClassTO;
+import org.apache.syncope.common.lib.to.AnyTypeTO;
+import org.apache.syncope.common.lib.types.AnyTypeKind;
+import org.apache.syncope.common.lib.types.ClientExceptionType;
+import org.apache.syncope.common.rest.api.service.AnyTypeClassService;
+import org.apache.syncope.common.rest.api.service.AnyTypeService;
+import org.apache.syncope.fit.AbstractITCase;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
+@FixMethodOrder(MethodSorters.JVM)
+public class AnyTypeITCase extends AbstractITCase {
+
+ @Test
+ public void read() {
+ AnyTypeTO userType = anyTypeService.read(AnyTypeKind.USER.name());
+ assertNotNull(userType);
+ assertEquals(AnyTypeKind.USER, userType.getKind());
+ assertEquals(AnyTypeKind.USER.name(), userType.getKey());
+ assertFalse(userType.getClasses().isEmpty());
+
+ AnyTypeTO groupType = anyTypeService.read(AnyTypeKind.GROUP.name());
+ assertNotNull(groupType);
+ assertEquals(AnyTypeKind.GROUP, groupType.getKind());
+ assertEquals(AnyTypeKind.GROUP.name(), groupType.getKey());
+ assertFalse(groupType.getClasses().isEmpty());
+
+ AnyTypeTO otherType = anyTypeService.read("PRINTER");
+ assertNotNull(otherType);
+ assertEquals(AnyTypeKind.ANY_OBJECT, otherType.getKind());
+ assertEquals("PRINTER", otherType.getKey());
+ }
+
+ @Test
+ public void list() {
+ List<AnyTypeTO> list = anyTypeService.list();
+ assertFalse(list.isEmpty());
+ }
+
+ @Test
+ public void crud() {
+ AnyTypeTO newType = new AnyTypeTO();
+ newType.setKey("new type");
+ newType.setKind(AnyTypeKind.ANY_OBJECT);
+ newType.getClasses().add("generic membership");
+ newType.getClasses().add("csv");
+
+ Response response = anyTypeService.create(newType);
+ assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode());
+
+ newType = getObject(response.getLocation(), AnyTypeService.class, AnyTypeTO.class);
+ assertNotNull(newType);
+ assertEquals(2, newType.getClasses().size());
+ assertTrue(newType.getClasses().contains("generic membership"));
+ assertTrue(newType.getClasses().contains("csv"));
+
+ newType.getClasses().remove("generic membership");
+ anyTypeService.update(newType);
+
+ newType = anyTypeService.read(newType.getKey());
+ assertNotNull(newType);
+ assertEquals(1, newType.getClasses().size());
+ assertTrue(newType.getClasses().contains("csv"));
+
+ anyTypeService.delete(newType.getKey());
+
+ try {
+ anyTypeService.read(newType.getKey());
+ fail();
+ } catch (SyncopeClientException e) {
+ assertEquals(ClientExceptionType.NotFound, e.getType());
+ }
+ }
+
+ @Test
+ public void createInvalidKind() {
+ AnyTypeTO newType = new AnyTypeTO();
+ newType.setKey("new type");
+ newType.setKind(AnyTypeKind.USER);
+ try {
+ anyTypeService.create(newType);
+ fail();
+ } catch (SyncopeClientException e) {
+ assertEquals(ClientExceptionType.InvalidAnyType, e.getType());
+ }
+ }
+
+ @Test
+ public void createInvalidName() {
+ AnyTypeTO newType = new AnyTypeTO();
+ newType.setKey("group");
+ newType.setKind(AnyTypeKind.ANY_OBJECT);
+ try {
+ anyTypeService.create(newType);
+ fail();
+ } catch (SyncopeClientException e) {
+ assertEquals(ClientExceptionType.InvalidAnyType, e.getType());
+ }
+ }
+
+ @Test
+ public void deleteInvalid() {
+ try {
+ anyTypeService.delete(AnyTypeKind.USER.name());
+ fail();
+ } catch (SyncopeClientException e) {
+ assertEquals(ClientExceptionType.InvalidAnyType, e.getType());
+ }
+ }
+
+ @Test
+ public void deleteTypeClass() {
+ AnyTypeClassTO newClass = new AnyTypeClassTO();
+ newClass.setKey("new class" + getUUIDString());
+ newClass.getDerSchemas().add("cn");
+
+ Response response = anyTypeClassService.create(newClass);
+ assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode());
+
+ newClass = getObject(response.getLocation(), AnyTypeClassService.class, AnyTypeClassTO.class);
+ assertNotNull(newClass);
+
+ AnyTypeTO other = anyTypeService.read("PRINTER");
+ assertNotNull(other);
+
+ other.getClasses().add(newClass.getKey());
+ anyTypeService.update(other);
+
+ other = anyTypeService.read(other.getKey());
+ assertNotNull(other);
+ assertTrue(other.getClasses().contains(newClass.getKey()));
+
+ anyTypeClassService.delete(newClass.getKey());
+
+ other = anyTypeService.read(other.getKey());
+ assertNotNull(other);
+ assertFalse(other.getClasses().contains(newClass.getKey()));
+ }
+
+ @Test
+ public void issueSYNCOPE754() {
+ AnyTypeClassTO other = anyTypeClassService.read("other");
+ assertNotNull(other);
+
+ AnyTypeTO group = anyTypeService.read(AnyTypeKind.GROUP.name());
+ try {
+ assertFalse(group.getClasses().contains("other"));
+ group.getClasses().add("other");
+
+ anyTypeService.update(group);
+
+ group = anyTypeService.read(AnyTypeKind.GROUP.name());
+ assertTrue(group.getClasses().contains("other"));
+
+ other = anyTypeClassService.read("other");
+ assertEquals(2, other.getInUseByTypes().size());
+ assertTrue(other.getInUseByTypes().contains(AnyTypeKind.USER.name()));
+ assertTrue(other.getInUseByTypes().contains(AnyTypeKind.GROUP.name()));
+ } finally {
+ group.getClasses().remove("other");
+ anyTypeService.update(group);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/17d5d892/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AuthenticationITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AuthenticationITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AuthenticationITCase.java
new file mode 100644
index 0000000..58b1b40
--- /dev/null
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/AuthenticationITCase.java
@@ -0,0 +1,567 @@
+/*
+ * 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;
+
+import org.apache.syncope.fit.ActivitiDetector;
+
+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.security.AccessControlException;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import javax.ws.rs.core.GenericType;
+import javax.ws.rs.core.Response;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.collections4.IterableUtils;
+import org.apache.commons.collections4.Predicate;
+import org.apache.commons.collections4.Transformer;
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.syncope.client.lib.SyncopeClient;
+import org.apache.syncope.common.lib.SyncopeClientException;
+import org.apache.syncope.common.lib.SyncopeConstants;
+import org.apache.syncope.common.lib.patch.DeassociationPatch;
+import org.apache.syncope.common.lib.patch.PasswordPatch;
+import org.apache.syncope.common.lib.patch.StatusPatch;
+import org.apache.syncope.common.lib.patch.StringPatchItem;
+import org.apache.syncope.common.lib.patch.StringReplacePatchItem;
+import org.apache.syncope.common.lib.patch.UserPatch;
+import org.apache.syncope.common.lib.to.AnyObjectTO;
+import org.apache.syncope.common.lib.to.AnyTypeClassTO;
+import org.apache.syncope.common.lib.to.AnyTypeTO;
+import org.apache.syncope.common.lib.to.BulkActionResult;
+import org.apache.syncope.common.lib.to.MembershipTO;
+import org.apache.syncope.common.lib.to.PagedResult;
+import org.apache.syncope.common.lib.to.PlainSchemaTO;
+import org.apache.syncope.common.lib.to.ProvisioningResult;
+import org.apache.syncope.common.lib.to.RoleTO;
+import org.apache.syncope.common.lib.to.UserTO;
+import org.apache.syncope.common.lib.to.WorkflowFormPropertyTO;
+import org.apache.syncope.common.lib.to.WorkflowFormTO;
+import org.apache.syncope.common.lib.types.AnyTypeKind;
+import org.apache.syncope.common.lib.types.AttrSchemaType;
+import org.apache.syncope.common.lib.types.CipherAlgorithm;
+import org.apache.syncope.common.lib.types.ClientExceptionType;
+import org.apache.syncope.common.lib.types.PatchOperation;
+import org.apache.syncope.common.lib.types.ResourceDeassociationAction;
+import org.apache.syncope.common.lib.types.SchemaType;
+import org.apache.syncope.common.lib.types.StandardEntitlement;
+import org.apache.syncope.common.lib.types.StatusPatchType;
+import org.apache.syncope.common.rest.api.RESTHeaders;
+import org.apache.syncope.common.rest.api.beans.AnySearchQuery;
+import org.apache.syncope.common.rest.api.service.AnyObjectService;
+import org.apache.syncope.common.rest.api.service.SchemaService;
+import org.apache.syncope.common.rest.api.service.UserService;
+import org.apache.syncope.core.misc.security.Encryptor;
+import org.apache.syncope.fit.AbstractITCase;
+import org.junit.Assume;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+@FixMethodOrder(MethodSorters.JVM)
+public class AuthenticationITCase extends AbstractITCase {
+
+ private int getFailedLogins(final UserService userService, final long userId) {
+ UserTO readUserTO = userService.read(userId);
+ assertNotNull(readUserTO);
+ assertNotNull(readUserTO.getFailedLogins());
+ return readUserTO.getFailedLogins();
+ }
+
+ private void assertReadFails(final SyncopeClient client) {
+ try {
+ client.self();
+ fail("access should not work");
+ } catch (Exception e) {
+ assertNotNull(e);
+ }
+ }
+
+ @Test
+ public void testReadEntitlements() {
+ // 1. as not authenticated (not allowed)
+ try {
+ clientFactory.create().self();
+ fail();
+ } catch (AccessControlException e) {
+ assertNotNull(e);
+ }
+
+ // 2. as anonymous
+ Pair<Map<String, Set<String>>, UserTO> self = clientFactory.create(ANONYMOUS_UNAME, ANONYMOUS_KEY).self();
+ assertEquals(1, self.getKey().size());
+ assertTrue(self.getKey().keySet().contains(StandardEntitlement.ANONYMOUS));
+ assertEquals(ANONYMOUS_UNAME, self.getValue().getUsername());
+
+ // 3. as admin
+ self = adminClient.self();
+ assertEquals(syncopeService.info().getEntitlements().size(), self.getKey().size());
+ assertFalse(self.getKey().keySet().contains(StandardEntitlement.ANONYMOUS));
+ assertEquals(ADMIN_UNAME, self.getValue().getUsername());
+
+ // 4. as user
+ self = clientFactory.create("bellini", ADMIN_PWD).self();
+ assertFalse(self.getKey().isEmpty());
+ assertFalse(self.getKey().keySet().contains(StandardEntitlement.ANONYMOUS));
+ assertEquals("bellini", self.getValue().getUsername());
+ }
+
+ @Test
+ public void testUserSchemaAuthorization() {
+ String schemaName = "authTestSchema" + getUUIDString();
+
+ // 1. create a schema (as admin)
+ PlainSchemaTO schemaTO = new PlainSchemaTO();
+ schemaTO.setKey(schemaName);
+ schemaTO.setMandatoryCondition("false");
+ schemaTO.setType(AttrSchemaType.String);
+
+ PlainSchemaTO newPlainSchemaTO = createSchema(SchemaType.PLAIN, schemaTO);
+ assertEquals(schemaTO, newPlainSchemaTO);
+
+ // 2. create an user with the role created above (as admin)
+ UserTO userTO = UserITCase.getUniqueSampleTO("auth@test.org");
+ userTO = createUser(userTO).getAny();
+ assertNotNull(userTO);
+
+ // 3. read the schema created above (as admin) - success
+ schemaTO = schemaService.read(SchemaType.PLAIN, schemaName);
+ assertNotNull(schemaTO);
+
+ // 4. read the schema created above (as user) - success
+ SchemaService schemaService2 = clientFactory.create(userTO.getUsername(), "password123").
+ getService(SchemaService.class);
+ schemaTO = schemaService2.read(SchemaType.PLAIN, schemaName);
+ assertNotNull(schemaTO);
+
+ // 5. update the schema create above (as user) - failure
+ try {
+ schemaService2.update(SchemaType.PLAIN, schemaTO);
+ fail("Schemaupdate as user should not work");
+ } catch (AccessControlException e) {
+ // CXF Service will throw this exception
+ assertNotNull(e);
+ }
+
+ assertEquals(0, getFailedLogins(userService, userTO.getKey()));
+ }
+
+ @Test
+ public void testUserRead() {
+ UserTO userTO = UserITCase.getUniqueSampleTO("testuserread@test.org");
+ userTO.getRoles().add("User manager");
+
+ userTO = createUser(userTO).getAny();
+ assertNotNull(userTO);
+
+ UserService userService2 = clientFactory.create(userTO.getUsername(), "password123").
+ getService(UserService.class);
+
+ UserTO readUserTO = userService2.read(1L);
+ assertNotNull(readUserTO);
+
+ UserService userService3 = clientFactory.create("puccini", ADMIN_PWD).getService(UserService.class);
+
+ try {
+ userService3.read(3L);
+ fail();
+ } catch (SyncopeClientException e) {
+ assertNotNull(e);
+ assertEquals(ClientExceptionType.DelegatedAdministration, e.getType());
+ }
+ }
+
+ @Test
+ public void testUserSearch() {
+ UserTO userTO = UserITCase.getUniqueSampleTO("testusersearch@test.org");
+ userTO.getRoles().add("User reviewer");
+
+ userTO = createUser(userTO).getAny();
+ assertNotNull(userTO);
+
+ // 1. user assigned to role 1, with search entitlement on realms /odd and /even: won't find anything with
+ // root realm
+ UserService userService2 = clientFactory.create(userTO.getUsername(), "password123").
+ getService(UserService.class);
+
+ PagedResult<UserTO> matchedUsers = userService2.search(
+ new AnySearchQuery.Builder().realm(SyncopeConstants.ROOT_REALM).
+ fiql(SyncopeClient.getUserSearchConditionBuilder().isNotNull("key").query()).build());
+ assertNotNull(matchedUsers);
+ assertFalse(matchedUsers.getResult().isEmpty());
+ Set<Long> matchedUserKeys = CollectionUtils.collect(matchedUsers.getResult(),
+ new Transformer<UserTO, Long>() {
+
+ @Override
+ public Long transform(final UserTO input) {
+ return input.getKey();
+ }
+ }, new HashSet<Long>());
+ assertTrue(matchedUserKeys.contains(1L));
+ assertFalse(matchedUserKeys.contains(2L));
+ assertFalse(matchedUserKeys.contains(5L));
+
+ // 2. user assigned to role 4, with search entitlement on realm /even/two
+ UserService userService3 = clientFactory.create("puccini", ADMIN_PWD).getService(UserService.class);
+
+ matchedUsers = userService3.search(
+ new AnySearchQuery.Builder().realm("/even/two").
+ fiql(SyncopeClient.getUserSearchConditionBuilder().isNotNull("loginDate").query()).build());
+ assertNotNull(matchedUsers);
+ assertTrue(IterableUtils.matchesAll(matchedUsers.getResult(), new Predicate<UserTO>() {
+
+ @Override
+ public boolean evaluate(final UserTO matched) {
+ return "/even/two".equals(matched.getRealm());
+ }
+ }));
+ }
+
+ @Test
+ public void delegatedUserCRUD() {
+ String roleKey = null;
+ Long delegatedAdminKey = null;
+ try {
+ // 1. create role for full user administration, under realm /even/two
+ RoleTO role = new RoleTO();
+ role.setKey("Delegated user admin");
+ role.getEntitlements().add(StandardEntitlement.USER_CREATE);
+ role.getEntitlements().add(StandardEntitlement.USER_UPDATE);
+ role.getEntitlements().add(StandardEntitlement.USER_DELETE);
+ role.getEntitlements().add(StandardEntitlement.USER_LIST);
+ role.getEntitlements().add(StandardEntitlement.USER_READ);
+ role.getRealms().add("/even/two");
+
+ roleKey = roleService.create(role).getHeaderString(RESTHeaders.RESOURCE_KEY);
+ assertNotNull(roleKey);
+
+ // 2. as admin, create delegated admin user, and assign the role just created
+ UserTO delegatedAdmin = UserITCase.getUniqueSampleTO("admin@syncope.apache.org");
+ delegatedAdmin.getRoles().add(roleKey);
+ delegatedAdmin = createUser(delegatedAdmin).getAny();
+ delegatedAdminKey = delegatedAdmin.getKey();
+
+ // 3. instantiate a delegate user service client, for further operatins
+ UserService delegatedUserService =
+ clientFactory.create(delegatedAdmin.getUsername(), "password123").getService(UserService.class);
+
+ // 4. as delegated, create user under realm / -> fail
+ UserTO user = UserITCase.getUniqueSampleTO("delegated@syncope.apache.org");
+ try {
+ delegatedUserService.create(user);
+ fail();
+ } catch (SyncopeClientException e) {
+ assertEquals(ClientExceptionType.DelegatedAdministration, e.getType());
+ }
+
+ // 5. set realm to /even/two -> succeed
+ user.setRealm("/even/two");
+
+ Response response = delegatedUserService.create(user);
+ assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
+
+ user = response.readEntity(new GenericType<ProvisioningResult<UserTO>>() {
+ }).getAny();
+ assertEquals("surname", user.getPlainAttrMap().get("surname").getValues().get(0));
+
+ // 5. as delegated, update user attempting to move under realm / -> fail
+ UserPatch userPatch = new UserPatch();
+ userPatch.setKey(user.getKey());
+ userPatch.setRealm(new StringReplacePatchItem.Builder().value("/odd").build());
+ userPatch.getPlainAttrs().add(attrAddReplacePatch("surname", "surname2"));
+
+ try {
+ delegatedUserService.update(userPatch);
+ fail();
+ } catch (SyncopeClientException e) {
+ assertEquals(ClientExceptionType.DelegatedAdministration, e.getType());
+ }
+
+ // 6. revert realm change -> succeed
+ userPatch.setRealm(null);
+
+ response = delegatedUserService.update(userPatch);
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
+
+ user = response.readEntity(new GenericType<ProvisioningResult<UserTO>>() {
+ }).getAny();
+ assertEquals("surname2", user.getPlainAttrMap().get("surname").getValues().get(0));
+
+ // 7. as delegated, delete user
+ delegatedUserService.delete(user.getKey());
+
+ try {
+ userService.read(user.getKey());
+ fail();
+ } catch (SyncopeClientException e) {
+ assertEquals(ClientExceptionType.NotFound, e.getType());
+ }
+ } finally {
+ if (roleKey != null) {
+ roleService.delete(roleKey);
+ }
+ if (delegatedAdminKey != null) {
+ userService.delete(delegatedAdminKey);
+ }
+ }
+ }
+
+ @Test
+ public void checkFailedLogins() {
+ UserTO userTO = UserITCase.getUniqueSampleTO("checkFailedLogin@syncope.apache.org");
+ userTO.getRoles().add("User manager");
+
+ userTO = createUser(userTO).getAny();
+ assertNotNull(userTO);
+ long userId = userTO.getKey();
+
+ UserService userService2 = clientFactory.create(userTO.getUsername(), "password123").
+ getService(UserService.class);
+ assertEquals(0, getFailedLogins(userService2, userId));
+
+ // authentications failed ...
+ SyncopeClient badPwdClient = clientFactory.create(userTO.getUsername(), "wrongpwd1");
+ assertReadFails(badPwdClient);
+ assertReadFails(badPwdClient);
+
+ assertEquals(2, getFailedLogins(userService, userId));
+
+ UserService userService4 = clientFactory.create(userTO.getUsername(), "password123").
+ getService(UserService.class);
+ assertEquals(0, getFailedLogins(userService4, userId));
+ }
+
+ @Test
+ public void checkUserSuspension() {
+ UserTO userTO = UserITCase.getUniqueSampleTO("checkSuspension@syncope.apache.org");
+ userTO.setRealm("/odd");
+ userTO.getRoles().add("User manager");
+
+ userTO = createUser(userTO).getAny();
+ long userKey = userTO.getKey();
+ assertNotNull(userTO);
+
+ assertEquals(0, getFailedLogins(userService, userKey));
+
+ // authentications failed ...
+ SyncopeClient badPwdClient = clientFactory.create(userTO.getUsername(), "wrongpwd1");
+ assertReadFails(badPwdClient);
+ assertReadFails(badPwdClient);
+ assertReadFails(badPwdClient);
+
+ assertEquals(3, getFailedLogins(userService, userKey));
+
+ // last authentication before suspension
+ assertReadFails(badPwdClient);
+
+ userTO = userService.read(userTO.getKey());
+ assertNotNull(userTO);
+ assertNotNull(userTO.getFailedLogins());
+ assertEquals(3, userTO.getFailedLogins(), 0);
+ assertEquals("suspended", userTO.getStatus());
+
+ // Access with correct credentials should fail as user is suspended
+ SyncopeClient goodPwdClient = clientFactory.create(userTO.getUsername(), "password123");
+ assertReadFails(goodPwdClient);
+
+ StatusPatch reactivate = new StatusPatch();
+ reactivate.setKey(userTO.getKey());
+ reactivate.setType(StatusPatchType.REACTIVATE);
+ userTO = userService.status(reactivate).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
+ }).getAny();
+ assertNotNull(userTO);
+ assertEquals("active", userTO.getStatus());
+
+ assertEquals(0, goodPwdClient.self().getValue().getFailedLogins(), 0);
+ }
+
+ @Test
+ public void anyTypeEntitlement() {
+ final String anyTypeKey = "FOLDER " + getUUIDString();
+
+ // 1. no entitlement exists (yet) for the any type to be created
+ assertFalse(IterableUtils.matchesAny(syncopeService.info().getEntitlements(), new Predicate<String>() {
+
+ @Override
+ public boolean evaluate(final String entitlement) {
+ return entitlement.contains(anyTypeKey);
+ }
+ }));
+
+ // 2. create plain schema, any type class and any type
+ PlainSchemaTO path = new PlainSchemaTO();
+ path.setKey("path" + getUUIDString());
+ path.setType(AttrSchemaType.String);
+ path = createSchema(SchemaType.PLAIN, path);
+
+ AnyTypeClassTO anyTypeClass = new AnyTypeClassTO();
+ anyTypeClass.setKey("folder" + getUUIDString());
+ anyTypeClass.getPlainSchemas().add(path.getKey());
+ anyTypeClassService.create(anyTypeClass);
+
+ AnyTypeTO anyTypeTO = new AnyTypeTO();
+ anyTypeTO.setKey(anyTypeKey);
+ anyTypeTO.setKind(AnyTypeKind.ANY_OBJECT);
+ anyTypeTO.getClasses().add(anyTypeClass.getKey());
+ anyTypeService.create(anyTypeTO);
+
+ // 2. now entitlement exists for the any type just created
+ assertTrue(IterableUtils.matchesAny(syncopeService.info().getEntitlements(), new Predicate<String>() {
+
+ @Override
+ public boolean evaluate(final String entitlement) {
+ return entitlement.contains(anyTypeKey);
+ }
+ }));
+
+ // 3. attempt to create an instance of the type above: fail because no entitlement was assigned
+ AnyObjectTO folder = new AnyObjectTO();
+ folder.setRealm(SyncopeConstants.ROOT_REALM);
+ folder.setType(anyTypeKey);
+ folder.getPlainAttrs().add(attrTO(path.getKey(), "/home"));
+
+ SyncopeClient belliniClient = clientFactory.create("bellini", ADMIN_PWD);
+ try {
+ belliniClient.getService(AnyObjectService.class).create(folder);
+ fail();
+ } catch (SyncopeClientException e) {
+ assertEquals(ClientExceptionType.DelegatedAdministration, e.getType());
+ }
+
+ // 4. give create entitlement for the any type just created
+ RoleTO role = new RoleTO();
+ role.setKey("role" + getUUIDString());
+ role.getRealms().add(SyncopeConstants.ROOT_REALM);
+ role.getEntitlements().add(anyTypeKey + "_READ");
+ role.getEntitlements().add(anyTypeKey + "_CREATE");
+ role = createRole(role);
+
+ UserTO bellini = readUser("bellini");
+ UserPatch patch = new UserPatch();
+ patch.setKey(bellini.getKey());
+ patch.getRoles().add(new StringPatchItem.Builder().
+ operation(PatchOperation.ADD_REPLACE).value(role.getKey()).build());
+ bellini = updateUser(patch).getAny();
+ assertTrue(bellini.getRoles().contains(role.getKey()));
+
+ // 5. now the instance of the type above can be created successfully
+ belliniClient.getService(AnyObjectService.class).create(folder);
+ }
+
+ @Test
+ public void issueSYNCOPE434() {
+ Assume.assumeTrue(ActivitiDetector.isActivitiEnabledForUsers(syncopeService));
+
+ // 1. create user with group 9 (users with group 9 are defined in workflow as subject to approval)
+ UserTO userTO = UserITCase.getUniqueSampleTO("createWithReject@syncope.apache.org");
+ userTO.getMemberships().add(new MembershipTO.Builder().group(9L).build());
+
+ userTO = createUser(userTO).getAny();
+ assertNotNull(userTO);
+ assertEquals("createApproval", userTO.getStatus());
+
+ // 2. try to authenticate: fail
+ try {
+ clientFactory.create(userTO.getUsername(), "password123").self();
+ fail();
+ } catch (AccessControlException e) {
+ assertNotNull(e);
+ }
+
+ // 3. approve user
+ WorkflowFormTO form = userWorkflowService.getFormForUser(userTO.getKey());
+ form = userWorkflowService.claimForm(form.getTaskId());
+ Map<String, WorkflowFormPropertyTO> props = form.getPropertyMap();
+ props.get("approve").setValue(Boolean.TRUE.toString());
+ form.getProperties().clear();
+ form.getProperties().addAll(props.values());
+ userTO = userWorkflowService.submitForm(form);
+ assertNotNull(userTO);
+ assertEquals("active", userTO.getStatus());
+
+ // 4. try to authenticate again: success
+ Pair<Map<String, Set<String>>, UserTO> self =
+ clientFactory.create(userTO.getUsername(), "password123").self();
+ assertNotNull(self);
+ assertNotNull(self.getKey());
+ assertNotNull(self.getValue());
+ }
+
+ @Test
+ public void issueSYNCOPE164() throws Exception {
+ // 1. create user with db resource
+ UserTO user = UserITCase.getUniqueSampleTO("syncope164@syncope.apache.org");
+ user.setRealm("/even/two");
+ user.setPassword("password123");
+ user.getResources().add(RESOURCE_NAME_TESTDB);
+ user = createUser(user).getAny();
+ assertNotNull(user);
+
+ // 2. unlink the resource from the created user
+ DeassociationPatch deassociationPatch = new DeassociationPatch();
+ deassociationPatch.setKey(user.getKey());
+ deassociationPatch.setAction(ResourceDeassociationAction.UNLINK);
+ deassociationPatch.getResources().add(RESOURCE_NAME_TESTDB);
+ assertNotNull(userService.deassociate(deassociationPatch).readEntity(BulkActionResult.class));
+
+ // 3. change password on Syncope
+ UserPatch userPatch = new UserPatch();
+ userPatch.setKey(user.getKey());
+ userPatch.setPassword(new PasswordPatch.Builder().value("password234").build());
+ user = updateUser(userPatch).getAny();
+ assertNotNull(user);
+
+ // 4. check that the db resource has still the initial password value
+ final JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
+ String value = jdbcTemplate.queryForObject(
+ "SELECT PASSWORD FROM test WHERE ID=?", String.class, user.getUsername());
+ assertEquals(Encryptor.getInstance().encode("password123", CipherAlgorithm.SHA1), value.toUpperCase());
+
+ // 5. successfully authenticate with old (on db resource) and new (on internal storage) password values
+ Pair<Map<String, Set<String>>, UserTO> self =
+ clientFactory.create(user.getUsername(), "password123").self();
+ assertNotNull(self);
+ self = clientFactory.create(user.getUsername(), "password234").self();
+ assertNotNull(self);
+ }
+
+ @Test
+ public void issueSYNCOPE706() {
+ String username = getUUIDString();
+ try {
+ userService.getUserKey(username);
+ fail();
+ } catch (SyncopeClientException e) {
+ assertEquals(ClientExceptionType.NotFound, e.getType());
+ }
+
+ try {
+ clientFactory.create(username, "anypassword").self();
+ fail();
+ } catch (AccessControlException e) {
+ assertNotNull(e.getMessage());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/17d5d892/fit/core-reference/src/test/java/org/apache/syncope/fit/core/CamelRouteITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/CamelRouteITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/CamelRouteITCase.java
new file mode 100644
index 0000000..20c290f
--- /dev/null
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/CamelRouteITCase.java
@@ -0,0 +1,178 @@
+/*
+ * 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;
+
+import org.apache.syncope.fit.CamelDetector;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.List;
+import org.apache.commons.collections4.IterableUtils;
+import org.apache.syncope.common.lib.SyncopeConstants;
+import org.apache.syncope.common.lib.to.AnyTypeClassTO;
+import org.apache.syncope.common.lib.to.CamelRouteTO;
+import org.apache.syncope.common.lib.to.PlainSchemaTO;
+import org.apache.syncope.common.lib.to.UserTO;
+import org.apache.syncope.common.lib.types.AnyTypeKind;
+import org.apache.syncope.common.lib.types.AttrSchemaType;
+import org.apache.syncope.common.lib.types.SchemaType;
+import org.apache.syncope.fit.AbstractITCase;
+import org.junit.Assume;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
+@FixMethodOrder(MethodSorters.JVM)
+public class CamelRouteITCase extends AbstractITCase {
+
+ @Test
+ public void userRoutes() {
+ Assume.assumeTrue(CamelDetector.isCamelEnabledForUsers(syncopeService));
+
+ List<CamelRouteTO> userRoutes = camelRouteService.list(AnyTypeKind.USER);
+ assertNotNull(userRoutes);
+ assertEquals(16, userRoutes.size());
+ for (CamelRouteTO route : userRoutes) {
+ assertNotNull(route.getContent());
+ }
+ }
+
+ @Test
+ public void groupRoutes() {
+ Assume.assumeTrue(CamelDetector.isCamelEnabledForGroups(syncopeService));
+
+ List<CamelRouteTO> groupRoutes = camelRouteService.list(AnyTypeKind.GROUP);
+ assertNotNull(groupRoutes);
+ assertEquals(8, groupRoutes.size());
+ for (CamelRouteTO route : groupRoutes) {
+ assertNotNull(route.getContent());
+ }
+ }
+
+ private CamelRouteTO doUpdate(final String key, final String content) {
+ CamelRouteTO route = camelRouteService.read(key);
+ route.setContent(content);
+ camelRouteService.update(route);
+ // getting new route definition
+ return camelRouteService.read(key);
+ }
+
+ @Test
+ public void update() {
+ Assume.assumeTrue(CamelDetector.isCamelEnabledForUsers(syncopeService));
+
+ CamelRouteTO oldRoute = camelRouteService.read("createUser");
+ assertNotNull(oldRoute);
+ String routeContent = "<route id=\"createUser\">\n"
+ + " <from uri=\"direct:createUser\"/>\n"
+ + " <setProperty propertyName=\"actual\">\n"
+ + " <simple>${body}</simple>\n"
+ + " </setProperty>\n"
+ + " <doTry>\n"
+ + " <bean ref=\"uwfAdapter\" method=\"create(${body},${property.disablePwdPolicyCheck},\n"
+ + " ${property.enabled},${property.storePassword})\"/>\n"
+ + " <process ref=\"userCreateProcessor\" />\n"
+ + " <to uri=\"direct:createPort\"/>\n"
+ + " <to uri=\"log:myLog\"/>\n"
+ + " <doCatch> \n"
+ + " <exception>java.lang.RuntimeException</exception>\n"
+ + " <handled>\n"
+ + " <constant>false</constant>\n"
+ + " </handled>\n"
+ + " <to uri=\"direct:createPort\"/>\n"
+ + " </doCatch>\n"
+ + " </doTry>\n"
+ + "</route>";
+ try {
+ CamelRouteTO route = doUpdate("createUser", routeContent);
+ assertEquals(routeContent, route.getContent());
+ } finally {
+ doUpdate(oldRoute.getKey(), oldRoute.getContent());
+ }
+ }
+
+ @Test
+ public void scriptingUpdate() {
+ Assume.assumeTrue(CamelDetector.isCamelEnabledForUsers(syncopeService));
+
+ CamelRouteTO oldRoute = camelRouteService.read("createUser");
+ // updating route content including new attribute management
+
+ String routeContent = ""
+ + " <route id=\"createUser\">\n"
+ + " <from uri=\"direct:createUser\"/>\n"
+ + " <setProperty propertyName=\"actual\">\n"
+ + " <simple>${body}</simple>\n"
+ + " </setProperty>\n"
+ + " <setBody>\n"
+ + " <groovy>\n"
+ + " org.apache.commons.collections4."
+ + "CollectionUtils.get(request.body.getPlainAttrs(), 3).getValues().set(0,\"true\")\n"
+ + " return request.body\n"
+ + " </groovy>\n"
+ + " </setBody>\n"
+ + " <doTry>\n"
+ + " <bean ref=\"uwfAdapter\" method=\"create(${body},${property.disablePwdPolicyCheck},\n"
+ + " ${property.enabled},${property.storePassword})\"/>\n"
+ + " <process ref=\"userCreateProcessor\"/>\n"
+ + " <to uri=\"direct:createPort\"/>\n"
+ + " <doCatch> \n"
+ + " <exception>java.lang.RuntimeException</exception>\n"
+ + " <handled>\n"
+ + " <constant>false</constant>\n"
+ + " </handled>\n"
+ + " <to uri=\"direct:createPort\"/>\n"
+ + " </doCatch>\n"
+ + " </doTry>\n"
+ + " </route> ";
+ try {
+ doUpdate("createUser", routeContent);
+
+ // creating new schema attribute for user
+ PlainSchemaTO schemaTO = new PlainSchemaTO();
+ schemaTO.setKey("camelAttribute");
+ schemaTO.setType(AttrSchemaType.String);
+ createSchema(SchemaType.PLAIN, schemaTO);
+
+ AnyTypeClassTO typeClass = new AnyTypeClassTO();
+ typeClass.setKey("camelAttribute");
+ typeClass.getPlainSchemas().add(schemaTO.getKey());
+ anyTypeClassService.create(typeClass);
+
+ UserTO userTO = new UserTO();
+ userTO.setRealm(SyncopeConstants.ROOT_REALM);
+ userTO.getAuxClasses().add(typeClass.getKey());
+ String userId = getUUIDString() + "camelUser@syncope.apache.org";
+ userTO.setUsername(userId);
+ userTO.setPassword("password123");
+ userTO.getPlainAttrs().add(attrTO("userId", userId));
+ userTO.getPlainAttrs().add(attrTO("fullname", userId));
+ userTO.getPlainAttrs().add(attrTO("surname", userId));
+ userTO.getPlainAttrs().add(attrTO("camelAttribute", "false"));
+
+ userTO = createUser(userTO).getAny();
+ assertNotNull(userTO);
+ assertEquals("true", IterableUtils.get(userTO.getPlainAttrs(), 3).getValues().get(0));
+ } finally {
+ doUpdate(oldRoute.getKey(), oldRoute.getContent());
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/17d5d892/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ConfigurationITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ConfigurationITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ConfigurationITCase.java
new file mode 100644
index 0000000..574c147
--- /dev/null
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ConfigurationITCase.java
@@ -0,0 +1,173 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+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.io.UnsupportedEncodingException;
+import java.util.List;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+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.to.AttrTO;
+import org.apache.syncope.common.lib.to.PlainSchemaTO;
+import org.apache.syncope.common.lib.types.AttrSchemaType;
+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.fit.AbstractITCase;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
+@FixMethodOrder(MethodSorters.JVM)
+public class ConfigurationITCase extends AbstractITCase {
+
+ @Test
+ public void create() {
+ PlainSchemaTO testKey = new PlainSchemaTO();
+ testKey.setKey("testKey" + getUUIDString());
+ testKey.setType(AttrSchemaType.String);
+ createSchema(SchemaType.PLAIN, testKey);
+
+ AttrTO conf = new AttrTO.Builder().schema(testKey.getKey()).value("testValue").build();
+
+ configurationService.set(conf);
+
+ AttrTO actual = configurationService.get(conf.getSchema());
+ assertEquals(actual, conf);
+ }
+
+ @Test
+ public void createRequired() {
+ PlainSchemaTO testKey = new PlainSchemaTO();
+ testKey.setKey("testKey" + getUUIDString());
+ testKey.setType(AttrSchemaType.String);
+ testKey.setMandatoryCondition("true");
+ createSchema(SchemaType.PLAIN, testKey);
+
+ AttrTO conf = new AttrTO.Builder().schema(testKey.getKey()).build();
+ try {
+ configurationService.set(conf);
+ fail();
+ } catch (SyncopeClientException e) {
+ assertEquals(ClientExceptionType.RequiredValuesMissing, e.getType());
+ }
+
+ conf.getValues().add("testValue");
+ configurationService.set(conf);
+
+ AttrTO actual = configurationService.get(conf.getSchema());
+ assertEquals(actual, conf);
+ }
+
+ @Test
+ public void delete() throws UnsupportedEncodingException {
+ try {
+ configurationService.delete("nonExistent");
+ fail("The delete operation should throw an exception because of nonExistent schema");
+ } catch (SyncopeClientException e) {
+ assertEquals(Response.Status.NOT_FOUND, e.getType().getResponseStatus());
+ }
+
+ AttrTO tokenLength = configurationService.get("token.length");
+
+ configurationService.delete("token.length");
+
+ AttrTO actual = configurationService.get(tokenLength.getSchema());
+ assertNotEquals(actual, tokenLength);
+
+ configurationService.set(tokenLength);
+
+ actual = configurationService.get(tokenLength.getSchema());
+ assertEquals(actual, tokenLength);
+ }
+
+ @Test
+ public void list() {
+ List<AttrTO> wholeConf = configurationService.list();
+ assertNotNull(wholeConf);
+ for (AttrTO conf : wholeConf) {
+ assertNotNull(conf);
+ }
+ }
+
+ @Test
+ public void read() {
+ AttrTO conf = configurationService.get("token.expireTime");
+ assertNotNull(conf);
+ }
+
+ @Test
+ public void update() {
+ AttrTO expireTime = configurationService.get("token.expireTime");
+ int value = Integer.parseInt(expireTime.getValues().get(0));
+ value++;
+ expireTime.getValues().set(0, value + "");
+
+ configurationService.set(expireTime);
+
+ AttrTO newConfigurationTO = configurationService.get(expireTime.getSchema());
+ assertEquals(expireTime, newConfigurationTO);
+ }
+
+ @Test
+ public void dbExport() throws IOException {
+ Response response = configurationService.export();
+ assertNotNull(response);
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusInfo().getStatusCode());
+ assertTrue(response.getMediaType().toString().startsWith(MediaType.TEXT_XML));
+ String contentDisposition = response.getHeaderString(HttpHeaders.CONTENT_DISPOSITION);
+ assertNotNull(contentDisposition);
+
+ Object entity = response.getEntity();
+ assertTrue(entity instanceof InputStream);
+ String configExport = IOUtils.toString((InputStream) entity, SyncopeConstants.DEFAULT_ENCODING);
+ assertFalse(configExport.isEmpty());
+ assertTrue(configExport.length() > 1000);
+ }
+
+ @Test
+ public void issueSYNCOPE418() {
+ PlainSchemaTO failing = new PlainSchemaTO();
+ failing.setKey("http://schemas.examples.org/security/authorization/organizationUnit");
+ failing.setType(AttrSchemaType.String);
+
+ try {
+ createSchema(SchemaType.PLAIN, failing);
+ fail();
+ } catch (SyncopeClientException e) {
+ assertEquals(ClientExceptionType.InvalidPlainSchema, e.getType());
+
+ assertNotNull(e.getElements());
+ assertEquals(1, e.getElements().size());
+ assertTrue(e.getElements().iterator().next().contains(EntityViolationType.InvalidName.name()));
+ }
+ }
+}