<commit_before>/* 
 * Copyright (C) 2016 <NAME>
 * All rights reserved.
 *
 * This software may be modified and distributed under the terms
 * of the BSD license.  See the LICENSE file for details.
 */
package com.bouye.gw2.sab.query;

import api.web.gw2.mapping.core.APILevel;
import api.web.gw2.mapping.core.CoinAmount;
import api.web.gw2.mapping.core.EnumValueFactory;
import api.web.gw2.mapping.v2.account.Account;
import api.web.gw2.mapping.v2.characters.Character;
import api.web.gw2.mapping.v2.account.AccountAccessType;
import api.web.gw2.mapping.v2.characters.CharacterProfession;
import api.web.gw2.mapping.v2.items.Item;
import api.web.gw2.mapping.v2.items.ItemRarity;
import api.web.gw2.mapping.v2.items.ItemType;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.time.ZonedDateTime;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Test;
import org.junit.Before;
import org.junit.BeforeClass;
import static org.hamcrest.CoreMatchers.is;

/**
 * API automated tests.
 * @author <NAME>
 */
public class APITest {

    public APITest() {
    }

    private static final Properties SETTINGS = new Properties();

    @BeforeClass
    public static void setUpClass() throws IOException {
        final File file = new File("settings.properties"); // NOI18N.
        assertTrue(file.exists());
        assertTrue(file.canRead());
        try (final InputStream input = new FileInputStream(file)) {
            SETTINGS.load(input);
        }
        assertNotNull(SETTINGS.getProperty("app.key")); // NOI18N.
    }

    @AfterClass
    public static void tearDownClass() {
    }

    @Before
    public void setUp() {
    }

    @After
    public void tearDown() {
    }

    @Test
    public void testAccount() {
        System.out.println("testAccount");
        final String expId = SETTINGS.getProperty("account.id"); // NOI18N.
        final String expName = SETTINGS.getProperty("account.name"); // NOI18N.
        final ZonedDateTime expCreated = ZonedDateTime.parse(SETTINGS.getProperty("account.created")); // NOI18N.
        final int expWorld = Integer.parseInt(SETTINGS.getProperty("account.world")); // NOI18N.
        final AccountAccessType expAccess = EnumValueFactory.INSTANCE.mapEnumValue(AccountAccessType.class, SETTINGS.getProperty("account.access")); // NOI18N.
        final boolean expCommander = Boolean.parseBoolean(SETTINGS.getProperty("account.commander")); // NOI18N.
        final int expFractal = Integer.parseInt(SETTINGS.getProperty("account.fractal_level")); // NOI18N.
        assertNotNull(expId);
        assertNotNull(expName);
        //
        final Optional<Account> value = GW2APIClient.create()
                .applicationKey(SETTINGS.getProperty("app.key")) // NOI18N.
                .apiLevel(APILevel.V2)
                .endPoint("account") // NOI18N.
                .queryObject(Account.class);
        assertTrue(value.isPresent());
        assertEquals(expId, value.get().getId());
        assertEquals(expName, value.get().getName());
        assertEquals(expCreated, value.get().getCreated());
        assertEquals(expWorld, value.get().getWorld());
        assertEquals(expAccess, value.get().getAccess());
        assertEquals(expCommander, value.get().isCommander());
        assertEquals(expFractal, value.get().getFractalLevel());
    }

    @Test
    public void testCharacters() {
        System.out.println("testCharacters");
        final List<String> expNames = Arrays.asList(SETTINGS.getProperty("characters.names").split(",")); // NOI18N.
        //
        final List<String> value = GW2APIClient.create()
                .applicationKey(SETTINGS.getProperty("app.key")) // NOI18N.
                .apiLevel(APILevel.V2)
                .endPoint("characters") // NOI18N.
                .queryArray(String.class);
        // Order is not important.
        assertThat(new HashSet<>(value), is(new HashSet<>(expNames)));
    }

    @Test
    public void testCharacter() {
        System.out.println("testCharacter");
        final String expName = SETTINGS.getProperty("character.name"); // NOI18N.
        final int expLevel = Integer.parseInt(SETTINGS.getProperty("character.level")); // NOI18N.
        final CharacterProfession expProfession = EnumValueFactory.INSTANCE.mapEnumValue(CharacterProfession.class, SETTINGS.getProperty("character.profession")); // NOI18N.
        assertNotNull(expName);
        //
        final String id = SETTINGS.getProperty("character.name"); // NOI18N.
        final Optional<Character> value = GW2APIClient.create()
                .applicationKey(SETTINGS.getProperty("app.key")) // NOI18N.
                .apiLevel(APILevel.V2)
                .endPoint("characters") // NOI18N.
                .id(id)
                .queryObject(Character.class);
        assertTrue(value.isPresent());
        assertEquals(expName, value.get().getName());
        assertEquals(expLevel, value.get().getLevel());
        assertEquals(expProfession, value.get().getProfession());
    }

