<commit_before>package teams.voot;

import io.restassured.response.ValidatableResponse;
import io.restassured.specification.RequestSpecification;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Value;
import teams.AbstractApplicationTest;

import java.util.Optional;

import static io.restassured.RestAssured.given;
import static org.apache.http.HttpStatus.SC_NOT_FOUND;
import static org.apache.http.HttpStatus.SC_OK;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItems;

public class VootApiControllerTest extends AbstractApplicationTest {

    private String contextPath = "/api/voot/";

    @Value("${security.user.name}")
    protected String user;

    @Value("${security.user.password}")
    protected String password;

    @Test
    public void findByLocalGroupId() throws Exception {
        start("group/demo:openconext:org:giants")
                .body("displayName", equalTo("giants"));
    }

    @Test
    public void findByLocalGroupIdNonExistent() throws Exception {
        start("group/demo:openconext:org:nope", SC_NOT_FOUND);
    }

    @Test
    public void linkedLocalTeamsGroup() throws Exception {
        String[] params = {"externalGroupIds", "urn:collab:group:example.org:name1,urn:collab:group:example.org:name2"};
        start("linked-locals", Optional.of(params), SC_OK)
                .body("size()", equalTo(2))
                .body("displayName", hasItems("riders", "giants"));
    }

    @Test
    public void linkedExternalGroupIds() throws Exception {
        String[] params = {"teamId", "demo:openconext:org:riders"};
        start("linked-externals", Optional.of(params), SC_OK)
                .body("size()", equalTo(2))
                .body("", hasItems("urn:collab:group:example.org:name1", "urn:collab:group:example.org:name2"));
    }

    @Test
    public void getMembers() throws Exception {
        start("members/demo:openconext:org:giants")
                .body("size()", equalTo(4))
                .body("name", hasItems("<NAME>", "<NAME>", "<NAME>", "<NAME>"));
    }

    @Test
    public void getAllGroups() throws Exception {
        start("groups")
                .body("size()", equalTo(5))
                .body("displayName", hasItems("riders", "giants", "gliders", "masters", "wolves"));
    }

    @Test
    public void getGroupsForMember() throws Exception {
        start("user/urn:collab:person:surfnet.nl:tdoe/groups")
                .body("size()", equalTo(2))
                .body("displayName", hasItems("giants", "gliders"))
                .body("membership", hasItems("admin", "member"));
    }

    @Test
    public void getGroupsForMemberAndTeamUrn() throws Exception {
        start("user/urn:collab:person:surfnet.nl:tdoe/groups/demo:openconext:org:gliders")
                //four properties, not elements
                .body("size()", equalTo(4))
                .body("displayName", equalTo("gliders"))
                .body("membership", equalTo("admin"));
    }

    @Test
    public void getGroupsForMemberAndTeamUrnNotExists() throws Exception {
        start("user/urn:collab:person:surfnet.nl:nope/groups/demo:openconext:org:nope", SC_NOT_FOUND);
    }

    private ValidatableResponse start(String path) {
        return start(path, Optional.empty(), SC_OK);
    }

    private ValidatableResponse start(String path, int statusCode) {
        return start(path, Optional.empty(), statusCode);
    }

    private ValidatableResponse start(String path, Optional<String[]> paramsOptional, int statusCode) {
        RequestSpecification specification = given()<commit_msg>Fixex tests after upgrading manager to admin voor VOOT roles<commit_after>package teams.voot;

import io.restassured.response.ValidatableResponse;
import io.restassured.specification.RequestSpecification;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Value;
import teams.AbstractApplicationTest;

import java.util.Optional;

import static io.restassured.RestAssured.given;
import static org.apache.http.HttpStatus.SC_NOT_FOUND;
import static org.apache.http.HttpStatus.SC_OK;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItems;

public class VootApiControllerTest extends AbstractApplicationTest {

    private String contextPath = "/api/voot/";

    @Value("${security.user.name}")
    protected String user;

    @Value("${security.user.password}")
    protected String password;

    @Test
    public void findByLocalGroupId() throws Exception {
        start("group/demo:openconext:org:giants")
                .body("displayName", equalTo("giants"));
    }

    @Test
    public void findByLocalGroupIdNonExistent() throws Exception {
        start("group/demo:openconext:org:nope", SC_NOT_FOUND);
    }

    @Test
    public void linkedLocalTeamsGroup() throws Exception {
        String[] params = {"externalGroupIds", "urn:collab:group:example.org:name1,urn:collab:group:example.org:name2"};
        start("linked-locals", Optional.of(params), SC_OK)
                .body("size()", equalTo(2))
                .body("displayName", hasItems("riders", "giants"));
    }

    @Test
    public void linkedExternalGroupIds() throws Exception {
        String[] params = {"teamId", "demo:openconext:org:riders"};
        start("linked-externals", Optional.of(params), SC_OK)
                .body("size()", equalTo(2))
                .body("", hasItems("urn:collab:group:example.org:name1", "urn:collab:group:example.org:name2"));
    }

    @Test
    public void getMembers() throws Exception {
        start("members/demo:openconext:org:giants")
                .body("size()", equalTo(4))
                .body("name", hasItems("<NAME>", "<NAME>", "<NAME>", "<NAME>"));
    }

    @Test
    public void getAllGroups() throws Exception {
        start("groups")
                .body("size()", equalTo(5))
                .body("displayName", hasItems("riders", "giants", "gliders", "masters", "wolves"));
    }

    @Test
    public void getGroupsForMember() throws Exception {
        start("user/urn:collab:person:surfnet.nl:tdoe/groups")
                .body("size()", equalTo(2))
                .body("displayName", hasItems("giants", "gliders"))
                .body("membership", hasItems("admin", "admin"));
    }

    @Test
    public void getGroupsForMemberAndTeamUrn() throws Exception {
        start("user/urn:collab:person:surfnet.nl:tdoe/groups/demo:openconext:org:gliders")
                //four properties, not elements
                .body("size()", equalTo(4))
                .body("displayName", equalTo("gliders"))
                .body("membership", equalTo("admin"));
    }

    @Test
    public void getGroupsForMemberAndTeamUrnNotExists() throws Exception {
        start("user/urn:collab:person:surfnet.nl:nope/groups/demo:openconext:org:nope", SC_NOT_FOUND);
    }

    private ValidatableResponse start(String path) {
        return start(path, Optional.empty(), SC_OK);
    }

    private ValidatableResponse start(String path, int statusCode) {
        return start(path, Optional.empty(), statusCode);
    }

    private ValidatableResponse start(String path, Optional<String[]> paramsOptional, int statusCode) {
        RequestSpecification specification = given()
{'fraction_non_alphanumeric': 0.13714754995893785, 'fraction_numerical': 0.002737476047084588, 'mean_word_length': 3.3185579196217496, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '7589559', 'n_tokens_mistral': 2175, 'n_tokens_neox': 2111, 'n_words': 402}