<commit_before>package org.jsmart.zerocode.core.kafka.helper;

import org.jsmart.zerocode.core.kafka.consume.ConsumerLocalConfigs;
import org.jsmart.zerocode.core.kafka.consume.ConsumerLocalConfigsWrap;
import org.jsmart.zerocode.core.kafka.receive.ConsumerCommonConfigs;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.jsmart.zerocode.core.kafka.helper.KafkaHelper.deriveEffectiveConfigs;

public class KafkaHelperTest {

    ConsumerCommonConfigs consumerCommon;
    ConsumerLocalConfigs consumerLocal;

    //ObjectMapper objectMapper = (new ObjectMapperProvider()).get();

    @Rule
    public ExpectedException expectedException = ExpectedException.none();

    @Test
    public void test_effectiveConfigsIsLocal() throws Exception{

        consumerCommon = new ConsumerCommonConfigs(true, false, "aTestFile", "JSON", true);
        consumerLocal = new ConsumerLocalConfigs("sTestLocalFile", "RAW", true, false, false);

        ConsumerLocalConfigs consumerEffectiveConfigs = deriveEffectiveConfigs(consumerLocal, consumerCommon);

        assertThat(consumerEffectiveConfigs.getFileDumpTo(), is("sTestLocalFile"));
        assertThat(consumerEffectiveConfigs.getFileDumpType(), is("RAW"));
        assertThat(consumerEffectiveConfigs.getCommitAsync(), is(true));
        assertThat(consumerEffectiveConfigs.getCommitSync(), is(false));
        assertThat(consumerEffectiveConfigs.getShowRecordsAsResponse(), is(false));
    }

    @Test
    public void test_effectiveConfigsIsCentrall() throws Exception{

        consumerCommon = new ConsumerCommonConfigs(true, false, "aTestFile", "JSON", true);
        consumerLocal = null;

        ConsumerLocalConfigs consumerEffectiveConfigs = deriveEffectiveConfigs(consumerLocal, consumerCommon);

        assertThat(consumerEffectiveConfigs.getFileDumpTo(), is("aTestFile"));
        assertThat(consumerEffectiveConfigs.getFileDumpType(), is("JSON"));
        assertThat(consumerEffectiveConfigs.getCommitAsync(), is(false));
        assertThat(consumerEffectiveConfigs.getCommitSync(), is(true));
        assertThat(consumerEffectiveConfigs.getShowRecordsAsResponse(), is(true));
    }

    @Test
    public void test_syncAsyncTrueCommon() throws Exception{
        consumerCommon = new ConsumerCommonConfigs(true, true, "aTestFile", "JSON", true);

        expectedException.expectMessage("Both commitSync and commitAsync can not be true");
        ConsumerLocalConfigs consumerEffectiveConfigs = deriveEffectiveConfigs(null, consumerCommon);
    }

    @Test
    public void test_syncAsyncTrueLocal() throws Exception{
        consumerCommon = new ConsumerCommonConfigs(true, false, "aTestFile", "JSON", true);
        consumerLocal = new ConsumerLocalConfigs("sTestLocalFile", "RAW", true, true, false);
        ConsumerLocalConfigsWrap localConfigsWrap = new ConsumerLocalConfigsWrap(consumerLocal);

        expectedException.expectMessage("Both commitSync and commitAsync can not be true");
        ConsumerLocalConfigs consumerEffectiveConfigs = deriveEffectiveConfigs(consumerLocal, consumerCommon);
    }

}<commit_msg>ISS-104 # Effective commitSync, commitAsync -covered<commit_after>package org.jsmart.zerocode.core.kafka.helper;

import org.jsmart.zerocode.core.kafka.consume.ConsumerLocalConfigs;
import org.jsmart.zerocode.core.kafka.consume.ConsumerLocalConfigsWrap;
import org.jsmart.zerocode.core.kafka.receive.ConsumerCommonConfigs;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.nullValue;
import static org.jsmart.zerocode.core.kafka.helper.KafkaHelper.deriveEffectiveConfigs;

public class KafkaHelperTest {

    ConsumerCommonConfigs consumerCommon;
    ConsumerLocalConfigs consumerLocal;

    //ObjectMapper objectMapper = (new ObjectMapperProvider()).get();

    @Rule
    public ExpectedException expectedException = ExpectedException.none();

    @Test
    public void test_syncAsyncTrueCommon() throws Exception{
        consumerCommon = new ConsumerCommonConfigs(true, true, "aTestFile", "JSON", true);

        expectedException.expectMessage("Both commitSync and commitAsync can not be true");
        ConsumerLocalConfigs consumerEffectiveConfigs = deriveEffectiveConfigs(null, consumerCommon);
    }

