package com.dnastack.beacon.adapter.variants.client.ga4gh;

import com.dnastack.beacon.adapter.api.BeaconAdapter;
import com.dnastack.beacon.adater.variants.VariantsBeaconAdapter;
import com.dnastack.beacon.exceptions.BeaconException;
import com.dnastack.beacon.utils.AdapterConfig;
import com.dnastack.beacon.utils.ConfigValue;
import org.testng.annotations.Test;

import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

/**
 * Adapter test
 *
 * @author Andrey Mochalov (mochalovandrey@gmail.com)
 */
public class VariantsBeaconAdapterTest {

    private final static String BEACON_FILE = "test_beacon.json";
    private final static AdapterConfig adapterConfig = createConfig();

    private static AdapterConfig createConfig() {
        ClassLoader cl = VariantsBeaconAdapter.class.getClassLoader();
        try {
            String beaconJson = cl.getResource(BEACON_FILE).toURI().getPath();
            List<ConfigValue> values = new ArrayList<>();

            values.add(new ConfigValue("beaconJsonFile", beaconJson));

            return new AdapterConfig("variants_test_beacon", AdapterConfig.class.getCanonicalName(), values);
        } catch (URISyntaxException e) {
            throw new NullPointerException(e.getMessage());
        }
    }

    @Test
    public void testInitAdapter() throws BeaconException {
        BeaconAdapter adapter = new VariantsBeaconAdapter();
        adapter.initAdapter(adapterConfig);
        assertThat(adapter.getBeacon()).isNotNull();
    }

    @Test
    public void testAdapterMustBeInitialized() {
        BeaconAdapter adapter = new VariantsBeaconAdapter();
        assertThatThrownBy(adapter::getBeacon).isInstanceOf(IllegalStateException.class);
        assertThatThrownBy(() -> adapter.getBeaconAlleleResponse(null,
                null,
                null,
                null,
                null,
                null,
                null)).isInstanceOf(IllegalStateException.class);
        assertThatThrownBy(() -> adapter.getBeaconAlleleResponse(null)).isInstanceOf(IllegalStateException.class);
    }

}

@@ -1101,25 +1101,24 @@
 ayList%3C%3E();%0A
-%0A
             
@@ -1128,20 +1128,16 @@
 ues.add(
-new 
 ConfigVa
@@ -1139,16 +1139,31 @@
 figValue
+.builder().name
 (%22beacon
@@ -1171,18 +1171,24 @@
 sonFile%22
-, 
+).value(
 beaconJs
@@ -1190,16 +1190,24 @@
 conJson)
+.build()
 );%0A%0A    
@@ -1221,20 +1221,16 @@
  return 
-new 
 AdapterC
@@ -1234,16 +1234,31 @@
 erConfig
+.builder().name
 (%22varian
@@ -1272,18 +1272,31 @@
 _beacon%22
-, 
+).adapterClass(
 AdapterC
@@ -1329,16 +1329,37 @@
 me()
-, values
+).configValues(values).build(
 );%0A 

Use builder pattern in tests