com.eclipsesource.json.Json Java Examples

The following examples show how to use com.eclipsesource.json.Json. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OFAgentWebResourceTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the result of the rest api GET when there are no OFAgents.
 *
 * @throws IOException IO exception
 */
@Test
public void testEmptyOFAgentSet() throws IOException {
    expect(mockOFAgentService.agents()).andReturn(empty).anyTimes();
    replay(mockOFAgentService);

    final WebTarget wt = target();
    assertNotNull("WebTarget is null", wt);
    assertNotNull("WebTarget request is null", wt.request());
    final String response = wt.path("service/ofagents").request().get(String.class);
    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());
    assertThat(result.names(), hasSize(1));
    assertThat(response, is("{\"ofAgents\":[]}"));

    verify(mockOFAgentService);
}
 
Example #2
Source File: PortPairResourceTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the result of a rest api GET for port pair id.
 */
@Test
public void testGetPortPairId() {

    final Set<PortPair> portPairs = new HashSet<>();
    portPairs.add(portPair1);

    expect(portPairService.exists(anyObject())).andReturn(true).anyTimes();
    expect(portPairService.getPortPair(anyObject())).andReturn(portPair1).anyTimes();
    replay(portPairService);

    final WebTarget wt = target();
    final String response = wt.path("port_pairs/78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae")
            .request().get(String.class);
    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());
}
 
Example #3
Source File: FlowObjectiveResourceTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests obtaining a global unique nextId with GET.
 */
@Test
public void testNextId() {
    expect(mockFlowObjectiveService.allocateNextId()).andReturn(10).anyTimes();
    prepareService();

    WebTarget wt = target();
    final String response = wt.path("flowobjectives/next").request().get(String.class);
    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());

    assertThat(result.names(), hasSize(1));
    assertThat(result.names().get(0), is("nextId"));
    final int jsonNextId = result.get("nextId").asInt();
    assertThat(jsonNextId, is(10));
}
 
Example #4
Source File: ZCashClientCaller.java    From zencash-swing-wallet-ui with MIT License 6 votes vote down vote up
private JsonValue executeCommandAndGetJsonValue(String command1, String command2, String command3)
	throws WalletCallException, IOException, InterruptedException
{
	String strResponse = this.executeCommandAndGetSingleStringResponse(command1, command2, command3);

	JsonValue response = null;
	try
	{
	  	response = Json.parse(strResponse);
	} catch (ParseException pe)
	{
	  	throw new WalletCallException(strResponse + "\n" + pe.getMessage() + "\n", pe);
	}

	return response;
}
 
Example #5
Source File: HostResourceTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests fetch of one host by Id.
 */
@Test
public void testSingleHostByIdFetch() {
    final ProviderId pid = new ProviderId("of", "foo");
    final MacAddress mac1 = MacAddress.valueOf("00:00:11:00:00:01");
    final Set<IpAddress> ips1 = ImmutableSet.of(IpAddress.valueOf("1111:1111:1111:1::"));
    final Host host1 =
            new DefaultHost(pid, HostId.hostId(mac1), valueOf(1), vlanId((short) 1),
                    new HostLocation(DeviceId.deviceId("1"), portNumber(11), 1),
                    ips1);

    hosts.add(host1);

    expect(mockHostService.getHost(HostId.hostId("00:00:11:00:00:01/1")))
            .andReturn(host1)
            .anyTimes();
    replay(mockHostService);

    WebTarget wt = target();
    String response = wt.path("hosts/00:00:11:00:00:01%2F1").request().get(String.class);
    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, matchesHost(host1));
}
 
Example #6
Source File: MetersResourceTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the results of a rest api GET for a device.
 */
