javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/JSONTest.java
branchmodel
changeset 943 28aae214c202
parent 941 d1e482f73507
child 944 1e2b0dcc8326
     1.1 --- a/javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/JSONTest.java	Sun Apr 07 17:42:50 2013 +0200
     1.2 +++ b/javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/JSONTest.java	Sun Apr 07 19:29:55 2013 +0200
     1.3 @@ -137,6 +137,12 @@
     1.4          throw new IllegalStateException("Got in array him: " + Arrays.asList(p));
     1.5      }
     1.6      
     1.7 +    @OnReceive(url="/{url}")
     1.8 +    static void fetchPeople(People p, JSONik model) {
     1.9 +        model.setFetchedCount(p.getInfo().size());
    1.10 +        model.setFetched(p.getInfo().get(0));
    1.11 +    }
    1.12 +    
    1.13      @Http(@Http.Resource(
    1.14          content = "{'firstName': 'Sitar', 'sex': 'MALE'}", 
    1.15          path="/person.json", 
    1.16 @@ -207,6 +213,32 @@
    1.17      }
    1.18      
    1.19      @Http(@Http.Resource(
    1.20 +        content = "{'info':[{'firstName': 'Gitar', 'sex': 'FEMALE'}]}", 
    1.21 +        path="/people.json", 
    1.22 +        mimeType = "application/json"
    1.23 +    ))
    1.24 +    @BrwsrTest public void loadAndParseArrayInPeople() throws InterruptedException {
    1.25 +        if (js == null) {
    1.26 +            js = new JSONik();
    1.27 +            js.applyBindings();
    1.28 +        
    1.29 +            js.fetchPeople("people.json");
    1.30 +        }
    1.31 +        
    1.32 +        if (0 == js.getFetchedCount()) {
    1.33 +            throw new InterruptedException();
    1.34 +        }
    1.35 +
    1.36 +        assert js.getFetchedCount() == 1 : "One person loaded: " + js.getFetchedCount();
    1.37 +        
    1.38 +        Person p = js.getFetched();
    1.39 +        
    1.40 +        assert p != null : "We should get our person back: " + p;
    1.41 +        assert "Gitar".equals(p.getFirstName()) : "Expecting Gitar: " + p.getFirstName();
    1.42 +//        assert Sex.MALE.equals(p.getSex()) : "Expecting MALE: " + p.getSex();
    1.43 +    }
    1.44 +    
    1.45 +    @Http(@Http.Resource(
    1.46          content = "[{'firstName': 'Gitar', 'sex': 'FEMALE'},"
    1.47          + "{'firstName': 'Peter', 'sex': 'MALE'}"
    1.48          + "]",