<commit_before>/*
 * Copyright (c) 2017.
 * <NAME>
 */

package com.jmelzer.jitty.rest;

import com.jmelzer.jitty.model.dto.TournamentClassDTO;
import com.jmelzer.jitty.model.dto.TournamentPlayerDTO;
import org.junit.Before;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;

import static com.jmelzer.jitty.rest.TestUtil.*;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.greaterThan;
import static org.junit.Assert.*;

/**
 * Created by <NAME> on 19.05.2016.
 * Test player controller
 */
public class PlayerControllerTest extends SecureResourceTest {


    @Before
    public void before() {
        doLogin();
    }

    @Test
    public void testGetList() throws Exception {
        try {

            ResponseEntity<TournamentPlayerDTO[]> entity = http(HttpMethod.GET, "api/players",
                    createHttpEntity(null, loginHeaders), TournamentPlayerDTO[].class);

            assertTrue(entity.getStatusCode().is2xxSuccessful());
            assertThat(entity.getBody()[0].getId(), is(greaterThan(1L)));

        } catch (HttpClientErrorException e) {
            System.out.println(e.getResponseBodyAsString());
            fail();
        }
    }

    @Test
    public void testGetOne() throws Exception {
        try {
            ResponseEntity<TournamentPlayerDTO> entity = http(HttpMethod.GET, "api/players/2",
                    createHttpEntity(null, loginHeaders), TournamentPlayerDTO.class);

            assertTrue(entity.getStatusCode().is2xxSuccessful());
            assertThat(entity.getBody().getId(), is(2L));

        } catch (HttpClientErrorException e) {
            System.out.println(e.getResponseBodyAsString());
            fail();
        }
    }

    @Test
    public void possibleTournaments() throws Exception {
        try {
            TournamentPlayerDTO playerDTO = new TournamentPlayerDTO();
            ResponseEntity<TournamentClassDTO[]> entity = http(HttpMethod.POST, "api/players/possible-tournaments-classes?id=4",
                    createHttpEntity(playerDTO, loginHeaders), TournamentClassDTO[].class);

            assertTrue(entity.getStatusCode().is2xxSuccessful());
            assertThat(entity.getBody().length, is(greaterThan(0)));

        } catch (HttpClientErrorException e) {
            System.out.println(e.getResponseBodyAsString());
            fail();
        }
    }


    @Test
    public void testImport() throws Exception {
        try {

            Long tId = createTournament("player import", 6, 1);
            System.out.println("tId = " + tId);
            //create a class
            TournamentClassDTO tournamentClass = createClz(tId, "Damen/Herren");
            JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
            int count = jdbcTemplate.queryForObject("select count(*) from T_PLAYER where TOURNAMENTS_ID = " + tId, Integer.class);
            assertThat(count, is(0));

            RestTemplate restTemplate = new RestTemplate();
            LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
            map.add("Content-Type", "image/jpeg");
            map.add("file", new ClassPathResource("/Turnierteilnehmer.xml"));
            ResponseEntity<String> entity =
                    restTemplate.exchange("http://localhost:9999/api/players/import-from-click-tt", HttpMethod.POST,
                            createHttpEntity(map, loginHeaders, true), String.class);

            assertTrue(entity.getStatusCode().is2xxSuccessful());
            assertThat(entity.getBody(), is("Es wurden 12 Spieler importiert"));

            count = jdbcTemplate.queryForObject("select count(*) from T_PLAYER where TOURNAMENTS_ID = " + tId, Integer.class);
            assertThat(count, is(12));

//secomnd time. no new player shall be imported
            entity =
                    restTemplate.exchange("http://localhost:9999/api/players/import-from-click-tt", HttpMethod.POST,
                            createHttpEntity(map, loginHeaders, true), String.class);
            assertTrue(entity.getStatusCode().is2xxSuccessful());
            assertThat(entity.getBody(), is("Es wurden 12 Spieler importiert"));

            count = jdbcTemplate.queryForObject("select count(*) from T_PLAYER where TOURNAMENTS_ID = " + tId, Integer.class);
            assertThat(count, is(12));


        } catch (HttpClientErrorException e) {
            System.err.println(e.getResponseBodyAsString());
            fail();
        }
    }
}<commit_msg>minor fixes<commit_after>/*
 * Copyright (c) 2017.
 * <NAME>
 */

