/razpub/test_src/com/razie/pub/lightsoa/test/TestLightServerSoaAssets.java

http://razpub.googlecode.com/ · Java · 78 lines · 44 code · 14 blank · 20 comment · 2 complexity · 2f66076b5beb546a3ef3eec5e4387a5f MD5 · raw file

  1. /**
  2. * Razvan's public code. Copyright 2008 based on Apache license (share alike) see LICENSE.txt for
  3. * details. No warranty implied nor any liability assumed for this code.
  4. */
  5. package com.razie.pub.lightsoa.test;
  6. import java.io.BufferedReader;
  7. import java.io.IOException;
  8. import java.io.InputStreamReader;
  9. import java.net.URL;
  10. import razie.JAS;
  11. import razie.base.ActionItem;
  12. import razie.base.ActionToInvoke;
  13. import com.razie.pub.assets.JavaAssetMgr;
  14. import com.razie.pub.base.ExecutionContext;
  15. import com.razie.pub.base.log.Log;
  16. import com.razie.pub.http.test.TestLightBase;
  17. import com.razie.pub.lightsoa.HttpAssetSoaBinding;
  18. /**
  19. * setup a light server with soa assets management and test a few calls to a sample asset
  20. *
  21. * @author razvanc99
  22. */
  23. public class TestLightServerSoaAssets extends TestLightBase {
  24. static String PK = TestLocalSoaAssets.PLAYERKEY.toUrlEncodedString();
  25. public void setUp() {
  26. if (server == null) {
  27. ExecutionContext.DFLT_CTX.enter(); // this is important - someone mangles the context and it all gets fucked
  28. super.setUp();
  29. // initialize the main asset manager - is responsible for instantiating assets by key
  30. JavaAssetMgr.init(new razie.assets.InventoryAssetMgr());
  31. JAS.manage(new SampleAsset("1"));
  32. JAS.manage (new SampleAsset2("2"));
  33. HttpAssetSoaBinding soa = new HttpAssetSoaBinding();
  34. // register the test asset
  35. soa.register(SampleAsset.class);
  36. // register the asset management service
  37. cmdGET.registerSoa(soa);
  38. }
  39. }
  40. /**
  41. * test the SOA simple echo via the proper URL reader (check implementation as a proper http
  42. * server)
  43. */
  44. public void testSoaEchoUrl() throws IOException, InterruptedException {
  45. // send echo command
  46. URL url = new URL("http://localhost:" + PORT + "/lightsoa/asset/" + PK + "/play?movie="
  47. + TestLocalSoaAssets.MOVIEKEY.toUrlEncodedString());
  48. BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
  49. String result = in.readLine();
  50. in.close();
  51. assertTrue(result.contains(TestLocalSoaAssets.MOVIEKEY.getId()));
  52. }
  53. /**
  54. */
  55. public void testSoaEchoAction() throws IOException, InterruptedException {
  56. // send echo command
  57. ActionToInvoke action = razie.JAS.aati("http://localhost:" + PORT,
  58. TestLocalSoaAssets.PLAYERKEY, new ActionItem("play"),
  59. "movie", TestLocalSoaAssets.MOVIEKEY);
  60. String result = (String) action.act(null);
  61. assertTrue(result.contains(TestLocalSoaAssets.MOVIEKEY.getId()));
  62. }
  63. static final Log logger = Log.factory.create(TestLightServerSoaAssets.class.getName());
  64. }