    @Test
    public void testItem() {
        System.out.println("testItem");
        final int expId = Integer.parseInt(SETTINGS.getProperty("item.id")); // NOI18N.
        final String expName = SETTINGS.getProperty("item.name"); // NOI18N.
        final ItemType expType = EnumValueFactory.INSTANCE.mapEnumValue(ItemType.class, SETTINGS.getProperty("item.type")); // NOI18N.
        final int expLevel = Integer.parseInt(SETTINGS.getProperty("item.level")); // NOI18N.
        final ItemRarity expRarity = EnumValueFactory.INSTANCE.mapEnumValue(ItemRarity.class, SETTINGS.getProperty("item.rarity")); // NOI18N.\
        final CoinAmount expVendorValue = CoinAmount.ofCopper(Integer.parseInt(SETTINGS.getProperty("item.vendor_value"))); // NOI18N.)
        final OptionalInt expDefaultSkin = OptionalInt.of(Integer.parseInt(SETTINGS.getProperty("item.default_skin"))); // NOI18N.
        assertNotNull(expName);
        //
        final String id = SETTINGS.getProperty("item.id"); // NOI18N.
        final String lang = SETTINGS.getProperty("lang"); // NOI18N.
        final Optional<Item> value = GW2APIClient.create()
                .apiLevel(APILevel.V2)
                .endPoint("items") // NOI18N.
                .language(lang)
                .id(id)
                .queryObject(Item.class);
        assertTrue(value.isPresent());
        assertEquals(expId, value.get().getId());
        assertEquals(expName, value.get().getName());
        assertEquals(expType, value.get().getType());
        assertEquals(expLevel, value.get().getLevel());
        assertEquals(expRarity, value.get().getRarity());
        assertEquals(expVendorValue, value.get().getVendorValue());
        assertEquals(expDefaultSkin, value.get().getDefaultSkin());
    }
}
<commit_msg>Expanded test to run on multiple objects.<commit_after>/* 
 * Copyright (C) 2016 <NAME>
 * All rights reserved.
 *
 * This software may be modified and distributed under the terms
 * of the BSD license.  See the LICENSE file for details.
 */
package com.bouye.gw2.sab.query;

import api.web.gw2.mapping.core.APILevel;
import api.web.gw2.mapping.core.CoinAmount;
import api.web.gw2.mapping.core.EnumValueFactory;
import api.web.gw2.mapping.v2.account.Account;
import api.web.gw2.mapping.v2.characters.Character;
import api.web.gw2.mapping.v2.account.AccountAccessType;
import api.web.gw2.mapping.v2.characters.CharacterProfession;
import api.web.gw2.mapping.v2.items.Item;
import api.web.gw2.mapping.v2.items.ItemRarity;
import api.web.gw2.mapping.v2.items.ItemType;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.time.ZonedDateTime;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.Properties;
import java.util.function.Function;
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Test;
import org.junit.Before;
import org.junit.BeforeClass;
import static org.hamcrest.CoreMatchers.is;

/**
 * API automated tests.
 * @author <NAME>
 */
public class APITest {

    public APITest() {
    }

    private static final Properties SETTINGS = new Properties();

    @BeforeClass
    public static void setUpClass() throws IOException {
        final File file = new File("settings.properties"); // NOI18N.
        assertTrue(file.exists());
        assertTrue(file.canRead());
        try (final InputStream input = new FileInputStream(file)) {
            SETTINGS.load(input);
        }
        assertNotNull(SETTINGS.getProperty("app.key")); // NOI18N.
    }

    @AfterClass
    public static void tearDownClass() {
    }

    @Before
    public void setUp() {
    }

    @After
    public void tearDown() {
    }

    @Test
    public void testAccount() {
        System.out.println("testAccount");
        final String expId = SETTINGS.getProperty("account.id"); // NOI18N.
        final String expName = SETTINGS.getProperty("account.name"); // NOI18N.
        final ZonedDateTime expCreated = ZonedDateTime.parse(SETTINGS.getProperty("account.created")); // NOI18N.
        final int expWorld = Integer.parseInt(SETTINGS.getProperty("account.world")); // NOI18N.
        final AccountAccessType expAccess = EnumValueFactory.INSTANCE.mapEnumValue(AccountAccessType.class, SETTINGS.getProperty("account.access")); // NOI18N.
        final boolean expCommander = Boolean.parseBoolean(SETTINGS.getProperty("account.commander")); // NOI18N.
        final int expFractal = Integer.parseInt(SETTINGS.getProperty("account.fractal_level")); // NOI18N.
        assertNotNull(expId);
        assertNotNull(expName);
        //
        final Optional<Account> value = GW2APIClient.create()
                .applicationKey(SETTINGS.getProperty("app.key")) // NOI18N.
                .apiLevel(APILevel.V2)
                .endPoint("account") // NOI18N.
                .queryObject(Account.class);
        assertTrue(value.isPresent());
        assertEquals(expId, value.get().getId());
        assertEquals(expName, value.get().getName());
        assertEquals(expCreated, value.get().getCreated());
        assertEquals(expWorld, value.get().getWorld());
        assertEquals(expAccess, value.get().getAccess());
        assertEquals(expCommander, value.get().isCommander());
        assertEquals(expFractal, value.get().getFractalLevel());
    }

