/** 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); }
@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 testToString() { Container c = Container.of("foo", new TreeSet<>()); assertThat(c.toString(), equalTo("Container{name=foo, testrigs=[]}")); }
@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())));