PageRenderTime 18ms CodeModel.GetById 13ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

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