Example usage for com.fasterxml.jackson.databind JsonNode size

List of usage examples for com.fasterxml.jackson.databind JsonNode size

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind JsonNode size.

Prototype

public int size() 

Source Link

Usage

From source file:org.jasig.cas.support.oauth.web.OAuth20MetadataPrincipalControllerTests.java

@Test
public void verifyOKWithAccessToken() throws Exception {
    final AccessToken accessToken = mock(AccessToken.class);
    when(accessToken.getId()).thenReturn(AT_ID);

    final List<PrincipalMetadata> principalMetas = Arrays.asList(
            new PrincipalMetadata(CLIENT_ID, PRINC_NAME_ONE, PRINC_DESCR_ONE),
            new PrincipalMetadata(CLIENT_ID, PRINC_NAME_TWO, PRINC_DESCR_TWO));

    final CentralOAuthService centralOAuthService = mock(CentralOAuthService.class);
    when(centralOAuthService.getToken(AT_ID, AccessToken.class)).thenReturn(accessToken);
    when(centralOAuthService.getPrincipalMetadata(accessToken)).thenReturn(principalMetas);

    final MockHttpServletRequest mockRequest = new MockHttpServletRequest("POST",
            CONTEXT + OAuthConstants.METADATA_URL);
    mockRequest.setParameter(OAuthConstants.ACCESS_TOKEN, AT_ID);
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();

    final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
    oauth20WrapperController.setCentralOAuthService(centralOAuthService);
    oauth20WrapperController.afterPropertiesSet();

    final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse);
    assertNull(modelAndView);//  www. j av a  2 s . c om
    assertEquals(HttpStatus.SC_OK, mockResponse.getStatus());
    assertEquals(CONTENT_TYPE, mockResponse.getContentType());

    final ObjectMapper mapper = new ObjectMapper();

    final String expected = "{\"data\":[" + "{\"client_id\":\"" + CLIENT_ID + "\",\"name\":\"" + PRINC_NAME_ONE
            + "\",\"description\":\"" + PRINC_DESCR_ONE + "\",\"scope\":[]}," + "{\"client_id\":\"" + CLIENT_ID
            + "\",\"name\":\"" + PRINC_NAME_TWO + "\",\"description\":\"" + PRINC_DESCR_TWO
            + "\",\"scope\":[]}]}";
    final JsonNode expectedObj = mapper.readTree(expected);
    final JsonNode receivedObj = mapper.readTree(mockResponse.getContentAsString());

    final JsonNode expectedData = expectedObj.get("data");
    final JsonNode receivedData = receivedObj.get("data");
    assertEquals(expectedData.size(), receivedData.size());

    final JsonNode expectedPrincipalOne = expectedData.get(0);
    final JsonNode receivedPrincipalOne = receivedData.get(0);
    assertEquals(expectedPrincipalOne.get("client_id"), receivedPrincipalOne.get("client_id"));
    assertEquals(expectedPrincipalOne.get("name"), receivedPrincipalOne.get("name"));
    assertEquals(expectedPrincipalOne.get("description"), receivedPrincipalOne.get("description"));
    assertEquals(expectedPrincipalOne.get("scope").size(), receivedPrincipalOne.get("scope").size());

    final JsonNode expectedPrincipalTwo = expectedData.get(1);
    final JsonNode receivedPrincipalTwo = receivedData.get(1);
    assertEquals(expectedPrincipalTwo.get("client_id"), receivedPrincipalTwo.get("client_id"));
    assertEquals(expectedPrincipalTwo.get("name"), receivedPrincipalTwo.get("name"));
    assertEquals(expectedPrincipalTwo.get("description"), receivedPrincipalTwo.get("description"));
    assertEquals(expectedPrincipalTwo.get("scope").size(), receivedPrincipalTwo.get("scope").size());
}

From source file:org.jasig.cas.support.oauth.web.OAuth20MetadataPrincipalControllerTests.java