package com.jmelzer.jitty.rest;

import com.jmelzer.jitty.model.dto.TournamentClassDTO;
import com.jmelzer.jitty.model.dto.TournamentPlayerDTO;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;

import static com.jmelzer.jitty.rest.TestUtil.*;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.greaterThan;
import static org.junit.Assert.*;

/**
 * Created by <NAME> on 19.05.2016.
 * Test player controller
 */
public class PlayerControllerTest extends SecureResourceTest {


    @Test
    public void testGetList() throws Exception {
        try {

            createTournament("playertest1", 4, 2);
            ResponseEntity<TournamentPlayerDTO[]> entity = http(HttpMethod.GET, "api/players",
                    createHttpEntity(null, loginHeaders), TournamentPlayerDTO[].class);

            assertTrue(entity.getStatusCode().is2xxSuccessful());
            assertThat(entity.getBody().length, is(0));

        } catch (HttpClientErrorException e) {
            System.out.println(e.getResponseBodyAsString());
            fail();
        }
    }

    @Test
    public void testGetOne() throws Exception {
        try {
            ResponseEntity<TournamentPlayerDTO> entity = http(HttpMethod.GET, "api/players/2",
                    createHttpEntity(null, loginHeaders), TournamentPlayerDTO.class);

            assertTrue(entity.getStatusCode().is2xxSuccessful());
            assertThat(entity.getBody().getId(), is(2L));

        } catch (HttpClientErrorException e) {
            System.out.println(e.getResponseBodyAsString());
            fail();
        }
    }

    @Test
    public void possibleTournaments() throws Exception {
        try {
            TournamentPlayerDTO playerDTO = new TournamentPlayerDTO();
            ResponseEntity<TournamentClassDTO[]> entity = http(HttpMethod.POST, "api/players/possible-tournaments-classes?id=4",
                    createHttpEntity(playerDTO, loginHeaders), TournamentClassDTO[].class);

            assertTrue(entity.getStatusCode().is2xxSuccessful());
            assertThat(entity.getBody().length, is(greaterThan(0)));

        } catch (HttpClientErrorException e) {
            System.out.println(e.getResponseBodyAsString());
            fail();
        }
    }


    @Test
    public void testImport() throws Exception {
        try {

            Long tId = createTournament("player import", 6, 1);
            System.out.println("tId = " + tId);
            //create a class
            TournamentClassDTO tournamentClass = createClz(tId, "Damen/Herren");
            JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
            int count = jdbcTemplate.queryForObject("select count(*) from T_PLAYER where TOURNAMENTS_ID = " + tId, Integer.class);
            assertThat(count, is(0));

            RestTemplate restTemplate = new RestTemplate();
            LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
            map.add("Content-Type", "image/jpeg");
            map.add("file", new ClassPathResource("/Turnierteilnehmer.xml"));
            ResponseEntity<String> entity =
                    restTemplate.exchange("http://localhost:9999/api/players/import-from-click-tt", HttpMethod.POST,
                            createHttpEntity(map, loginHeaders, true), String.class);

            assertTrue(entity.getStatusCode().is2xxSuccessful());
            assertThat(entity.getBody(), is("Es wurden 12 Spieler importiert"));

            count = jdbcTemplate.queryForObject("select count(*) from T_PLAYER where TOURNAMENTS_ID = " + tId, Integer.class);
            assertThat(count, is(12));

//secomnd time. no new player shall be imported
            entity =
                    restTemplate.exchange("http://localhost:9999/api/players/import-from-click-tt", HttpMethod.POST,
                            createHttpEntity(map, loginHeaders, true), String.class);
            assertTrue(entity.getStatusCode().is2xxSuccessful());
            assertThat(entity.getBody(), is("Es wurden 12 Spieler importiert"));

            count = jdbcTemplate.queryForObject("select count(*) from T_PLAYER where TOURNAMENTS_ID = " + tId, Integer.class);
            assertThat(count, is(12));


        } catch (HttpClientErrorException e) {
            System.err.println(e.getResponseBodyAsString());
            fail();
        }
    }
}
{'fraction_non_alphanumeric': 0.11538061022597106, 'fraction_numerical': 0.008955534728730605, 'mean_word_length': 2.7915515199368337, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '533054', 'n_tokens_mistral': 2671, 'n_tokens_neox': 2591, 'n_words': 487}