package kz.arta.synergy.workflow.mobile.android.offline;

import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;

import java.util.ArrayList;
import java.util.List;

import kz.arta.synergy.workflow.mobile.android.attachments.models.AttachmentItem;
import kz.arta.synergy.workflow.mobile.android.comments.models.CommentItem;
import kz.arta.synergy.workflow.mobile.android.common.models.LogSyncItem;
import kz.arta.synergy.workflow.mobile.android.common.offline.get.FinishProcessTable;
import kz.arta.synergy.workflow.mobile.android.common.offline.get.FormCompletionTable;
import kz.arta.synergy.workflow.mobile.android.common.offline.get.LogsTable;
import kz.arta.synergy.workflow.mobile.android.common.offline.get.SettingsTable;
import kz.arta.synergy.workflow.mobile.android.common.offline.get.WorkActionsTable;
import kz.arta.synergy.workflow.mobile.android.common.offline.get.WorkAttachmentsTable;
import kz.arta.synergy.workflow.mobile.android.common.offline.get.WorkCommentsTable;
import kz.arta.synergy.workflow.mobile.android.common.offline.get.WorkFiltersTable;
import kz.arta.synergy.workflow.mobile.android.common.offline.get.WorksTable;
import kz.arta.synergy.workflow.mobile.android.works.models.CompletionResultItem;
import kz.arta.synergy.workflow.mobile.android.works.models.ScreenFinishInfoItem;
import kz.arta.synergy.workflow.mobile.android.works.models.WorkActionsItem;
import kz.arta.synergy.workflow.mobile.android.works.models.WorkItem;

/**
 * Created by neox on 12.10.16.
 */
public class WorksOfflineUnitTest {

    @Test
    public void getScreenFinishInfoByActionID() {
        ScreenFinishInfoItem result = new ScreenFinishInfoItem();
        result.setActionID("actionID");
        FinishProcessTable db = Mockito.mock(FinishProcessTable.class);
        Mockito.when(db.get("actionID")).thenReturn(result);
        Assert.assertNotNull(db.get("actionID"));
        Assert.assertEquals(db.get("actionID"), result);
    }

    @Test
    public void getCompletionResult() {
        CompletionResultItem result = new CompletionResultItem();
        result.setActionID("actionID");
        FormCompletionTable db = Mockito.mock(FormCompletionTable.class);
        Mockito.when(db.getByWorkId("actionID")).thenReturn(result);
        Assert.assertNotNull(db.getByWorkId("actionID"));
        Assert.assertEquals(db.getByWorkId("actionID"), result);
    }

    @Test
    public void getLogs() {
        LogSyncItem logSyncItem = new LogSyncItem("type", "message", "date", "number");
        List<LogSyncItem> result = new ArrayList<>();
        result.add(logSyncItem);
        LogsTable db = Mockito.mock(LogsTable.class);
        Mockito.when(db.getMessages()).thenReturn(result);
        Assert.assertNotNull(db.getMessages());
        Assert.assertEquals(db.getMessages().size(), 1);
        Assert.assertEquals(db.getMessages(), result);
    }

    @Test
    public void getSettingsTest() {
        String result = "";
        SettingsTable db = Mockito.mock(SettingsTable.class);
        Mockito.when(db.get()).thenReturn(result);
        Assert.assertNotNull(db.get());
        Assert.assertEquals(db.get(), result);
    }

    @Test
    public void getActionsByActionID() {
        WorkActionsItem item = new WorkActionsItem();
        item.setLabel("label");
        item.setActionID("actionID");
        item.setAction("action");
        item.setColor("color");
        item.setOperation("operation");
        List<WorkActionsItem> result = new ArrayList<>();
        result.add(item);
        WorkActionsTable db = Mockito.mock(WorkActionsTable.class);
        Mockito.when(db.get("actionID")).thenReturn(result);
        Assert.assertNotNull(db.get("actionID"));
        Assert.assertEquals(db.get("actionID").size(), 1);
        Assert.assertEquals(db.get("actionID"), result);
    }