@Test
public void verifyOKWithAuthHeader() throws Exception {
    final AccessToken accessToken = mock(AccessToken.class);
    when(accessToken.getId()).thenReturn(AT_ID);

    final List<PrincipalMetadata> principalMetas = Arrays.asList(
            new PrincipalMetadata(CLIENT_ID, PRINC_NAME_ONE, PRINC_DESCR_ONE),
            new PrincipalMetadata(CLIENT_ID, PRINC_NAME_TWO, PRINC_DESCR_TWO));

    final CentralOAuthService centralOAuthService = mock(CentralOAuthService.class);
    when(centralOAuthService.getToken(AT_ID, AccessToken.class)).thenReturn(accessToken);
    when(centralOAuthService.getPrincipalMetadata(accessToken)).thenReturn(principalMetas);

    final MockHttpServletRequest mockRequest = new MockHttpServletRequest("POST",
            CONTEXT + OAuthConstants.METADATA_URL);
    mockRequest.addHeader("Authorization", OAuthConstants.BEARER_TOKEN + " " + AT_ID);
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();

    final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
    oauth20WrapperController.setCentralOAuthService(centralOAuthService);
    oauth20WrapperController.afterPropertiesSet();

    final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse);
    assertNull(modelAndView);//w w  w.  java  2 s  . c  o  m
    assertEquals(HttpStatus.SC_OK, mockResponse.getStatus());
    assertEquals(CONTENT_TYPE, mockResponse.getContentType());

    final ObjectMapper mapper = new ObjectMapper();

    final String expected = "{\"data\":[" + "{\"client_id\":\"" + CLIENT_ID + "\",\"name\":\"" + PRINC_NAME_ONE
            + "\",\"description\":\"" + PRINC_DESCR_ONE + "\",\"scope\":[]}," + "{\"client_id\":\"" + CLIENT_ID
            + "\",\"name\":\"" + PRINC_NAME_TWO + "\",\"description\":\"" + PRINC_DESCR_TWO
            + "\",\"scope\":[]}]}";
    final JsonNode expectedObj = mapper.readTree(expected);
    final JsonNode receivedObj = mapper.readTree(mockResponse.getContentAsString());

    final JsonNode expectedData = expectedObj.get("data");
    final JsonNode receivedData = receivedObj.get("data");
    assertEquals(expectedData.size(), receivedData.size());

    final JsonNode expectedPrincipalOne = expectedData.get(0);
    final JsonNode receivedPrincipalOne = receivedData.get(0);
    assertEquals(expectedPrincipalOne.get("client_id"), receivedPrincipalOne.get("client_id"));
    assertEquals(expectedPrincipalOne.get("name"), receivedPrincipalOne.get("name"));
    assertEquals(expectedPrincipalOne.get("description"), receivedPrincipalOne.get("description"));
    assertEquals(expectedPrincipalOne.get("scope").size(), receivedPrincipalOne.get("scope").size());

    final JsonNode expectedPrincipalTwo = expectedData.get(1);
    final JsonNode receivedPrincipalTwo = receivedData.get(1);
    assertEquals(expectedPrincipalTwo.get("client_id"), receivedPrincipalTwo.get("client_id"));
    assertEquals(expectedPrincipalTwo.get("name"), receivedPrincipalTwo.get("name"));
    assertEquals(expectedPrincipalTwo.get("description"), receivedPrincipalTwo.get("description"));
    assertEquals(expectedPrincipalTwo.get("scope").size(), receivedPrincipalTwo.get("scope").size());
}

From source file:org.activiti.rest.service.api.form.FormDataResourceTest.java

