/** Return a {@link Container container} contains all snapshots directories inside it. */ public Container getContainer(String networkName) { if (!_idManager.hasNetworkId(networkName)) { throw new IllegalArgumentException(String.format("Network '%s' does not exist", networkName)); } NetworkId networkId = _idManager.getNetworkId(networkName); SortedSet<String> testrigs = ImmutableSortedSet.copyOf(_idManager.listSnapshots(networkId)); return Container.of(networkName, testrigs); }
@JsonCreator public static Container of( @JsonProperty(PROP_NAME) String name, @JsonProperty(PROP_TESTRIGS) SortedSet<String> testrigs) { return new Container(name, testrigs); }
/** * Get information of the container (first element in {@code parameters}). * * <p>Returns {@code true} if successfully get container information, {@code false} otherwise */ private boolean getNetwork(List<String> options, List<String> parameters) { if (!isValidArgument(options, parameters, 0, 1, 1, Command.GET_NETWORK)) { return false; } String containerName = parameters.get(0); Container container = _workHelper.getNetwork(containerName); if (container != null) { _logger.output(container.getTestrigs() + "\n"); return true; } return false; }
@Test public void testGetContainer() { String containerName = "someContainer"; Main.getWorkMgr().initNetwork(containerName, null); Response response = getNetworkTarget(containerName).get(); assertThat(response.getStatus(), equalTo(OK.getStatusCode())); assertThat( response.readEntity(new GenericType<Container>() {}).getName(), equalTo(containerName)); }
@Test public void testEquals() { Container c = Container.of("foo", new TreeSet<>()); Container cCopy = Container.of("foo", new TreeSet<>()); Container cWithTestrig = Container.of("foo", Sets.newTreeSet(Collections.singletonList("testrig"))); Container cOtherName = Container.of("bar", new TreeSet<>()); new EqualsTester() .addEqualityGroup(c, cCopy) .addEqualityGroup(cWithTestrig) .addEqualityGroup(cOtherName) .testEquals(); } }
@Test public void getNonEmptyNetwork() throws Exception { initNetwork(); initSnapshot(); Response response = _service.getNetwork("100", "0.0.0", _networkName); Container network = BatfishObjectMapper.mapper().readValue(response.getEntity().toString(), Container.class); Container expected = Container.of(_networkName, Sets.newTreeSet(Collections.singleton(_snapshotName))); assertThat(network, equalTo(expected)); }
@Test public void getNonEmptyContainer() throws Exception { initNetwork(); initSnapshot(); Response response = _service.getNetwork("100", "0.0.0", _networkName); String entityStr = response.getEntity().toString(); Container network = BatfishObjectMapper.mapper().readValue(entityStr, Container.class); Container expected = Container.of(_networkName, Sets.newTreeSet(Collections.singleton(_snapshotName))); assertThat(network, equalTo(expected)); }
@Test public void getEmptyContainer() { _manager.initNetwork("container", null); Container container = _manager.getContainer("container"); assertThat(container, equalTo(Container.of("container", new TreeSet<>()))); }
@Test public void getNonEmptyContainer() { String network = "container"; String snapshot = "testrig"; _manager.initNetwork(network, null); NetworkId networkId = _idManager.getNetworkId(network); _idManager.assignSnapshot(snapshot, networkId, _idManager.generateSnapshotId()); Container container = _manager.getContainer(network); assertThat( container, equalTo(Container.of(network, Sets.newTreeSet(Collections.singleton(snapshot))))); }
assertThat( resp.readEntity(Container.class), equalTo(Container.of(containerName, Collections.emptySortedSet())));