diff --git a/src/com/jbidwatcher/auction/server/ebay/ebayServer.java b/src/com/jbidwatcher/auction/server/ebay/ebayServer.java index 27ffd69a..8e46a8a7 100644 --- a/src/com/jbidwatcher/auction/server/ebay/ebayServer.java +++ b/src/com/jbidwatcher/auction/server/ebay/ebayServer.java @@ -417,6 +417,15 @@ public String extractIdentifierFromURLString(String urlStyle) { } } + try { + URL pieces = new URL(urlStyle); + String path = pieces.getPath(); + String digits = path.substring(path.lastIndexOf('/')+1); + if(StringTools.isNumberOnly(digits)) return(digits); + } catch (Exception e) { + JConfig.log().logDebug("Failed to parse " + urlStyle + " as a URL"); + } + JConfig.log().logDebug("extractIdentifierFromURLString failed."); return null; } diff --git a/test/com/jbidwatcher/auction/server/ebay/ebayServerTest.java b/test/com/jbidwatcher/auction/server/ebay/ebayServerTest.java new file mode 100644 index 00000000..71316039 --- /dev/null +++ b/test/com/jbidwatcher/auction/server/ebay/ebayServerTest.java @@ -0,0 +1,35 @@ +package com.jbidwatcher.auction.server.ebay; + +import com.jbidwatcher.auction.server.AuctionServer; +import junit.framework.TestCase; + +/** + * Created by IntelliJ IDEA. + * User: mrs + * Date: Apr 26, 2010 + * Time: 12:54:48 AM + * To change this template use File | Settings | File Templates. + */ +public class ebayServerTest extends TestCase { + public void testExtractIdentifierFromURLString() throws Exception { + AuctionServer ebay = new ebayServer(); + String id = ebay.extractIdentifierFromURLString("http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&item=220594110651"); + assertEquals("220594110651", id); + id = ebay.extractIdentifierFromURLString("http://cgi.ebay.com/Panasonic-Lumix-20mm-/220594110651?cmd=ViewItem&pt=Camera_Lenses&hash=item335c6f00bb"); + assertEquals("220594110651", id); + id = ebay.extractIdentifierFromURLString("http://cgi.ebay.com/220594110651"); + assertEquals("220594110651", id); + } + + public void testGetStringURLFromItem() throws Exception { + } + + public void testGetBrowsableURLFromItem() throws Exception { + } + + public void testIsDefaultUser() throws Exception { + } + + public void testGetUserId() throws Exception { + } +}