@Deployment
public void testGetFormData() throws Exception {
    Map<String, Object> variableMap = new HashMap<String, Object>();
    variableMap.put("SpeakerName", "John Doe");
    Address address = new Address();
    variableMap.put("address", address);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", variableMap);
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();

    CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX
            + RestUrls.createRelativeResourceUrl(RestUrls.URL_FORM_DATA) + "?taskId=" + task.getId()),
            HttpStatus.SC_OK);//from   w  w w  .jav  a2  s . co  m

    // Check resulting task
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertEquals(7, responseNode.get("formProperties").size());
    Map<String, JsonNode> mappedProperties = new HashMap<String, JsonNode>();
    for (JsonNode propNode : responseNode.get("formProperties")) {
        mappedProperties.put(propNode.get("id").asText(), propNode);
    }
    JsonNode propNode = mappedProperties.get("room");
    assertNotNull(propNode);
    assertEquals("room", propNode.get("id").asText());
    assertTrue(propNode.get("name").isNull());
    assertTrue(propNode.get("type").isNull());
    assertTrue(propNode.get("value").isNull());
    assertTrue(propNode.get("readable").asBoolean());
    assertTrue(propNode.get("writable").asBoolean());
    assertTrue(propNode.get("required").asBoolean() == false);

    propNode = mappedProperties.get("duration");
    assertNotNull(propNode);
    assertEquals("duration", propNode.get("id").asText());
    assertTrue(propNode.get("name").isNull());
    assertEquals("long", propNode.get("type").asText());
    assertTrue(propNode.get("value").isNull());
    assertTrue(propNode.get("readable").asBoolean());
    assertTrue(propNode.get("writable").asBoolean());
    assertTrue(propNode.get("required").asBoolean() == false);

    propNode = mappedProperties.get("speaker");
    assertNotNull(propNode);
    assertEquals("speaker", propNode.get("id").asText());
    assertTrue(propNode.get("name").isNull());
    assertTrue(propNode.get("type").isNull());
    assertEquals("John Doe", propNode.get("value").asText());
    assertTrue(propNode.get("readable").asBoolean());
    assertTrue(propNode.get("writable").asBoolean() == false);
    assertTrue(propNode.get("required").asBoolean() == false);

    propNode = mappedProperties.get("street");
    assertNotNull(propNode);
    assertEquals("street", propNode.get("id").asText());
    assertTrue(propNode.get("name").isNull());
    assertTrue(propNode.get("type").isNull());
    assertTrue(propNode.get("value").isNull());
    assertTrue(propNode.get("readable").asBoolean());
    assertTrue(propNode.get("writable").asBoolean());
    assertTrue(propNode.get("required").asBoolean());

    propNode = mappedProperties.get("start");
    assertNotNull(propNode);
    assertEquals("start", propNode.get("id").asText());
    assertTrue(propNode.get("name").isNull());
    assertEquals("date", propNode.get("type").asText());
    assertTrue(propNode.get("value").isNull());
    assertEquals("dd-MMM-yyyy", propNode.get("datePattern").asText());
    assertTrue(propNode.get("readable").asBoolean());
    assertTrue(propNode.get("writable").asBoolean());
    assertTrue(propNode.get("required").asBoolean() == false);

    propNode = mappedProperties.get("end");
    assertNotNull(propNode);
    assertEquals("end", propNode.get("id").asText());
    assertEquals("End", propNode.get("name").asText());
    assertEquals("date", propNode.get("type").asText());
    assertTrue(propNode.get("value").isNull());
    assertEquals("dd/MM/yyyy", propNode.get("datePattern").asText());
    assertTrue(propNode.get("readable").asBoolean());
    assertTrue(propNode.get("writable").asBoolean());
    assertTrue(propNode.get("required").asBoolean() == false);

    propNode = mappedProperties.get("direction");
    assertNotNull(propNode);
    assertEquals("direction", propNode.get("id").asText());
    assertTrue(propNode.get("name").isNull());
    assertEquals("enum", propNode.get("type").asText());
    assertTrue(propNode.get("value").isNull());
    assertTrue(propNode.get("datePattern").isNull());
    assertTrue(propNode.get("readable").asBoolean());
    assertTrue(propNode.get("writable").asBoolean());
    assertTrue(propNode.get("required").asBoolean() == false);
    JsonNode enumValues = propNode.get("enumValues");
    assertEquals(4, enumValues.size());
    Map<String, String> mappedEnums = new HashMap<String, String>();
    for (JsonNode enumNode : enumValues) {
        mappedEnums.put(enumNode.get("id").asText(), enumNode.get("name").asText());
    }
    assertEquals("Go Left", mappedEnums.get("left"));
    assertEquals("Go Right", mappedEnums.get("right"));
    assertEquals("Go Up", mappedEnums.get("up"));
    assertEquals("Go Down", mappedEnums.get("down"));

    response = executeRequest(
            new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_FORM_DATA)
                    + "?processDefinitionId=" + processInstance.getProcessDefinitionId()),
            HttpStatus.SC_OK);

    // Check resulting task
    responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertEquals(2, responseNode.get("formProperties").size());
    mappedProperties.clear();
    for (JsonNode propertyNode : responseNode.get("formProperties")) {
        mappedProperties.put(propertyNode.get("id").asText(), propertyNode);
    }

    propNode = mappedProperties.get("number");
    assertNotNull(propNode);
    assertEquals("number", propNode.get("id").asText());
    assertEquals("Number", propNode.get("name").asText());
    assertEquals("long", propNode.get("type").asText());
    assertTrue(propNode.get("value").isNull());
    assertTrue(propNode.get("readable").asBoolean());
    assertTrue(propNode.get("writable").asBoolean());
    assertTrue(propNode.get("required").asBoolean() == false);

    propNode = mappedProperties.get("description");
    assertNotNull(propNode);
    assertEquals("description", propNode.get("id").asText());
    assertEquals("Description", propNode.get("name").asText());
    assertTrue(propNode.get("type").isNull());
    assertTrue(propNode.get("value").isNull());
    assertTrue(propNode.get("readable").asBoolean());
    assertTrue(propNode.get("writable").asBoolean());
    assertTrue(propNode.get("required").asBoolean() == false);

    closeResponse(executeRequest(new HttpGet(SERVER_URL_PREFIX
            + RestUrls.createRelativeResourceUrl(RestUrls.URL_FORM_DATA) + "?processDefinitionId=123"),
            HttpStatus.SC_NOT_FOUND));

    closeResponse(executeRequest(new HttpGet(SERVER_URL_PREFIX
            + RestUrls.createRelativeResourceUrl(RestUrls.URL_FORM_DATA) + "?processDefinitionId2=123"),
            HttpStatus.SC_BAD_REQUEST));
}

