<commit_before>package com.faforever.integration.factories;

import com.faforever.api.client.ClientType;
import com.faforever.api.client.OAuthClient;
import com.faforever.api.data.domain.Player;
import com.faforever.api.data.domain.User;
import com.faforever.integration.TestDatabase;
import lombok.Data;
import lombok.SneakyThrows;
import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.map.ObjectMapper;
import org.junit.Assert;
import org.springframework.security.authentication.encoding.ShaPasswordEncoder;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.util.Base64Utils;

import static junitx.framework.ComparableAssert.assertEquals;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

public class SessionFactory {

  private static final String OAUTH_CLIENT_ID = "1234";
  private static final String OAUTH_SECRET = "secret";

  private static ObjectMapper objectMapper = new ObjectMapper();
  private static ShaPasswordEncoder shaPasswordEncoder = new ShaPasswordEncoder(256);

  @SneakyThrows
  public static Session createUserAndGetAccessToken(TestDatabase database,
                                                    MockMvc mvc) {
    return createUserAndGetAccessToken("Dragonfire", "foo",
        database, mvc);
  }

  @SneakyThrows
  public static Session createUserAndGetAccessToken(String login,
                                                    String password,
                                                    TestDatabase database,
                                                    MockMvc mvc) {
    OAuthClient client = new OAuthClient()
        .setId(OAUTH_CLIENT_ID)
        .setName("test")
        .setClientSecret(OAUTH_SECRET)
        .setRedirectUris("test")
        .setDefaultRedirectUri("test")
        .setDefaultScope("test")
        .setClientType(ClientType.PUBLIC);
    database.getOAuthClientRepository().save(client);

    long userCounter = database.getUserRepository().count();
    User user = (User) new User()
        .setPassword(shaPasswordEncoder.encodePassword(password, null))
        .setLogin(login)
        .setEmail(login + "@<EMAIL>");
    database.getUserRepository().save(user);
    assertEquals((userCounter + 1), database.getUserRepository().count());

    Player player = database.getPlayerRepository().findOne(user.getId());
    Assert.assertNotNull(player);
<commit_msg>Rename some constants to test like values<commit_after>package com.faforever.integration.factories;

import com.faforever.api.client.ClientType;
import com.faforever.api.client.OAuthClient;
import com.faforever.api.data.domain.Player;
import com.faforever.api.data.domain.User;
import com.faforever.integration.TestDatabase;
import lombok.Data;
import lombok.SneakyThrows;
import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.map.ObjectMapper;
import org.junit.Assert;
import org.springframework.security.authentication.encoding.ShaPasswordEncoder;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.util.Base64Utils;

import static junitx.framework.ComparableAssert.assertEquals;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

public class SessionFactory {

  private static final String OAUTH_CLIENT_ID = "1234";
  private static final String OAUTH_SECRET = "secret";

  private static ObjectMapper objectMapper = new ObjectMapper();
  private static ShaPasswordEncoder shaPasswordEncoder = new ShaPasswordEncoder(256);

  @SneakyThrows
  public static Session createUserAndGetAccessToken(TestDatabase database,
                                                    MockMvc mvc) {
    return createUserAndGetAccessToken("<PASSWORD>", "<PASSWORD>",
        database, mvc);
  }

  @SneakyThrows
  public static Session createUserAndGetAccessToken(String login,
                                                    String password,
                                                    TestDatabase database,
                                                    MockMvc mvc) {
    OAuthClient client = new OAuthClient()
        .setId(OAUTH_CLIENT_ID)
        .setName("test")
        .setClientSecret(OAUTH_SECRET)
        .setRedirectUris("test")
        .setDefaultRedirectUri("test")
        .setDefaultScope("test")
        .setClientType(ClientType.PUBLIC);
    database.getOAuthClientRepository().save(client);

    long userCounter = database.getUserRepository().count();
    User user = (User) new User()
        .setPassword(shaPasswordEncoder.encodePassword(password, null))
        .setLogin(login)
        .setEmail(login + "@example.<EMAIL>");
    database.getUserRepository().save(user);
    assertEquals((userCounter + 1), database.getUserRepository().count());

    Player player = database.getPlayerRepository().findOne(user.getId());
    Assert.assertNotNull(player);

{'fraction_non_alphanumeric': 0.09364742228229388, 'fraction_numerical': 0.003861749372465727, 'mean_word_length': 3.3529411764705883, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3229156', 'n_tokens_mistral': 1373, 'n_tokens_neox': 1352, 'n_words': 254}