mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-29 15:21:53 +00:00
Merged 5.1.1 (5.1.1) to 5.1.N (5.1.2)
125498 slanglois: MNT-16155 Update source headers - remove svn:eol-style property on Java and JSP source files git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.1.N/root@125605 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,72 +1,72 @@
|
||||
package org.alfresco.repo.domain.schema.script;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.alfresco.util.ApplicationContextHelper;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
/**
|
||||
* Integration tests for the {@link ScriptBundleExecutorImpl} class.
|
||||
*
|
||||
* @author Matt Ward
|
||||
*/
|
||||
public class ScriptBundleExecutorImplIntegrationTest
|
||||
{
|
||||
private static ApplicationContext ctx;
|
||||
private ScriptBundleExecutor bundleExecutor;
|
||||
private DataSource dataSource;
|
||||
private JdbcTemplate jdbcTmpl;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception
|
||||
{
|
||||
String[] config = new String[] {
|
||||
"classpath:alfresco/application-context.xml",
|
||||
"classpath:scriptexec/script-exec-test.xml"
|
||||
};
|
||||
ctx = ApplicationContextHelper.getApplicationContext(config);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
bundleExecutor = ctx.getBean("bundleExecutor", ScriptBundleExecutorImpl.class);
|
||||
dataSource = ctx.getBean("dataSource", DataSource.class);
|
||||
jdbcTmpl = new JdbcTemplate(dataSource);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canExecuteBundle()
|
||||
{
|
||||
bundleExecutor.exec("scriptexec/${db.script.dialect}/bundle", "script_a.sql", "script_b.sql", "script_c.sql");
|
||||
|
||||
String select = "select message from alf_test_bundle order by message asc";
|
||||
List<String> res = jdbcTmpl.queryForList(select, String.class);
|
||||
assertEquals(2, res.size());
|
||||
// script_c deleted "script_a message 1"
|
||||
assertEquals("script_a message 2", res.get(0));
|
||||
assertEquals("script_b", res.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postScriptIsRunFinallyEvenAfterEarlierFailure()
|
||||
{
|
||||
// script_b.sql will fail
|
||||
bundleExecutor.execWithPostScript("scriptexec/${db.script.dialect}/bundle2",
|
||||
"post_script.sql", "script_a.sql", "script_b.sql");
|
||||
|
||||
String select = "select message from alf_test_bundle2 order by message asc";
|
||||
List<String> res = jdbcTmpl.queryForList(select, String.class);
|
||||
assertEquals(1, res.size());
|
||||
// post_script deleted "script_a message 1"
|
||||
assertEquals("script_a message 2", res.get(0));
|
||||
}
|
||||
}
|
||||
package org.alfresco.repo.domain.schema.script;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.alfresco.util.ApplicationContextHelper;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
/**
|
||||
* Integration tests for the {@link ScriptBundleExecutorImpl} class.
|
||||
*
|
||||
* @author Matt Ward
|
||||
*/
|
||||
public class ScriptBundleExecutorImplIntegrationTest
|
||||
{
|
||||
private static ApplicationContext ctx;
|
||||
private ScriptBundleExecutor bundleExecutor;
|
||||
private DataSource dataSource;
|
||||
private JdbcTemplate jdbcTmpl;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception
|
||||
{
|
||||
String[] config = new String[] {
|
||||
"classpath:alfresco/application-context.xml",
|
||||
"classpath:scriptexec/script-exec-test.xml"
|
||||
};
|
||||
ctx = ApplicationContextHelper.getApplicationContext(config);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
bundleExecutor = ctx.getBean("bundleExecutor", ScriptBundleExecutorImpl.class);
|
||||
dataSource = ctx.getBean("dataSource", DataSource.class);
|
||||
jdbcTmpl = new JdbcTemplate(dataSource);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canExecuteBundle()
|
||||
{
|
||||
bundleExecutor.exec("scriptexec/${db.script.dialect}/bundle", "script_a.sql", "script_b.sql", "script_c.sql");
|
||||
|
||||
String select = "select message from alf_test_bundle order by message asc";
|
||||
List<String> res = jdbcTmpl.queryForList(select, String.class);
|
||||
assertEquals(2, res.size());
|
||||
// script_c deleted "script_a message 1"
|
||||
assertEquals("script_a message 2", res.get(0));
|
||||
assertEquals("script_b", res.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postScriptIsRunFinallyEvenAfterEarlierFailure()
|
||||
{
|
||||
// script_b.sql will fail
|
||||
bundleExecutor.execWithPostScript("scriptexec/${db.script.dialect}/bundle2",
|
||||
"post_script.sql", "script_a.sql", "script_b.sql");
|
||||
|
||||
String select = "select message from alf_test_bundle2 order by message asc";
|
||||
List<String> res = jdbcTmpl.queryForList(select, String.class);
|
||||
assertEquals(1, res.size());
|
||||
// post_script deleted "script_a message 1"
|
||||
assertEquals("script_a message 2", res.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,75 +1,75 @@
|
||||
package org.alfresco.repo.domain.schema.script;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.same;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InOrder;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
/**
|
||||
* Unit tests for the {@link ScriptBundleExecutorImpl} class.
|
||||
*
|
||||
* @author Matt Ward
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ScriptBundleExecutorImplTest
|
||||
{
|
||||
// Class under test
|
||||
private ScriptBundleExecutorImpl bundleExecutor;
|
||||
private @Mock ScriptExecutor scriptExecutor;
|
||||
private @Mock Log log;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
bundleExecutor = new ScriptBundleExecutorImpl(scriptExecutor);
|
||||
bundleExecutor.log = log;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canExecuteMultipleScripts() throws Exception
|
||||
{
|
||||
bundleExecutor.exec("/path/to/script/dir", "one.sql", "two.sql", "three.sql");
|
||||
|
||||
InOrder inOrder = Mockito.inOrder(scriptExecutor);
|
||||
inOrder.verify(scriptExecutor).executeScriptUrl("/path/to/script/dir/one.sql");
|
||||
inOrder.verify(scriptExecutor).executeScriptUrl("/path/to/script/dir/two.sql");
|
||||
inOrder.verify(scriptExecutor).executeScriptUrl("/path/to/script/dir/three.sql");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void willAlwaysRunPostBatchScript() throws Exception
|
||||
{
|
||||
// The first of the "main" scripts will fail...
|
||||
Exception e = new RuntimeException("Script failure!");
|
||||
doThrow(e).when(scriptExecutor).executeScriptUrl("/path/to/script/dir/work01.sql");
|
||||
|
||||
bundleExecutor.execWithPostScript("/path/to/script/dir", "post.sql", "pre.sql", "work01.sql", "work02.sql");
|
||||
|
||||
InOrder inOrder = Mockito.inOrder(scriptExecutor);
|
||||
inOrder.verify(scriptExecutor).executeScriptUrl("/path/to/script/dir/pre.sql");
|
||||
inOrder.verify(scriptExecutor).executeScriptUrl("/path/to/script/dir/work01.sql");
|
||||
// work02.sql will NOT be executed, but the post-script will be.
|
||||
inOrder.verify(scriptExecutor, never()).executeScriptUrl("/path/to/script/dir/work02.sql");
|
||||
inOrder.verify(scriptExecutor).executeScriptUrl("/path/to/script/dir/post.sql");
|
||||
|
||||
verify(log).error(anyString(), same(e));
|
||||
}
|
||||
}
|
||||
package org.alfresco.repo.domain.schema.script;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.same;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InOrder;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
/**
|
||||
* Unit tests for the {@link ScriptBundleExecutorImpl} class.
|
||||
*
|
||||
* @author Matt Ward
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ScriptBundleExecutorImplTest
|
||||
{
|
||||
// Class under test
|
||||
private ScriptBundleExecutorImpl bundleExecutor;
|
||||
private @Mock ScriptExecutor scriptExecutor;
|
||||
private @Mock Log log;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
bundleExecutor = new ScriptBundleExecutorImpl(scriptExecutor);
|
||||
bundleExecutor.log = log;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canExecuteMultipleScripts() throws Exception
|
||||
{
|
||||
bundleExecutor.exec("/path/to/script/dir", "one.sql", "two.sql", "three.sql");
|
||||
|
||||
InOrder inOrder = Mockito.inOrder(scriptExecutor);
|
||||
inOrder.verify(scriptExecutor).executeScriptUrl("/path/to/script/dir/one.sql");
|
||||
inOrder.verify(scriptExecutor).executeScriptUrl("/path/to/script/dir/two.sql");
|
||||
inOrder.verify(scriptExecutor).executeScriptUrl("/path/to/script/dir/three.sql");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void willAlwaysRunPostBatchScript() throws Exception
|
||||
{
|
||||
// The first of the "main" scripts will fail...
|
||||
Exception e = new RuntimeException("Script failure!");
|
||||
doThrow(e).when(scriptExecutor).executeScriptUrl("/path/to/script/dir/work01.sql");
|
||||
|
||||
bundleExecutor.execWithPostScript("/path/to/script/dir", "post.sql", "pre.sql", "work01.sql", "work02.sql");
|
||||
|
||||
InOrder inOrder = Mockito.inOrder(scriptExecutor);
|
||||
inOrder.verify(scriptExecutor).executeScriptUrl("/path/to/script/dir/pre.sql");
|
||||
inOrder.verify(scriptExecutor).executeScriptUrl("/path/to/script/dir/work01.sql");
|
||||
// work02.sql will NOT be executed, but the post-script will be.
|
||||
inOrder.verify(scriptExecutor, never()).executeScriptUrl("/path/to/script/dir/work02.sql");
|
||||
inOrder.verify(scriptExecutor).executeScriptUrl("/path/to/script/dir/post.sql");
|
||||
|
||||
verify(log).error(anyString(), same(e));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user