From source file:org.flowable.rest.service.api.form.FormDataResourceTest.java

@Deployment
public void testGetFormData() throws Exception {
    Map<String, Object> variableMap = new HashMap<String, Object>();
    variableMap.put("SpeakerName", "John Doe");
    Address address = new Address();
    variableMap.put("address", address);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess", variableMap);
    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();

    CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX
            + RestUrls.createRelativeResourceUrl(RestUrls.URL_FORM_DATA) + "?taskId=" + task.getId()),
            HttpStatus.SC_OK);//w  ww .  j  a va 2 s. c om

    // Check resulting task
    JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertEquals(7, responseNode.get("formProperties").size());
    Map<String, JsonNode> mappedProperties = new HashMap<String, JsonNode>();
    for (JsonNode propNode : responseNode.get("formProperties")) {
        mappedProperties.put(propNode.get("id").asText(), propNode);
    }
    JsonNode propNode = mappedProperties.get("room");
    assertNotNull(propNode);
    assertEquals("room", propNode.get("id").asText());
    assertTrue(propNode.get("name").isNull());
    assertTrue(propNode.get("type").isNull());
    assertTrue(propNode.get("value").isNull());
    assertTrue(propNode.get("readable").asBoolean());
    assertTrue(propNode.get("writable").asBoolean());
    assertFalse(propNode.get("required").asBoolean());

    propNode = mappedProperties.get("duration");
    assertNotNull(propNode);
    assertEquals("duration", propNode.get("id").asText());
    assertTrue(propNode.get("name").isNull());
    assertEquals("long", propNode.get("type").asText());
    assertTrue(propNode.get("value").isNull());
    assertTrue(propNode.get("readable").asBoolean());
    assertTrue(propNode.get("writable").asBoolean());
    assertFalse(propNode.get("required").asBoolean());

    propNode = mappedProperties.get("speaker");
    assertNotNull(propNode);
    assertEquals("speaker", propNode.get("id").asText());
    assertTrue(propNode.get("name").isNull());
    assertTrue(propNode.get("type").isNull());
    assertEquals("John Doe", propNode.get("value").asText());
    assertTrue(propNode.get("readable").asBoolean());
    assertFalse(propNode.get("writable").asBoolean());
    assertFalse(propNode.get("required").asBoolean());

    propNode = mappedProperties.get("street");
    assertNotNull(propNode);
    assertEquals("street", propNode.get("id").asText());
    assertTrue(propNode.get("name").isNull());
    assertTrue(propNode.get("type").isNull());
    assertTrue(propNode.get("value").isNull());
    assertTrue(propNode.get("readable").asBoolean());
    assertTrue(propNode.get("writable").asBoolean());
    assertTrue(propNode.get("required").asBoolean());

    propNode = mappedProperties.get("start");
    assertNotNull(propNode);
    assertEquals("start", propNode.get("id").asText());
    assertTrue(propNode.get("name").isNull());
    assertEquals("date", propNode.get("type").asText());
    assertTrue(propNode.get("value").isNull());
    assertEquals("dd-MMM-yyyy", propNode.get("datePattern").asText());
    assertTrue(propNode.get("readable").asBoolean());
    assertTrue(propNode.get("writable").asBoolean());
    assertFalse(propNode.get("required").asBoolean());

    propNode = mappedProperties.get("end");
    assertNotNull(propNode);
    assertEquals("end", propNode.get("id").asText());
    assertEquals("End", propNode.get("name").asText());
    assertEquals("date", propNode.get("type").asText());
    assertTrue(propNode.get("value").isNull());
    assertEquals("dd/MM/yyyy", propNode.get("datePattern").asText());
    assertTrue(propNode.get("readable").asBoolean());
    assertTrue(propNode.get("writable").asBoolean());
    assertFalse(propNode.get("required").asBoolean());

    propNode = mappedProperties.get("direction");
    assertNotNull(propNode);
    assertEquals("direction", propNode.get("id").asText());
    assertTrue(propNode.get("name").isNull());
    assertEquals("enum", propNode.get("type").asText());
    assertTrue(propNode.get("value").isNull());
    assertTrue(propNode.get("datePattern").isNull());
    assertTrue(propNode.get("readable").asBoolean());
    assertTrue(propNode.get("writable").asBoolean());
    assertFalse(propNode.get("required").asBoolean());
    JsonNode enumValues = propNode.get("enumValues");
    assertEquals(4, enumValues.size());
    Map<String, String> mappedEnums = new HashMap<String, String>();
    for (JsonNode enumNode : enumValues) {
        mappedEnums.put(enumNode.get("id").asText(), enumNode.get("name").asText());
    }
    assertEquals("Go Left", mappedEnums.get("left"));
    assertEquals("Go Right", mappedEnums.get("right"));
    assertEquals("Go Up", mappedEnums.get("up"));
    assertEquals("Go Down", mappedEnums.get("down"));

    response = executeRequest(
            new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_FORM_DATA)
                    + "?processDefinitionId=" + processInstance.getProcessDefinitionId()),
            HttpStatus.SC_OK);

    // Check resulting task
    responseNode = objectMapper.readTree(response.getEntity().getContent());
    closeResponse(response);
    assertEquals(2, responseNode.get("formProperties").size());
    mappedProperties.clear();
    for (JsonNode propertyNode : responseNode.get("formProperties")) {
        mappedProperties.put(propertyNode.get("id").asText(), propertyNode);
    }

    propNode = mappedProperties.get("number");
    assertNotNull(propNode);
    assertEquals("number", propNode.get("id").asText());
    assertEquals("Number", propNode.get("name").asText());
    assertEquals("long", propNode.get("type").asText());
    assertTrue(propNode.get("value").isNull());
    assertTrue(propNode.get("readable").asBoolean());
    assertTrue(propNode.get("writable").asBoolean());
    assertFalse(propNode.get("required").asBoolean());

    propNode = mappedProperties.get("description");
    assertNotNull(propNode);
    assertEquals("description", propNode.get("id").asText());
    assertEquals("Description", propNode.get("name").asText());
    assertTrue(propNode.get("type").isNull());
    assertTrue(propNode.get("value").isNull());
    assertTrue(propNode.get("readable").asBoolean());
    assertTrue(propNode.get("writable").asBoolean());
    assertFalse(propNode.get("required").asBoolean());

    closeResponse(executeRequest(new HttpGet(SERVER_URL_PREFIX
            + RestUrls.createRelativeResourceUrl(RestUrls.URL_FORM_DATA) + "?processDefinitionId=123"),
            HttpStatus.SC_NOT_FOUND));

    closeResponse(executeRequest(new HttpGet(SERVER_URL_PREFIX
            + RestUrls.createRelativeResourceUrl(RestUrls.URL_FORM_DATA) + "?processDefinitionId2=123"),
            HttpStatus.SC_BAD_REQUEST));
}

