From 56931a03df77bfcfa51cf5baade16dded13ad4bb Mon Sep 17 00:00:00 2001 From: Paul Williams Date: Fri, 14 Nov 2014 16:13:27 +0000 Subject: [PATCH] FakeAuctionServer is talking to vines albeit it with hardcoded arther credentials --- pom.xml | 12 +- .../auction/fakes/FakeAuctionServer.java | 119 +++++++++++------- 2 files changed, 85 insertions(+), 46 deletions(-) diff --git a/pom.xml b/pom.xml index 5cda25b..e7edb2e 100644 --- a/pom.xml +++ b/pom.xml @@ -25,9 +25,15 @@ 1.3 - jivesoftware - smack - 3.1.0 + org.igniterealtime.smack + smack-core + 4.0.5 + + + org.igniterealtime.smack + smack-tcp + 4.0.5 + test \ No newline at end of file diff --git a/src/test/java/uk/me/paulswilliams/auction/fakes/FakeAuctionServer.java b/src/test/java/uk/me/paulswilliams/auction/fakes/FakeAuctionServer.java index ac31313..7d62293 100644 --- a/src/test/java/uk/me/paulswilliams/auction/fakes/FakeAuctionServer.java +++ b/src/test/java/uk/me/paulswilliams/auction/fakes/FakeAuctionServer.java @@ -2,51 +2,84 @@ import org.jivesoftware.smack.*; import org.jivesoftware.smack.packet.Message; +import org.jivesoftware.smack.parsing.ExceptionLoggingCallback; +import org.jivesoftware.smack.tcp.XMPPTCPConnection; + +import javax.net.ssl.SSLContext; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; +import javax.security.sasl.SaslException; +import java.io.IOException; +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; import static java.lang.String.format; public class FakeAuctionServer { - public static final String XMPP_HOSTNAME = "localhost"; - private static final String ITEM_ID_AS_LOGIN = "auction-%s"; - private static final String AUCTION_PASSWORD = "auction"; - private static final String AUCTION_RESOURCE = "Auction"; - private final XMPPConnection connection; - private String itemId; - private Chat currentChat; - private final SingleMessageListener messageListener = new SingleMessageListener(); - - public FakeAuctionServer(String itemId) { - this.itemId = itemId; - this.connection = new XMPPConnection(XMPP_HOSTNAME); - } - - public void startSellingItem() throws XMPPException { - connection.connect(); - connection.login(format(ITEM_ID_AS_LOGIN, itemId), AUCTION_PASSWORD, AUCTION_RESOURCE); - connection.getChatManager().addChatListener( - new ChatManagerListener() { - @Override - public void chatCreated(Chat chat, boolean createdLocally) { - currentChat = chat; - chat.addMessageListener(messageListener); - } - } - ); - } - - public void hasReceivedJoinRequestFromSniper() throws InterruptedException { - messageListener.receivesAMessage(); - } - - public void announceClosed() throws XMPPException { - currentChat.sendMessage(new Message()); - } - - public void stop() { - connection.disconnect(); - } - - public String getItemId() { - return itemId; - } + public static final String XMPP_HOSTNAME = "localhost"; + + private static final String ITEM_ID_AS_LOGIN = "arthur"; + + private static final String AUCTION_PASSWORD = "secr3t"; + + private static final String AUCTION_RESOURCE = "Auction"; + + private XMPPConnection connection; + + private String itemId; + + private Chat currentChat; + + private final SingleMessageListener messageListener = new SingleMessageListener(); + + public FakeAuctionServer(String itemId) { + this.itemId = itemId; + + try { + ConnectionConfiguration connectionConfig = new ConnectionConfiguration(XMPP_HOSTNAME, 5222); + connectionConfig.setSecurityMode(ConnectionConfiguration.SecurityMode.required); + + System.setProperty("javax.net.ssl.trustStore", "akeystore.jks"); + this.connection = new XMPPTCPConnection(connectionConfig); + this.connection.connect(); + this.connection.login(format(ITEM_ID_AS_LOGIN, itemId), AUCTION_PASSWORD, AUCTION_RESOURCE); + } + catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("connection failed"); + } + + } + + public void startSellingItem() throws XMPPException, IOException, SmackException { + + // connection.getChatManager().addChatListener( + // new ChatManagerListener() { + // @Override + // public void chatCreated(Chat chat, boolean createdLocally) { + // currentChat = chat; + // chat.addMessageListener(messageListener); + // } + // } + // ); + } + + public void hasReceivedJoinRequestFromSniper() throws InterruptedException { + messageListener.receivesAMessage(); + } + + public void announceClosed() throws XMPPException { + // currentChat.sendMessage(new Message()); + } + + public void stop() { + // connection.disconnect(); + } + + public String getItemId() { + return itemId; + } }