<commit_before>package com.kloudless;

import com.fasterxml.jackson.databind.JsonNode;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.kloudless.exception.KloudlessException;
import com.kloudless.model.*;
import com.kloudless.net.KloudlessResponse;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;

import java.io.IOException;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static com.kloudless.StaticImporter.TestInfo;
import static org.assertj.core.api.Assertions.assertThat;

public class KloudlessTest extends KloudlessBaseTest {

	static Gson GSON = new GsonBuilder().create();
	static List<String> testAccounts;

	@BeforeClass
	public static void setUp() {
		Kloudless.apiKey = TestInfo.getApiKey();
		testAccounts = TestInfo.getTestAccounts();
		Kloudless.overrideApiBase(TestInfo.getApiBasedUrl());

		// Insert Custom Headers
		HashMap<String, String> customHeaders = new HashMap<String, String>();

		// USER IMPERSONATION
    // customHeaders.put("X-Kloudless-As-User", "INSERT USER ID HERE");
		Kloudless.addCustomHeaders(customHeaders);
	}

	// Begin Account Tests
	@Test
	public void testAccountAll() throws KloudlessException {
		AccountCollection accounts = Account.all(null);
		List<Account> list = accounts.objects.stream().filter(x -> testAccounts
        .contains(x.id)).collect(Collectors.toList());
		assertThat(list.size()).isGreaterThan(0);
	}

	@Test
	public void testAccountRetrieve() throws KloudlessException {
		for (String testAccount : testAccounts) {
			Account account = Account.retrieve(testAccount, null);
			String jsonTree = TestInfo.getOneTestAccountJson();
      try {
        JsonNode root = mapper.readTree(jsonTree);
        int id = root.at("/id").asInt();
        assertThat(Integer.parseInt(account.id)).isEqualTo(id);
        String acnt = root.at("/account").asText();
        assertThat(account.account).isEqualTo(acnt);
        String service = root.at("/service").asText();
        assertThat(account.service).isEqualTo(service);
      } catch (IOException e) {
        e.printStackTrace();
      }
		}
	}

	@Test
	public void testAccountSearch() throws KloudlessException {
	  final String folderName = "new test fold\u00e9r";

		for (String testAccount : testAccounts) {
		  createTestFolder(folderName, getRootFolderId(testAccount), testAccount);
      try {
        Thread.sleep(2000);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }

      Map<String, Object> params = new HashMap<>();
      params.put("q", folderName);
			MetadataCollection results = Account.search(testAccount, params);<commit_msg>Fix partialy Dev-542 of newer binary upload format<commit_after>package com.kloudless;

import com.fasterxml.jackson.databind.JsonNode;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.kloudless.exception.KloudlessException;
import com.kloudless.model.*;
import com.kloudless.net.KloudlessResponse;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;

import java.io.IOException;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static com.kloudless.StaticImporter.TestInfo;
import static org.assertj.core.api.Assertions.assertThat;

public class KloudlessTest extends KloudlessBaseTest {

	static Gson GSON = new GsonBuilder().create();
	static List<String> testAccounts;

	@BeforeClass
	public static void setUp() {
		Kloudless.apiKey = TestInfo.getApiKey();
		testAccounts = TestInfo.getTestAccounts();
		Kloudless.overrideApiBase(TestInfo.getApiBasedUrl());

		// Insert Custom Headers
		HashMap<String, String> customHeaders = new HashMap<String, String>();

		// USER IMPERSONATION
    // customHeaders.put("X-Kloudless-As-User", "INSERT USER ID HERE");
		Kloudless.addCustomHeaders(customHeaders);
	}

	// Begin Account Tests
	@Test
	public void testAccountAll() throws KloudlessException {
		AccountCollection accounts = Account.all(null);
		List<Account> list = accounts.objects.stream().filter(x -> testAccounts
        .contains(x.id)).collect(Collectors.toList());
		assertThat(list.size()).isGreaterThan(0);
	}

	@Test
	public void testAccountRetrieve() throws KloudlessException {
		for (String testAccount : testAccounts) {
			Account account = Account.retrieve(testAccount, null);
			String jsonTree = TestInfo.getOneTestAccountJson();
      try {
        JsonNode root = mapper.readTree(jsonTree);
        int id = root.at("/id").asInt();
        assertThat(Integer.parseInt(account.id)).isEqualTo(id);
        String acnt = root.at("/account").asText();
        assertThat(account.account).isEqualTo(acnt);
        String service = root.at("/service").asText();
        assertThat(account.service).isEqualTo(service);
      } catch (IOException e) {
        e.printStackTrace();
      }
		}
	}

	@Test
	public void testAccountSearch() throws KloudlessException {
	  final String folderName = "new test fold\u00e9r";
		for (String testAccount : testAccounts) {
		  createTestFolder(folderName, getRootFolderId(testAccount), testAccount);
      try {
        Thread.sleep(2000);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }

      Map<String, Object> params = new HashMap<>();
      params.put("q", folderName);
			MetadataCollection results = Account.search(testAccount, params);
{'fraction_non_alphanumeric': 0.1195139644541168, 'fraction_numerical': 0.0034457743924555676, 'mean_word_length': 4.252380952380952, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '1207598', 'n_tokens_mistral': 1728, 'n_tokens_neox': 1650, 'n_words': 344}