@Test
public void testMeterSingleDevice() {
    setupMockMeters();

    final Set<Meter> meters1 = new HashSet<>();
    meters1.add(meter1);
    meters1.add(meter2);

    expect(mockMeterService.getMeters(anyObject())).andReturn(meters1).anyTimes();
    replay(mockMeterService);
    replay(mockDeviceService);

    final WebTarget wt = target();
    final String response = wt.path("meters/" + deviceId1.toString()).request().get(String.class);
    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());

    assertThat(result.names(), hasSize(1));
    assertThat(result.names().get(0), is("meters"));
    final JsonArray jsonMeters = result.get("meters").asArray();
    assertThat(jsonMeters, notNullValue());
    assertThat(jsonMeters, hasMeter(meter1));
    assertThat(jsonMeters, hasMeter(meter2));
}
 
Example #7
Source File: MetersResourceTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the result of the rest api GET when there are active meters.
 */
@Test
public void testMetersPopulatedArray() {
    setupMockMeters();
    replay(mockMeterService);
    replay(mockDeviceService);
    final WebTarget wt = target();
    final String response = wt.path("meters").request().get(String.class);
    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());

    assertThat(result.names(), hasSize(1));
    assertThat(result.names().get(0), is("meters"));
    final JsonArray jsonMeters = result.get("meters").asArray();
    assertThat(jsonMeters, notNullValue());
    assertThat(jsonMeters, hasMeter(meter1));
    assertThat(jsonMeters, hasMeter(meter2));
    assertThat(jsonMeters, hasMeter(meter3));
    assertThat(jsonMeters, hasMeter(meter4));
}
 
Example #8
Source File: OFAgentWebResourceTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the result of the rest api GET for OFAgent.
 *
 * @throws IOException IO exception
 */
@Test
public void testOFAgent() throws IOException {
    expect(mockOFAgentService.agent(eq(NETWORK))).andReturn(OF_AGENT).anyTimes();
    replay(mockOFAgentService);

    final WebTarget wt = target();
    assertNotNull("WebTarget is null", wt);
    assertNotNull("WebTarget request is null", wt.request());
    final Response response = wt.path("service/ofagent/" + NETWORK).request().get();
    final JsonObject result = Json.parse(response.readEntity(String.class)).asObject();
    assertThat(result, notNullValue());
    assertThat(result.names(), hasSize(4));
    assertThat(result.get("networkId").asString(), is(NETWORK.id().toString()));
    assertThat(result.get("tenantId").asString(), is(TENANT.id()));
    assertThat(result.get("state").asString(), is(STOPPED.toString()));

    verify(mockOFAgentService);
}
 
Example #9
Source File: MappingsWebResourceTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the result of the rest api GET with a device ID when there are
 * active mappings.
 */
@Test
public void testMappingsByDevIdPopulateArray() {
    setupMockMappings();
    expect(mockDeviceService.getDevice(deviceId2)).andReturn(device2);
    expect(mockMappingService.getMappingEntries(MAP_DATABASE, deviceId2))
            .andReturn(mappings.get(deviceId2)).once();
    replay(mockDeviceService);
    replay(mockMappingService);

    final WebTarget wt = target();
    final String response = wt.path(PREFIX + "/" + deviceId2 + "/" + DATABASE)
            .request().get(String.class);

    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());

    assertThat(result.names(), hasSize(1));
    assertThat(result.names().get(0), is("mappings"));
    final JsonArray jsonMappings = result.get("mappings").asArray();
    assertThat(jsonMappings, notNullValue());
    assertThat(jsonMappings, hasMapping(mapping3));
    assertThat(jsonMappings, hasMapping(mapping4));
}
 
Example #10
Source File: StatisticsResourceTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests GET of a single Load statistics object.
 */
@Test
public void testSingleLoadGet() throws UnsupportedEncodingException {
    final WebTarget wt = target();
    final String response = wt.path("statistics/flows/link")
            .queryParam("device", "of:0000000000000001")
            .queryParam("port", "2")
            .request()
            .get(String.class);

    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());

    assertThat(result.names(), hasSize(1));
    assertThat(result.names().get(0), is("loads"));

    final JsonArray jsonLoads = result.get("loads").asArray();
    assertThat(jsonLoads, notNullValue());
    assertThat(jsonLoads.size(), is(1));

    JsonObject load1 = jsonLoads.get(0).asObject();
    checkValues(load1, 111, 222, true, "src3");
}
 
