/*
 * Copyright © 2021 by Data Virtuality GmbH
 */
package org.teiid.translator.salesforce.execution;

import com.sforce.soap.partner.QueryResult;
import com.sforce.soap.partner.sobject.SObject;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.teiid.cdk.api.TranslationUtility;
import org.teiid.language.Select;
import org.teiid.metadata.RuntimeMetadata;
import org.teiid.translator.ExecutionContext;
import org.teiid.translator.salesforce.SalesForceExecutionFactory;
import org.teiid.translator.salesforce.SalesforceConnection;
import org.teiid.translator.salesforce.execution.visitors.TestVisitors;

import java.util.Arrays;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
 * @author Roman Pedchenko
 * @date 2021.03.30
 */
public class TestTypesDvcore7139Impl {
    private static final TranslationUtility translationUtility = new TranslationUtility(TestVisitors.exampleSalesforce());

    @Test
    public void testValues() throws Exception {
        final String query = "SELECT NewValue, OldValue FROM LeadHistory";
        Select command = (Select)translationUtility.parseCommand(query);
        SalesforceConnection sfc = Mockito.mock(SalesforceConnection.class);

        QueryResult qr = new QueryResult();
        SObject so = new SObject();
        so.setType("LeadHistory");
        so.addField("NewValue", true);
        so.addField("OldValue", false);
        qr.setRecords(new SObject[] {so});
        qr.setDone(true);

        Mockito.when(sfc.query(query, 0, false)).thenReturn(qr);
        QueryExecutionImpl qei = new QueryExecutionImpl(command, sfc, Mockito.mock(RuntimeMetadata.class), Mockito.mock(ExecutionContext.class), new SalesForceExecutionFactory());
        qei.execute();
        assertEquals(Arrays.asList("true", "false"), qei.next());
    }
}
