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 2018/04/12 10:42:08 UTC

[5/6] syncope git commit: [SYNCOPE-1299] Core implementation

http://git-wip-us.apache.org/repos/asf/syncope/blob/e5860a76/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ReconciliationITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ReconciliationITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ReconciliationITCase.java
new file mode 100644
index 0000000..172e69c
--- /dev/null
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ReconciliationITCase.java
@@ -0,0 +1,134 @@
+/*
+ * 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.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Date;
+import javax.sql.DataSource;
+import org.apache.syncope.common.lib.to.AnyObjectTO;
+import org.apache.syncope.common.lib.to.AttrTO;
+import org.apache.syncope.common.lib.to.ReconciliationRequest;
+import org.apache.syncope.common.lib.to.ReconciliationStatus;
+import org.apache.syncope.common.lib.types.AnyTypeKind;
+import org.apache.syncope.common.lib.types.ReconciliationAction;
+import org.apache.syncope.fit.AbstractITCase;
+import org.identityconnectors.framework.common.objects.OperationalAttributes;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
+
+@SpringJUnitConfig(locations = { "classpath:testJDBCEnv.xml" })
+public class ReconciliationITCase extends AbstractITCase {
+
+    @Autowired
+    private DataSource testDataSource;
+
+    @Test
+    public void push() {
+        // 1. create printer, with no resources
+        AnyObjectTO printer = AnyObjectITCase.getSampleTO("reconciliation");
+        printer.getResources().clear();
+        printer = createAnyObject(printer).getEntity();
+        assertNotNull(printer.getKey());
+
+        // 2. verify no printer with that name is on the external resource's db
+        JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
+        assertEquals(0, jdbcTemplate.queryForList(
+                "SELECT id FROM testPRINTER WHERE printername=?", printer.getName()).size());
+
+        // 3. verify reconciliation status
+        ReconciliationStatus status =
+                reconciliationService.status(AnyTypeKind.ANY_OBJECT, printer.getName(), "resource-db-scripted");
+        assertNotNull(status);
+        assertNotNull(status.getOnSyncope());
+        assertNull(status.getOnResource());
+
+        // 4. push
+        ReconciliationRequest request = new ReconciliationRequest();
+        request.setAction(ReconciliationAction.PUSH);
+        request.setAnyKey(printer.getKey());
+        request.setAnyTypeKind(AnyTypeKind.ANY_OBJECT);
+        request.setResourceKey("resource-db-scripted");
+        reconciliationService.reconcile(request);
+
+        // 5. verify that printer is now propagated
+        assertEquals(1, jdbcTemplate.queryForList(
+                "SELECT id FROM testPRINTER WHERE printername=?", printer.getName()).size());
+
+        // 6. verify resource was not assigned
+        printer = anyObjectService.read(printer.getKey());
+        assertTrue(printer.getResources().isEmpty());
+
+        // 7. verify reconciliation status
+        status = reconciliationService.status(AnyTypeKind.ANY_OBJECT, printer.getName(), "resource-db-scripted");
+        assertNotNull(status);
+        assertNotNull(status.getOnSyncope());
+        assertNotNull(status.getOnResource());
+
+        // __ENABLE__ management depends on the actual connector...
+        AttrTO enable = status.getOnSyncope().getAttr(OperationalAttributes.ENABLE_NAME).orElse(null);
+        if (enable != null) {
+            status.getOnSyncope().getAttrs().remove(enable);
+        }
+        assertEquals(status.getOnSyncope(), status.getOnResource());
+    }
+
+    @Test
+    public void pull() {
+        // 1. create printer, with no resources
+        AnyObjectTO printer = AnyObjectITCase.getSampleTO("reconciliation");
+        printer.getResources().clear();
+        printer = createAnyObject(printer).getEntity();
+        assertNotNull(printer.getKey());
+        assertNotEquals("Nowhere", printer.getPlainAttr("location").get().getValues().get(0));
+
+        // 2. create table into the external resource's db, with same name
+        JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
+        jdbcTemplate.update(
+                "INSERT INTO TESTPRINTER (id, printername, location, deleted, lastmodification) VALUES (?,?,?,?,?)",
+                printer.getKey(), printer.getName(), "Nowhere", false, new Date());
+
+        // 3. verify reconciliation status
+        ReconciliationStatus status =
+                reconciliationService.status(AnyTypeKind.ANY_OBJECT, printer.getName(), "resource-db-scripted");
+        assertNotNull(status);
+        assertNotNull(status.getOnSyncope());
+        assertNotNull(status.getOnResource());
+        assertNotEquals(status.getOnSyncope().getAttr("LOCATION"), status.getOnResource().getAttr("LOCATION"));
+
+        // 4. pull
+        ReconciliationRequest request = new ReconciliationRequest();
+        request.setAction(ReconciliationAction.PULL);
+        request.setAnyKey(printer.getKey());
+        request.setAnyTypeKind(AnyTypeKind.ANY_OBJECT);
+        request.setResourceKey("resource-db-scripted");
+        reconciliationService.reconcile(request);
+
+        // 5. verify reconciliation result (and resource is still not assigned)
+        printer = anyObjectService.read(printer.getKey());
+        assertEquals("Nowhere", printer.getPlainAttr("location").get().getValues().get(0));
+        assertTrue(printer.getResources().isEmpty());
+    }
+}