package org.coner.it;

import org.coner.api.request.AddCompetitionGroupRequest;
import org.coner.util.TestConstants;
import org.coner.util.UnitTestUtils;
import org.eclipse.jetty.http.HttpStatus;
import org.junit.Test;

import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.net.URI;

import static org.assertj.core.api.Assertions.assertThat;

/**
 *
 */
public class CompetitionGroupIntegrationTest extends AbstractIntegrationTest {

    @Test
    public void whenCreateCompetitionGroupItShouldPersist() {
        URI competitionGroupsUri = IntegrationTestUtils.jerseyUriBuilderForApp(RULE)
                .path("/competitionGroups")
                .build();


        AddCompetitionGroupRequest addCompetitionGroupRequest = new AddCompetitionGroupRequest();
        addCompetitionGroupRequest.setName(TestConstants.COMPETITION_GROUP_NAME);
        addCompetitionGroupRequest.setHandicapFactor(TestConstants.COMPETITION_GROUP_HANDICAP_FACTOR);
        addCompetitionGroupRequest.setResultTimeType(TestConstants.COMPETITION_GROUP_RESULT_TIME_TYPE.name());
        addCompetitionGroupRequest.setGrouping(TestConstants.COMPETITION_GROUP_GROUPING);

        Response addCompetitionGroupResponseContainer = client.target(competitionGroupsUri)
                .request(MediaType.APPLICATION_JSON_TYPE)
                .accept(MediaType.APPLICATION_JSON_TYPE)
                .post(Entity.json(addCompetitionGroupRequest));

        assertThat(addCompetitionGroupResponseContainer.getStatus())
                .isEqualTo(HttpStatus.CREATED_201);
        String competitionGroupId = UnitTestUtils.getEntityIdFromResponse(addCompetitionGroupResponseContainer);
        assertThat(competitionGroupId).isNotNull();
    }

}

@@ -73,16 +73,62 @@
 equest;%0A
+import org.coner.api.response.ErrorsResponse;%0A
 import o
@@ -156,16 +156,16 @@
 stants;%0A
-
 import o
@@ -534,16 +534,96 @@
 Test %7B%0A%0A
+    private static final String COMPETITION_GROUP_PATH = %22/competitionGroups%22;%0A%0A
     @Tes
@@ -793,36 +793,38 @@
   .path(
-%22/competitionGroups%22
+COMPETITION_GROUP_PATH
 )%0A      
@@ -1836,16 +1836,16 @@
 ainer);%0A
-
         
@@ -1895,10 +1895,909 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void whenCreateInvalidHandicapGroupItShouldReject() %7B%0A        URI competitionGroupsUri = IntegrationTestUtils.jerseyUriBuilderForApp(RULE)%0A                .path(COMPETITION_GROUP_PATH)%0A                .build();%0A        AddCompetitionGroupRequest addCompetitionGroupRequest = new AddCompetitionGroupRequest();%0A%0A        Response addCompetitionGroupResponseContainer = client.target(competitionGroupsUri)%0A                .request(MediaType.APPLICATION_JSON_TYPE)%0A                .accept(MediaType.APPLICATION_JSON_TYPE)%0A                .post(Entity.json(addCompetitionGroupRequest));%0A%0A        assertThat(addCompetitionGroupResponseContainer.getStatus()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY_422);%0A        ErrorsResponse errorsResponse = addCompetitionGroupResponseContainer.readEntity(ErrorsResponse.class);%0A        assertThat(errorsResponse.getErrors()).isNotEmpty();%0A    %7D%0A%0A
 %7D%0A

Bring CompetitionGroup IT to coverage parity with HandicapGroup IT