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/03/30 11:49:15 UTC
[3/3] syncope git commit: [SYNCOPE-753] Adding test to migrate conf
[SYNCOPE-753] Adding test to migrate conf
Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/3d286f86
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/3d286f86
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/3d286f86
Branch: refs/heads/master
Commit: 3d286f86fb9ed30f90bb0324dbca39f5946e2f2d
Parents: 3d58788
Author: Francesco Chicchiriccò <il...@apache.org>
Authored: Wed Mar 30 11:49:05 2016 +0200
Committer: Francesco Chicchiriccò <il...@apache.org>
Committed: Wed Mar 30 11:49:05 2016 +0200
----------------------------------------------------------------------
client/cli/pom.xml | 22 +
.../cli/commands/migrate/MigrateConf.java | 145 ++-
.../client/cli/commands/MigrateTest.java | 93 ++
.../client/cli/util/CommandUtilsTest.java | 16 +-
.../client/cli/util/JasyptUtilsTest.java | 8 +-
client/cli/src/test/resources/content12.xml | 1154 ++++++++++++++++++
client/cli/src/test/resources/log4j2.xml | 33 +
client/cli/src/test/resources/schema20.sql | 218 ++++
client/cli/src/test/resources/test.properties | 17 +
.../jpa/content/ContentLoaderHandler.java | 32 +-
.../jpa/content/XMLContentLoader.java | 2 +-
.../org/apache/syncope/fit/cli/CLIITCase.java | 7 +-
12 files changed, 1677 insertions(+), 70 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/syncope/blob/3d286f86/client/cli/pom.xml
----------------------------------------------------------------------
diff --git a/client/cli/pom.xml b/client/cli/pom.xml
index 5325a2f..f8ea8ae 100644
--- a/client/cli/pom.xml
+++ b/client/cli/pom.xml
@@ -81,6 +81,22 @@ under the License.
</dependency>
<dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-jdbc</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.syncope.core</groupId>
+ <artifactId>syncope-core-persistence-jpa</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
@@ -153,6 +169,12 @@ under the License.
</resource>
</resources>
+ <testResources>
+ <testResource>
+ <directory>src/test/resources</directory>
+ <filtering>true</filtering>
+ </testResource>
+ </testResources>
</build>
<profiles>
http://git-wip-us.apache.org/repos/asf/syncope/blob/3d286f86/client/cli/src/main/java/org/apache/syncope/client/cli/commands/migrate/MigrateConf.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/migrate/MigrateConf.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/migrate/MigrateConf.java
index 563db63..8de6d04 100644
--- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/migrate/MigrateConf.java
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/migrate/MigrateConf.java
@@ -34,6 +34,7 @@ import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
+import org.apache.commons.lang3.StringUtils;
import org.apache.cxf.staxutils.PrettyPrintXMLStreamWriter;
import org.apache.syncope.client.cli.Input;
import org.slf4j.Logger;
@@ -82,6 +83,45 @@ public class MigrateConf {
return value;
}
+ private static String toNewIntMappingType(final String oldIntMappingType) {
+ String newIntMappingType;
+ switch (oldIntMappingType) {
+ case "UserId":
+ newIntMappingType = "UserKey";
+ break;
+
+ case "UserSchema":
+ case "MembershipSchema":
+ newIntMappingType = "UserPlainSchema";
+ break;
+
+ case "MembershipDerivedSchema":
+ newIntMappingType = "UserDerivedSchema";
+ break;
+
+ case "RoleId":
+ newIntMappingType = "GroupKey";
+ break;
+
+ case "RoleName":
+ newIntMappingType = "GroupName";
+ break;
+
+ case "RoleOwnerSchema":
+ newIntMappingType = "GroupOwnerSchema";
+ break;
+
+ case "RoleSchema":
+ newIntMappingType = "RolePlainSchema";
+ break;
+
+ default:
+ newIntMappingType = oldIntMappingType;
+ }
+
+ return newIntMappingType;
+ }
+
private static void exec(final String src, final String dst) throws XMLStreamException, IOException {
XMLStreamWriter writer = new PrettyPrintXMLStreamWriter(
OUTPUT_FACTORY.createXMLStreamWriter(new FileWriter(dst)), 2);
@@ -247,7 +287,8 @@ public class MigrateConf {
JsonNode allowNullPassword = specification.get("allowNullPassword");
if (allowNullPassword != null) {
- writer.writeAttribute("allowNullPassword", allowNullPassword.asText());
+ writer.writeAttribute(
+ "allowNullPassword", allowNullPassword.asBoolean() ? "1" : "0");
specification.remove("allowNullPassword");
}
JsonNode historyLength = specification.get("historyLength");
@@ -278,7 +319,8 @@ public class MigrateConf {
JsonNode propagateSuspension = specification.get("propagateSuspension");
if (propagateSuspension != null) {
- writer.writeAttribute("propagateSuspension", propagateSuspension.asText());
+ writer.writeAttribute(
+ "propagateSuspension", propagateSuspension.asBoolean() ? "1" : "0");
specification.remove("propagateSuspension");
}
JsonNode permittedLoginRetries = specification.get("permittedLoginRetries");
@@ -293,7 +335,7 @@ public class MigrateConf {
writer.writeStartElement("AccountRuleConfInstance");
writer.writeAttribute("id", policyId);
- writer.writeAttribute("passwordPolicy_id", policyId);
+ writer.writeAttribute("accountPolicy_id", policyId);
writer.writeAttribute("serializedInstance", specification.toString());
writer.writeEndElement();
break;
@@ -319,7 +361,7 @@ public class MigrateConf {
if (!connInstanceCapabilities.contains(connInstanceId + capabilities)) {
writer.writeStartElement("ConnInstance_capabilities");
writer.writeAttribute("ConnInstance_id", connInstanceId);
- writer.writeAttribute("capabilities", capabilities);
+ writer.writeAttribute("capability", capabilities);
writer.writeEndElement();
connInstanceCapabilities.add(connInstanceId + capabilities);
@@ -329,15 +371,22 @@ public class MigrateConf {
case "externalresource":
writer.writeStartElement("ExternalResource");
copyAttrs(reader, writer,
- "syncTraceLevel", "userializedSyncToken", "rserializedSyncToken");
+ "syncTraceLevel", "userializedSyncToken", "rserializedSyncToken",
+ "propagationMode", "propagationPrimary", "syncPolicy_id");
+ String syncPolicyId = getAttributeValue(reader, "syncPolicy_id");
writer.writeAttribute(
"pullTraceLevel", getAttributeValue(reader, "syncTraceLevel"));
+ if (StringUtils.isNotBlank(syncPolicyId)) {
+ writer.writeAttribute(
+ "pullPolicy_id", getAttributeValue(reader, "syncPolicy_id"));
+ }
writer.writeEndElement();
break;
case "externalresource_propactions":
writer.writeStartElement("ExternalResource_PropActions");
- copyAttrs(reader, writer, "element");
+
+ writer.writeAttribute("resource_name", getAttributeValue(reader, "externalResource_name"));
String propActionClassName = getAttributeValue(reader, "element");
switch (propActionClassName) {
@@ -363,7 +412,8 @@ public class MigrateConf {
case "policy_externalresource":
writer.writeStartElement("AccountPolicy_ExternalResource");
- copyAttrs(reader, writer);
+ writer.writeAttribute("accountPolicy_id", getAttributeValue(reader, "account_policy_id"));
+ writer.writeAttribute("resource_name", getAttributeValue(reader, "resource_name"));
writer.writeEndElement();
break;
@@ -382,7 +432,7 @@ public class MigrateConf {
writer.writeAttribute("provision_id", umappingId);
String uaccountLink = getAttributeValue(reader, "accountlink");
- if (uaccountLink != null && !uaccountLink.isEmpty()) {
+ if (StringUtils.isNotBlank(uaccountLink)) {
writer.writeAttribute("connObjectLink", uaccountLink);
}
writer.writeEndElement();
@@ -396,14 +446,15 @@ public class MigrateConf {
reporter.writeEndElement();
} else {
writer.writeStartElement("MappingItem");
- copyAttrs(reader, writer, "accountid");
+ copyAttrs(reader, writer, "accountid", "intMappingType");
+ writer.writeAttribute("intMappingType", toNewIntMappingType(uIntMappingType));
writer.writeAttribute("connObjectKey", getAttributeValue(reader, "accountid"));
writer.writeEndElement();
}
break;
case "rmapping":
- String rmappingId = getAttributeValue(reader, "id");
+ String rmappingId = "10" + getAttributeValue(reader, "id");
writer.writeStartElement("Provision");
writer.writeAttribute("id", rmappingId);
writer.writeAttribute(
@@ -417,7 +468,7 @@ public class MigrateConf {
writer.writeAttribute("provision_id", rmappingId);
String raccountLink = getAttributeValue(reader, "accountlink");
- if (raccountLink != null && !raccountLink.isEmpty()) {
+ if (StringUtils.isNotBlank(raccountLink)) {
writer.writeAttribute("connObjectLink", raccountLink);
}
writer.writeEndElement();
@@ -431,7 +482,8 @@ public class MigrateConf {
reporter.writeEndElement();
} else {
writer.writeStartElement("MappingItem");
- copyAttrs(reader, writer, "accountid");
+ copyAttrs(reader, writer, "accountid", "intMappingType");
+ writer.writeAttribute("intMappingType", toNewIntMappingType(rIntMappingType));
writer.writeAttribute("connObjectKey", getAttributeValue(reader, "accountid"));
writer.writeEndElement();
}
@@ -441,7 +493,8 @@ public class MigrateConf {
writer.writeStartElement("Task");
copyAttrs(reader, writer,
"DTYPE", "propagationMode", "subjectType", "subjectId", "xmlAttributes",
- "jobClassName", "userTemplate", "roleTemplate", "userFilter", "roleFilter");
+ "jobClassName", "userTemplate", "roleTemplate", "userFilter", "roleFilter",
+ "propagationOperation", "syncStatus", "fullReconciliation");
String taskId = getAttributeValue(reader, "id");
@@ -454,29 +507,48 @@ public class MigrateConf {
"anyKey", getAttributeValue(reader, "subjectId"));
writer.writeAttribute(
"attributes", getAttributeValue(reader, "xmlAttributes"));
+ writer.writeAttribute(
+ "operation", getAttributeValue(reader, "propagationOperation"));
writer.writeEndElement();
break;
case "SyncTask":
writer.writeAttribute("DTYPE", "PullTask");
+ writer.writeAttribute("pullStatus", getAttributeValue(reader, "syncStatus"));
+
+ String fullReconciliation = getAttributeValue(reader, "fullReconciliation");
+ if ("1".equals(fullReconciliation)) {
+ writer.writeAttribute("pullMode", "FULL_RECONCILIATION");
+ } else if ("0".equals(fullReconciliation)) {
+ writer.writeAttribute("pullMode", "INCREMENTAL");
+ }
+
writer.writeEndElement();
String userTemplate = getAttributeValue(reader, "userTemplate");
- if (userTemplate != null && !userTemplate.isEmpty()) {
+ if (StringUtils.isNotBlank(userTemplate)) {
+ ObjectNode template = (ObjectNode) OBJECT_MAPPER.readTree(userTemplate);
+ JsonNode plainAttrs = template.remove("attrs");
+ template.set("plainAttrs", plainAttrs);
+
writer.writeStartElement("AnyTemplatePullTask");
- writer.writeAttribute("id", taskId);
+ writer.writeAttribute("id", taskId + "1");
writer.writeAttribute("pullTask_id", taskId);
writer.writeAttribute("anyType_name", "USER");
- writer.writeAttribute("template", userTemplate);
+ writer.writeAttribute("template", template.toString());
writer.writeEndElement();
}
String roleTemplate = getAttributeValue(reader, "roleTemplate");
- if (roleTemplate != null && !roleTemplate.isEmpty()) {
+ if (StringUtils.isNotBlank(roleTemplate)) {
+ ObjectNode template = (ObjectNode) OBJECT_MAPPER.readTree(roleTemplate);
+ JsonNode plainAttrs = template.remove("attrs");
+ template.set("plainAttrs", plainAttrs);
+
writer.writeStartElement("AnyTemplatePullTask");
- writer.writeAttribute("id", taskId);
+ writer.writeAttribute("id", taskId + "2");
writer.writeAttribute("pullTask_id", taskId);
writer.writeAttribute("anyType_name", "GROUP");
- writer.writeAttribute("template", roleTemplate);
+ writer.writeAttribute("template", template.toString());
writer.writeEndElement();
}
break;
@@ -498,19 +570,19 @@ public class MigrateConf {
writer.writeEndElement();
String userFilter = getAttributeValue(reader, "userFilter");
- if (userFilter != null && !userFilter.isEmpty()) {
+ if (StringUtils.isNotBlank(userFilter)) {
writer.writeStartElement("PushTaskAnyFilter");
- writer.writeAttribute("id", taskId);
- writer.writeAttribute("pusTask_id", taskId);
+ writer.writeAttribute("id", taskId + "1");
+ writer.writeAttribute("pushTask_id", taskId);
writer.writeAttribute("anyType_name", "USER");
writer.writeAttribute("fiql", userFilter);
writer.writeEndElement();
}
String roleFilter = getAttributeValue(reader, "roleFilter");
- if (roleFilter != null && !roleFilter.isEmpty()) {
+ if (StringUtils.isNotBlank(roleFilter)) {
writer.writeStartElement("PushTaskAnyFilter");
- writer.writeAttribute("id", taskId);
- writer.writeAttribute("pusTask_id", taskId);
+ writer.writeAttribute("id", taskId + "2");
+ writer.writeAttribute("pushTask_id", taskId);
writer.writeAttribute("anyType_name", "GROUP");
writer.writeAttribute("fiql", roleFilter);
writer.writeEndElement();
@@ -556,22 +628,23 @@ public class MigrateConf {
case "notification":
writer.writeStartElement("Notification");
- copyAttrs(reader, writer, "recipientAttrType", "template");
+ copyAttrs(reader, writer, "recipientAttrType", "template",
+ "userAbout", "roleAbout", "recipients");
String recipientAttrType = getAttributeValue(reader, "recipientAttrType");
- if ("UserSchema".equals(recipientAttrType)) {
- recipientAttrType = "UserPlainSchema";
- } else if ("RoleSchema".equals(recipientAttrType)) {
- recipientAttrType = "GroupPlainSchema";
+ if (StringUtils.isNotBlank(recipientAttrType)) {
+ writer.writeAttribute("recipientAttrType", toNewIntMappingType(recipientAttrType));
}
- writer.writeAttribute("recipientAttrType", recipientAttrType);
- writer.writeAttribute(
- "template_name", getAttributeValue(reader, "template"));
+ String recipients = getAttributeValue(reader, "recipients");
+ if (StringUtils.isNotBlank(recipients)) {
+ writer.writeAttribute("recipientsFIQL", getAttributeValue(reader, "recipients"));
+ }
+ writer.writeAttribute("template_name", getAttributeValue(reader, "template"));
writer.writeEndElement();
String notificationId = getAttributeValue(reader, "id");
String userAbout = getAttributeValue(reader, "userAbout");
- if (userAbout != null && !userAbout.isEmpty()) {
+ if (StringUtils.isNotBlank(userAbout)) {
writer.writeStartElement("AnyAbout");
writer.writeAttribute("id", notificationId);
writer.writeAttribute("notification_id", notificationId);
@@ -580,7 +653,7 @@ public class MigrateConf {
writer.writeEndElement();
}
String roleAbout = getAttributeValue(reader, "roleAbout");
- if (roleAbout != null && !roleAbout.isEmpty()) {
+ if (StringUtils.isNotBlank(roleAbout)) {
writer.writeStartElement("AnyAbout");
writer.writeAttribute("id", notificationId);
writer.writeAttribute("notification_id", notificationId);
@@ -592,7 +665,7 @@ public class MigrateConf {
case "notification_events":
writer.writeStartElement("Notification_events");
- copyAttrs(reader, writer, "event");
+ copyAttrs(reader, writer, "events");
writer.writeAttribute(
"event", getAttributeValue(reader, "events").
replaceAll("Controller", "Logic"));
http://git-wip-us.apache.org/repos/asf/syncope/blob/3d286f86/client/cli/src/test/java/org/apache/syncope/client/cli/commands/MigrateTest.java
----------------------------------------------------------------------
diff --git a/client/cli/src/test/java/org/apache/syncope/client/cli/commands/MigrateTest.java b/client/cli/src/test/java/org/apache/syncope/client/cli/commands/MigrateTest.java
new file mode 100644
index 0000000..e782744
--- /dev/null
+++ b/client/cli/src/test/java/org/apache/syncope/client/cli/commands/MigrateTest.java
@@ -0,0 +1,93 @@
+/*
+ * 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.client.cli.commands;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+import javax.sql.DataSource;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+import org.apache.commons.io.IOUtils;
+import org.apache.syncope.client.cli.Input;
+import org.apache.syncope.client.cli.commands.migrate.MigrateCommand;
+import org.apache.syncope.core.persistence.jpa.content.ContentLoaderHandler;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.jdbc.datasource.DriverManagerDataSource;
+import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
+
+public class MigrateTest {
+
+ private static final String ROOT_ELEMENT = "dataset";
+
+ private static String BASE_PATH;
+
+ @BeforeClass
+ public static void before() {
+ Properties props = new Properties();
+ InputStream propStream = null;
+ try {
+ propStream = MigrateTest.class.getResourceAsStream("/test.properties");
+ props.load(propStream);
+
+ BASE_PATH = props.getProperty("testClasses");
+ } catch (IOException e) {
+ fail(e.getMessage());
+ } finally {
+ IOUtils.closeQuietly(propStream);
+ }
+ assertNotNull(BASE_PATH);
+ }
+
+ @Test
+ public void conf() throws Exception {
+ // 1. migrate
+ String[] args = new String[4];
+ args[0] = "migrate";
+ args[1] = "--conf";
+ args[2] = BASE_PATH + File.separator + "content12.xml";
+ args[3] = BASE_PATH + File.separator + "MasterContent.xml";
+
+ new MigrateCommand().execute(new Input(args));
+
+ // 2. initialize db as persistence-jpa does
+ DataSource dataSource = new DriverManagerDataSource("jdbc:h2:mem:syncopedb;DB_CLOSE_DELAY=-1", "sa", null);
+
+ new ResourceDatabasePopulator(new ClassPathResource("/schema20.sql")).execute(dataSource);
+
+ // 3. attempt to set initial content from the migrated MasterContent.xml
+ SAXParserFactory factory = SAXParserFactory.newInstance();
+ InputStream in = null;
+ try {
+ in = new FileInputStream(args[3]);
+
+ SAXParser parser = factory.newSAXParser();
+ parser.parse(in, new ContentLoaderHandler(dataSource, ROOT_ELEMENT, false));
+ } finally {
+ IOUtils.closeQuietly(in);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/3d286f86/client/cli/src/test/java/org/apache/syncope/client/cli/util/CommandUtilsTest.java
----------------------------------------------------------------------
diff --git a/client/cli/src/test/java/org/apache/syncope/client/cli/util/CommandUtilsTest.java b/client/cli/src/test/java/org/apache/syncope/client/cli/util/CommandUtilsTest.java
index 78ed4c1..b87f970 100644
--- a/client/cli/src/test/java/org/apache/syncope/client/cli/util/CommandUtilsTest.java
+++ b/client/cli/src/test/java/org/apache/syncope/client/cli/util/CommandUtilsTest.java
@@ -30,20 +30,16 @@ import org.junit.Test;
public class CommandUtilsTest {
@Test
- public void fromArgs() {
- final String commandName = "logger";
- try {
- final AbstractCommand command = CommandUtils.fromArgs(commandName);
- assertEquals(commandName, command.getClass().getAnnotation(Command.class).name());
- } catch (final IllegalAccessException | IllegalArgumentException | InstantiationException ex) {
- fail(ex.getMessage());
- }
+ public void fromArgs() throws InstantiationException, IllegalAccessException {
+ String commandName = "logger";
+ AbstractCommand command = CommandUtils.fromArgs(commandName);
+ assertEquals(commandName, command.getClass().getAnnotation(Command.class).name());
- final String wrongCommandName = "wrong";
+ String wrongCommandName = "wrong";
try {
CommandUtils.fromArgs(wrongCommandName);
fail(wrongCommandName + " isn't a right command, why you are here?");
- } catch (final IllegalAccessException | IllegalArgumentException | InstantiationException ex) {
+ } catch (IllegalArgumentException ex) {
assertEquals(IllegalArgumentException.class, ex.getClass());
assertEquals(wrongCommandName + " is not a valid command", ex.getMessage());
}
http://git-wip-us.apache.org/repos/asf/syncope/blob/3d286f86/client/cli/src/test/java/org/apache/syncope/client/cli/util/JasyptUtilsTest.java
----------------------------------------------------------------------
diff --git a/client/cli/src/test/java/org/apache/syncope/client/cli/util/JasyptUtilsTest.java b/client/cli/src/test/java/org/apache/syncope/client/cli/util/JasyptUtilsTest.java
index fce9ae1..9fd0dba 100644
--- a/client/cli/src/test/java/org/apache/syncope/client/cli/util/JasyptUtilsTest.java
+++ b/client/cli/src/test/java/org/apache/syncope/client/cli/util/JasyptUtilsTest.java
@@ -26,10 +26,10 @@ public class JasyptUtilsTest {
@Test
public void encryption() {
- final String password = "password";
- final JasyptUtils jasyptUtils = JasyptUtils.getJasyptUtils();
- final String encPassword = jasyptUtils.encrypt(password);
- final String decPassword = jasyptUtils.decrypt(encPassword);
+ String password = "password";
+ JasyptUtils jasyptUtils = JasyptUtils.getJasyptUtils();
+ String encPassword = jasyptUtils.encrypt(password);
+ String decPassword = jasyptUtils.decrypt(encPassword);
assertEquals(password, decPassword);
}
}