Example #11
Source File: NetworkConfigWebResourceTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the result of the rest api GET when there is a config.
 */
@Test
public void testConfigs() {
    setUpConfigData();
    final WebTarget wt = target();
    final String response = wt.path("network/configuration").request().get(String.class);

    final JsonObject result = Json.parse(response).asObject();
    Assert.assertThat(result, notNullValue());

    Assert.assertThat(result.names(), hasSize(2));

    JsonValue devices = result.get("devices");
    Assert.assertThat(devices, notNullValue());

    JsonValue device1 = devices.asObject().get("device1");
    Assert.assertThat(device1, notNullValue());

    JsonValue basic = device1.asObject().get("basic");
    Assert.assertThat(basic, notNullValue());

    checkBasicAttributes(basic);
}
 
Example #12
Source File: ApplicationsResourceTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests a GET of an applicationId entry with the given numeric id.
 */
@Test
public void getAppIdByShortId() {
    expect(coreService.getAppId((short) 1)).andReturn(id1);
    replay(coreService);

    WebTarget wt = target();
    String response = wt.path("applications/ids/entry")
            .queryParam("id", 1).request().get(String.class);

    JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());

    assertThat(result, matchesAppId(id1));

    verify(coreService);
}
 
Example #13
Source File: JsonLoader.java    From Cubes with MIT License 6 votes vote down vote up
private static Multimap<JsonStage, JsonValue> load(Map<String, FileHandle> map) throws IOException {
  Multimap<JsonStage, JsonValue> m = new Multimap<JsonStage, JsonValue>();
  for (Map.Entry<String, FileHandle> entry : map.entrySet()) {
    JsonStage stage = null;
    if (entry.getKey().startsWith("block")) {
      stage = JsonStage.BLOCK;
    } else if (entry.getKey().startsWith("item")) {
      stage = JsonStage.ITEM;
    } else if (entry.getKey().startsWith("recipe")) {
      stage = JsonStage.RECIPE;
    } else {
      throw new CubesException("Invalid json file path \"" + entry.getKey() + "\"");
    }

    Reader reader = entry.getValue().reader();
    try {
      m.put(stage, Json.parse(reader));
    } finally {
      reader.close();
    }
  }
  return m;
}
 
Example #14
Source File: Main.java    From jpexs-decompiler with GNU General Public License v3.0 6 votes vote down vote up
private static JsonValue urlGetJson(String getUrl) {
    try {
        String proxyAddress = Configuration.updateProxyAddress.get();
        URL url = new URL(getUrl);

        URLConnection uc;
        if (proxyAddress != null && !proxyAddress.isEmpty()) {
            int port = 8080;
            if (proxyAddress.contains(":")) {
                String[] parts = proxyAddress.split(":");
                port = Integer.parseInt(parts[1]);
                proxyAddress = parts[0];
            }

            uc = url.openConnection(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyAddress, port)));
        } else {
            uc = url.openConnection();
        }
        uc.setRequestProperty("User-Agent", ApplicationInfo.shortApplicationVerName);
        uc.connect();
        JsonValue value = Json.parse(new InputStreamReader(uc.getInputStream()));
        return value;
    } catch (IOException | NumberFormatException ex) {
        return null;
    }
}
 
Example #15
Source File: ProActiveVersionUtility.java    From scheduling with GNU Affero General Public License v3.0 6 votes vote down vote up
protected static String handleResponse(HttpResponse response) throws IOException {
    int statusCode = response.getStatusLine().getStatusCode();

    if (statusCode >= 200 && statusCode < 300) {
        HttpEntity entity = response.getEntity();

        if (entity != null) {
            JsonValue jsonValue = Json.parse(EntityUtils.toString(entity));

            if (jsonValue.isObject()) {
                JsonObject jsonObject = jsonValue.asObject();
                return jsonObject.get("rest").asString();
            }
        }
    }

    return null;
}
 