    @Test
    public void testCharacters() {
        System.out.println("testCharacters");
        final List<String> expNames = Arrays.asList(SETTINGS.getProperty("characters.names").split(",")); // NOI18N.
        //
        final List<String> value = GW2APIClient.create()
                .applicationKey(SETTINGS.getProperty("app.key")) // NOI18N.
                .apiLevel(APILevel.V2)
                .endPoint("characters") // NOI18N.
                .queryArray(String.class);
        // Order is not important.
        assertThat(new HashSet<>(value), is(new HashSet<>(expNames)));
    }

    @Test
    public void testCharacter() {
        System.out.println("testCharacter");
        final String expName = SETTINGS.getProperty("character.name"); // NOI18N.
        final int expLevel = Integer.parseInt(SETTINGS.getProperty("character.level")); // NOI18N.
        final CharacterProfession expProfession = EnumValueFactory.INSTANCE.mapEnumValue(CharacterProfession.class, SETTINGS.getProperty("character.profession")); // NOI18N.
        assertNotNull(expName);
        //
        final String id = SETTINGS.getProperty("character.name"); // NOI18N.
        final Optional<Character> value = GW2APIClient.create()
                .applicationKey(SETTINGS.getProperty("app.key")) // NOI18N.
                .apiLevel(APILevel.V2)
                .endPoint("characters") // NOI18N.
                .id(id)
                .queryObject(Character.class);
        assertTrue(value.isPresent());
        assertEquals(expName, value.get().getName());
        assertEquals(expLevel, value.get().getLevel());
        assertEquals(expProfession, value.get().getProfession());
    }

    @Test
    public void testItems() {
        System.out.println("testItems"); // NOI18N.
        final int[] ids = Arrays.stream(SETTINGS.getProperty("items.ids").split(",")) // NOI18N.
                .mapToInt(Integer::parseInt)
                .toArray();
        Arrays.stream(ids)
                .forEach(this::testItem);
    }

    private void testItem(final int idToTest) {
        System.out.printf("testItem(%d)%n", idToTest); // NOI18N.
        final String prefix = String.format("item.%d.", idToTest); // NOI18N.
        final int expId = Integer.parseInt(SETTINGS.getProperty(prefix + "id")); // NOI18N.
        final String expName = SETTINGS.getProperty(prefix + "name"); // NOI18N.
        final Optional<String> expDescription = getOptional(prefix + "description", value -> value); // NOI18N.
        final ItemType expType = EnumValueFactory.INSTANCE.mapEnumValue(ItemType.class, SETTINGS.getProperty(prefix + "type")); // NOI18N.
        final int expLevel = Integer.parseInt(SETTINGS.getProperty(prefix + "level")); // NOI18N.
        final ItemRarity expRarity = EnumValueFactory.INSTANCE.mapEnumValue(ItemRarity.class, SETTINGS.getProperty(prefix + "rarity")); // NOI18N.\
        final CoinAmount expVendorValue = CoinAmount.ofCopper(Integer.parseInt(SETTINGS.getProperty(prefix + "vendor_value"))); // NOI18N.)
        final OptionalInt expDefaultSkin = getOptionalInt(prefix + "default_skin"); // NOI18N.
        assertNotNull(expName);
        //
        final String lang = SETTINGS.getProperty("lang"); // NOI18N.
        final Optional<Item> value = GW2APIClient.create()
                .apiLevel(APILevel.V2)
                .endPoint("items") // NOI18N.
                .language(lang)
                .id(idToTest)
                .queryObject(Item.class);
        assertTrue(value.isPresent());
        assertEquals(expId, value.get().getId());
        assertEquals(expName, value.get().getName());
        assertEquals(expDescription, value.get().getDescription());
        assertEquals(expType, value.get().getType());
        assertEquals(expLevel, value.get().getLevel());
        assertEquals(expRarity, value.get().getRarity());
        assertEquals(expVendorValue, value.get().getVendorValue());
        assertEquals(expDefaultSkin, value.get().getDefaultSkin());
    }
    private <T> Optional<T> getOptional(final String property, Function<String, T> converter) {
        final String value = SETTINGS.getProperty(property);
        return (value == null) ? Optional.empty() : Optional.of(converter.apply(value));
    }

    private OptionalInt getOptionalInt(final String property) {
        final String value = SETTINGS.getProperty(property);
        return (value == null) ? OptionalInt.empty() : OptionalInt.of(Integer.parseInt(value));
    }

}

{'fraction_non_alphanumeric': 0.13360881542699724, 'fraction_numerical': 0.012331103240194149, 'mean_word_length': 2.986143790849673, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 26, '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': '7052584', 'n_tokens_mistral': 4502, 'n_tokens_neox': 4500, 'n_words': 801}