diff --git a/spring-integration-twitter/.project b/spring-integration-twitter/.project
index f39a076dcd..97116a18c4 100644
--- a/spring-integration-twitter/.project
+++ b/spring-integration-twitter/.project
@@ -15,8 +15,14 @@
+
+ org.springframework.ide.eclipse.core.springbuilder
+
+
+
+ org.springframework.ide.eclipse.core.springnature
org.maven.ide.eclipse.maven2Nature
org.eclipse.jdt.core.javanature
diff --git a/spring-integration-twitter/pom.xml b/spring-integration-twitter/pom.xml
index cb2b66c141..4f7a070454 100644
--- a/spring-integration-twitter/pom.xml
+++ b/spring-integration-twitter/pom.xml
@@ -1,5 +1,6 @@
-
+
4.0.0
org.springframework.integration
@@ -21,9 +22,14 @@
org.twitter4j
twitter4j-core
-
+
2.1.3
+
+ org.aspectj
+ aspectjweaver
+ 1.6.10
+
org.slf4j
nlog4j
diff --git a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/DirectMessage.java b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/DirectMessage.java
index eb2180ba26..28434a6543 100644
--- a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/DirectMessage.java
+++ b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/DirectMessage.java
@@ -25,13 +25,8 @@ import java.util.Date;
* @author Josh Long
* @since 2.0
*/
-public interface DirectMessage {
- int getId();
-
- String getText();
-
- Date getCreatedAt();
-
+public interface DirectMessage extends TwitterMessage{
+
User getSender() ;
User getRecipient();
diff --git a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/Status.java b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/Status.java
index 097685b54a..ee9dbd9284 100644
--- a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/Status.java
+++ b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/Status.java
@@ -1,37 +1,31 @@
/*
- * Copyright 2010 the original author or authors
+ * Copyright 2002-2010 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
+ * 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
+ * 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.
+ * 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.twitter.core;
-import java.util.Date;
/**
- * describes a simple status message on twitter. this could be a message
- * that updates a timeline on behalf of a user, or it could be a message that contains a reply.
- *
- *
+ * describes a simple status message on twitter. this could be a message that
+ * updates a timeline on behalf of a user, or it could be a message that
+ * contains a reply.
+ *
+ *
* @author Josh Long
- * @since 2.0
+ * @since 2.0
*/
-public interface Status {
-
- Date getCreatedAt();
-
- long getId();
-
- String getText();
+public interface Status extends TwitterMessage{
String getSource();
@@ -45,11 +39,11 @@ public interface Status {
boolean isFavorited();
- User getUser();
+ User getUser();
boolean isRetweet();
- Status getRetweetedStatus();
+ Status getRetweetedStatus();
String[] getContributors();
diff --git a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/Twitter4jDecorator.java b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/Twitter4jDecorator.java
new file mode 100644
index 0000000000..127d1098b4
--- /dev/null
+++ b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/Twitter4jDecorator.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2002-2010 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.integration.twitter.core;
+
+import java.lang.reflect.Method;
+
+import org.aopalliance.intercept.MethodInterceptor;
+import org.aopalliance.intercept.MethodInvocation;
+import org.springframework.util.Assert;
+import org.springframework.util.ReflectionUtils;
+
+import twitter4j.DirectMessage;
+import twitter4j.GeoLocation;
+import twitter4j.Status;
+import twitter4j.User;
+
+/**
+ * Sine our Twitter domain model is modeled after Twitter4j API
+ * this interceptor will delegate method calls that are made on SI Twitter interfaces
+ * to the corresponding Twitter4j objects.
+ *
+ * @author Oleg Zhurakousky
+ * @since 2.0
+ */
+class Twitter4jDecorator implements MethodInterceptor {
+
+ private final Object twitterObject;
+
+ public Twitter4jDecorator(Object twitterObject){
+ this.validateTwitter4JObject(twitterObject);
+ this.twitterObject = twitterObject;
+ }
+
+ /* (non-Javadoc)
+ * @see org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation)
+ */
+ @Override
+ public Object invoke(MethodInvocation invocation) throws Throwable {
+ Class> twitter4jClass = twitterObject.getClass();
+ Object[] args = invocation.getArguments();
+ Class>[] argsType = new Class[args.length];
+ for (int i = 0; i < args.length; i++) {
+ Object object = args[i];
+ argsType[i] = object.getClass();
+ }
+ String invokedmethodName = invocation.getMethod().getName();
+ Method targetMethod = ReflectionUtils.findMethod(twitter4jClass, invokedmethodName, argsType);
+ return targetMethod.invoke(twitterObject, args);
+ }
+
+ private void validateTwitter4JObject(Object twitterObject){
+ Assert.notNull(twitterObject, "'twitterObject' must not be null");
+ Assert.isTrue(twitterObject instanceof Status ||
+ twitterObject instanceof DirectMessage ||
+ twitterObject instanceof User ||
+ twitterObject instanceof GeoLocation,
+ "Only twitter4j.DirectMessage, twitter4j.Status, twitter4j.User, twitter4j.GeoLocation is supported");
+ }
+}
diff --git a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/TwitterFactory.java b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/TwitterFactory.java
new file mode 100644
index 0000000000..3f293831e9
--- /dev/null
+++ b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/TwitterFactory.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2002-2010 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.integration.twitter.core;
+
+import org.springframework.aop.framework.ProxyFactory;
+import org.springframework.aop.target.EmptyTargetSource;
+import org.springframework.util.Assert;
+
+import twitter4j.DirectMessage;
+import twitter4j.Status;
+
+/**
+ * Factory class with several static factory methods for constructing
+ * Twitter objects that are independent from the underlying API (e.g., twitter4j)
+ *
+ * @author Oleg Zhurakousky
+ * @since 2.0
+ */
+public class TwitterFactory {
+
+ private TwitterFactory(){}
+
+ /**
+ * Will construct either {@link org.springframework.integration.twitter.core.Status} or
+ * {@link org.springframework.integration.twitter.core.DirectMessage} from the instances of
+ * {@link Status} pr {@link DirectMessage}
+ *
+ * @param twitterMessage
+ * @return
+ */
+ public static TwitterMessage formTwitter4jMessage(Object twitterMessage){
+ Assert.isTrue(twitterMessage instanceof Status || twitterMessage instanceof DirectMessage,
+ "'twitterMessage' must be an instance of either twitter4j.DirectMessage or twitter4j.Status");
+ Class> interfaze = twitterMessage instanceof DirectMessage
+ ? org.springframework.integration.twitter.core.DirectMessage.class
+ : org.springframework.integration.twitter.core.Status.class;
+ ProxyFactory factory = new ProxyFactory(interfaze, EmptyTargetSource.INSTANCE);
+ factory.addAdvice(new Twitter4jDecorator(twitterMessage));
+ return (TwitterMessage) factory.getProxy();
+ }
+ /**
+ * Will constuct {@link GeoLocation} from 'latitude' and 'longitude'
+ *
+ * @param latitude
+ * @param longitude
+ * @return
+ */
+ public static GeoLocation fromLatitudeLongitude(double latitude, double longitude){
+ twitter4j.GeoLocation geolocation = new twitter4j.GeoLocation(latitude, longitude);
+ return fromTwitter4jGeoLocation(geolocation);
+ }
+ /**
+ * Will constuct {@link GeoLocation} from {@link twitter4j.GeoLocation}
+ * @param geolocation
+ * @return
+ */
+ public static GeoLocation fromTwitter4jGeoLocation(twitter4j.GeoLocation geolocation){
+ ProxyFactory factory = new ProxyFactory(GeoLocation.class, EmptyTargetSource.INSTANCE);
+ factory.addAdvice(new Twitter4jDecorator(geolocation));
+ return (GeoLocation) factory.getProxy();
+ }
+}
diff --git a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/TwitterMessage.java b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/TwitterMessage.java
new file mode 100644
index 0000000000..07300f4ba8
--- /dev/null
+++ b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/TwitterMessage.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2002-2010 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.integration.twitter.core;
+
+import java.util.Date;
+
+/**
+ * @author Oleg Zhurakousky
+ * @since 2.0
+ */
+public interface TwitterMessage {
+ int getId();
+
+ String getText();
+
+ Date getCreatedAt();
+}
diff --git a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/twitter/Twitter4jDirectMessage.java b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/twitter/Twitter4jDirectMessage.java
deleted file mode 100644
index f6b0322f09..0000000000
--- a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/twitter/Twitter4jDirectMessage.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright 2002-2010 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.integration.twitter.core.twitter;
-
-import org.springframework.integration.twitter.core.User;
-import org.springframework.util.Assert;
-
-import twitter4j.DirectMessage;
-
-import java.util.Date;
-
-/**
- * {@link twitter4j.DirectMessage} wrapper for {@link org.springframework.integration.twitter.core.DirectMessage}.
- *
- * @author Josh Long
- * @author Oleg ZHurakousky
- * @since 2.0
- */
-public class Twitter4jDirectMessage implements org.springframework.integration.twitter.core.DirectMessage {
- private DirectMessage directMessage;
-
- public Twitter4jDirectMessage(DirectMessage directMessage) {
- Assert.notNull(directMessage, "'directMessage' must not be null");
- this.directMessage = directMessage;
- }
-
- public DirectMessage getDirectMessage() {
- return this.directMessage;
- }
-
- public int getId() {
- return this.directMessage.getId();
- }
-
- public User getSender() {
- return new Twitter4jUser(this.directMessage.getSender());
- }
-
- public User getRecipient() {
- return new Twitter4jUser(this.directMessage.getRecipient());
- }
-
- public String getText() {
- return this.directMessage.getText();
- }
-
- public int getSenderId() {
- return this.directMessage.getSenderId();
- }
-
- public int getRecipientId() {
- return this.directMessage.getRecipientId();
- }
-
- public Date getCreatedAt() {
- return this.directMessage.getCreatedAt();
- }
-
- public String getSenderScreenName() {
- return this.directMessage.getSenderScreenName();
- }
-
- public String getRecipientScreenName() {
- return this.directMessage.getRecipientScreenName();
- }
-}
diff --git a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/twitter/Twitter4jGeoLocation.java b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/twitter/Twitter4jGeoLocation.java
deleted file mode 100644
index 576ef9972f..0000000000
--- a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/twitter/Twitter4jGeoLocation.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright 2010 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.integration.twitter.core.twitter;
-
-import org.springframework.integration.twitter.core.GeoLocation;
-
-/**
- * Implements a notion of GeoLocation that forwards calls to {@link twitter4j.GeoLocation} instance
- *
- * @author Josh Long
- * @since 2.0
- */
-public class Twitter4jGeoLocation implements GeoLocation {
-
- private twitter4j.GeoLocation geoLocation;
-
- public twitter4j.GeoLocation getGeoLocation() {
- return this.geoLocation;
- }
- public Twitter4jGeoLocation(double lat, double lon){
- this.geoLocation = new twitter4j.GeoLocation(lat,lon);
- }
- public Twitter4jGeoLocation(twitter4j.GeoLocation gl) {
- this.geoLocation = gl;
- }
-
- public double getLongitude() {
- return this.geoLocation.getLongitude();
- }
-
- public double getLatitude() {
- return this.geoLocation.getLatitude();
- }
-
-}
diff --git a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/twitter/Twitter4jStatus.java b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/twitter/Twitter4jStatus.java
deleted file mode 100644
index cc38c55f39..0000000000
--- a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/twitter/Twitter4jStatus.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright 2010 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.integration.twitter.core.twitter;
-
-import org.springframework.integration.twitter.core.Status;
-import org.springframework.integration.twitter.core.User;
-
-import java.util.Date;
-
-/**
- *
- * An implemention o the {@link org.springframework.integration.twitter.core.Status} interface that
- * forwards requests to a {@link twitter4j.Status} implementation
- *
- * @author Josh Long
- * @since 2.0
- */
-public class Twitter4jStatus implements Status {
- private twitter4j.Status status;
-
- public Twitter4jStatus(twitter4j.Status s) {
- this.status = s;
- }
-
- public Date getCreatedAt() {
- return this.status.getCreatedAt();
- }
-
- public long getId() {
- return this.status.getId();
- }
-
- public String getText() {
- return this.status.getText();
- }
-
- public String getSource() {
- return this.status.getSource();
- }
-
- public boolean isTruncated() {
- return this.status.isTruncated();
- }
-
- public long getInReplyToStatusId() {
- return this.status.getInReplyToStatusId();
- }
-
- public int getInReplyToUserId() {
- return this.status.getInReplyToUserId();
- }
-
- public String getInReplyToScreenName() {
- return this.status.getInReplyToScreenName();
- }
-
- public boolean isFavorited() {
- return this.status.isFavorited();
- }
-
- public User getUser() {
- return new Twitter4jUser(this.status.getUser());
- }
-
- public boolean isRetweet() {
- return this.status.isRetweet();
- }
-
- public Status getRetweetedStatus() {
- return new Twitter4jStatus(this.status.getRetweetedStatus());
- }
-
- public String[] getContributors() {
- return this.status.getContributors();
- }
-}
diff --git a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/twitter/Twitter4jUser.java b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/twitter/Twitter4jUser.java
deleted file mode 100644
index 10cbf8bbbc..0000000000
--- a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/twitter/Twitter4jUser.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright 2010 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.integration.twitter.core.twitter;
-
-import twitter4j.User;
-
-import java.net.URL;
-
-
-/**
- * implementation of the User interfce to represent Users in a Twitter application
- *
- * @author Josh Long
- * @since 2.0
- */
-public class Twitter4jUser implements org.springframework.integration.twitter.core.User {
-
- private twitter4j.User user;
-
- public Twitter4jUser(User u) {
- this.user = u;
- }
-
- public int getId() {
- return this.user.getId();
- }
-
- public String getName() {
- return user.getName();
- }
-
- public String getScreenName() {
- return this.user.getScreenName();
- }
-
- public String getLocation() {
- return this.user.getLocation();
- }
-
- public String getDescription() {
- return user.getDescription();
- }
-
- public boolean isContributorsEnabled() {
- return user.isContributorsEnabled();
- }
-
- public URL getProfileImageURL() {
- return user.getProfileImageURL();
- }
-
- public URL getURL() {
- return this.user.getURL();
- }
-
- public boolean isProtected() {
- return this.user.isProtected();
- }
-
- public int getFollowersCount() {
- return this.user.getFollowersCount();
- }
-}
diff --git a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/inbound/AbstractInboundTwitterStatusEndpointSupport.java b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/inbound/AbstractInboundTwitterStatusEndpointSupport.java
index 2be4967d30..fb2efc68d6 100644
--- a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/inbound/AbstractInboundTwitterStatusEndpointSupport.java
+++ b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/inbound/AbstractInboundTwitterStatusEndpointSupport.java
@@ -14,14 +14,14 @@
* limitations under the License.
*/
package org.springframework.integration.twitter.inbound;
-import org.springframework.integration.twitter.core.Status;
-import org.springframework.integration.twitter.core.twitter.Twitter4jStatus;
-
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
+import org.springframework.integration.twitter.core.Status;
+import org.springframework.integration.twitter.core.TwitterFactory;
+
/**
* Simple base class for the reply and timeline cases (as well as any other {@link twitter4j.Status} implementations of
@@ -40,7 +40,9 @@ abstract public class AbstractInboundTwitterStatusEndpointSupport extends Abstra
protected List fromTwitter4jStatuses(List stats) {
List fwd = new ArrayList();
for (twitter4j.Status s : stats) {
- fwd.add(new Twitter4jStatus(s));
+// ProxyFactory factory = new ProxyFactory(Status.class, EmptyTargetSource.INSTANCE);
+// factory.addAdvice(new Twitter4jDecorator(s));
+ fwd.add((Status) TwitterFactory.formTwitter4jMessage(s));
}
return fwd;
}
diff --git a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/inbound/InboundDirectMessageEndpoint.java b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/inbound/InboundDirectMessageEndpoint.java
index 487a122302..0c816d1047 100644
--- a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/inbound/InboundDirectMessageEndpoint.java
+++ b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/inbound/InboundDirectMessageEndpoint.java
@@ -22,7 +22,7 @@ import java.util.List;
import org.springframework.integration.MessagingException;
import org.springframework.integration.twitter.core.DirectMessage;
-import org.springframework.integration.twitter.core.twitter.Twitter4jDirectMessage;
+import org.springframework.integration.twitter.core.TwitterFactory;
import twitter4j.Paging;
@@ -77,7 +77,9 @@ public class InboundDirectMessageEndpoint extends AbstractInboundTwitterEndpoint
List dmsToFwd = new ArrayList();
for( twitter4j.DirectMessage dm : dms) {
- dmsToFwd.add( new Twitter4jDirectMessage( dm));
+// ProxyFactory factory = new ProxyFactory(DirectMessage.class, EmptyTargetSource.INSTANCE);
+// factory.addAdvice(new Twitter4jDecorator(dm));
+ dmsToFwd.add((DirectMessage) TwitterFactory.formTwitter4jMessage(dm));
}
forwardAll(dmsToFwd);
} catch (Exception e) {
diff --git a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/outbound/OutboundDirectMessageMessageHandler.java b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/outbound/OutboundDirectMessageMessageHandler.java
index 8c1d7e53d8..b93d6c994e 100644
--- a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/outbound/OutboundDirectMessageMessageHandler.java
+++ b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/outbound/OutboundDirectMessageMessageHandler.java
@@ -16,6 +16,7 @@
package org.springframework.integration.twitter.outbound;
import org.springframework.integration.Message;
+import org.springframework.integration.MessageHandlingException;
import org.springframework.integration.twitter.core.TwitterHeaders;
import org.springframework.util.Assert;
@@ -26,35 +27,37 @@ import twitter4j.TwitterException;
* Simple adapter to support sending outbound direct messages ("DM"s) using twitter
*
* @author Josh Long
- * @see org.springframework.integration.twitter.core.TwitterHeaders
- * @see twitter4j.Twitter
+ * @author Oleg Zhurakousky
* @since 2.0
*/
public class OutboundDirectMessageMessageHandler extends AbstractOutboundTwitterEndpointSupport {
@Override
protected void handleMessageInternal(Message> message) throws Exception {
+ if (this.twitter == null){
+ this.afterPropertiesSet();
+ }
try {
- String txt = (String) message.getPayload();
+ Object payload = (String) message.getPayload();
+ Assert.isInstanceOf(String.class, payload, "Only payload of type String is supported. If your payload " +
+ "is not of type String you may want to introduce transformer");
Object toUser = message.getHeaders().containsKey(TwitterHeaders.TWITTER_DM_TARGET_USER_ID) ?
message.getHeaders().get(TwitterHeaders.TWITTER_DM_TARGET_USER_ID) :
null;
- Assert.notNull(txt, "the message payload must be a String to be used as the direct message body text");
-
Assert.notNull(toUser, "the header '" + TwitterHeaders.TWITTER_DM_TARGET_USER_ID + "' must be present");
Assert.state(toUser instanceof String || toUser instanceof Integer,
"the header '" + TwitterHeaders.TWITTER_DM_TARGET_USER_ID + "' must be either a String (a screenname) or an int (a user ID)");
if (toUser instanceof Integer) {
- this.twitter.sendDirectMessage((Integer) toUser, txt);
- } else if (toUser instanceof String) {
- this.twitter.sendDirectMessage((String) toUser, txt);
+ this.twitter.sendDirectMessage((Integer) toUser, (String) payload);
+ }
+ else if (toUser instanceof String) {
+ this.twitter.sendDirectMessage((String) toUser, (String) payload);
}
} catch (TwitterException e) {
- logger.debug(e);
- throw new RuntimeException(e);
+ throw new MessageHandlingException(message, e);
}
}
}
diff --git a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/outbound/OutboundStatusUpdateMessageMapper.java b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/outbound/OutboundStatusUpdateMessageMapper.java
index 9ad5f7a470..65f37688b3 100644
--- a/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/outbound/OutboundStatusUpdateMessageMapper.java
+++ b/spring-integration-twitter/src/main/java/org/springframework/integration/twitter/outbound/OutboundStatusUpdateMessageMapper.java
@@ -19,8 +19,8 @@ import org.springframework.integration.Message;
import org.springframework.integration.MessageHandlingException;
import org.springframework.integration.mapping.OutboundMessageMapper;
import org.springframework.integration.twitter.core.TwitterHeaders;
-import org.springframework.integration.twitter.core.twitter.Twitter4jGeoLocation;
import org.springframework.util.StringUtils;
+
import twitter4j.StatusUpdate;
@@ -33,16 +33,16 @@ import twitter4j.StatusUpdate;
* @since 2.0
*/
public class OutboundStatusUpdateMessageMapper implements OutboundMessageMapper {
- /**
- * convenient, interface-oriented way of obtaining a reference to a {@link org.springframework.integration.twitter.core.twitter.Twitter4jGeoLocation}
- *
- * @param lat the latitude
- * @param lon the longitude
- * @return a {@link org.springframework.integration.twitter.core.GeoLocation} instance
- */
- public org.springframework.integration.twitter.core.GeoLocation fromLatitudeLongitudePair(double lat, double lon) {
- return new Twitter4jGeoLocation(lat, lon);
- }
+// /**
+// * convenient, interface-oriented way of obtaining a reference to a {@link org.springframework.integration.twitter.core.twitter.Twitter4jGeoLocation}
+// *
+// * @param lat the latitude
+// * @param lon the longitude
+// * @return a {@link org.springframework.integration.twitter.core.GeoLocation} instance
+// */
+// public org.springframework.integration.twitter.core.GeoLocation fromLatitudeLongitudePair(double lat, double lon) {
+// return new Twitter4jGeoLocation(lat, lon);
+// }
/**
* {@link StatusUpdate} instances are used to drive status updates.
@@ -79,16 +79,16 @@ public class OutboundStatusUpdateMessageMapper implements OutboundMessageMapper<
if (message.getHeaders().containsKey(TwitterHeaders.TWITTER_GEOLOCATION)) {
- org.springframework.integration.twitter.core.GeoLocation geoLocation = (org.springframework.integration.twitter.core.GeoLocation) message.getHeaders()
- .get(TwitterHeaders.TWITTER_GEOLOCATION);
- twitter4j.GeoLocation gl = null;
-
- if (geoLocation instanceof Twitter4jGeoLocation) {
- gl = ((Twitter4jGeoLocation) geoLocation).getGeoLocation();
- if (null != gl) {
- statusUpdate.location(gl);
- }
- }
+// org.springframework.integration.twitter.core.GeoLocation geoLocation = (org.springframework.integration.twitter.core.GeoLocation) message.getHeaders()
+// .get(TwitterHeaders.TWITTER_GEOLOCATION);
+// twitter4j.GeoLocation gl = null;
+//
+// if (geoLocation instanceof Twitter4jGeoLocation) {
+// gl = ((Twitter4jGeoLocation) geoLocation).getGeoLocation();
+// if (null != gl) {
+// statusUpdate.location(gl);
+// }
+// }
}
if (message.getHeaders()
diff --git a/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/InboundDirectMessageStatusEndpointTests.java b/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/InboundDirectMessageStatusEndpointTests.java
index fdfacf8489..6385baa555 100644
--- a/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/InboundDirectMessageStatusEndpointTests.java
+++ b/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/InboundDirectMessageStatusEndpointTests.java
@@ -33,7 +33,6 @@ import org.mockito.Mockito;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.Message;
import org.springframework.integration.channel.QueueChannel;
-import org.springframework.integration.twitter.core.twitter.Twitter4jDirectMessage;
import org.springframework.integration.twitter.inbound.InboundDirectMessageEndpoint;
import org.springframework.integration.twitter.oauth.OAuthConfiguration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
@@ -79,10 +78,11 @@ public class InboundDirectMessageStatusEndpointTests {
endpoint.start();
Message message1 = channel.receive(3000);
assertNotNull(message1);
- assertEquals(secondMessage, ((Twitter4jDirectMessage)message1.getPayload()).getDirectMessage());
+ System.out.println();
+ assertEquals(secondMessage.getId(), ((org.springframework.integration.twitter.core.DirectMessage)message1.getPayload()).getId());
Message message2 = channel.receive(3000);
assertNotNull(message2);
- assertEquals(firstMessage, ((Twitter4jDirectMessage)message2.getPayload()).getDirectMessage());
+ assertEquals(firstMessage.getId(), ((org.springframework.integration.twitter.core.DirectMessage)message2.getPayload()).getId());
}
@Before
diff --git a/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/TestSendingDMsUsingNamespace.java b/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/TestSendingDMsUsingNamespace.java
deleted file mode 100644
index 4434cd913a..0000000000
--- a/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/TestSendingDMsUsingNamespace.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright 2010 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.integration.twitter;
-
-import org.junit.Ignore;
-import org.junit.Test;
-
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.integration.MessageChannel;
-import org.springframework.integration.core.MessagingTemplate;
-import org.springframework.integration.support.MessageBuilder;
-import org.springframework.integration.twitter.core.twitter.Twitter4jGeoLocation;
-import org.springframework.integration.twitter.core.TwitterHeaders;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
-import org.springframework.util.Assert;
-import org.springframework.util.StringUtils;
-
-
-/**
- * @author Josh Long
- */
-@ContextConfiguration
-public class TestSendingDMsUsingNamespace extends AbstractJUnit4SpringContextTests {
-
- private volatile MessagingTemplate messagingTemplate = new MessagingTemplate();
-
- @Value("#{out}") private MessageChannel channel;
-
- @Test
- @Ignore
- public void testSendingATweet() throws Throwable {
-
- String dmUsr = System.getProperties().getProperty("twitter.dm.user");
- Assert.notNull( dmUsr , "the DM user's null");
- MessageBuilder mb = MessageBuilder.withPayload("'Hello world!', from the Spring Integration outbound Twitter adapter")
- .setHeader(TwitterHeaders.TWITTER_GEOLOCATION, new Twitter4jGeoLocation(-76.226823, 23.642465)) // antarctica
- .setHeader(TwitterHeaders.TWITTER_DISPLAY_COORDINATES, true);
-
- if (StringUtils.hasText(dmUsr)) {
- mb.setHeader(TwitterHeaders.TWITTER_DM_TARGET_USER_ID, dmUsr);
- }
-
- this.messagingTemplate.send(this.channel, mb.build());
- }
-}
diff --git a/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/TestSendingUpdatesUsingNamespace.java b/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/TestSendingUpdatesUsingNamespace.java
index cb324536cc..a098e15d4e 100644
--- a/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/TestSendingUpdatesUsingNamespace.java
+++ b/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/TestSendingUpdatesUsingNamespace.java
@@ -23,7 +23,6 @@ import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.core.MessagingTemplate;
import org.springframework.integration.support.MessageBuilder;
-import org.springframework.integration.twitter.core.twitter.Twitter4jGeoLocation;
import org.springframework.integration.twitter.core.TwitterHeaders;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
@@ -43,7 +42,7 @@ public class TestSendingUpdatesUsingNamespace extends AbstractJUnit4SpringContex
public void testSendingATweet() throws Throwable {
MessageBuilder mb = MessageBuilder.withPayload("simple test demonstrating the ability to encode location information")
.setHeader(TwitterHeaders.TWITTER_IN_REPLY_TO_STATUS_ID, 21927437001L)
- .setHeader(TwitterHeaders.TWITTER_GEOLOCATION, new Twitter4jGeoLocation(-76.226823, 23.642465)) // antarctica
+ //.setHeader(TwitterHeaders.TWITTER_GEOLOCATION, new Twitter4jGeoLocation(-76.226823, 23.642465)) // antarctica
.setHeader(TwitterHeaders.TWITTER_DISPLAY_COORDINATES, true);
Message m = mb.build();
this.messagingTemplate.send(this.channel, m);
diff --git a/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/TestReceivingUsingNamespace-context.xml b/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/config/TestReceivingUsingNamespace-context.xml
similarity index 80%
rename from spring-integration-twitter/src/test/java/org/springframework/integration/twitter/TestReceivingUsingNamespace-context.xml
rename to spring-integration-twitter/src/test/java/org/springframework/integration/twitter/config/TestReceivingUsingNamespace-context.xml
index ea3d775a5c..6a5b8c4734 100644
--- a/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/TestReceivingUsingNamespace-context.xml
+++ b/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/config/TestReceivingUsingNamespace-context.xml
@@ -1,21 +1,4 @@
-
-
-
-
-
-
-
+ consumer-secret="${twitter.oauth.consumerSecret}"/>
-
-
-
+
+
diff --git a/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/config/TestSendingDMsUsingNamespace.java b/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/config/TestSendingDMsUsingNamespace.java
new file mode 100644
index 0000000000..52631b2786
--- /dev/null
+++ b/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/config/TestSendingDMsUsingNamespace.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2002-2010 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.integration.twitter.config;
+
+import org.junit.Ignore;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.integration.MessageChannel;
+import org.springframework.integration.support.MessageBuilder;
+import org.springframework.integration.twitter.core.TwitterFactory;
+import org.springframework.integration.twitter.core.TwitterHeaders;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
+import org.springframework.util.StringUtils;
+
+/**
+ * @author Josh Long
+ * @author Oleg Zhurakouksy
+ */
+@ContextConfiguration
+public class TestSendingDMsUsingNamespace extends AbstractJUnit4SpringContextTests {
+
+ @Autowired
+ @Qualifier("inputChannel")
+ private MessageChannel inputChannel;
+
+ @Test
+ @Ignore
+ public void testSendigRealDirectMessage() throws Throwable {
+
+ String dmUsr = "z_oleg";
+ MessageBuilder mb = MessageBuilder.withPayload("'Hello world!', from the Spring Integration outbound Twitter adapter " + System.currentTimeMillis())
+ .setHeader(TwitterHeaders.TWITTER_GEOLOCATION, TwitterFactory.fromLatitudeLongitude(-76.226823, 23.642465)) // antarctica
+ .setHeader(TwitterHeaders.TWITTER_DISPLAY_COORDINATES, true);
+
+ if (StringUtils.hasText(dmUsr)) {
+ mb.setHeader(TwitterHeaders.TWITTER_DM_TARGET_USER_ID, dmUsr);
+ }
+ inputChannel.send(mb.build());
+ }
+}
diff --git a/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/core/Twitter4jDecoratorTests.java b/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/core/Twitter4jDecoratorTests.java
new file mode 100644
index 0000000000..434e7a6238
--- /dev/null
+++ b/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/core/Twitter4jDecoratorTests.java
@@ -0,0 +1,34 @@
+/**
+ *
+ */
+package org.springframework.integration.twitter.core;
+
+import static junit.framework.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.junit.Test;
+import org.springframework.aop.framework.ProxyFactory;
+import org.springframework.aop.target.EmptyTargetSource;
+import org.springframework.integration.twitter.core.Twitter4jDecorator;
+
+import twitter4j.Status;
+
+/**
+ * @author ozhurakousky
+ *
+ */
+public class Twitter4jDecoratorTests {
+
+ @Test
+ public void testTwitter4JDecorator(){
+ Status status = mock(Status.class);
+ when(status.getSource()).thenReturn("Hello World");
+ ProxyFactory factory = new ProxyFactory(org.springframework.integration.twitter.core.Status.class, EmptyTargetSource.INSTANCE);
+ factory.addAdvice(new Twitter4jDecorator(status));
+ Object decoratedStatus = factory.getProxy();
+ assertTrue(decoratedStatus instanceof org.springframework.integration.twitter.core.Status);
+ String source = ((org.springframework.integration.twitter.core.Status)decoratedStatus).getSource();
+ System.out.println("source: " + source);
+ }
+}
diff --git a/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/inbound/InboundDirectMessageStatusEndpointTests.java b/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/inbound/InboundDirectMessageStatusEndpointTests.java
new file mode 100644
index 0000000000..0cbebcabc5
--- /dev/null
+++ b/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/inbound/InboundDirectMessageStatusEndpointTests.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2002-2010 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.integration.twitter.inbound;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNotNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.springframework.integration.Message;
+import org.springframework.integration.channel.QueueChannel;
+import org.springframework.integration.twitter.oauth.OAuthConfiguration;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
+
+import twitter4j.DirectMessage;
+import twitter4j.Paging;
+import twitter4j.RateLimitStatus;
+import twitter4j.ResponseList;
+import twitter4j.Twitter;
+
+/**
+ * @author Oleg Zhurakousky
+ *
+ */
+public class InboundDirectMessageStatusEndpointTests {
+ private DirectMessage firstMessage;
+ private DirectMessage secondMessage;
+ private Twitter twitter;
+
+ @Test
+ public void testTwitterMockedUpdates() throws Exception{
+ QueueChannel channel = new QueueChannel();
+
+ InboundDirectMessageEndpoint endpoint = new InboundDirectMessageEndpoint();
+ endpoint.setOutputChannel(channel);
+ ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
+ scheduler.afterPropertiesSet();
+ endpoint.setTaskScheduler(scheduler);
+
+ endpoint.setConfiguration(this.getTestConfigurationForDirectMessages());
+ endpoint.afterPropertiesSet();
+ endpoint.start();
+ Message message1 = channel.receive(3000);
+ assertNotNull(message1);
+ System.out.println();
+ assertEquals(secondMessage.getId(), ((org.springframework.integration.twitter.core.DirectMessage)message1.getPayload()).getId());
+ Message message2 = channel.receive(3000);
+ assertNotNull(message2);
+ assertEquals(firstMessage.getId(), ((org.springframework.integration.twitter.core.DirectMessage)message2.getPayload()).getId());
+ }
+
+ @Before
+ public void prepare(){
+ twitter = mock(Twitter.class);
+ firstMessage = mock(DirectMessage.class);
+ when(firstMessage.getCreatedAt()).thenReturn(new Date(5555555555L));
+ when(firstMessage.getId()).thenReturn(200);
+ secondMessage = mock(DirectMessage.class);
+ when(secondMessage.getCreatedAt()).thenReturn(new Date(2222222222L));
+ when(secondMessage.getId()).thenReturn(2000);
+ }
+
+ @SuppressWarnings("unchecked")
+ private OAuthConfiguration getTestConfigurationForDirectMessages() throws Exception{
+ OAuthConfiguration configuration = mock(OAuthConfiguration.class);
+ RateLimitStatus rateLimitStatus = mock(RateLimitStatus.class);
+ when(twitter.getRateLimitStatus()).thenReturn(rateLimitStatus);
+ when(configuration.getTwitter()).thenReturn(twitter);
+
+ when(rateLimitStatus.getSecondsUntilReset()).thenReturn(2464);
+ when(rateLimitStatus.getRemainingHits()).thenReturn(250);
+
+ ResponseList responses = mock(ResponseList.class);
+ List testMessages = new ArrayList();
+
+ testMessages.add(firstMessage);
+ testMessages.add(secondMessage);
+
+ when(responses.iterator()).thenReturn(testMessages.iterator());
+ when(twitter.getDirectMessages()).thenReturn(responses);
+
+ when(twitter.getDirectMessages(Mockito.any(Paging.class))).thenReturn(responses);
+ return configuration;
+ }
+}
diff --git a/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/outbound/OutboundDirectMessageMessageHandlerTests.java b/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/outbound/OutboundDirectMessageMessageHandlerTests.java
new file mode 100644
index 0000000000..e2f7a970ce
--- /dev/null
+++ b/spring-integration-twitter/src/test/java/org/springframework/integration/twitter/outbound/OutboundDirectMessageMessageHandlerTests.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2002-2010 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.integration.twitter.outbound;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import org.junit.Test;
+import org.springframework.integration.support.MessageBuilder;
+import org.springframework.integration.twitter.core.TwitterFactory;
+import org.springframework.integration.twitter.core.TwitterHeaders;
+import org.springframework.integration.twitter.oauth.OAuthConfiguration;
+
+import twitter4j.Twitter;
+
+/**
+ * @author Oleg Zhurakousky
+ *
+ */
+public class OutboundDirectMessageMessageHandlerTests {
+ private Twitter twitter;
+
+ @Test
+ public void validateSendDirectMessage() throws Exception{
+ MessageBuilder mb = MessageBuilder.withPayload("hello")
+ .setHeader(TwitterHeaders.TWITTER_GEOLOCATION, TwitterFactory.fromLatitudeLongitude(-76.226823, 23.642465)) // antarctica
+ .setHeader(TwitterHeaders.TWITTER_DISPLAY_COORDINATES, true)
+ .setHeader(TwitterHeaders.TWITTER_DM_TARGET_USER_ID, "foo");
+ OutboundDirectMessageMessageHandler handler = new OutboundDirectMessageMessageHandler();
+
+ handler.setConfiguration(this.getTestConfiguration());
+ handler.afterPropertiesSet();
+
+ handler.handleMessage(mb.build());
+ verify(twitter, times(1)).sendDirectMessage("foo", "hello");
+
+ mb = MessageBuilder.withPayload("hello")
+ .setHeader(TwitterHeaders.TWITTER_GEOLOCATION, TwitterFactory.fromLatitudeLongitude(-76.226823, 23.642465)) // antarctica
+ .setHeader(TwitterHeaders.TWITTER_DISPLAY_COORDINATES, true)
+ .setHeader(TwitterHeaders.TWITTER_DM_TARGET_USER_ID, 123);
+
+ handler.handleMessage(mb.build());
+ verify(twitter, times(1)).sendDirectMessage(123, "hello");
+ }
+
+ private OAuthConfiguration getTestConfiguration() throws Exception{
+ twitter = mock(Twitter.class);
+ OAuthConfiguration configuration = mock(OAuthConfiguration.class);
+ when(configuration.getTwitter()).thenReturn(twitter);
+ return configuration;
+ }
+}
diff --git a/spring-integration-twitter/src/test/java/twitter.properties b/spring-integration-twitter/src/test/java/twitter.properties
index d21e6292f9..4434f0ab55 100644
--- a/spring-integration-twitter/src/test/java/twitter.properties
+++ b/spring-integration-twitter/src/test/java/twitter.properties
@@ -1,5 +1,5 @@
twitter.oauth.consumerKey=
twitter.oauth.consumerSecret=
-twitter.oauth.pin=
twitter.oauth.accessToken=
-twitter.oauth.accessTokenSecret=
\ No newline at end of file
+twitter.oauth.accessTokenSecret=
+twitter.oauth.pin=
\ No newline at end of file
diff --git a/spring-integration-twitter/template.mf b/spring-integration-twitter/template.mf
index 8821b649d5..396acd3706 100644
--- a/spring-integration-twitter/template.mf
+++ b/spring-integration-twitter/template.mf
@@ -3,10 +3,12 @@ Bundle-Name: Spring Integration Twitter Support
Bundle-Vendor: SpringSource
Bundle-ManifestVersion: 2
Import-Template:
+ org.aopalliance.*;version="[1.0.0, 2.0.0)",
org.apache.commons.logging;version="[1.1.1, 2.0.0)",
org.apache.commons.lang.*;version="[2.5.0, 3.0.0)",
org.springframework.integration.*;version="[2.0.0, 2.0.1)",
org.springframework.scheduling.*;version="[3.0.5, 4.0.0)",
+ org.springframework.aop.*;version="[3.0.5, 4.0.0)",
org.springframework.beans.*;version="[3.0.5, 4.0.0)",
org.springframework.context;version="[3.0.5, 4.0.0)",
org.springframework.core.*;version="[3.0.5, 4.0.0)",