Example #16
Source File: NetworkConfigWebResourceTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the result of the rest api single subject key GET when
 * there is a config.
 */
@Test
public void testSingleSubjectKeyConfig() {
    setUpConfigData();
    final WebTarget wt = target();
    final String response = wt.path("network/configuration/devices").request().get(String.class);

    final JsonObject result = Json.parse(response).asObject();
    Assert.assertThat(result, notNullValue());

    Assert.assertThat(result.names(), hasSize(1));

    JsonValue device1 = result.asObject().get("device1");
    Assert.assertThat(device1, notNullValue());

    JsonValue basic = device1.asObject().get("basic");
    Assert.assertThat(basic, notNullValue());

    checkBasicAttributes(basic);
}
 
Example #17
Source File: OpenstackNodeWebResourceTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the result of the REST API GET when there are valid nodes.
 */
@Test
public void testGetNodesPopulatedArray() {
    expect(mockOpenstackNodeService.nodes()).
            andReturn(ImmutableSet.of(openstackNode)).anyTimes();
    replay(mockOpenstackNodeService);

    final WebTarget wt = target();
    final String response = wt.path(PATH).request().get(String.class);
    final JsonObject result = Json.parse(response).asObject();

    assertThat(result, notNullValue());
    assertThat(result.names(), hasSize(1));
    assertThat(result.names().get(0), is("nodes"));
    final JsonArray jsonNodes = result.get("nodes").asArray();
    assertThat(jsonNodes, notNullValue());
    assertThat(jsonNodes.size(), is(1));
    assertThat(jsonNodes, hasNode(openstackNode));

    verify(mockOpenstackNodeService);
}
 
Example #18
Source File: MastershipResourceTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the result of the REST API GET when there are active master roles.
 */
@Test
public void testGetLocalRole() {
    expect(mockService.getLocalRole(anyObject())).andReturn(role1).anyTimes();
    replay(mockService);

    final WebTarget wt = target();
    final String response = wt.path("mastership/" + deviceId1.toString() +
                            "/local").request().get(String.class);
    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());

    assertThat(result.names(), hasSize(1));
    assertThat(result.names().get(0), is("role"));

    final String role = result.get("role").asString();
    assertThat(role, notNullValue());
    assertThat(role, is("MASTER"));
}
 
Example #19
Source File: JsonObjectFactory.java    From dungeon with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Makes a new JsonObject from the resource file pointed to by the specified filename.
 *
 * @param filename the name of the JSON file, must end with .json, not null
 * @return a JsonObject that reads from the specified file
 * @throws IllegalFilenameExtensionException if the provided filename does not end with .json
 */
public static JsonObject makeJsonObject(@NotNull String filename) {
  if (!filename.endsWith(JSON_EXTENSION)) {
    throw new IllegalFilenameExtensionException("filename must end with " + JSON_EXTENSION + ".");
  }
  // Using a BufferedReader here does not improve performance as the library is already buffered.
  try (Reader reader = ResourceStreamFactory.getInputStreamReader(filename)) {
    return Json.parse(reader).asObject();
  } catch (IOException fatal) {
    throw new RuntimeException(fatal);
  }
}
 
Example #20
Source File: ForecastIO.java    From forecastio-lib-java with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Parses the forecast reports for the given coordinates with the set options
 * Useful to use with an external http library
 * @param http_response String
 * @return boolean
 */

public boolean getForecast(String http_response) {
	this.forecast = Json.parse(http_response).asObject();
	//this.forecast = JsonObject.readFrom(http_response);
	return getForecast(this.forecast);
}
 
Example #21
Source File: PeriodJsonRuleTest.java    From dungeon with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void percentageJsonRuleShouldPassOnValidYearPeriod() {
  JsonValue oneYear = Json.value("1 year");
  JsonValue twoYears = Json.value("2 years");
  periodJsonRule.validate(oneYear);
  periodJsonRule.validate(twoYears);
}
 
