Mercurial > hg > audiodb
view bindings/as3/src/tests/TestQuerier.as @ 734:35bfc91b67d3
Added initial search functions and tests.
author | mas01mj |
---|---|
date | Wed, 15 Sep 2010 11:59:47 +0000 |
parents | 3a0b9700b3d2 |
children |
line wrap: on
line source
package tests { import asunit.framework.TestCase; import org.omras2.audiodb.LookupEvent; import org.omras2.audiodb.Querier; import org.omras2.audiodb.SearchEvent; import org.omras2.audiodb.model.SearchResult; import flash.events.ErrorEvent; /** * @author mikej */ public class TestQuerier extends TestCase { private var _querier : Querier; public function TestQuerier(testMethod : String) { super(testMethod); } override protected function setUp() : void { super.setUp(); this._querier = new Querier("http://127.0.0.1:8080"); } public function testLookupSuccess() : void { var handler : Function = addAsync(handleLookupSuccessComplete, 2000); _querier.addEventListener(LookupEvent.COMPLETE, handler); _querier.lookup("AWAL1000"); } public function testLookupFail() : void { var handler : Function = addAsync(handleLookupFailComplete, 2000); _querier.addEventListener(ErrorEvent.ERROR, handler); _querier.lookup("AWAL10000"); } private function handleLookupFailComplete(event : ErrorEvent) : void { assertEquals(event.text, 'Invalid key'); } protected function handleLookupSuccessComplete(event : LookupEvent) : void { assertEquals(event.track.uid, 'AWAL1000'); assertEquals(event.track.artist, 'Moscow Drive'); assertEquals(event.track.seconds, '221000'); } public function testSearchSuccess() : void { var handler : Function = addAsync(handleSearchSuccessComplete, 10000); _querier.addEventListener(SearchEvent.COMPLETE, handler); _querier.search("AWAL1000"); } protected function handleSearchSuccessComplete(event : SearchEvent) : void { assertEquals(20, event.results.length); var firstMatch : SearchResult = (event.results[0] as SearchResult); assertEquals("AWAL1000", firstMatch.uid); assertEquals(0, firstMatch.ipos); assertEquals(0, firstMatch.qpos); } } }