From source file:org.n52.io.geojson.GeoJSONDecoder.java

protected Coordinate[] decodeCoordinates(JsonNode node) throws GeoJSONException {
    if (!node.isArray()) {
        throw new GeoJSONException("expected array");
    }/*from  w ww  . j  a  va2  s  .  c o m*/
    Coordinate[] coordinates = new Coordinate[node.size()];
    for (int i = 0; i < node.size(); ++i) {
        coordinates[i] = decodeCoordinate(node.get(i));
    }
    return coordinates;
}

From source file:org.n52.io.geojson.GeoJSONDecoder.java

protected Polygon decodePolygonCoordinates(JsonNode coordinates, GeometryFactory fac) throws GeoJSONException {
    if (!coordinates.isArray()) {
        throw new GeoJSONException("expected array");
    }/*from w  ww. j  a va 2 s  .c om*/
    if (coordinates.size() < 1) {
        throw new GeoJSONException("missing polygon shell");
    }
    LinearRing shell = fac.createLinearRing(decodeCoordinates(coordinates.get(0)));
    LinearRing[] holes = new LinearRing[coordinates.size() - 1];
    for (int i = 1; i < coordinates.size(); ++i) {
        holes[i - 1] = fac.createLinearRing(decodeCoordinates(coordinates.get(i)));
    }
    return fac.createPolygon(shell, holes);
}