Example #22
Source File: PeriodJsonRuleTest.java    From dungeon with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void percentageJsonRuleShouldPassOnValidDaysPeriod() {
  JsonValue oneDay = Json.value("1 day");
  JsonValue twoDays = Json.value("2 days");
  periodJsonRule.validate(oneDay);
  periodJsonRule.validate(twoDays);
}
 
Example #23
Source File: LinksResourceTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the result of the rest api GET of links for a specific device.
 */
@Test
public void testLinksByDevice() {
    expect(mockLinkService.getDeviceLinks(isA(DeviceId.class)))
            .andReturn(ImmutableSet.of(link2))
            .anyTimes();

    replay(mockLinkService);

    WebTarget wt = target();
    String response = wt
            .path("links")
            .queryParam("device", "src2")
            .request()
            .get(String.class);
    assertThat(response, containsString("{\"links\":["));

    JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());

    assertThat(result.names(), hasSize(1));
    assertThat(result.names().get(0), is("links"));

    JsonArray jsonLinks = result.get("links").asArray();
    assertThat(jsonLinks, notNullValue());
    assertThat(jsonLinks.size(), is(1));

    assertThat(jsonLinks, hasLink(link2));
}
 
Example #24
Source File: RegionsResourceTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Tests retrieving device ids that are associated with the given region.
 */
@Test
public void testGetRegionDevices() {
    final DeviceId deviceId1 = DeviceId.deviceId("1");
    final DeviceId deviceId2 = DeviceId.deviceId("2");
    final DeviceId deviceId3 = DeviceId.deviceId("3");

    final Set<DeviceId> deviceIds = ImmutableSet.of(deviceId1, deviceId2, deviceId3);

    expect(mockRegionService.getRegionDevices(anyObject()))
            .andReturn(deviceIds).anyTimes();
    replay(mockRegionService);

    final WebTarget wt = target();
    final String response = wt.path("regions/" +
            region1.id().toString() + "/devices").request().get(String.class);
    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());

    assertThat(result.names(), hasSize(1));
    assertThat(result.names().get(0), is("deviceIds"));
    final JsonArray jsonDeviceIds = result.get("deviceIds").asArray();
    assertThat(jsonDeviceIds.size(), is(3));
    assertThat(jsonDeviceIds.get(0).asString(), is("1"));
    assertThat(jsonDeviceIds.get(1).asString(), is("2"));
    assertThat(jsonDeviceIds.get(2).asString(), is("3"));

    verify(mockRegionService);
}
 
Example #25
Source File: PlayerAction.java    From microrts with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a PlayerAction from a JSON object
 * @param JSON
 * @param gs
 * @param utt
 * @return
 */
public static PlayerAction fromJSON(String JSON, GameState gs, UnitTypeTable utt) {
    PlayerAction pa = new PlayerAction();
    JsonArray a = Json.parse(JSON).asArray();
    for(JsonValue v:a.values()) {
        JsonObject o = v.asObject();
        int id = o.getInt("unitID", -1);
        Unit u = gs.getUnit(id);
        UnitAction ua = UnitAction.fromJSON(o.get("unitAction").asObject(), utt);
        pa.addUnitAction(u, ua);
    }
    return pa;
}
 
Example #26
Source File: TypeScriptBuildPath.java    From typescript.java with MIT License 5 votes vote down vote up
public static ITypeScriptBuildPath load(IProject project, String json) {
	TypeScriptBuildPath buildPath = new TypeScriptBuildPath(project);
	JsonObject object = Json.parse(json).asObject();
	for (Member member : object) {
		IPath path = new Path(member.getName());
		path = toTsconfigFilePath(path, project);
		if (project.exists(path)) {
			TypeScriptBuildPathEntry entry = new TypeScriptBuildPathEntry(path);
			buildPath.addEntry(entry);
		}
	}
	return buildPath;
}
 
Example #27
Source File: ApplicationsResourceTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Tests a GET of all applications with data.
 */
