/*
 * Copyright 2016 Palantir Technologies, Inc. All rights reserved.
 */

package com.palantir.docker.compose;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;

import com.palantir.docker.compose.configuration.ShutdownStrategy;
import com.palantir.docker.compose.logging.DoNothingLogCollector;
import org.junit.Test;

public class AggressiveShutdownStrategyIntegrationTest {

    private final DockerComposeRule rule = DockerComposeRule.builder()
            .file("src/test/resources/shutdown-strategy.yaml")
            .logCollector(new DoNothingLogCollector())
            .retryAttempts(0)
            .shutdownStrategy(ShutdownStrategy.AGGRESSIVE)
            .build();

    @Test
    public void shut_down_multiple_containers_immediately() throws Exception {
        assertThat(rule.dockerCompose().ps(), is(TestContainerNames.of()));

        rule.before();
        assertThat(rule.dockerCompose().ps().size(), is(2));
        rule.after();

        assertThat(rule.dockerCompose().ps(), is(TestContainerNames.of()));
    }

    @Test
    public void clean_up_created_networks_when_shutting_down() throws Exception {
        String networksBeforeRun = rule.docker().listNetworks();

        rule.before();
        assertThat(rule.docker().listNetworks(), is(not(networksBeforeRun)));
        rule.after();

        assertThat(rule.docker().listNetworks(), is(networksBeforeRun));
    }
}

@@ -241,16 +241,55 @@
 s.not;%0A%0A
+import com.google.common.collect.Sets;%0A
 import c
@@ -413,16 +413,63 @@
 lector;%0A
+import java.util.Arrays;%0Aimport java.util.Set;%0A
 import o
@@ -1303,14 +1303,19 @@
     
+Set%3C
 String
+%3E
  net
@@ -1331,16 +1331,43 @@
 reRun = 
+parseLinesFromOutputString(
 rule.doc
@@ -1386,16 +1386,17 @@
 tworks()
+)
 ;%0A%0A     
@@ -1424,32 +1424,59 @@
      assertThat(
+parseLinesFromOutputString(
 rule.docker().li
@@ -1483,24 +1483,25 @@
 stNetworks()
+)
 , is(not(net
@@ -1553,32 +1553,59 @@
      assertThat(
+parseLinesFromOutputString(
 rule.docker().li
@@ -1616,16 +1616,17 @@
 tworks()
+)
 , is(net
@@ -1648,11 +1648,153 @@
 );%0A    %7D
+%0A%0A    private Set%3CString%3E parseLinesFromOutputString(String output) %7B%0A        return Sets.newHashSet(Arrays.asList(output.split(%22%5Cn%22)));%0A    %7D
 %0A%7D%0A

Make network list test not depend on order of networks