From source file:com.irccloud.android.data.ServersDataSource.java

public void updateIgnores(int cid, JsonNode ignores) {
    Server s = getServer(cid);/* w ww .j av  a 2s .c  o m*/
    if (s != null) {
        s.raw_ignores = ignores;
        s.ignores = new ArrayList<String>();
        for (int i = 0; i < ignores.size(); i++) {
            String mask = ignores.get(i).asText().toLowerCase().replace("\\", "\\\\").replace("(", "\\(")
                    .replace(")", "\\)").replace("[", "\\[").replace("]", "\\]").replace("{", "\\{")
                    .replace("}", "\\}").replace("-", "\\-").replace("^", "\\^").replace("$", "\\$")
                    .replace("|", "\\|").replace("+", "\\+").replace("?", "\\?").replace(".", "\\.")
                    .replace(",", "\\,").replace("#", "\\#").replace("*", ".*").replace("!~", "!");
            if (!mask.contains("!"))
                if (mask.contains("@"))
                    mask = ".*!" + mask;
                else
                    mask += "!.*";
            if (!mask.contains("@"))
                if (mask.contains("!"))
                    mask = mask.replace("!", "!.*@");
                else
                    mask += "@.*";
            if (mask.equals(".*!.*@.*"))
                continue;
            s.ignores.add(mask);
        }
    }
}

From source file:com.vaushell.superpipes.tools.scribe.linkedin.LinkedInClient.java