    @Test
    public void getWorkAttachmentsByActionID() {
        AttachmentItem item = new AttachmentItem();
        item.setActionID("actionID");
        List<AttachmentItem> result = new ArrayList<>();
        result.add(item);
        WorkAttachmentsTable db = Mockito.mock(WorkAttachmentsTable.class);
        Mockito.when(db.get("actionID")).thenReturn(result);
        Assert.assertNotNull(db.get("actionID"));
        Assert.assertEquals(db.get("actionID").size(), 1);
        Assert.assertEquals(db.get("actionID"), result);
    }

    @Test
    public void getFilePathByUUID() {
        String result = "";
        WorkAttachmentsTable db = Mockito.mock(WorkAttachmentsTable.class);
        Mockito.when(db.getFilePathByUUID("uuid")).thenReturn(result);
        Assert.assertNotNull(db.getFilePathByUUID("uuid"));
        Assert.assertEquals(db.getFilePathByUUID("uuid"), result);
    }

    @Test
    public void getWorkCommentsByActionId() {
        CommentItem item = new CommentItem();
        item.setActionID("actionID");
        List<CommentItem> result = new ArrayList<>();
        result.add(item);
        WorkCommentsTable db = Mockito.mock(WorkCommentsTable.class);
        Mockito.when(db.getByWorkID("actionID")).thenReturn(result);
        Assert.assertNotNull(db.getByWorkID("actionID"));
        Assert.assertEquals(db.getByWorkID("actionID").size(), 1);
        Assert.assertEquals(db.getByWorkID("actionID"), result);
    }

    @Test
    public void getWorkCommentsByActionIdAndType() {
        CommentItem item = new CommentItem();
        item.setActionID("actionID");
        List<CommentItem> result = new ArrayList<>();
        result.add(item);
        WorkCommentsTable db = Mockito.mock(WorkCommentsTable.class);
        Mockito.when(db.getByWorkIDAndType("actionID", "type")).thenReturn(result);
        Assert.assertNotNull(db.getByWorkIDAndType("actionID", "type"));
        Assert.assertEquals(db.getByWorkIDAndType("actionID", "type").size(), 1);
        Assert.assertEquals(db.getByWorkIDAndType("actionID", "type"), result);
    }

    @Test
    public void getWorkFilters() {
        String result = "";
        WorkFiltersTable db = Mockito.mock(WorkFiltersTable.class);
        Mockito.when(db.getFilter("uuid")).thenReturn(result);
        Assert.assertNotNull(db.getFilter("uuid"));
        Assert.assertEquals(db.getFilter("uuid"), result);
    }

    @Test
    public void getAllWorks() {
        WorkItem item = new WorkItem();
        item.setActionID("actionID");
        List<WorkItem> result = new ArrayList<>();
        result.add(item);
        result.add(item);
        result.add(item);
        WorksTable db = Mockito.mock(WorksTable.class);
        Mockito.when(db.getWorks()).thenReturn(result);
        Assert.assertNotNull(db.getWorks());
        Assert.assertEquals(db.getWorks().size(), 3);
        Assert.assertEquals(db.getWorks(), result);
    }

    @Test
    public void getWorksById() {
        String[] uuid = {"uuid1", "uuid2"};
        WorkItem item = new WorkItem();
        item.setActionID("actionID");
        List<WorkItem> result = new ArrayList<>();
        result.add(item);
        result.add(item);
        result.add(item);
        WorksTable db = Mockito.mock(WorksTable.class);
        Mockito.when(db.getWorksById(uuid)).thenReturn(result);
        Assert.assertNotNull(db.getWorksById(uuid));
        Assert.assertEquals(db.getWorksById(uuid).size(), 3);
        Assert.assertEquals(db.getWorksById(uuid), result);
    }

    @Test
    public void getWorkInfo() {
        WorkItem result = new WorkItem();
        result.setActionID("actionID");
        WorksTable db = Mockito.mock(WorksTable.class);
        Mockito.when(db.getWorkInfo("actionID")).thenReturn(result);
        Assert.assertNotNull(db.getWorkInfo("actionID"));
        Assert.assertEquals(db.getWorkInfo("actionID"), result);
    }

}
