Changeset 60
- Timestamp:
- 08/20/08 01:14:40 (3 months ago)
- Files:
-
- AudioScrobbler/branches/Pantsuit/src/net/buckyschwarz/pantsuit/domain/TopArtists.as (modified) (5 diffs)
- AudioScrobbler/branches/Pantsuit/src/net/buckyschwarz/pantsuit/gateway/TopArtistsGateway.as (modified) (1 diff)
- AudioScrobbler/branches/Pantsuit/src/test/net/buckyschwarz/pantsuit/TopArtistsTest.as (modified) (3 diffs)
- AudioScrobbler/branches/Pantsuit/src/test/net/buckyschwarz/pantsuit/stubs/TopArtistsGatewayStub.as (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
AudioScrobbler/branches/Pantsuit/src/net/buckyschwarz/pantsuit/domain/TopArtists.as
r57 r60 29 29 public class TopArtists extends EventDispatcher 30 30 { 31 private var _ topArtistsXMLListCollection : XMLListCollection31 private var _xmlListCollection : XMLListCollection 32 32 private var _artistCollection : ArrayCollection; 33 private var _xml : XML List33 private var _xml : XML; 34 34 private var _user : User; 35 35 36 36 public function TopArtists() 37 37 { 38 _ topArtistsXMLListCollection = new XMLListCollection();38 _xmlListCollection = new XMLListCollection(); 39 39 _artistCollection = new ArrayCollection(); 40 40 _xml = null; … … 43 43 public function getTruncatedXMLListCollection(count : int) : XMLListCollection 44 44 { 45 var collection : XMLListCollection ;45 var collection : XMLListCollection = _xmlListCollection; 46 46 47 47 if (count > 0) 48 48 { 49 collection = new XMLListCollection(XMLList( topArtistsXMLListCollection.getItemAt(0)));49 collection = new XMLListCollection(XMLList(xmlListCollection.getItemAt(0))); 50 50 for(var i : int = 1; i < count; i++) 51 51 { 52 collection.addItem(XMLList( topArtistsXMLListCollection.getItemAt(i)));52 collection.addItem(XMLList(_xmlListCollection.getItemAt(i))); 53 53 } 54 54 } … … 62 62 for(var i : int = 0; i < count; i++) 63 63 { 64 var artist : Artist = new Artist(); 65 66 artist.name = topArtistsXMLListCollection.getItemAt(i).name; 67 artist.mbid = topArtistsXMLListCollection.getItemAt(i).mbid; 68 artist.playCount = topArtistsXMLListCollection.getItemAt(i).playcount; 69 artist.rank = topArtistsXMLListCollection.getItemAt(i).rank; 70 artist.url = topArtistsXMLListCollection.getItemAt(i).url; 71 artist.thumbnail = topArtistsXMLListCollection.getItemAt(i).thumbnail; 72 artist.image = topArtistsXMLListCollection.getItemAt(i).image; 73 74 collection.addItem(artist); 64 collection.addItemAt(_artistCollection.getItemAt(i), i); 75 65 } 76 66 return collection; … … 78 68 79 69 /** 80 * Calls the methods to populate the topArtistsXMLListCollection and artistCollections70 * Calls the methods to populate the xmlListCollection and artistCollections 81 71 * 82 72 * @throws xml is null error … … 90 80 else 91 81 { 92 _topArtistsXMLListCollection = new XMLListCollection(new XMLList(_xml));93 _artistCollection = getTruncatedArtistCollection(0);82 buildXMLListCollection(); 83 buildArtistCollection(); 94 84 } 95 85 } 96 86 97 public function get xml() : XMLList 87 private function buildArtistCollection() : void 88 { 89 var artist : Artist; 90 for(var i : int = 0; i < _xmlListCollection.length; i++) 91 { 92 artist = new Artist(); 93 artist.name = _xmlListCollection.getItemAt(i).name; 94 artist.mbid = _xmlListCollection.getItemAt(i).mbid; 95 artist.playCount = _xmlListCollection.getItemAt(i).playcount; 96 artist.rank = _xmlListCollection.getItemAt(i).@rank; 97 artist.url = _xmlListCollection.getItemAt(i).url; 98 artist.thumbnail = _xmlListCollection.getItemAt(i).image.(@size=="small"); 99 artist.image = _xmlListCollection.getItemAt(i).image.(@size=="large"); 100 101 _artistCollection.addItem(artist); 102 } 103 } 104 105 private function buildXMLListCollection() : void 106 { 107 _xmlListCollection = new XMLListCollection(_xml.topartists.artist); 108 } 109 110 111 public function get xml() : XML 98 112 { 99 113 return _xml; 100 114 } 101 115 102 public function set xml(xml : XML List) : void116 public function set xml(xml : XML) : void 103 117 { 104 118 _xml = xml; 105 119 } 106 120 107 public function get topArtistsXMLListCollection() : XMLListCollection121 public function get xmlListCollection() : XMLListCollection 108 122 { 109 if (null == _ topArtistsXMLListCollection)123 if (null == _xmlListCollection) 110 124 { 111 _topArtistsXMLListCollection = new XMLListCollection(_xml);125 buildXMLListCollection(); 112 126 } 113 return _topArtistsXMLListCollection; 114 } 115 116 public function set topArtistsXMLListCollection(topArtistsXMLListCollection : XMLListCollection) : void 117 { 118 if (null != topArtistsXMLListCollection) 119 { 120 _topArtistsXMLListCollection = topArtistsXMLListCollection; 121 } 127 return _xmlListCollection; 122 128 } 123 129 AudioScrobbler/branches/Pantsuit/src/net/buckyschwarz/pantsuit/gateway/TopArtistsGateway.as
r58 r60 96 96 } 97 97 98 public function get xml() : XML List98 public function get xml() : XML 99 99 { 100 return _xml .artist;100 return _xml; 101 101 } 102 102 AudioScrobbler/branches/Pantsuit/src/test/net/buckyschwarz/pantsuit/TopArtistsTest.as
r57 r60 51 51 override public function setUp() : void 52 52 { 53 topArtists = new TopArtists(); 54 topArtistsGatewayStub = new TopArtistsGatewayStub(); 55 artist = new Artist(); 56 57 xml = <artist> 53 xml = <artist rank="1"> 58 54 <name>The Beatles</name> 55 <playcount>2019</playcount> 59 56 <mbid>b10bbbfc-cf9e-42e0-be17-e2c3e1d2600d</mbid> 60 <playcount>1262</playcount>61 <rank>1</rank>62 57 <url>http://www.last.fm/music/The+Beatles</url> 63 <thumbnail>http://userserve-ak.last.fm/serve/50/298947.jpg</thumbnail> 64 <image>http://userserve-ak.last.fm/serve/160/298947.jpg</image> 58 <streamable>0</streamable> 59 <image size="small">http://userserve-ak.last.fm/serve/34/67726.jpg</image> 60 <image size="medium">http://userserve-ak.last.fm/serve/64/67726.jpg</image> 61 <image size="large">http://userserve-ak.last.fm/serve/126/67726.jpg</image> 65 62 </artist>; 66 fullxml = <topartists user="buckyhana" type="overall">67 <artist>68 <name>The Beatles</name>69 <mbid>b10bbbfc-cf9e-42e0-be17-e2c3e1d2600d</mbid>70 <playcount>1262</playcount>71 <rank>1</rank>72 <url>http://www.last.fm/music/The+Beatles</url>73 <thumbnail>http://userserve-ak.last.fm/serve/50/298947.jpg</thumbnail>74 <image>http://userserve-ak.last.fm/serve/160/298947.jpg</image>75 </artist>76 <artist>77 <name>Minus the Bear</name>78 <mbid>c1e98e4a-4628-4c89-a7a6-0e0171600b05</mbid>79 <playcount>559</playcount>80 <rank>2</rank>81 <url>http://www.last.fm/music/Minus+the+Bear</url>82 <thumbnail>http://userserve-ak.last.fm/serve/50/267884.jpg</thumbnail>83 <image>http://userserve-ak.last.fm/serve/160/267884.jpg</image>84 </artist>85 <artist>86 <name>Death Cab for Cutie</name>87 <mbid>0039c7ae-e1a7-4a7d-9b49-0cbc716821a6</mbid>88 <playcount>374</playcount>89 <rank>3</rank>90 <url>http://www.last.fm/music/Death+Cab+for+Cutie</url>91 <thumbnail>http://userserve-ak.last.fm/serve/50/202695.jpg</thumbnail>92 <image>http://userserve-ak.last.fm/serve/160/202695.jpg</image>93 </artist>94 </topartists>;95 artist.name = "The Beatles";96 artist.mbid = "b10bbbfc-cf9e-42e0-be17-e2c3e1d2600d";97 artist.url = "http://www.last.fm/music/The+Beatles";98 artist.thumbnail = "http://userserve-ak.last.fm/serve/50/298947.jpg";99 artist.image = "http://userserve-ak.last.fm/serve/160/298947.jpg";100 101 firstArtistXMLListCollection = new XMLListCollection(new XMLList(xml));102 fullXMLListColleciton = new XMLListCollection(new XMLList(fullxml.artist));103 104 topArtists.xml = new XMLList(fullxml.artist);105 topArtists.buildTopArtists();106 63 } 107 64 108 65 public function testBuildTopArtists() : void 109 66 { 110 var topArtistsBuild : TopArtists = new TopArtists(); 67 var topArtists : TopArtists = new TopArtists(); 68 var topArtistsGatewayStub : TopArtistsGatewayStub = new TopArtistsGatewayStub(); 111 69 var error : Error = new Error("Xml is null. Try calling the TopArtistsController::fetchTopArtists method first."); 112 70 113 71 try 114 72 { 115 topArtists Build.buildTopArtists();73 topArtists.buildTopArtists(); 116 74 } 117 75 catch (e : Error) … … 120 78 } 121 79 122 topArtistsBuild.xml = fullxml.artist; 123 topArtistsBuild.buildTopArtists(); 124 assertEquals(fullXMLListColleciton.toString(), topArtistsBuild.topArtistsXMLListCollection.toString()); 80 topArtistsGatewayStub.fetch(); 81 topArtists.xml = topArtistsGatewayStub.xml; 82 83 var collection : XMLListCollection = new XMLListCollection(new XMLList(topArtistsGatewayStub.xml.topartists.artist)); 84 85 topArtists.buildTopArtists(); 86 assertEquals(collection.toString(), topArtists.xmlListCollection.toString()); 125 87 } 126 88 127 89 public function testGetTruncatedXMLListCollection() : void 128 90 { 129 assertEquals(firstArtistXMLListCollection.toString(), topArtists.getTruncatedXMLListCollection(1).toString()); 91 var topArtists : TopArtists = new TopArtists(); 92 var gatewayStub : TopArtistsGatewayStub = new TopArtistsGatewayStub(); 93 94 gatewayStub.fetch(); 95 topArtists.xml = gatewayStub.xml; 96 topArtists.buildTopArtists(); 97 98 assertEquals(new XMLListCollection(new XMLList(xml)).toString(), topArtists.getTruncatedXMLListCollection(1).toString()); 130 99 } 131 100 132 101 public function testGetTruncatedArtistCollection() : void 133 102 { 103 var topArtists : TopArtists = new TopArtists(); 104 var gatewayStub : TopArtistsGatewayStub = new TopArtistsGatewayStub(); 105 var artist : Artist = new Artist(); 106 107 gatewayStub.fetch(); 108 topArtists.xml = gatewayStub.xml; 109 topArtists.buildTopArtists(); 110 111 artist.name = "The Beatles"; 112 artist.mbid = "b10bbbfc-cf9e-42e0-be17-e2c3e1d2600d"; 113 artist.url = "http://www.last.fm/music/The+Beatles"; 114 artist.thumbnail = "http://userserve-ak.last.fm/serve/34/67726.jpg"; 115 artist.image = "http://userserve-ak.last.fm/serve/126/67726.jpg"; 116 artist.rank = 1; 117 134 118 var truncatedArtist : Artist = topArtists.getTruncatedArtistCollection(1).getItemAt(0) as Artist; 135 119 … … 137 121 assertEquals(artist.mbid, truncatedArtist.mbid); 138 122 assertEquals(artist.url, truncatedArtist.url); 139 assertEquals(artist.thumbnail, truncatedArtist.thumbnail);140 123 assertEquals(artist.image, truncatedArtist.image); 124 assertEquals(artist.rank, truncatedArtist.rank); 141 125 } 142 126 } AudioScrobbler/branches/Pantsuit/src/test/net/buckyschwarz/pantsuit/stubs/TopArtistsGatewayStub.as
r56 r60 36 36 override public function fetch() : void 37 37 { 38 _xml = <topartists user="buckyhana" type="overall"> 39 <artist> 40 <name>The Beatles</name> 41 <mbid>b10bbbfc-cf9e-42e0-be17-e2c3e1d2600d</mbid> 42 <playcount>1262</playcount> 43 <rank>1</rank> 44 <url>http://www.last.fm/music/The+Beatles</url> 45 <thumbnail>http://userserve-ak.last.fm/serve/50/298947.jpg</thumbnail> 46 <image>http://userserve-ak.last.fm/serve/160/298947.jpg</image> 47 </artist> 48 <artist> 49 <name>Minus the Bear</name> 50 <mbid>c1e98e4a-4628-4c89-a7a6-0e0171600b05</mbid> 51 <playcount>559</playcount> 52 <rank>2</rank> 53 <url>http://www.last.fm/music/Minus+the+Bear</url> 54 <thumbnail>http://userserve-ak.last.fm/serve/50/267884.jpg</thumbnail> 55 <image>http://userserve-ak.last.fm/serve/160/267884.jpg</image> 56 </artist> 57 <artist> 58 <name>Death Cab for Cutie</name> 59 <mbid>0039c7ae-e1a7-4a7d-9b49-0cbc716821a6</mbid> 60 <playcount>374</playcount> 61 <rank>3</rank> 62 <url>http://www.last.fm/music/Death+Cab+for+Cutie</url> 63 <thumbnail>http://userserve-ak.last.fm/serve/50/202695.jpg</thumbnail> 64 <image>http://userserve-ak.last.fm/serve/160/202695.jpg</image> 65 </artist> 66 </topartists>; 38 _xml = <lfm status="ok"> 39 <topartists user="buckyhana" type="overall"> 40 <artist rank="1"> 41 <name>The Beatles</name> 42 <playcount>2019</playcount> 43 <mbid>b10bbbfc-cf9e-42e0-be17-e2c3e1d2600d</mbid> 44 <url>http://www.last.fm/music/The+Beatles</url> 45 <streamable>0</streamable> 46 <image size="small">http://userserve-ak.last.fm/serve/34/67726.jpg</image> 47 <image size="medium">http://userserve-ak.last.fm/serve/64/67726.jpg</image> 48 <image size="large">http://userserve-ak.last.fm/serve/126/67726.jpg</image> 49 </artist> 50 <artist rank="2"> 51 <name>Minus the Bear</name> 52 <playcount>649</playcount> 53 <mbid>c1e98e4a-4628-4c89-a7a6-0e0171600b05</mbid> 54 <url>http://www.last.fm/music/Minus+the+Bear</url> 55 <streamable>1</streamable> 56 <image size="small">http://userserve-ak.last.fm/serve/34/170922.jpg</image> 57 <image size="medium">http://userserve-ak.last.fm/serve/64/170922.jpg</image> 58 <image size="large">http://userserve-ak.last.fm/serve/126/170922.jpg</image> 59 </artist> 60 <artist rank="3"> 61 <name>Death Cab for Cutie</name> 62 <playcount>488</playcount> 63 <mbid>0039c7ae-e1a7-4a7d-9b49-0cbc716821a6</mbid> 64 <url>http://www.last.fm/music/Death+Cab+for+Cutie</url> 65 <streamable>1</streamable> 66 <image size="small">http://userserve-ak.last.fm/serve/34/74052.jpg</image> 67 <image size="medium">http://userserve-ak.last.fm/serve/64/74052.jpg</image> 68 <image size="large">http://userserve-ak.last.fm/serve/126/74052.jpg</image> 69 </artist> 70 </topartists> 71 </lfm>; 67 72 68 73 dispatchEvent(new TopArtistsEvent(TopArtistsEvent.RESULT));