package com.atlassian.bitbucket.internal.importer;

import com.atlassian.httpclient.api.Response;

import java.io.IOException;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class ExternalRepositoryServiceTestHelper {

    public static Response getResponse(String entity) throws IOException {
        Response response = mock(Response.class);
        when(response.getEntity()).thenReturn(entity);
        when(response.isOk()).thenReturn(true);
        when(response.getStatusText()).thenReturn("OK");
        return response;
    }

    public static Response getResponse(String content, String link) throws IOException {
        Response response = getResponse(content);
        when(response.getHeader("Link")).thenReturn(link);
        return response;
    }

    public static Response getResponse(String content, String headerName, String headerValue) throws IOException {
        Response response = getResponse(content);
        when(response.getHeader(headerName)).thenReturn(headerValue);
        return response;
    }

    public static void assertUser(ExternalUser user, String name, String description, String avatar) {
        assertEquals(avatar, user.getAvatarUrl());
        assertEquals(name, user.getName());
        assertEquals(description, user.getDescription());
    }

    public static void assertOwner(ExternalOwner owner, String name, String description, String avatar) {
        assertEquals(avatar, owner.getAvatarUrl());
        assertEquals(name, owner.getName());
        assertEquals(description, owner.getDescription());
    }

    public static void assertRepository(ExternalRepository repository, String name, String description, String cloneUrl) {
        assertEquals(name, repository.getName());
        assertEquals(description, repository.getDescription());
        assertEquals(cloneUrl, repository.getCloneUrl());
    }
}