@Test
public void getAllApplicationsPopulated() {
    expect(appService.getApplications())
            .andReturn(ImmutableSet.of(app1, app2, app3, app4));
    replay(appService);

    WebTarget wt = target();
    String response = wt.path("applications").request().get(String.class);
    assertThat(response, containsString("{\"applications\":["));

    JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());

    assertThat(result.names(), hasSize(1));
    assertThat(result.names().get(0), is("applications"));

    JsonArray jsonApps = result.get("applications").asArray();
    assertThat(jsonApps, notNullValue());
    assertThat(jsonApps.size(), is(4));

    assertThat(jsonApps.get(0).asObject(), matchesApp(app1));
    assertThat(jsonApps.get(1).asObject(), matchesApp(app2));
    assertThat(jsonApps.get(2).asObject(), matchesApp(app3));
    assertThat(jsonApps.get(3).asObject(), matchesApp(app4));

    verify(appService);
}
 
Example #28
Source File: IntentsResourceTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the result of the rest api GET when intents are defined.
 */
@Test
public void testIntentsArray() {
    replay(mockIntentService);

    final Intent intent1 = new MockIntent(1L, Collections.emptyList());
    final HashSet<NetworkResource> resources = new HashSet<>();
    resources.add(new MockResource(1));
    resources.add(new MockResource(2));
    resources.add(new MockResource(3));
    final Intent intent2 = new MockIntent(2L, resources);

    intents.add(intent1);
    intents.add(intent2);
    final WebTarget wt = target();
    final String response = wt.path("intents").request().get(String.class);
    assertThat(response, containsString("{\"intents\":["));

    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());

    assertThat(result.names(), hasSize(1));
    assertThat(result.names().get(0), is("intents"));

    final JsonArray jsonIntents = result.get("intents").asArray();
    assertThat(jsonIntents, notNullValue());

    assertThat(jsonIntents, hasIntent(intent1));
    assertThat(jsonIntents, hasIntent(intent2));
}
 
Example #29
Source File: VirtualNetworkWebResourceTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the result of the REST API GET when virtual hosts are defined.
 */
@Test
public void testGetVirtualHostsArray() {
    NetworkId networkId = networkId3;
    final Set<VirtualHost> vhostSet = ImmutableSet.of(vhost1, vhost2);
    expect(mockVnetService.getVirtualHosts(networkId)).andReturn(vhostSet).anyTimes();
    replay(mockVnetService);

    WebTarget wt = target();
    String location = "vnets/" + networkId.toString() + "/hosts";
    String response = wt.path(location).request().get(String.class);
    assertThat(response, containsString("{\"hosts\":["));

    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());

    assertThat(result.names(), hasSize(1));
    assertThat(result.names().get(0), is("hosts"));

    final JsonArray vnetJsonArray = result.get("hosts").asArray();
    assertThat(vnetJsonArray, notNullValue());
    assertEquals("Virtual hosts array is not the correct size.",
                 vhostSet.size(), vnetJsonArray.size());

    vhostSet.forEach(vhost -> assertThat(vnetJsonArray, hasVhost(vhost)));

    verify(mockVnetService);
}
 
Example #30
Source File: ApplicationsResourceTest.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Tests a GET of all application Ids.
 */
@Test
public void getAllApplicationIdsPopulated() {
    expect(coreService.getAppIds())
            .andReturn(ImmutableSet.of(id1, id2, id3, id4));
    replay(coreService);

    WebTarget wt = target();
    String response = wt.path("applications/ids").request().get(String.class);

    assertThat(response, containsString("{\"applicationIds\":["));

    JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());

    assertThat(result.names(), hasSize(1));
    assertThat(result.names().get(0), is("applicationIds"));

    JsonArray jsonApps = result.get("applicationIds").asArray();
    assertThat(jsonApps, notNullValue());
    assertThat(jsonApps.size(), is(4));

    assertThat(jsonApps.get(0).asObject(), matchesAppId(id1));
    assertThat(jsonApps.get(1).asObject(), matchesAppId(id2));
    assertThat(jsonApps.get(2).asObject(), matchesAppId(id3));
    assertThat(jsonApps.get(3).asObject(), matchesAppId(id4));

    verify(coreService);
}