DATACASS-242 - Fix shutdown script issue with XML Configuration.

The XML Configuration now handles configured shutdown scripts correctly.

Original pull request: #67.
This commit is contained in:
John Blum
2016-06-16 19:56:36 -07:00
committed by Mark Paluch
parent 56c46f9460
commit 2958d13923
2 changed files with 41 additions and 1 deletions

View File

@@ -161,7 +161,7 @@ public class CassandraCqlClusterParser extends AbstractBeanDefinitionParser {
poolingOptionsBuilder, parserContext, element));
builder.addPropertyValue("startupScripts", startupScripts);
builder.addPropertyValue("shutdownScripts", startupScripts);
builder.addPropertyValue("shutdownScripts", shutdownScripts);
}
/**

View File

@@ -20,6 +20,8 @@ import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import static org.springframework.cassandra.support.BeanDefinitionTestUtils.*;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -262,6 +264,44 @@ public class CassandraCqlClusterParserUnitTests {
verify(localPoolingOptionsElement).getAttribute(eq("min-simultaneous-requests"));
}
/**
* @see <a href="https://jira.spring.io/browse/DATACASS-242">DATACASS-242</a>
*/
@Test
public void parseChildElementsWithStartupAndShutdownScripts() {
Element mockStartupCqlOne = mock(Element.class, "MockStartupCqlOne");
Element mockStartupCqlTwo = mock(Element.class, "MockStartupCqlTwo");
Element mockShutdownCqlOne = mock(Element.class, "MockShutdownCqlOne");
Element mockShutdownCqlTwo = mock(Element.class, "MockShutdownCqlTwo");
when(mockStartupCqlOne.getLocalName()).thenReturn("startup-cql");
when(mockStartupCqlTwo.getLocalName()).thenReturn("startup-cql");
when(mockStartupCqlOne.getTextContent()).thenReturn("CREATE KEYSPACE test;");
when(mockStartupCqlTwo.getTextContent()).thenReturn("CREATE TABLE test.table;");
when(mockShutdownCqlOne.getLocalName()).thenReturn("shutdown-cql");
when(mockShutdownCqlTwo.getLocalName()).thenReturn("shutdown-cql");
when(mockShutdownCqlOne.getTextContent()).thenReturn("DROP KEYSPACE test;");
when(mockShutdownCqlTwo.getTextContent()).thenReturn("DROP USER jblum;");
NodeList mockNodeList = mockNodeList(mockStartupCqlOne, mockStartupCqlTwo,
mockShutdownCqlOne, mockShutdownCqlTwo);
when(mockElement.getChildNodes()).thenReturn(mockNodeList);
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition();
parser.parseChildElements(mockElement, mockParserContext(null), builder);
BeanDefinition beanDefinition = builder.getBeanDefinition();
List<String> startupScripts = getPropertyValue(beanDefinition, "startupScripts");
assertThat(startupScripts, contains("CREATE KEYSPACE test;", "CREATE TABLE test.table;"));
List<String> shutdownScripts = getPropertyValue(beanDefinition, "shutdownScripts");
assertThat(shutdownScripts, contains("DROP KEYSPACE test;", "DROP USER jblum;"));
}
/**
* @see <a href="https://jira.spring.io/browse/DATACASS-298">DATACASS-298</a>
*/