INTEXT-105: Fix "index" property according to the schema

JIRA: https://jira.spring.io/browse/INTEXT-105

Previously the `SplunkIndexWriter` has property `indexName`,
however the XSD for `<int-splunk:index-writer/>` provides the `index` attribute

Rename the property and add parser test
This commit is contained in:
Olivier Lamy
2014-06-12 14:06:03 +03:00
committed by Artem Bilan
parent 9df12e5a2b
commit 9b651a5261
3 changed files with 54 additions and 51 deletions

View File

@@ -1,66 +1,63 @@
/*
* Copyright 2002-2013 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
* Copyright 2002-2014 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
*
* 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.integration.splunk.support;
import java.io.IOException;
import java.net.Socket;
import org.springframework.integration.splunk.core.ServiceFactory;
import org.springframework.util.Assert;
import com.splunk.Args;
import com.splunk.Index;
import com.splunk.Receiver;
import com.splunk.Service;
import org.springframework.integration.splunk.core.ServiceFactory;
import org.springframework.util.Assert;
/**
*
* DataWriter to stream data into Splunk using an optional index. If no index specified,
*
* DataWriter to stream data into Splunk using an optional index. If no index specified,
* the main default index is used.
*
* @author Jarred Li
* @author David Turanski
* @author Olivier Lamy
* @since 1.0
*
*/
public class SplunkIndexWriter extends AbstractSplunkDataWriter {
private String indexName;
/**
*
* @param serviceFactory
* @param args
*/
private String index;
public SplunkIndexWriter(ServiceFactory serviceFactory, Args args) {
super(serviceFactory, args);
}
/* (non-Javadoc)
* @see org.springframework.integration.splunk.support.SplunkDataWriter#createSocket(com.splunk.Service)
*/
@Override
protected Socket createSocket(Service service) throws IOException {
Index indexObject = null;
Receiver receiver = null;
Socket socket = null;
if (indexName != null) {
indexObject = service.getIndexes().get(indexName);
Assert.notNull(indexObject,String.format("cannot find index [%s]",indexName));
if (index != null) {
indexObject = service.getIndexes().get(index);
Assert.notNull(indexObject, String.format("cannot find index [%s]", index));
socket = indexObject.attach(args);
} else {
}
else {
receiver = service.getReceiver();
socket = receiver.attach(args);
}
@@ -69,6 +66,14 @@ public class SplunkIndexWriter extends AbstractSplunkDataWriter {
}
return socket;
}
public String getIndex() {
return index;
}
public void setIndex(String index) {
this.index = index;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011-2012 the original author or authors.
* Copyright 2011-2014 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.
@@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.splunk.config.xml;
import static org.junit.Assert.*;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -30,6 +30,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Jarred Li
* @author Artem Bilan
* @since 1.0
*
*/
@@ -40,18 +41,16 @@ public class SplunkOutboundChannelAdapterParserStreamTests {
@Autowired
private ApplicationContext appContext;
/**
* Test method for {@link org.springframework.integration.splunk.config.xml.SplunkOutboundChannelAdapterParser#parseConsumer(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext)}.
*/
@Test
public void testParseConsumerElementParserContext() {
Object adapter = appContext.getBean("splunkOutboundChannelAdapter");
Assert.assertNotNull(adapter);
assertNotNull(adapter);
AbstractSplunkDataWriter writer = appContext.getBean("splunkOutboundChannelAdapter.splunkExecutor.writer",
AbstractSplunkDataWriter.class);
Assert.assertNotNull(writer);
assertTrue(writer instanceof SplunkIndexWriter);
assertNotNull(writer);
assertTrue(writer instanceof SplunkIndexWriter);
assertEquals("foo", ((SplunkIndexWriter) writer).getIndex());
}
}

View File

@@ -1,24 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframework.org/schema/integration"
xmlns:stream="http://www.springframework.org/schema/integration/stream"
xmlns:int-splunk="http://www.springframework.org/schema/integration/splunk"
xsi:schemaLocation="
http://www.springframework.org/schema/integration/stream http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-splunk="http://www.springframework.org/schema/integration/splunk"
xsi:schemaLocation="
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration/splunk http://www.springframework.org/schema/integration/splunk/spring-integration-splunk.xsd">
<import resource="../../SplunkCommon-context.xml" />
<import resource="../../SplunkCommon-context.xml"/>
<int:channel id="outputToSplunk"/>
<int-splunk:outbound-channel-adapter
id="splunkOutboundChannelAdapter" auto-startup="false" order="1"
channel="outputToSplunk" splunk-server-ref="splunkServer"
source-type="spring-integration" source="example5"
host="test.host" host-regex="test.host.*">
<int-splunk:index-writer/>
id="splunkOutboundChannelAdapter" auto-startup="false" order="1"
channel="outputToSplunk" splunk-server-ref="splunkServer"
source-type="spring-integration" source="example5"
host="test.host" host-regex="test.host.*">
<int-splunk:index-writer index="foo"/>
</int-splunk:outbound-channel-adapter>
</beans>