package com.auth0.json.mgmt;

import com.auth0.json.JsonMatcher;
import com.auth0.json.JsonTest;
import org.junit.Test;

import java.util.Arrays;
import java.util.HashMap;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;

public class ConnectionTest extends JsonTest<Connection> {

    private static final String json = "{\"name\":\"my-connection\",\"strategy\":\"auth0\",\"options\":{},\"enabled_clients\":[\"client1\",\"client2\"]}";
    private static final String readOnlyJson = "{\"id\":\"connectionId\"}";

    @Test
    public void shouldSerialize() throws Exception {
        Connection connection = new Connection("my-connection", "auth0");
        connection.setOptions(new HashMap<String, Object>());
        connection.setEnabledClients(Arrays.asList("client1", "client2"));

        String serialized = toJSON(connection);
        assertThat(serialized, is(notNullValue()));
        assertThat(serialized, JsonMatcher.hasEntry("name", "my-connection"));
        assertThat(serialized, JsonMatcher.hasEntry("strategy", "auth0"));
        assertThat(serialized, JsonMatcher.hasEntry("options", notNullValue()));
        assertThat(serialized, JsonMatcher.hasEntry("enabled_clients", Arrays.asList("client1", "client2")));
    }

    @Test
    public void shouldDeserialize() throws Exception {
        Connection connection = fromJSON(json, Connection.class);

        assertThat(connection, is(notNullValue()));
        assertThat(connection.getName(), is("my-connection"));
        assertThat(connection.getOptions(), is(notNullValue()));
        assertThat(connection.getStrategy(), is("auth0"));
        assertThat(connection.getEnabledClients(), contains("client1", "client2"));
    }

    @Test
    public void shouldIncludeReadOnlyValuesOnDeserialize() throws Exception {
        Connection connection = fromJSON(readOnlyJson, Connection.class);
        assertThat(connection, is(notNullValue()));

        assertThat(connection.getId(), is("connectionId"));
    }
}
@@ -551,16 +551,243 @@
 d%5C%22%7D%22;%0A%0A
+    private static final String jsonAd = %22%7B%5C%22name%5C%22:%5C%22my-ad-connection%5C%22,%5C%22strategy%5C%22:%5C%22ad%5C%22,%5C%22provisioning_ticket_url%5C%22:%5C%22https://demo.auth0.com/p/ad/ddQTRlVt%5C%22,%5C%22options%5C%22:%7B%7D,%5C%22enabled_clients%5C%22:%5B%5C%22client1%5C%22,%5C%22client2%5C%22%5D%7D%22;%0A%0A
     @Tes
@@ -780,32 +780,32 @@
 %5D%7D%22;%0A%0A    @Test%0A
-
     public void 
@@ -1494,24 +1494,111 @@
 lient2%22)));%0A
+        assertThat(serialized, JsonMatcher.hasEntry(%22provisioning_ticket_url%22, null));%0A
     %7D%0A%0A    @
@@ -1955,32 +1955,32 @@
 , is(%22auth0%22));%0A
-
         assertTh
@@ -2043,24 +2043,669 @@
 client2%22));%0A
+        assertThat(connection.getProvisioningTicketUrl(), is(nullValue()));%0A    %7D%0A%0A    @Test%0A    public void shouldDeserializeAd() throws Exception %7B%0A        Connection connection = fromJSON(jsonAd, Connection.class);%0A%0A        assertThat(connection, is(notNullValue()));%0A        assertThat(connection.getName(), is(%22my-ad-connection%22));%0A        assertThat(connection.getOptions(), is(notNullValue()));%0A        assertThat(connection.getStrategy(), is(%22ad%22));%0A        assertThat(connection.getEnabledClients(), contains(%22client1%22, %22client2%22));%0A        assertThat(connection.getProvisioningTicketUrl(), is(%22https://demo.auth0.com/p/ad/ddQTRlVt%22));%0A
     %7D%0A%0A    @

Add test for ad ticket url support