Package org.sonar.wsclient.services

Examples of org.sonar.wsclient.services.ResourceSearchResult


public class ResourceSearchUnmarshaller extends AbstractUnmarshaller<ResourceSearchResult> {

  @Override
  protected ResourceSearchResult parse(Object json) {
    WSUtils utils = WSUtils.getINSTANCE();
    ResourceSearchResult result = new ResourceSearchResult();
    result.setPage(utils.getInteger(json, "page"));
    result.setPageSize(utils.getInteger(json, "page_size"));
    result.setTotal(utils.getInteger(json, "total"));

    List<ResourceSearchResult.Resource> resources = new ArrayList<ResourceSearchResult.Resource>();
    JSONArray dataJson = JsonUtils.getArray((JSONObject) json, "data");
    if (dataJson != null) {
      for (Object jsonResource : dataJson) {
        ResourceSearchResult.Resource resource = new ResourceSearchResult.Resource();
        resource.setKey(JsonUtils.getString((JSONObject) jsonResource, "key"));
        resource.setName(JsonUtils.getString((JSONObject) jsonResource, "nm"));
        resource.setQualifier(JsonUtils.getString((JSONObject) jsonResource, "q"));
        resources.add(resource);
      }
    }
    result.setResources(resources);
    return result;
  }
View Full Code Here


public class ResourceSearchUnmarshallerTest extends UnmarshallerTestCase {

  @Test
  public void testToModel() {
    ResourceSearchResult result = new ResourceSearchUnmarshaller().toModel(loadFile("/resources/search.json"));
    assertThat(result.getPage(), is(1));
    assertThat(result.getPageSize(), is(10));
    assertThat(result.getTotal(), is(4));
    assertThat(result.getResources().size(), is(4));

  }
View Full Code Here

TOP

Related Classes of org.sonar.wsclient.services.ResourceSearchResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.