syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject svn commit: r1431495 [2/2] - in /syncope/trunk/core: ./ src/main/java/org/apache/syncope/core/persistence/beans/ src/main/java/org/apache/syncope/core/sync/ src/test/java/org/apache/syncope/core/connid/ src/test/java/org/apache/syncope/core/persistence...
Date Thu, 10 Jan 2013 16:52:32 GMT
Propchange: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/data/ResourceDataTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/data/ResourceDataTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/data/ResourceDataTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: syncope/trunk/core/src/test/java/org/apache/syncope/core/sync/SyncTaskTest.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/sync/SyncTaskTest.java?rev=1431495&view=auto
==============================================================================
--- syncope/trunk/core/src/test/java/org/apache/syncope/core/sync/SyncTaskTest.java (added)
+++ syncope/trunk/core/src/test/java/org/apache/syncope/core/sync/SyncTaskTest.java Thu Jan
10 16:52:31 2013
@@ -0,0 +1,123 @@
+/*
+ * 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.core.sync;
+
+import static org.junit.Assert.*;
+
+import org.apache.syncope.client.to.UserTO;
+import org.apache.syncope.core.persistence.beans.ExternalResource;
+import org.apache.syncope.core.persistence.beans.SyncTask;
+import org.apache.syncope.core.persistence.dao.AbstractDAOTest;
+import org.apache.syncope.core.persistence.dao.ResourceDAO;
+import org.apache.syncope.core.persistence.dao.TaskDAO;
+import org.apache.syncope.core.persistence.validation.entity.InvalidEntityException;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+@Transactional
+public class SyncTaskTest extends AbstractDAOTest {
+
+    @Autowired
+    private TaskDAO taskDAO;
+
+    @Autowired
+    private ResourceDAO resourceDAO;
+
+    @Test
+    public void saveSyncTask() {
+        ExternalResource resource = resourceDAO.find("ws-target-resource-1");
+        assertNotNull(resource);
+
+        SyncTask task = new SyncTask();
+        task.setName("saveSyncTask");
+        task.setDescription("SyncTask description");
+        task.setUserTemplate(new UserTO());
+        task.setCronExpression("BLA BLA");
+
+        // this save() fails because of an invalid Cron Expression
+        InvalidEntityException exception = null;
+        try {
+            taskDAO.save(task);
+        } catch (InvalidEntityException e) {
+            exception = e;
+        }
+        assertNotNull(exception);
+
+        task.setCronExpression(null);
+        // this save() fails because a SyncTask requires a target resource
+        exception = null;
+        try {
+            taskDAO.save(task);
+        } catch (InvalidEntityException e) {
+            exception = e;
+        }
+        assertNotNull(exception);
+
+        task.setResource(resource);
+        task.setActionsClassName(getClass().getName());
+
+        // this save() fails because jobActionsClassName does not implement 
+        // the right interface
+        exception = null;
+        try {
+            taskDAO.save(task);
+        } catch (InvalidEntityException e) {
+            exception = e;
+        }
+        assertNotNull(exception);
+
+        task.setActionsClassName(TestSyncActions.class.getName());
+        // this save() finally works
+        task = taskDAO.save(task);
+        assertNotNull(task);
+
+        SyncTask actual = taskDAO.find(task.getId());
+        assertEquals(task, actual);
+    }
+
+    @Test
+    public void issueSYNCOPE144() {
+        ExternalResource resource = resourceDAO.find("ws-target-resource-1");
+        assertNotNull(resource);
+
+        SyncTask task = new SyncTask();
+
+        task.setResource(resource);
+        task.setName("issueSYNCOPE144");
+        task.setDescription("issueSYNCOPE144 Description");
+        task.setActionsClassName(TestSyncActions.class.getName());
+
+        task = taskDAO.save(task);
+        assertNotNull(task);
+
+        SyncTask actual = taskDAO.find(task.getId());
+        assertEquals(task, actual);
+        assertEquals("issueSYNCOPE144", actual.getName());
+        assertEquals("issueSYNCOPE144 Description", actual.getDescription());
+
+        actual.setName("issueSYNCOPE144_2");
+        actual.setDescription("issueSYNCOPE144 Description_2");
+
+        actual = taskDAO.save(actual);
+        assertNotNull(actual);
+        assertEquals("issueSYNCOPE144_2", actual.getName());
+        assertEquals("issueSYNCOPE144 Description_2", actual.getDescription());
+    }
+}

Propchange: syncope/trunk/core/src/test/java/org/apache/syncope/core/sync/SyncTaskTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: syncope/trunk/core/src/test/java/org/apache/syncope/core/sync/SyncTaskTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: syncope/trunk/core/src/test/java/org/apache/syncope/core/sync/SyncTaskTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: syncope/trunk/core/src/test/java/org/apache/syncope/core/sync/TestSyncActions.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/sync/TestSyncActions.java?rev=1431495&view=auto
==============================================================================
--- syncope/trunk/core/src/test/java/org/apache/syncope/core/sync/TestSyncActions.java (added)
+++ syncope/trunk/core/src/test/java/org/apache/syncope/core/sync/TestSyncActions.java Thu
Jan 10 16:52:31 2013
@@ -0,0 +1,77 @@
+/*
+ * 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.core.sync;
+
+import java.util.Collections;
+import org.apache.syncope.client.mod.AbstractAttributableMod;
+import org.apache.syncope.client.mod.AttributeMod;
+import org.apache.syncope.client.to.AbstractAttributableTO;
+import org.apache.syncope.client.to.AttributeTO;
+import org.identityconnectors.framework.common.objects.SyncDelta;
+import org.identityconnectors.framework.common.objects.SyncResultsHandler;
+import org.quartz.JobExecutionException;
+
+public class TestSyncActions extends DefaultSyncActions {
+
+    private int counter = 0;
+
+    @Override
+    public <T extends AbstractAttributableTO> SyncDelta beforeCreate(final SyncResultsHandler
handler,
+            final SyncDelta delta, final T subject) throws JobExecutionException {
+
+        AttributeTO attrTO = null;
+        for (int i = 0; i < subject.getAttributes().size(); i++) {
+            if ("fullname".equals(subject.getAttributes().get(i).getSchema())) {
+                attrTO = subject.getAttributes().get(i);
+            }
+        }
+        if (attrTO == null) {
+            attrTO = new AttributeTO();
+            attrTO.setSchema("fullname");
+            subject.addAttribute(attrTO);
+        }
+        attrTO.setValues(Collections.singletonList(String.valueOf(counter++)));
+
+        return delta;
+    }
+
+    @Override
+    public <T extends AbstractAttributableTO, K extends AbstractAttributableMod> SyncDelta
beforeUpdate(
+            final SyncResultsHandler handler, final SyncDelta delta, final T subject, final
K subjectMod)
+            throws JobExecutionException {
+
+        subjectMod.addAttributeToBeRemoved("fullname");
+
+        AttributeMod fullnameMod = null;
+        for (AttributeMod attrMod : subjectMod.getAttributesToBeUpdated()) {
+            if ("fullname".equals(attrMod.getSchema())) {
+                fullnameMod = attrMod;
+            }
+        }
+        if (fullnameMod == null) {
+            fullnameMod = new AttributeMod();
+            fullnameMod.setSchema("fullname");
+            subjectMod.addAttributeToBeUpdated(fullnameMod);
+        }
+
+        fullnameMod.setValuesToBeAdded(Collections.singletonList(String.valueOf(counter++)));
+
+        return delta;
+    }
+}

Propchange: syncope/trunk/core/src/test/java/org/apache/syncope/core/sync/TestSyncActions.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: syncope/trunk/core/src/test/java/org/apache/syncope/core/sync/TestSyncActions.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: syncope/trunk/core/src/test/java/org/apache/syncope/core/sync/TestSyncActions.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message