http://git-wip-us.apache.org/repos/asf/syncope/blob/027b6bdf/core/upgrade/src/main/resources/syncopeupgrade.bat ---------------------------------------------------------------------- diff --git a/core/upgrade/src/main/resources/syncopeupgrade.bat b/core/upgrade/src/main/resources/syncopeupgrade.bat new file mode 100644 index 0000000..a1a7a7c --- /dev/null +++ b/core/upgrade/src/main/resources/syncopeupgrade.bat @@ -0,0 +1,27 @@ +@ECHO OFF + +rem Licensed to the Apache Software Foundation (ASF) under one +rem or more contributor license agreements. See the NOTICE file +rem distributed with this work for additional information +rem regarding copyright ownership. The ASF licenses this file +rem to you under the Apache License, Version 2.0 (the +rem "License"); you may not use this file except in compliance +rem with the License. You may obtain a copy of the License at +rem +rem http://www.apache.org/licenses/LICENSE-2.0 +rem +rem Unless required by applicable law or agreed to in writing, +rem software distributed under the License is distributed on an +rem "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +rem KIND, either express or implied. See the License for the +rem specific language governing permissions and limitations +rem under the License. + +setLocal EnableDelayedExpansion +set CLASSPATH=" +for /R ./lib %%a in (*.jar) do ( + set CLASSPATH=!CLASSPATH!;%%a +) +set CLASSPATH=!CLASSPATH!" + +java -Xms256m -Xmx512m -classpath !CLASSPATH! org.apache.syncope.core.upgrade.GenerateUpgradeSQL %* \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/syncope/blob/027b6bdf/core/upgrade/src/main/resources/syncopeupgrade.sh ---------------------------------------------------------------------- diff --git a/core/upgrade/src/main/resources/syncopeupgrade.sh b/core/upgrade/src/main/resources/syncopeupgrade.sh new file mode 100755 index 0000000..466e986 --- /dev/null +++ b/core/upgrade/src/main/resources/syncopeupgrade.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +# 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. + +LIB=`ls lib` +CLASSPATH=lib/`echo $LIB | sed "s/jar /jar:lib\//g"` + +java -Xms256m -Xmx512m -classpath "$CLASSPATH" org.apache.syncope.core.upgrade.GenerateUpgradeSQL "$@" \ No newline at end of file http://git-wip-us.apache.org/repos/asf/syncope/blob/027b6bdf/core/upgrade/src/test/java/org/apache/syncope/core/upgrade/GeneratedUpgradeSQLTest.java ---------------------------------------------------------------------- diff --git a/core/upgrade/src/test/java/org/apache/syncope/core/upgrade/GeneratedUpgradeSQLTest.java b/core/upgrade/src/test/java/org/apache/syncope/core/upgrade/GeneratedUpgradeSQLTest.java new file mode 100644 index 0000000..3d44e37 --- /dev/null +++ b/core/upgrade/src/test/java/org/apache/syncope/core/upgrade/GeneratedUpgradeSQLTest.java @@ -0,0 +1,120 @@ +/* + * 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.upgrade; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.AssertionsKt.fail; + +import java.io.StringWriter; +import java.nio.charset.StandardCharsets; +import javax.annotation.Resource; +import javax.sql.DataSource; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.ByteArrayResource; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.datasource.init.DataSourceInitializer; +import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; + +@SpringJUnitConfig(locations = { + "classpath:testJDBCEnv.xml" +}) +public class GeneratedUpgradeSQLTest { + + @Resource(name = "driverClassName") + private String driverClassName; + + @Resource(name = "jdbcURL") + private String jdbcURL; + + @Resource(name = "username") + private String username; + + @Resource(name = "password") + private String password; + + @Autowired + private DataSource syncope20DataSource; + + @Test + public void upgradefrom20() throws Exception { + StringWriter out = new StringWriter(); + GenerateUpgradeSQL.setWriter(out); + + String[] args = new String[] { driverClassName, jdbcURL, username, password, "h2" }; + GenerateUpgradeSQL.main(args); + + String upgradeSQL = out.toString(); + + try { + DataSourceInitializer adminUsersInit = new DataSourceInitializer(); + adminUsersInit.setDataSource(syncope20DataSource); + adminUsersInit.setDatabasePopulator( + new ResourceDatabasePopulator(new ByteArrayResource(upgradeSQL.getBytes(StandardCharsets.UTF_8)))); + adminUsersInit.afterPropertiesSet(); + } catch (Exception e) { + fail("Unexpected error while upgrading", e); + } + + JdbcTemplate jdbcTemplate = new JdbcTemplate(syncope20DataSource); + + Integer implementations = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM Implementation", Integer.class); + assertNotNull(implementations); + assertEquals(16, implementations.intValue()); + + Integer pullTaskActions = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM PullTaskAction", Integer.class); + assertNotNull(pullTaskActions); + assertEquals(1, pullTaskActions.intValue()); + + Integer pushTaskActions = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM PushTaskAction", Integer.class); + assertNotNull(pushTaskActions); + assertEquals(0, pushTaskActions.intValue()); + + Integer propagationTaskActions = jdbcTemplate.queryForObject( + "SELECT COUNT(*) FROM ExternalResourcePropagationAction", Integer.class); + assertNotNull(propagationTaskActions); + assertEquals(1, propagationTaskActions.intValue()); + + Integer realmActions = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM RealmAction", Integer.class); + assertNotNull(realmActions); + assertEquals(0, realmActions.intValue()); + + Integer accountPolicyRules = jdbcTemplate.queryForObject( + "SELECT COUNT(*) FROM AccountPolicyRule", Integer.class); + assertNotNull(accountPolicyRules); + assertEquals(2, accountPolicyRules.intValue()); + + Integer passwordPolicyRules = jdbcTemplate.queryForObject( + "SELECT COUNT(*) FROM PasswordPolicyRule", Integer.class); + assertNotNull(passwordPolicyRules); + assertEquals(3, passwordPolicyRules.intValue()); + + Integer pullCorrelationRuleEntities = jdbcTemplate.queryForObject( + "SELECT COUNT(*) FROM PullCorrelationRuleEntity", Integer.class); + assertNotNull(pullCorrelationRuleEntities); + assertEquals(1, pullCorrelationRuleEntities.intValue()); + + Integer pushCorrelationRuleEntities = jdbcTemplate.queryForObject( + "SELECT COUNT(*) FROM PushCorrelationRuleEntity", Integer.class); + assertNotNull(pushCorrelationRuleEntities); + assertEquals(0, pushCorrelationRuleEntities.intValue()); + } +}