package se.arbetsformedlingen.venice.tpjadmin;

import org.junit.Test;
import se.arbetsformedlingen.venice.common.*;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

public class TPJAdminResponseParserTest {

    @Test
    public void parse_response() {
        Application application = new Application("geo");
        Environment environment = new Environment("PROD");
        Host host1 = new Host("l7700746.wpa.ams.se");
        Host host2 = new Host("l7700747.wpa.ams.se");
        Host host3 = new Host("l7700770.wpa.ams.se");
        Port port = new Port("8180");

        ApplicationServer geo1 = new ApplicationServer(application, environment, host1, port);
        ApplicationServer geo2 = new ApplicationServer(application, environment, host2, port);
        ApplicationServer geo3 = new ApplicationServer(application, environment, host3, port);

        String jsonSample = "{\"l7700770.wpa.ams.se\":1, \"l7700747.wpa.ams.se\":1, \"l7700746.wpa.ams.se\":1}";

        List<ApplicationServer> actual = TPJAdminResponseParser.parse(application, environment, jsonSample);

        assertThat(actual).containsExactlyInAnyOrder(geo1, geo2, geo3);
    }

}

@@ -1189,10 +1189,922 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void skip_parsing_response_with_broken_instance_number() %7B%0A        Application application = new Application(%22geo%22);%0A        Environment environment = new Environment(%22PROD%22);%0A        Host host1 = new Host(%22l7700746.wpa.ams.se%22);%0A        Host host3 = new Host(%22l7700770.wpa.ams.se%22);%0A        Port port = new Port(%228180%22);%0A%0A        ApplicationServer geo1 = new ApplicationServer(application, environment, host1, port);%0A        ApplicationServer geo3 = new ApplicationServer(application, environment, host3, port);%0A%0A        String instanceNumber = %22broken instance number%22;%0A        String jsonSample = %22%7B%5C%22l7700770.wpa.ams.se%5C%22:1, %5C%22l7700747.wpa.ams.se%5C%22: %22 + instanceNumber + %22, %5C%22l7700746.wpa.ams.se%5C%22:1%7D%22;%0A%0A        List%3CApplicationServer%3E actual = TPJAdminResponseParser.parse(application, environment, jsonSample);%0A%0A        assertThat(actual).containsExactlyInAnyOrder(geo1, geo3);%0A    %7D%0A%0A
 %7D%0A

Verify that we can handle broken Json from TPJAdmin