    @Test
    public void test_syncAsyncTrueLocal() throws Exception{
        consumerCommon = new ConsumerCommonConfigs(true, false, "aTestFile", "JSON", true);
        consumerLocal = new ConsumerLocalConfigs("sTestLocalFile", "RAW", true, true, false);
        ConsumerLocalConfigsWrap localConfigsWrap = new ConsumerLocalConfigsWrap(consumerLocal);

        expectedException.expectMessage("Both commitSync and commitAsync can not be true");
        ConsumerLocalConfigs consumerEffectiveConfigs = deriveEffectiveConfigs(consumerLocal, consumerCommon);
    }

    @Test
    public void test_effectiveConfigsIsLocal() throws Exception{

        consumerCommon = new ConsumerCommonConfigs(true, false, "aTestFile", "JSON", true);
        consumerLocal = new ConsumerLocalConfigs("sTestLocalFile", "RAW", true, false, false);

        ConsumerLocalConfigs consumerEffectiveConfigs = deriveEffectiveConfigs(consumerLocal, consumerCommon);

        assertThat(consumerEffectiveConfigs.getFileDumpTo(), is("sTestLocalFile"));
        assertThat(consumerEffectiveConfigs.getFileDumpType(), is("RAW"));
        assertThat(consumerEffectiveConfigs.getCommitAsync(), is(true));
        assertThat(consumerEffectiveConfigs.getCommitSync(), is(false));
        assertThat(consumerEffectiveConfigs.getShowRecordsAsResponse(), is(false));
    }

    @Test
    public void test_effectiveConfigsIsCentrall() throws Exception{

        consumerCommon = new ConsumerCommonConfigs(true, false, "aTestFile", "JSON", true);
        consumerLocal = null;

        ConsumerLocalConfigs consumerEffectiveConfigs = deriveEffectiveConfigs(consumerLocal, consumerCommon);

        assertThat(consumerEffectiveConfigs.getFileDumpTo(), is("aTestFile"));
        assertThat(consumerEffectiveConfigs.getFileDumpType(), is("JSON"));
        assertThat(consumerEffectiveConfigs.getCommitAsync(), is(false));
        assertThat(consumerEffectiveConfigs.getCommitSync(), is(true));
        assertThat(consumerEffectiveConfigs.getShowRecordsAsResponse(), is(true));
    }

    @Test
    public void test_effectiveCommitAsync_true() throws Exception{

        consumerCommon = new ConsumerCommonConfigs(true, null, "aTestFile", "JSON", true);
        consumerLocal = new ConsumerLocalConfigs("sTestLocalFile", "RAW", true, false, false);

        ConsumerLocalConfigs consumerEffectiveConfigs = deriveEffectiveConfigs(consumerLocal, consumerCommon);

        assertThat(consumerEffectiveConfigs.getCommitAsync(), is(true));
        assertThat(consumerEffectiveConfigs.getCommitSync(), is(false));
    }

    @Test
    public void test_effectiveCommitSync_true() throws Exception{

        consumerCommon = new ConsumerCommonConfigs(null, true, "aTestFile", "JSON", true);
        consumerLocal = new ConsumerLocalConfigs("sTestLocalFile", "RAW", null, true, false);

        ConsumerLocalConfigs consumerEffectiveConfigs = deriveEffectiveConfigs(consumerLocal, consumerCommon);

        assertThat(consumerEffectiveConfigs.getCommitSync(), is(true));
        assertThat(consumerEffectiveConfigs.getCommitAsync(), nullValue());
    }

    @Test
    public void test_effectiveCommitSyncFromCommon_true() throws Exception{

        consumerCommon = new ConsumerCommonConfigs(true, false, "aTestFile", "JSON", true);
        consumerLocal = new ConsumerLocalConfigs("sTestLocalFile", "RAW", null, null, false);

        ConsumerLocalConfigs consumerEffectiveConfigs = deriveEffectiveConfigs(consumerLocal, consumerCommon);

        assertThat(consumerEffectiveConfigs.getCommitSync(), is(true));
        assertThat(consumerEffectiveConfigs.getCommitAsync(), is(false));
    }

    @Test
    public void test_effectiveCommitAsyncFromCommon_true() throws Exception{

        consumerCommon = new ConsumerCommonConfigs(null, true, "aTestFile", "JSON", true);
        consumerLocal = new ConsumerLocalConfigs("sTestLocalFile", "RAW", true, false, false);

        ConsumerLocalConfigs consumerEffectiveConfigs = deriveEffectiveConfigs(consumerLocal, consumerCommon);

        assertThat(consumerEffectiveConfigs.getCommitAsync(), is(true));
        assertThat(consumerEffectiveConfigs.getCommitSync(), is(false));
    }
}
{'fraction_non_alphanumeric': 0.09538603152686688, 'fraction_numerical': 0.00034518467380048324, 'mean_word_length': 5.138418079096045, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '535051', 'n_tokens_mistral': 2398, 'n_tokens_neox': 2301, 'n_words': 445}