annotate 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
rev   line source
mas01mj@732 1 package tests
mas01mj@732 2 {
mas01mj@732 3 import asunit.framework.TestCase;
mas01mj@732 4
mas01mj@732 5 import org.omras2.audiodb.LookupEvent;
mas01mj@732 6 import org.omras2.audiodb.Querier;
mas01mj@734 7 import org.omras2.audiodb.SearchEvent;
mas01mj@734 8 import org.omras2.audiodb.model.SearchResult;
mas01mj@732 9
mas01mj@732 10 import flash.events.ErrorEvent;
mas01mj@732 11
mas01mj@732 12 /**
mas01mj@732 13 * @author mikej
mas01mj@732 14 */
mas01mj@732 15 public class TestQuerier extends TestCase
mas01mj@732 16 {
mas01mj@732 17 private var _querier : Querier;
mas01mj@732 18
mas01mj@732 19 public function TestQuerier(testMethod : String)
mas01mj@732 20 {
mas01mj@732 21 super(testMethod);
mas01mj@732 22 }
mas01mj@732 23
mas01mj@732 24 override protected function setUp() : void
mas01mj@732 25 {
mas01mj@732 26 super.setUp();
mas01mj@732 27 this._querier = new Querier("http://127.0.0.1:8080");
mas01mj@732 28 }
mas01mj@732 29
mas01mj@732 30 public function testLookupSuccess() : void
mas01mj@732 31 {
mas01mj@732 32 var handler : Function = addAsync(handleLookupSuccessComplete, 2000);
mas01mj@732 33 _querier.addEventListener(LookupEvent.COMPLETE, handler);
mas01mj@732 34 _querier.lookup("AWAL1000");
mas01mj@732 35 }
mas01mj@732 36
mas01mj@732 37 public function testLookupFail() : void
mas01mj@732 38 {
mas01mj@732 39 var handler : Function = addAsync(handleLookupFailComplete, 2000);
mas01mj@732 40 _querier.addEventListener(ErrorEvent.ERROR, handler);
mas01mj@732 41 _querier.lookup("AWAL10000");
mas01mj@732 42 }
mas01mj@732 43
mas01mj@732 44 private function handleLookupFailComplete(event : ErrorEvent) : void
mas01mj@732 45 {
mas01mj@732 46 assertEquals(event.text, 'Invalid key');
mas01mj@732 47 }
mas01mj@732 48
mas01mj@732 49 protected function handleLookupSuccessComplete(event : LookupEvent) : void
mas01mj@732 50 {
mas01mj@732 51 assertEquals(event.track.uid, 'AWAL1000');
mas01mj@732 52 assertEquals(event.track.artist, 'Moscow Drive');
mas01mj@732 53 assertEquals(event.track.seconds, '221000');
mas01mj@732 54 }
mas01mj@734 55
mas01mj@734 56 public function testSearchSuccess() : void
mas01mj@734 57 {
mas01mj@734 58 var handler : Function = addAsync(handleSearchSuccessComplete, 10000);
mas01mj@734 59 _querier.addEventListener(SearchEvent.COMPLETE, handler);
mas01mj@734 60 _querier.search("AWAL1000");
mas01mj@734 61 }
mas01mj@734 62
mas01mj@734 63 protected function handleSearchSuccessComplete(event : SearchEvent) : void
mas01mj@734 64 {
mas01mj@734 65 assertEquals(20, event.results.length);
mas01mj@734 66 var firstMatch : SearchResult = (event.results[0] as SearchResult);
mas01mj@734 67 assertEquals("AWAL1000", firstMatch.uid);
mas01mj@734 68 assertEquals(0, firstMatch.ipos);
mas01mj@734 69 assertEquals(0, firstMatch.qpos);
mas01mj@734 70 }
mas01mj@732 71 }
mas01mj@732 72 }