private List<LNK_Status> readFeedImpl(final String url, final Properties properties)
        throws IOException, LinkedInException {
    if (url == null || properties == null) {
        throw new IllegalArgumentException();
    }//from   w  w w.  java2s . c  om

    final OAuthRequest request = new OAuthRequest(Verb.GET, url);

    for (final Map.Entry<Object, Object> entry : properties.entrySet()) {
        request.addQuerystringParameter((String) entry.getKey(), (String) entry.getValue());
    }

    final Response response = sendSignedRequest(request);

    final ObjectMapper mapper = new ObjectMapper();
    final JsonNode node = (JsonNode) mapper.readTree(response.getStream());

    checkErrors(response, node);

    final List<LNK_Status> status = new ArrayList<>();

    final JsonNode nValues = node.get("values");
    if (nValues != null && nValues.size() > 0) {
        for (final JsonNode nValue : nValues) {
            status.add(convertJsonToStatus(nValue));
        }
    }

    return status;
}

From source file:org.opendaylight.nemo.renderer.openflow.physicalnetwork.PhyConfigLoaderTest.java

public void testBuildPortAttributes() throws Exception {
    Class<PhyConfigLoader> class1 = PhyConfigLoader.class;
    Method method = class1.getDeclaredMethod("buildPortAttributes", new Class[] { JsonNode.class });
    method.setAccessible(true);//from   w w w.  j  a  va  2s . c  o m

    List<Attribute> attributeList;
    JsonNode attributes = mock(JsonNode.class);
    JsonNode portAttribute = mock(JsonNode.class);
    JsonNode jsonNode_temp = mock(JsonNode.class);

    when(attributes.size()).thenReturn(1);
    when(attributes.get(any(Integer.class))).thenReturn(portAttribute);
    //get into method "buildPortAttribute"
    when(portAttribute.path(any(String.class))).thenReturn(jsonNode_temp);
    when(jsonNode_temp.asText()).thenReturn(new String(""))//branch null
            .thenReturn(new String("zm"));
    attributeList = (List<Attribute>) method.invoke(phyConfigLoader, attributes);
    Assert.assertTrue(attributeList.size() == 0);
    //new AttributeName("zm");
    attributeList = (List<Attribute>) method.invoke(phyConfigLoader, attributes);
    Assert.assertTrue(attributeList.size() == 1);
    verify(portAttribute, times(3)).path(any(String.class));
    verify(jsonNode_temp, times(3)).asText();
}

From source file:com.github.alexfalappa.nbspringboot.projects.initializr.BootDependenciesPanel.java

public void init(JsonNode metaData) {
    JsonNode depArray = metaData.path("dependencies").path("values");
    final int nodeNum = depArray.size();
    // remove informative label
    if (nodeNum > 0) {
        this.remove(lNotInitialized);
    }/* w ww. ja va 2 s.  c  om*/
    // prepare dependencies checkboxes
    for (int i = 0; i < nodeNum; i++) {
        JsonNode gn = depArray.get(i);
        final String groupName = gn.path("name").asText();
        // group label
        JLabel lGroup = new JLabel(groupName);
        lGroup.setFont(lGroup.getFont().deriveFont(Font.BOLD, lGroup.getFont().getSize() + 2));
        grpLabels.add(lGroup);
        this.add(lGroup, constraintsForGroupLabel(i == 0));
        // starter checkboxes in two columns
        final JsonNode valArray = gn.path("values");
        for (int j = 0; j < valArray.size(); j++) {
            // first column
            JsonNode dn = valArray.get(j);
            this.add(checkBoxForNode(groupName, dn), constraintsForFirstColumnCheckbox());
            // second column (optional)
            if (++j < valArray.size()) {
                dn = valArray.get(j);
                this.add(checkBoxForNode(groupName, dn), constraintsForSecondColumnCheckbox());
            }
        }
    }
    initialized = true;
    // force recompute of increments
    unitIncrement = null;
    blockIncrement = null;
}