diff --git a/spring-cql/src/main/java/org/springframework/cassandra/config/xml/CassandraCqlClusterParser.java b/spring-cql/src/main/java/org/springframework/cassandra/config/xml/CassandraCqlClusterParser.java
index fa4d07c1c..ec6ac208f 100644
--- a/spring-cql/src/main/java/org/springframework/cassandra/config/xml/CassandraCqlClusterParser.java
+++ b/spring-cql/src/main/java/org/springframework/cassandra/config/xml/CassandraCqlClusterParser.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013-2014 the original author or authors.
+ * Copyright 2013-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/spring-cql/src/main/java/org/springframework/cassandra/config/xml/ParsingUtils.java b/spring-cql/src/main/java/org/springframework/cassandra/config/xml/ParsingUtils.java
index d6254b82b..6b038cd87 100644
--- a/spring-cql/src/main/java/org/springframework/cassandra/config/xml/ParsingUtils.java
+++ b/spring-cql/src/main/java/org/springframework/cassandra/config/xml/ParsingUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013-2014 the original author or authors.
+ * Copyright 2013-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/spring-cql/src/test/java/org/springframework/cassandra/config/PoolingOptionsFactoryBeanUnitTests.java b/spring-cql/src/test/java/org/springframework/cassandra/config/PoolingOptionsFactoryBeanUnitTests.java
index ec8b374e0..15b75c0bd 100644
--- a/spring-cql/src/test/java/org/springframework/cassandra/config/PoolingOptionsFactoryBeanUnitTests.java
+++ b/spring-cql/src/test/java/org/springframework/cassandra/config/PoolingOptionsFactoryBeanUnitTests.java
@@ -18,9 +18,9 @@ package org.springframework.cassandra.config;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.*;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyInt;
-import static org.mockito.Mockito.*;
import static org.mockito.Mockito.same;
import java.util.concurrent.Executor;
@@ -28,7 +28,6 @@ import java.util.concurrent.Executor;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.invocation.InvocationOnMock;
@@ -44,18 +43,14 @@ import com.datastax.driver.core.PoolingOptions;
* @author Sumit Kumar
* @author David Webb
* @author John Blum
- * @see org.springframework.cassandra.config.PoolingOptionsFactoryBean
* @see DATACASS-176
* @see DATACASS-298
*/
@RunWith(MockitoJUnitRunner.class)
public class PoolingOptionsFactoryBeanUnitTests {
- @Mock
- private Executor mockExecutor;
-
- @Spy
- private PoolingOptions poolingOptionsSpy;
+ @Mock Executor mockExecutor;
+ @Spy PoolingOptions poolingOptionsSpy;
private PoolingOptionsFactoryBean poolingOptionsFactoryBean;
@@ -85,6 +80,7 @@ public class PoolingOptionsFactoryBeanUnitTests {
*/
@Test
public void setAndGetFactoryBeanProperties() {
+
poolingOptionsFactoryBean.setHeartbeatIntervalSeconds(15);
poolingOptionsFactoryBean.setIdleTimeoutSeconds(120);
poolingOptionsFactoryBean.setInitializationExecutor(mockExecutor);
@@ -117,8 +113,10 @@ public class PoolingOptionsFactoryBeanUnitTests {
*/
@Test
public void afterPropertiesSetInitializesLocalPoolingOptions() throws Exception {
+
PoolingOptionsFactoryBean poolingOptionsFactoryBean = new PoolingOptionsFactoryBean() {
- @Override PoolingOptions newPoolingOptions() {
+ @Override
+ PoolingOptions newPoolingOptions() {
poolingOptionsSpy.setNewConnectionThreshold(HostDistance.LOCAL, 1);
return poolingOptionsSpy;
}
@@ -140,14 +138,14 @@ public class PoolingOptionsFactoryBeanUnitTests {
assertThat(poolingOptionsFactoryBean.getObject(), is(sameInstance(poolingOptionsSpy)));
assertThat(poolingOptionsFactoryBean.getObjectType(), is(equalTo((Class) poolingOptionsSpy.getClass())));
- verify(poolingOptionsSpy, times(1)).setHeartbeatIntervalSeconds(eq(60));
- verify(poolingOptionsSpy, times(1)).setIdleTimeoutSeconds(eq(300));
- verify(poolingOptionsSpy, times(1)).setInitializationExecutor(eq(mockExecutor));
- verify(poolingOptionsSpy, times(1)).setPoolTimeoutMillis(eq(180));
- verify(poolingOptionsSpy, times(1)).setCoreConnectionsPerHost(eq(HostDistance.LOCAL), eq(10));
- verify(poolingOptionsSpy, times(1)).setMaxConnectionsPerHost(eq(HostDistance.LOCAL), eq(100));
- verify(poolingOptionsSpy, times(1)).setMaxRequestsPerConnection(eq(HostDistance.LOCAL), eq(50));
- verify(poolingOptionsSpy, times(1)).setNewConnectionThreshold(eq(HostDistance.LOCAL), eq(5));
+ verify(poolingOptionsSpy).setHeartbeatIntervalSeconds(eq(60));
+ verify(poolingOptionsSpy).setIdleTimeoutSeconds(eq(300));
+ verify(poolingOptionsSpy).setInitializationExecutor(eq(mockExecutor));
+ verify(poolingOptionsSpy).setPoolTimeoutMillis(eq(180));
+ verify(poolingOptionsSpy).setCoreConnectionsPerHost(eq(HostDistance.LOCAL), eq(10));
+ verify(poolingOptionsSpy).setMaxConnectionsPerHost(eq(HostDistance.LOCAL), eq(100));
+ verify(poolingOptionsSpy).setMaxRequestsPerConnection(eq(HostDistance.LOCAL), eq(50));
+ verify(poolingOptionsSpy).setNewConnectionThreshold(eq(HostDistance.LOCAL), eq(5));
verify(poolingOptionsSpy, never()).setCoreConnectionsPerHost(eq(HostDistance.REMOTE), anyInt());
verify(poolingOptionsSpy, never()).setMaxConnectionsPerHost(eq(HostDistance.REMOTE), anyInt());
verify(poolingOptionsSpy, never()).setMaxRequestsPerConnection(eq(HostDistance.REMOTE), anyInt());
@@ -159,8 +157,10 @@ public class PoolingOptionsFactoryBeanUnitTests {
*/
@Test
public void afterPropertiesSetInitializesRemotePoolingOptions() throws Exception {
+
PoolingOptionsFactoryBean poolingOptionsFactoryBean = new PoolingOptionsFactoryBean() {
- @Override PoolingOptions newPoolingOptions() {
+ @Override
+ PoolingOptions newPoolingOptions() {
poolingOptionsSpy.setNewConnectionThreshold(HostDistance.REMOTE, 10);
return poolingOptionsSpy;
}
@@ -182,13 +182,13 @@ public class PoolingOptionsFactoryBeanUnitTests {
assertThat(poolingOptionsFactoryBean.getObject(), is(sameInstance(poolingOptionsSpy)));
assertThat(poolingOptionsFactoryBean.getObjectType(), is(equalTo((Class) poolingOptionsSpy.getClass())));
- verify(poolingOptionsSpy, times(1)).setHeartbeatIntervalSeconds(eq(30));
- verify(poolingOptionsSpy, times(1)).setIdleTimeoutSeconds(eq(120));
- verify(poolingOptionsSpy, times(1)).setInitializationExecutor(eq(mockExecutor));
- verify(poolingOptionsSpy, times(1)).setPoolTimeoutMillis(eq(120));
- verify(poolingOptionsSpy, times(1)).setCoreConnectionsPerHost(eq(HostDistance.REMOTE), eq(5));
- verify(poolingOptionsSpy, times(1)).setMaxConnectionsPerHost(eq(HostDistance.REMOTE), eq(50));
- verify(poolingOptionsSpy, times(1)).setMaxRequestsPerConnection(eq(HostDistance.REMOTE), eq(20));
+ verify(poolingOptionsSpy).setHeartbeatIntervalSeconds(eq(30));
+ verify(poolingOptionsSpy).setIdleTimeoutSeconds(eq(120));
+ verify(poolingOptionsSpy).setInitializationExecutor(eq(mockExecutor));
+ verify(poolingOptionsSpy).setPoolTimeoutMillis(eq(120));
+ verify(poolingOptionsSpy).setCoreConnectionsPerHost(eq(HostDistance.REMOTE), eq(5));
+ verify(poolingOptionsSpy).setMaxConnectionsPerHost(eq(HostDistance.REMOTE), eq(50));
+ verify(poolingOptionsSpy).setMaxRequestsPerConnection(eq(HostDistance.REMOTE), eq(20));
verify(poolingOptionsSpy, never()).setCoreConnectionsPerHost(eq(HostDistance.LOCAL), anyInt());
verify(poolingOptionsSpy, never()).setMaxConnectionsPerHost(eq(HostDistance.LOCAL), anyInt());
verify(poolingOptionsSpy, never()).setMaxRequestsPerConnection(eq(HostDistance.LOCAL), anyInt());
@@ -197,19 +197,20 @@ public class PoolingOptionsFactoryBeanUnitTests {
}
/**
- * This particular test case is technically an integration test since it uses an actual instance of
- * a DataStax Java driver class type... {@link PoolingOptions}!
- *
- * The max values should be set before setting core values. Otherwise the core values will be compared with the
- * default max values which is 8. Same for other min-max properties pairs. This test checks the same.
+ * This particular test case is technically an integration test since it uses an actual instance of a DataStax Java
+ * driver class type... {@link PoolingOptions}! The max values should be set before setting core values. Otherwise the
+ * core values will be compared with the default max values which is 8. Same for other min-max properties pairs. This
+ * test checks the same.
*
* @throws Exception Any unhandled scenarios will result in a test failure.
* @see DATACASS-176
*/
@Test
public void afterPropertiesSetProperlySetsPoolingOptionsMaxBeforeMinProperties() throws Exception {
+
poolingOptionsFactoryBean = new PoolingOptionsFactoryBean() {
- @Override PoolingOptions newPoolingOptions() {
+ @Override
+ PoolingOptions newPoolingOptions() {
return spy(super.newPoolingOptions());
}
};
@@ -239,20 +240,22 @@ public class PoolingOptionsFactoryBeanUnitTests {
assertThat(poolingOptions.getMaxRequestsPerConnection(HostDistance.REMOTE), is(equalTo(127)));
assertThat(poolingOptions.getNewConnectionThreshold(HostDistance.REMOTE), is(equalTo(111)));
- InOrder inOrder = inOrder(poolingOptions);
-
- inOrder.verify(poolingOptions, times(1)).setMaxConnectionsPerHost(eq(HostDistance.LOCAL), eq(200));
- inOrder.verify(poolingOptions, times(1)).setCoreConnectionsPerHost(eq(HostDistance.LOCAL), eq(100));
- inOrder.verify(poolingOptions, times(1)).setMaxRequestsPerConnection(eq(HostDistance.LOCAL), eq(99));
- inOrder.verify(poolingOptions, times(1)).setNewConnectionThreshold(eq(HostDistance.LOCAL), eq(97));
- inOrder.verify(poolingOptions, times(1)).setMaxConnectionsPerHost(eq(HostDistance.REMOTE), eq(210));
- inOrder.verify(poolingOptions, times(1)).setCoreConnectionsPerHost(eq(HostDistance.REMOTE), eq(110));
- inOrder.verify(poolingOptions, times(1)).setMaxRequestsPerConnection(eq(HostDistance.REMOTE), eq(127));
- inOrder.verify(poolingOptions, times(1)).setNewConnectionThreshold(eq(HostDistance.REMOTE), eq(111));
+ verify(poolingOptions).setMaxConnectionsPerHost(eq(HostDistance.LOCAL), eq(200));
+ verify(poolingOptions).setCoreConnectionsPerHost(eq(HostDistance.LOCAL), eq(100));
+ verify(poolingOptions).setMaxRequestsPerConnection(eq(HostDistance.LOCAL), eq(99));
+ verify(poolingOptions).setNewConnectionThreshold(eq(HostDistance.LOCAL), eq(97));
+ verify(poolingOptions).setMaxConnectionsPerHost(eq(HostDistance.REMOTE), eq(210));
+ verify(poolingOptions).setCoreConnectionsPerHost(eq(HostDistance.REMOTE), eq(110));
+ verify(poolingOptions).setMaxRequestsPerConnection(eq(HostDistance.REMOTE), eq(127));
+ verify(poolingOptions).setNewConnectionThreshold(eq(HostDistance.REMOTE), eq(111));
}
+ /**
+ * @see DATACASS-176
+ */
@Test
public void newLocalHostDistancePoolingOptionsReturnsLocalHostDistancePoolingOptionsFactoryBeanSettings() {
+
poolingOptionsFactoryBean.setLocalCoreConnections(50);
poolingOptionsFactoryBean.setLocalMaxConnections(500);
poolingOptionsFactoryBean.setLocalMaxSimultaneousRequests(1000);
@@ -262,8 +265,8 @@ public class PoolingOptionsFactoryBeanUnitTests {
poolingOptionsFactoryBean.setRemoteMaxSimultaneousRequests(400);
poolingOptionsFactoryBean.setRemoteMinSimultaneousRequests(40);
- PoolingOptionsFactoryBean.HostDistancePoolingOptions poolingOptions =
- poolingOptionsFactoryBean.newLocalHostDistancePoolingOptions();
+ PoolingOptionsFactoryBean.HostDistancePoolingOptions poolingOptions = poolingOptionsFactoryBean
+ .newLocalHostDistancePoolingOptions();
assertThat(poolingOptions.getHostDistance(), is(equalTo(HostDistance.LOCAL)));
assertThat(poolingOptions.getCoreConnectionsPerHost(), is(equalTo(50)));
@@ -272,8 +275,12 @@ public class PoolingOptionsFactoryBeanUnitTests {
assertThat(poolingOptions.getNewConnectionThreshold(), is(equalTo(100)));
}
+ /**
+ * @see DATACASS-176
+ */
@Test
public void newLocalHostDistancePoolingOptionsReturnsRemoteHostDistancePoolingOptionsFactoryBeanSettings() {
+
poolingOptionsFactoryBean.setLocalCoreConnections(50);
poolingOptionsFactoryBean.setLocalMaxConnections(500);
poolingOptionsFactoryBean.setLocalMaxSimultaneousRequests(1000);
@@ -283,8 +290,8 @@ public class PoolingOptionsFactoryBeanUnitTests {
poolingOptionsFactoryBean.setRemoteMaxSimultaneousRequests(400);
poolingOptionsFactoryBean.setRemoteMinSimultaneousRequests(40);
- PoolingOptionsFactoryBean.HostDistancePoolingOptions poolingOptions =
- poolingOptionsFactoryBean.newRemoteHostDistancePoolingOptions();
+ PoolingOptionsFactoryBean.HostDistancePoolingOptions poolingOptions = poolingOptionsFactoryBean
+ .newRemoteHostDistancePoolingOptions();
assertThat(poolingOptions.getHostDistance(), is(equalTo(HostDistance.REMOTE)));
assertThat(poolingOptions.getCoreConnectionsPerHost(), is(equalTo(20)));
@@ -293,55 +300,61 @@ public class PoolingOptionsFactoryBeanUnitTests {
assertThat(poolingOptions.getNewConnectionThreshold(), is(equalTo(40)));
}
+ /**
+ * @see DATACASS-176
+ */
@Test
public void configureLocalHostDistancePoolingOptionsCallsConfigureWithExpectedInstance() {
- final PoolingOptionsFactoryBean.HostDistancePoolingOptions mockHostDistancePoolingOptions = mock(
- PoolingOptionsFactoryBean.HostDistancePoolingOptions.class);
- when(mockHostDistancePoolingOptions.configure(any(PoolingOptions.class))).thenAnswer(
- new Answer() {
- @Override
- public PoolingOptions answer(InvocationOnMock invocationOnMock) throws Throwable {
- return invocationOnMock.getArgumentAt(0, PoolingOptions.class);
- }
+ final PoolingOptionsFactoryBean.HostDistancePoolingOptions mockHostDistancePoolingOptions = mock(
+ PoolingOptionsFactoryBean.HostDistancePoolingOptions.class);
+
+ when(mockHostDistancePoolingOptions.configure(any(PoolingOptions.class))).thenAnswer(new Answer() {
+ @Override
+ public PoolingOptions answer(InvocationOnMock invocationOnMock) throws Throwable {
+ return invocationOnMock.getArgumentAt(0, PoolingOptions.class);
}
- );
+ });
poolingOptionsFactoryBean = new PoolingOptionsFactoryBean() {
- @Override protected HostDistancePoolingOptions newLocalHostDistancePoolingOptions() {
+ @Override
+ protected HostDistancePoolingOptions newLocalHostDistancePoolingOptions() {
return mockHostDistancePoolingOptions;
}
};
assertThat(poolingOptionsFactoryBean.configureLocalHostDistancePoolingOptions(poolingOptionsSpy),
- is(sameInstance(poolingOptionsSpy)));
+ is(sameInstance(poolingOptionsSpy)));
- verify(mockHostDistancePoolingOptions, times(1)).configure(same(poolingOptionsSpy));
+ verify(mockHostDistancePoolingOptions).configure(same(poolingOptionsSpy));
}
+ /**
+ * @see DATACASS-176
+ */
@Test
public void configureRemoteHostDistancePoolingOptionsCallsConfigureWithExpectedInstance() {
- final PoolingOptionsFactoryBean.HostDistancePoolingOptions mockHostDistancePoolingOptions = mock(
- PoolingOptionsFactoryBean.HostDistancePoolingOptions.class);
- when(mockHostDistancePoolingOptions.configure(any(PoolingOptions.class))).thenAnswer(
- new Answer() {
- @Override
- public PoolingOptions answer(InvocationOnMock invocationOnMock) throws Throwable {
- return invocationOnMock.getArgumentAt(0, PoolingOptions.class);
- }
+ final PoolingOptionsFactoryBean.HostDistancePoolingOptions mockHostDistancePoolingOptions = mock(
+ PoolingOptionsFactoryBean.HostDistancePoolingOptions.class);
+
+ when(mockHostDistancePoolingOptions.configure(any(PoolingOptions.class))).thenAnswer(new Answer() {
+ @Override
+ public PoolingOptions answer(InvocationOnMock invocationOnMock) throws Throwable {
+ return invocationOnMock.getArgumentAt(0, PoolingOptions.class);
}
- );
+ });
poolingOptionsFactoryBean = new PoolingOptionsFactoryBean() {
- @Override protected HostDistancePoolingOptions newRemoteHostDistancePoolingOptions() {
+ @Override
+ protected HostDistancePoolingOptions newRemoteHostDistancePoolingOptions() {
return mockHostDistancePoolingOptions;
}
};
assertThat(poolingOptionsFactoryBean.configureRemoteHostDistancePoolingOptions(poolingOptionsSpy),
- is(sameInstance(poolingOptionsSpy)));
+ is(sameInstance(poolingOptionsSpy)));
- verify(mockHostDistancePoolingOptions, times(1)).configure(same(poolingOptionsSpy));
+ verify(mockHostDistancePoolingOptions).configure(same(poolingOptionsSpy));
}
}
diff --git a/spring-cql/src/test/java/org/springframework/cassandra/config/xml/CassandraCqlClusterParserUnitTests.java b/spring-cql/src/test/java/org/springframework/cassandra/config/xml/CassandraCqlClusterParserUnitTests.java
index cd3be124a..7157de063 100644
--- a/spring-cql/src/test/java/org/springframework/cassandra/config/xml/CassandraCqlClusterParserUnitTests.java
+++ b/spring-cql/src/test/java/org/springframework/cassandra/config/xml/CassandraCqlClusterParserUnitTests.java
@@ -18,14 +18,13 @@ package org.springframework.cassandra.config.xml;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
+import static org.springframework.cassandra.support.BeanDefinitionTestUtils.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
-import org.springframework.beans.PropertyValue;
import org.springframework.beans.factory.config.BeanDefinition;
-import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.parsing.PassThroughSourceExtractor;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
@@ -42,77 +41,45 @@ import org.w3c.dom.NodeList;
* Test suite of Unit tests testing the contract and functionality of the {@link CassandraCqlClusterParser}.
*
* @author John Blum
- * @see org.springframework.cassandra.config.xml.CassandraCqlClusterParser
- * @since 1.5.0
*/
// TODO add more tests!
@RunWith(MockitoJUnitRunner.class)
public class CassandraCqlClusterParserUnitTests {
- @Mock
- private Element mockElement;
+ @Mock Element mockElement;
private CassandraCqlClusterParser parser = new CassandraCqlClusterParser();
- @SuppressWarnings("unchecked")
- protected T getPropertyValue(BeanDefinition beanDefinition, String propertyName) {
- PropertyValue propertyValue = beanDefinition.getPropertyValues().getPropertyValue(propertyName);
-
- return (T) (propertyValue != null ? propertyValue.getValue() : null);
- }
-
- protected String getPropertyValueAsString(BeanDefinition beanDefinition, String propertyName) {
- Object value = getPropertyValue(beanDefinition, propertyName);
-
- return (value instanceof RuntimeBeanReference ? ((RuntimeBeanReference) value).getBeanName()
- : (value != null ? String.valueOf(value) : null));
- }
-
- protected BeanDefinitionParserDelegate mockBeanDefinitionParserDelegate(XmlReaderContext xmlReaderContext) {
- return new BeanDefinitionParserDelegate(xmlReaderContext);
- }
-
- protected NodeList mockNodeList(Element... childElements) {
- NodeList mockNodeList = mock(NodeList.class);
-
- when(mockNodeList.getLength()).thenReturn(childElements.length);
-
- for (int index = 0; index < childElements.length; index++) {
- when(mockNodeList.item(eq(index))).thenReturn(childElements[index]);
- }
-
- return mockNodeList;
- }
-
- protected ParserContext mockParserContext() {
- return mockParserContext(null);
- }
-
- protected ParserContext mockParserContext(BeanDefinition beanDefinition) {
- XmlReaderContext readerContext = mockXmlReaderContext();
- return new ParserContext(readerContext, mockBeanDefinitionParserDelegate(readerContext), beanDefinition);
- }
-
- protected XmlReaderContext mockXmlReaderContext() {
- return new XmlReaderContext(null, null, null, new PassThroughSourceExtractor(), null, null);
- }
-
+ /**
+ * @see DATACASS-298
+ */
@Test
public void resolveIdFromElement() {
+
when(mockElement.getAttribute(eq(CassandraCqlClusterParser.ID_ATTRIBUTE))).thenReturn("test");
+
assertThat(parser.resolveId(mockElement, null, null), is(equalTo("test")));
- verify(mockElement, times(1)).getAttribute(eq(CassandraCqlClusterParser.ID_ATTRIBUTE));
+ verify(mockElement).getAttribute(eq(CassandraCqlClusterParser.ID_ATTRIBUTE));
}
+ /**
+ * @see DATACASS-298
+ */
@Test
public void resolveIdUsingDefault() {
+
when(mockElement.getAttribute(eq(CassandraCqlClusterParser.ID_ATTRIBUTE))).thenReturn("");
+
assertThat(parser.resolveId(mockElement, null, null), is(equalTo(DefaultCqlBeanNames.CLUSTER)));
- verify(mockElement, times(1)).getAttribute(eq(CassandraCqlClusterParser.ID_ATTRIBUTE));
+ verify(mockElement).getAttribute(eq(CassandraCqlClusterParser.ID_ATTRIBUTE));
}
+ /**
+ * @see DATACASS-298
+ */
@Test
public void parseInternalCallsDoParseAndConstructsBeanDefinition() {
+
BeanDefinition mockContainingBeanDefinition = mock(BeanDefinition.class);
when(mockContainingBeanDefinition.getScope()).thenReturn("Singleton");
@@ -163,26 +130,30 @@ public class CassandraCqlClusterParserUnitTests {
assertThat(getPropertyValueAsString(beanDefinition, "sslEnabled"), is(equalTo("true")));
assertThat(getPropertyValueAsString(beanDefinition, "username"), is(equalTo("jonDoe")));
- verify(mockContainingBeanDefinition, times(1)).getScope();
- verify(mockElement, times(1)).getAttribute(eq("auth-info-provider-ref"));
- verify(mockElement, times(1)).getAttribute(eq("host-state-listener-ref"));
- verify(mockElement, times(1)).getAttribute(eq("latency-tracker-ref"));
- verify(mockElement, times(1)).getAttribute(eq("load-balancing-policy-ref"));
- verify(mockElement, times(1)).getAttribute(eq("reconnection-policy-ref"));
- verify(mockElement, times(1)).getAttribute(eq("retry-policy-ref"));
- verify(mockElement, times(1)).getAttribute(eq("ssl-options-ref"));
- verify(mockElement, times(1)).getAttribute(eq("contact-points"));
- verify(mockElement, times(1)).getAttribute(eq("compression"));
- verify(mockElement, times(1)).getAttribute(eq("jmx-reporting-enabled"));
- verify(mockElement, times(1)).getAttribute(eq("metrics-enabled"));
- verify(mockElement, times(1)).getAttribute(eq("password"));
- verify(mockElement, times(1)).getAttribute(eq("port"));
- verify(mockElement, times(1)).getAttribute(eq("ssl-enabled"));
- verify(mockElement, times(1)).getAttribute(eq("username"));
+ verify(mockContainingBeanDefinition).getScope();
+ verify(mockElement).getAttribute(eq("auth-info-provider-ref"));
+ verify(mockElement).getAttribute(eq("host-state-listener-ref"));
+ verify(mockElement).getAttribute(eq("latency-tracker-ref"));
+ verify(mockElement).getAttribute(eq("load-balancing-policy-ref"));
+ verify(mockElement).getAttribute(eq("reconnection-policy-ref"));
+ verify(mockElement).getAttribute(eq("retry-policy-ref"));
+ verify(mockElement).getAttribute(eq("ssl-options-ref"));
+ verify(mockElement).getAttribute(eq("contact-points"));
+ verify(mockElement).getAttribute(eq("compression"));
+ verify(mockElement).getAttribute(eq("jmx-reporting-enabled"));
+ verify(mockElement).getAttribute(eq("metrics-enabled"));
+ verify(mockElement).getAttribute(eq("password"));
+ verify(mockElement).getAttribute(eq("port"));
+ verify(mockElement).getAttribute(eq("ssl-enabled"));
+ verify(mockElement).getAttribute(eq("username"));
}
+ /**
+ * @see DATACASS-298
+ */
@Test
public void parseChildElementsWithLocalPoolingOptions() {
+
Element localPoolingOptionsElement = mock(Element.class);
NodeList mockNodeList = mockNodeList(localPoolingOptionsElement);
@@ -200,7 +171,7 @@ public class CassandraCqlClusterParserUnitTests {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition();
- parser.parseChildElements(mockElement, mockParserContext(), builder);
+ parser.parseChildElements(mockElement, mockParserContext(null), builder);
BeanDefinition beanDefinition = builder.getBeanDefinition();
@@ -221,20 +192,24 @@ public class CassandraCqlClusterParserUnitTests {
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "remoteMaxSimultaneousRequests"), is(nullValue()));
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "remoteMinSimultaneousRequests"), is(nullValue()));
- verify(mockElement, times(1)).getChildNodes();
- verify(mockElement, times(1)).getAttribute(eq("heartbeat-interval-seconds"));
- verify(mockElement, times(1)).getAttribute(eq("idle-timeout-seconds"));
- verify(mockElement, times(1)).getAttribute(eq("initialization-executor-ref"));
- verify(mockElement, times(1)).getAttribute(eq("pool-timeout-milliseconds"));
- verify(localPoolingOptionsElement, times(1)).getLocalName();
- verify(localPoolingOptionsElement, times(1)).getAttribute(eq("core-connections"));
- verify(localPoolingOptionsElement, times(1)).getAttribute(eq("max-connections"));
- verify(localPoolingOptionsElement, times(1)).getAttribute(eq("max-simultaneous-requests"));
- verify(localPoolingOptionsElement, times(1)).getAttribute(eq("min-simultaneous-requests"));
+ verify(mockElement).getChildNodes();
+ verify(mockElement).getAttribute(eq("heartbeat-interval-seconds"));
+ verify(mockElement).getAttribute(eq("idle-timeout-seconds"));
+ verify(mockElement).getAttribute(eq("initialization-executor-ref"));
+ verify(mockElement).getAttribute(eq("pool-timeout-milliseconds"));
+ verify(localPoolingOptionsElement).getLocalName();
+ verify(localPoolingOptionsElement).getAttribute(eq("core-connections"));
+ verify(localPoolingOptionsElement).getAttribute(eq("max-connections"));
+ verify(localPoolingOptionsElement).getAttribute(eq("max-simultaneous-requests"));
+ verify(localPoolingOptionsElement).getAttribute(eq("min-simultaneous-requests"));
}
+ /**
+ * @see DATACASS-298
+ */
@Test
public void parseChildElementsWithRemotePoolingOptions() {
+
Element localPoolingOptionsElement = mock(Element.class);
NodeList mockNodeList = mockNodeList(localPoolingOptionsElement);
@@ -252,7 +227,7 @@ public class CassandraCqlClusterParserUnitTests {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition();
- parser.parseChildElements(mockElement, mockParserContext(), builder);
+ parser.parseChildElements(mockElement, mockParserContext(null), builder);
BeanDefinition beanDefinition = builder.getBeanDefinition();
@@ -275,20 +250,24 @@ public class CassandraCqlClusterParserUnitTests {
assertThat(getPropertyValueAsString(poolingOptionsBeanDefinition, "remoteMinSimultaneousRequests"), is(equalTo(
"5")));
- verify(mockElement, times(1)).getChildNodes();
- verify(mockElement, times(1)).getAttribute(eq("heartbeat-interval-seconds"));
- verify(mockElement, times(1)).getAttribute(eq("idle-timeout-seconds"));
- verify(mockElement, times(1)).getAttribute(eq("initialization-executor-ref"));
- verify(mockElement, times(1)).getAttribute(eq("pool-timeout-milliseconds"));
- verify(localPoolingOptionsElement, times(1)).getLocalName();
- verify(localPoolingOptionsElement, times(1)).getAttribute(eq("core-connections"));
- verify(localPoolingOptionsElement, times(1)).getAttribute(eq("max-connections"));
- verify(localPoolingOptionsElement, times(1)).getAttribute(eq("max-simultaneous-requests"));
- verify(localPoolingOptionsElement, times(1)).getAttribute(eq("min-simultaneous-requests"));
+ verify(mockElement).getChildNodes();
+ verify(mockElement).getAttribute(eq("heartbeat-interval-seconds"));
+ verify(mockElement).getAttribute(eq("idle-timeout-seconds"));
+ verify(mockElement).getAttribute(eq("initialization-executor-ref"));
+ verify(mockElement).getAttribute(eq("pool-timeout-milliseconds"));
+ verify(localPoolingOptionsElement).getLocalName();
+ verify(localPoolingOptionsElement).getAttribute(eq("core-connections"));
+ verify(localPoolingOptionsElement).getAttribute(eq("max-connections"));
+ verify(localPoolingOptionsElement).getAttribute(eq("max-simultaneous-requests"));
+ verify(localPoolingOptionsElement).getAttribute(eq("min-simultaneous-requests"));
}
+ /**
+ * @see DATACASS-298
+ */
@Test
public void parseLocalPoolingOptionsProperlyConfiguresBeanDefinition() {
+
when(mockElement.getAttribute(eq("core-connections"))).thenReturn("50");
when(mockElement.getAttribute(eq("max-connections"))).thenReturn("200");
when(mockElement.getAttribute(eq("max-simultaneous-requests"))).thenReturn("50");
@@ -317,14 +296,18 @@ public class CassandraCqlClusterParserUnitTests {
verify(mockElement, never()).getAttribute(eq("idle-timeout-seconds"));
verify(mockElement, never()).getAttribute(eq("initialization-executor-ref"));
verify(mockElement, never()).getAttribute(eq("pool-timeout-milliseconds"));
- verify(mockElement, times(1)).getAttribute(eq("core-connections"));
- verify(mockElement, times(1)).getAttribute(eq("max-connections"));
- verify(mockElement, times(1)).getAttribute(eq("max-simultaneous-requests"));
- verify(mockElement, times(1)).getAttribute(eq("min-simultaneous-requests"));
+ verify(mockElement).getAttribute(eq("core-connections"));
+ verify(mockElement).getAttribute(eq("max-connections"));
+ verify(mockElement).getAttribute(eq("max-simultaneous-requests"));
+ verify(mockElement).getAttribute(eq("min-simultaneous-requests"));
}
+ /**
+ * @see DATACASS-298
+ */
@Test
public void parseRemotePoolingOptionsProperlyConfiguresBeanDefinition() {
+
when(mockElement.getAttribute(eq("core-connections"))).thenReturn("50");
when(mockElement.getAttribute(eq("max-connections"))).thenReturn("200");
when(mockElement.getAttribute(eq("max-simultaneous-requests"))).thenReturn("50");
@@ -353,21 +336,29 @@ public class CassandraCqlClusterParserUnitTests {
verify(mockElement, never()).getAttribute(eq("idle-timeout-seconds"));
verify(mockElement, never()).getAttribute(eq("initialization-executor-ref"));
verify(mockElement, never()).getAttribute(eq("pool-timeout-milliseconds"));
- verify(mockElement, times(1)).getAttribute(eq("core-connections"));
- verify(mockElement, times(1)).getAttribute(eq("max-connections"));
- verify(mockElement, times(1)).getAttribute(eq("max-simultaneous-requests"));
- verify(mockElement, times(1)).getAttribute(eq("min-simultaneous-requests"));
+ verify(mockElement).getAttribute(eq("core-connections"));
+ verify(mockElement).getAttribute(eq("max-connections"));
+ verify(mockElement).getAttribute(eq("max-simultaneous-requests"));
+ verify(mockElement).getAttribute(eq("min-simultaneous-requests"));
}
+ /**
+ * @see DATACASS-298
+ */
@Test
public void parseScript() {
+
when(mockElement.getTextContent()).thenReturn("CREATE TABLE schema.table;");
assertThat(parser.parseScript(mockElement), is(equalTo("CREATE TABLE schema.table;")));
- verify(mockElement, times(1)).getTextContent();
+ verify(mockElement).getTextContent();
}
+ /**
+ * @see DATACASS-298
+ */
@Test
public void newSocketOptionsBeanDefinitionIsProperlyInitialized() {
+
when(mockElement.getAttribute(eq("connect-timeout-millis"))).thenReturn("15000");
when(mockElement.getAttribute(eq("keep-alive"))).thenReturn("true");
when(mockElement.getAttribute(eq("read-timeout-millis"))).thenReturn("20000");
@@ -377,7 +368,7 @@ public class CassandraCqlClusterParserUnitTests {
when(mockElement.getAttribute(eq("so-linger"))).thenReturn("false");
when(mockElement.getAttribute(eq("tcp-no-delay"))).thenReturn("true");
- BeanDefinition beanDefinition = parser.newSocketOptionsBeanDefinition(mockElement, mockParserContext());
+ BeanDefinition beanDefinition = parser.newSocketOptionsBeanDefinition(mockElement, mockParserContext(null));
assertThat(beanDefinition, is(notNullValue(BeanDefinition.class)));
assertThat(beanDefinition.getBeanClassName(), is(equalTo(SocketOptionsFactoryBean.class.getName())));
@@ -391,13 +382,32 @@ public class CassandraCqlClusterParserUnitTests {
assertThat(getPropertyValueAsString(beanDefinition, "soLinger"), is(equalTo("false")));
assertThat(getPropertyValueAsString(beanDefinition, "tcpNoDelay"), is(equalTo("true")));
- verify(mockElement, times(1)).getAttribute(eq("connect-timeout-millis"));
- verify(mockElement, times(1)).getAttribute(eq("keep-alive"));
- verify(mockElement, times(1)).getAttribute(eq("read-timeout-millis"));
- verify(mockElement, times(1)).getAttribute(eq("receive-buffer-size"));
- verify(mockElement, times(1)).getAttribute(eq("reuse-address"));
- verify(mockElement, times(1)).getAttribute(eq("send-buffer-size"));
- verify(mockElement, times(1)).getAttribute(eq("so-linger"));
- verify(mockElement, times(1)).getAttribute(eq("tcp-no-delay"));
+ verify(mockElement).getAttribute(eq("connect-timeout-millis"));
+ verify(mockElement).getAttribute(eq("keep-alive"));
+ verify(mockElement).getAttribute(eq("read-timeout-millis"));
+ verify(mockElement).getAttribute(eq("receive-buffer-size"));
+ verify(mockElement).getAttribute(eq("reuse-address"));
+ verify(mockElement).getAttribute(eq("send-buffer-size"));
+ verify(mockElement).getAttribute(eq("so-linger"));
+ verify(mockElement).getAttribute(eq("tcp-no-delay"));
+ }
+
+ private NodeList mockNodeList(Element... childElements) {
+
+ NodeList mockNodeList = mock(NodeList.class);
+
+ when(mockNodeList.getLength()).thenReturn(childElements.length);
+
+ for (int index = 0; index < childElements.length; index++) {
+ when(mockNodeList.item(eq(index))).thenReturn(childElements[index]);
+ }
+
+ return mockNodeList;
+ }
+
+ private ParserContext mockParserContext(BeanDefinition beanDefinition) {
+
+ XmlReaderContext readerContext = new XmlReaderContext(null, null, null, new PassThroughSourceExtractor(), null, null);
+ return new ParserContext(readerContext, new BeanDefinitionParserDelegate(readerContext), beanDefinition);
}
}
diff --git a/spring-cql/src/test/java/org/springframework/cassandra/config/xml/ParsingUtilsUnitTests.java b/spring-cql/src/test/java/org/springframework/cassandra/config/xml/ParsingUtilsUnitTests.java
index e9a9dc02a..563198b6b 100644
--- a/spring-cql/src/test/java/org/springframework/cassandra/config/xml/ParsingUtilsUnitTests.java
+++ b/spring-cql/src/test/java/org/springframework/cassandra/config/xml/ParsingUtilsUnitTests.java
@@ -18,11 +18,11 @@ package org.springframework.cassandra.config.xml;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
+import static org.springframework.cassandra.support.BeanDefinitionTestUtils.*;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.springframework.beans.PropertyValue;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
@@ -31,26 +31,20 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder;
* Test suite of unit tests testing the contract and functionality of the {@link ParsingUtils} class.
*
* @author John Blum
- * @see org.springframework.cassandra.config.xml.ParsingUtils
- * @since 1.5.0
*/
// TODO: add more tests!
public class ParsingUtilsUnitTests {
- @Rule
- public ExpectedException exception = ExpectedException.none();
-
- @SuppressWarnings("unchecked")
- protected T getPropertyValue(BeanDefinition beanDefinition, String propertyName) {
- PropertyValue propertyValue = beanDefinition.getPropertyValues().getPropertyValue(propertyName);
-
- return (T) (propertyValue != null ? propertyValue.getValue() : null);
- }
+ @Rule public ExpectedException exception = ExpectedException.none();
+ /**
+ * @see DATACASS-298
+ */
@Test
public void addOptionalReferencePropertyUsesDefault() {
+
BeanDefinitionBuilder builder = ParsingUtils.addProperty(BeanDefinitionBuilder.genericBeanDefinition(),
- "referenceProperty", null, "defaultBeanReference", false, true);
+ "referenceProperty", null, "defaultBeanReference", false, true);
RuntimeBeanReference propertyValue = getPropertyValue(builder.getBeanDefinition(), "referenceProperty");
@@ -58,10 +52,14 @@ public class ParsingUtilsUnitTests {
assertThat(propertyValue.getBeanName(), is(equalTo("defaultBeanReference")));
}
+ /**
+ * @see DATACASS-298
+ */
@Test
public void addOptionalReferencePropertyWithNoValueDoesReturnsWithoutAdding() {
+
BeanDefinitionBuilder builder = ParsingUtils.addProperty(BeanDefinitionBuilder.genericBeanDefinition(),
- "referenceProperty", null, null, false, false);
+ "referenceProperty", null, null, false, false);
BeanDefinition beanDefinition = builder.getRawBeanDefinition();
@@ -69,20 +67,28 @@ public class ParsingUtilsUnitTests {
assertThat(beanDefinition.getPropertyValues().isEmpty(), is(true));
}
+ /**
+ * @see DATACASS-298
+ */
@Test
public void addOptionalValuePropertyUsesDefault() {
+
BeanDefinitionBuilder builder = ParsingUtils.addProperty(BeanDefinitionBuilder.genericBeanDefinition(),
- "valueProperty", null, "defaultValue", false, false);
+ "valueProperty", null, "defaultValue", false, false);
String propertyValue = getPropertyValue(builder.getBeanDefinition(), "valueProperty");
assertThat(propertyValue, is(equalTo("defaultValue")));
}
+ /**
+ * @see DATACASS-298
+ */
@Test
public void addOptionalValuePropertyWithNoValueDoesReturnsWithoutAdding() {
+
BeanDefinitionBuilder builder = ParsingUtils.addProperty(BeanDefinitionBuilder.genericBeanDefinition(),
- "valueProperty", null, null, false, false);
+ "valueProperty", null, null, false, false);
BeanDefinition beanDefinition = builder.getRawBeanDefinition();
@@ -90,10 +96,14 @@ public class ParsingUtilsUnitTests {
assertThat(beanDefinition.getPropertyValues().isEmpty(), is(true));
}
+ /**
+ * @see DATACASS-298
+ */
@Test
public void addRequiredReferencePropertyIsSuccessful() {
+
BeanDefinitionBuilder builder = ParsingUtils.addProperty(BeanDefinitionBuilder.genericBeanDefinition(),
- "referenceProperty", "reference", null, true, true);
+ "referenceProperty", "reference", null, true, true);
RuntimeBeanReference propertyValue = getPropertyValue(builder.getBeanDefinition(), "referenceProperty");
@@ -101,38 +111,54 @@ public class ParsingUtilsUnitTests {
assertThat(propertyValue.getBeanName(), is(equalTo("reference")));
}
+ /**
+ * @see DATACASS-298
+ */
@Test
public void addRequiredReferencePropertyWithNoReferenceFails() {
+
exception.expect(IllegalArgumentException.class);
exception.expectCause(is(nullValue(Throwable.class)));
exception.expectMessage("value required for property reference [referenceProperty] on class [null]");
ParsingUtils.addProperty(BeanDefinitionBuilder.genericBeanDefinition(), "referenceProperty", null,
- "defaultReference", true, true);
+ "defaultReference", true, true);
}
+ /**
+ * @see DATACASS-298
+ */
@Test
public void addRequiredValuePropertyIsSuccessful() {
+
BeanDefinitionBuilder builder = ParsingUtils.addProperty(BeanDefinitionBuilder.genericBeanDefinition(),
- "valueProperty", "value", null, true, false);
+ "valueProperty", "value", null, true, false);
String propertyValue = getPropertyValue(builder.getBeanDefinition(), "valueProperty");
assertThat(propertyValue, is(equalTo("value")));
}
+ /**
+ * @see DATACASS-298
+ */
@Test
public void addRequiredValuePropertyWithNoValueFails() {
+
exception.expect(IllegalArgumentException.class);
exception.expectCause(is(nullValue(Throwable.class)));
exception.expectMessage("value required for property [valueProperty] on class [null]");
- ParsingUtils.addProperty(BeanDefinitionBuilder.genericBeanDefinition(), "valueProperty", null,
- "defaultValue", true, false);
+ ParsingUtils.addProperty(BeanDefinitionBuilder.genericBeanDefinition(), "valueProperty", null, "defaultValue", true,
+ false);
}
+ /**
+ * @see DATACASS-298
+ */
@Test
public void addPropertyThrowsIllegalArgumentExceptionForNullBuilder() {
+
exception.expect(IllegalArgumentException.class);
exception.expectCause(is(nullValue(Throwable.class)));
exception.expectMessage("BeanDefinitionBuilder must not be null");
@@ -140,13 +166,16 @@ public class ParsingUtilsUnitTests {
ParsingUtils.addProperty(null, "propertyName", "value", "defaultValue", false, false);
}
+ /**
+ * @see DATACASS-298
+ */
@Test
public void addPropertyThrowsIllegalArgumentExceptionForNullPropertyName() {
+
exception.expect(IllegalArgumentException.class);
exception.expectCause(is(nullValue(Throwable.class)));
exception.expectMessage("Property name must not be null");
- ParsingUtils.addProperty(BeanDefinitionBuilder.genericBeanDefinition(), null, "value", "defaultValue",
- false, true);
+ ParsingUtils.addProperty(BeanDefinitionBuilder.genericBeanDefinition(), null, "value", "defaultValue", false, true);
}
}
diff --git a/spring-cql/src/test/java/org/springframework/cassandra/support/BeanDefinitionTestUtils.java b/spring-cql/src/test/java/org/springframework/cassandra/support/BeanDefinitionTestUtils.java
new file mode 100644
index 000000000..d6807dced
--- /dev/null
+++ b/spring-cql/src/test/java/org/springframework/cassandra/support/BeanDefinitionTestUtils.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2016 the original author or authors.
+ *
+ * Licensed 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.springframework.cassandra.support;
+
+import org.springframework.beans.PropertyValue;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.beans.factory.config.RuntimeBeanReference;
+import org.springframework.util.Assert;
+
+/**
+ * {@code BeanDefinitionTestUtils} is a collection of {@link org.springframework.beans.factory.config.BeanDefinition}
+ * -based utility methods for use in unit and integration testing scenarios.
+ *
+ * @author Mark Paluch
+ */
+public abstract class BeanDefinitionTestUtils {
+
+ /**
+ * Prevent instances.
+ */
+ private BeanDefinitionTestUtils() {}
+
+ /**
+ * Retrieve the {@code propertyValue} from a {@link BeanDefinition} by its {@code propertyName}.
+ *
+ * @param beanDefinition must not be {@literal null}.
+ * @param propertyName must not be {@literal null} or empty.
+ * @return the property value, may be {@literal null}.
+ */
+ @SuppressWarnings("unchecked")
+ public static T getPropertyValue(BeanDefinition beanDefinition, String propertyName) {
+
+ Assert.notNull(beanDefinition, "BeanDefinition must not be null");
+ Assert.notNull(propertyName, "Property name must not be empty");
+
+ PropertyValue propertyValue = beanDefinition.getPropertyValues().getPropertyValue(propertyName);
+ return (T) (propertyValue != null ? propertyValue.getValue() : null);
+ }
+
+ /**
+ * Retrieve the {@code propertyValue} as {@literal String} from a {@link BeanDefinition} by its {@code propertyName}.
+ *
+ * @param beanDefinition must not be {@literal null}.
+ * @param propertyName must not be {@literal null} or empty.
+ * @return the property value, may be {@literal null}.
+ */
+ public static String getPropertyValueAsString(BeanDefinition beanDefinition, String propertyName) {
+
+ Assert.notNull(beanDefinition, "BeanDefinition must not be null");
+ Assert.notNull(propertyName, "Property name must not be empty");
+
+ Object value = getPropertyValue(beanDefinition, propertyName);
+ return (value instanceof RuntimeBeanReference ? ((RuntimeBeanReference) value).getBeanName()
+ : (value != null ? String.valueOf(value) : null));
+ }
+
+}
diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/PropertyPlaceholderNamespaceCreatingXmlConfigIntegrationTests.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/PropertyPlaceholderNamespaceCreatingXmlConfigIntegrationTests.java
index 49a9ba4eb..1570df810 100644
--- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/PropertyPlaceholderNamespaceCreatingXmlConfigIntegrationTests.java
+++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/PropertyPlaceholderNamespaceCreatingXmlConfigIntegrationTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013-2014 the original author or authors.
+ * Copyright 2013-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,6 +34,8 @@ import com.datastax.driver.core.Session;
import com.datastax.driver.core.SocketOptions;
/**
+ * Integration tests for XML-based configuration using property placeholders.
+ *
* @author Mark Paluch
* @author John Blum
*/
@@ -43,14 +45,9 @@ import com.datastax.driver.core.SocketOptions;
public class PropertyPlaceholderNamespaceCreatingXmlConfigIntegrationTests
extends AbstractEmbeddedCassandraIntegrationTest {
- @Autowired
- private Cluster cassandraCluster;
-
- @Autowired
- private CqlOperations ops;
-
- @Autowired
- private Session session;
+ @Autowired private Cluster cassandraCluster;
+ @Autowired private CqlOperations ops;
+ @Autowired private Session session;
@Test
public void keyspaceExists() {
@@ -61,6 +58,9 @@ public class PropertyPlaceholderNamespaceCreatingXmlConfigIntegrationTests
assertNotNull(ops);
}
+ /**
+ * @see DATACASS-298
+ */
@Test
public void localAndRemotePoolingOptionsWereConfiguredProperly() {
@@ -80,6 +80,9 @@ public class PropertyPlaceholderNamespaceCreatingXmlConfigIntegrationTests
assertThat(poolingOptions.getNewConnectionThreshold(HostDistance.REMOTE), is(equalTo(5)));
}
+ /**
+ * @see DATACASS-298
+ */
@Test
public void socketOptionsWereConfiguredProperly() {
diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/XmlConfigIntegrationTests.java b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/XmlConfigIntegrationTests.java
index e156f4ee6..51b92b8cb 100644
--- a/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/XmlConfigIntegrationTests.java
+++ b/spring-cql/src/test/java/org/springframework/cassandra/test/integration/config/xml/XmlConfigIntegrationTests.java
@@ -49,15 +49,11 @@ public class XmlConfigIntegrationTests extends AbstractEmbeddedCassandraIntegrat
public static final String KEYSPACE = "xmlconfigtest";
- @Rule
- public KeyspaceRule keyspaceRule = new KeyspaceRule(cassandraEnvironment, KEYSPACE);
+ @Rule public KeyspaceRule keyspaceRule = new KeyspaceRule(cassandraEnvironment, KEYSPACE);
private ConfigurableApplicationContext applicationContext;
-
private Cluster cluster;
-
private Executor executor;
-
private Session session;
@Before
@@ -82,6 +78,9 @@ public class XmlConfigIntegrationTests extends AbstractEmbeddedCassandraIntegrat
IntegrationTestUtils.assertKeyspaceExists(KEYSPACE, session);
}
+ /**
+ * @see DATACASS-298
+ */
@Test
public void localAndRemotePoolingOptionsWereConfiguredProperly() {
@@ -102,6 +101,9 @@ public class XmlConfigIntegrationTests extends AbstractEmbeddedCassandraIntegrat
assertThat(poolingOptions.getNewConnectionThreshold(HostDistance.REMOTE), is(equalTo(25)));
}
+ /**
+ * @see DATACASS-298
+ */
@Test
public void socketOptionsWereConfiguredProperly() {
diff --git a/spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/PropertyPlaceholderNamespaceCreatingXmlConfigIntegrationTests-context.xml b/spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/PropertyPlaceholderNamespaceCreatingXmlConfigIntegrationTests-context.xml
index 7da0dbdc0..4824e4da4 100644
--- a/spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/PropertyPlaceholderNamespaceCreatingXmlConfigIntegrationTests-context.xml
+++ b/spring-cql/src/test/resources/org/springframework/cassandra/test/integration/config/xml/PropertyPlaceholderNamespaceCreatingXmlConfigIntegrationTests-context.xml
@@ -17,13 +17,6 @@
-
-