Created
November 11, 2014 21:12
-
-
Save paulspencerwilliams/f07104ecc51d14349799 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package uk.me.paulswilliams.auction.fakes; | |
import org.jivesoftware.smack.*; | |
import org.jivesoftware.smack.packet.Message; | |
import org.jivesoftware.smack.tcp.XMPPTCPConnection; | |
import java.io.IOException; | |
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; | |
ConnectionConfiguration connectionConfig = new ConnectionConfiguration(XMPP_HOSTNAME, 5222); | |
connectionConfig.setSecurityMode(ConnectionConfiguration.SecurityMode.required); | |
connectionConfig.setKeystorePath("/Users/will/src/auction_sniper_jruby/localhost.crt"); | |
//System.setProperty("javax.net.ssl.keyStore","/Users/will/src/auction_sniper_jruby/localhost.crt"); | |
System.setProperty("javax.net.ssl.trustStore","/Users/will/src/auction_sniper_jruby/ca-bundle.crt"); | |
this.connection = new XMPPTCPConnection(connectionConfig); | |
} | |
public void startSellingItem() throws XMPPException, IOException, SmackException { | |
connection.connect(); | |
connection.login(format(ITEM_ID_AS_LOGIN, itemId), AUCTION_PASSWORD, AUCTION_RESOURCE); | |
} | |
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment