Skip to content

Commit

Permalink
Added api prefix (#23)
Browse files Browse the repository at this point in the history
Added api prefix, moved API controllers to api package, fixed coverage configuration.
  • Loading branch information
samokisha authored and malikin committed Sep 13, 2019
1 parent 89db368 commit aa9314c
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 39 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

<!-- Code Coverage -->
<jacoco-maven-plugin.version>0.8.4</jacoco-maven-plugin.version>
<jacoco-maven-plugin.lines-coverage-ratio>0.8</jacoco-maven-plugin.lines-coverage-ratio>
<jacoco-maven-plugin.methods-coverage-ratio>0.8</jacoco-maven-plugin.methods-coverage-ratio>
<jacoco-maven-plugin.lines-coverage-ratio>80%</jacoco-maven-plugin.lines-coverage-ratio>
<jacoco-maven-plugin.methods-coverage-ratio>80%</jacoco-maven-plugin.methods-coverage-ratio>

<!-- Frontend -->
<frontend-maven-plugin.version>1.8.0</frontend-maven-plugin.version>
Expand Down Expand Up @@ -228,7 +228,7 @@
<configuration>
<rules>
<rule>
<element>PACKAGE</element>
<element>BUNDLE</element>
<limits>
<limit>
<counter>LINE</counter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ public Docket fullApi() {
}

private Predicate<RequestHandler> baseControllersPackage() {
return RequestHandlerSelectors.basePackage("io.hexlet.hexletcorrection.controller");
return RequestHandlerSelectors.basePackage("io.hexlet.hexletcorrection.controller.api");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

public class ControllerConstants {

final static String TEST_HOST = "http://localhost";
public final static String TEST_HOST = "http://localhost";

final static String CORRECTIONS_PATH = "/corrections";
public final static String API_PATH_V1 = "/api/v1";

final static String ACCOUNTS_PATH = "/accounts";
public final static String CORRECTIONS_PATH = "/corrections";

public final static String ACCOUNTS_PATH = "/accounts";
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.hexlet.hexletcorrection.controller;
package io.hexlet.hexletcorrection.controller.api.v1;

import io.hexlet.hexletcorrection.controller.exception.AccountNotFoundException;
import io.hexlet.hexletcorrection.domain.Account;
Expand All @@ -19,9 +19,10 @@
import java.util.List;

import static io.hexlet.hexletcorrection.controller.ControllerConstants.ACCOUNTS_PATH;
import static io.hexlet.hexletcorrection.controller.ControllerConstants.API_PATH_V1;

@RestController
@RequestMapping(ACCOUNTS_PATH)
@RequestMapping(API_PATH_V1 + ACCOUNTS_PATH)
@AllArgsConstructor
public class AccountController {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.hexlet.hexletcorrection.controller;
package io.hexlet.hexletcorrection.controller.api.v1;

import io.hexlet.hexletcorrection.controller.exception.CorrectionNotFoundException;
import io.hexlet.hexletcorrection.domain.Correction;
Expand All @@ -18,10 +18,11 @@
import javax.validation.Valid;
import java.util.List;

import static io.hexlet.hexletcorrection.controller.ControllerConstants.API_PATH_V1;
import static io.hexlet.hexletcorrection.controller.ControllerConstants.CORRECTIONS_PATH;

@RestController
@RequestMapping(CORRECTIONS_PATH)
@RequestMapping(API_PATH_V1 + CORRECTIONS_PATH)
@RequiredArgsConstructor
public class CorrectionController {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.hexlet.hexletcorrection.controller;
package io.hexlet.hexletcorrection.controller.api.v1;

import io.hexlet.hexletcorrection.domain.Account;
import io.hexlet.hexletcorrection.service.AccountService;
Expand All @@ -11,8 +11,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.test.context.junit4.SpringRunner;

import static io.hexlet.hexletcorrection.controller.ControllerConstants.TEST_HOST;
import static io.hexlet.hexletcorrection.controller.ControllerConstants.ACCOUNTS_PATH;
import static io.hexlet.hexletcorrection.controller.ControllerConstants.*;
import static io.hexlet.hexletcorrection.domain.EntityConstrainConstants.INVALID_EMAIL;
import static io.hexlet.hexletcorrection.domain.EntityConstrainConstants.MAX_ACCOUNT_NAME;
import static io.hexlet.hexletcorrection.domain.EntityConstrainConstants.NOT_EMPTY;
Expand All @@ -32,7 +31,7 @@ public class AccountControllerTest {
@Test
public void getAllAccountsTest() {
given().when()
.get(TEST_HOST + ":" + port + ACCOUNTS_PATH)
.get(TEST_HOST + ":" + port + API_PATH_V1 + ACCOUNTS_PATH)
.then()
.statusCode(HttpStatus.OK.value())
.contentType(ContentType.JSON);
Expand All @@ -43,7 +42,7 @@ public void getAccountByIdTest() {
Account account = createAccount();

given().when()
.get(TEST_HOST + ":" + port + ACCOUNTS_PATH + "/" + account.getId())
.get(TEST_HOST + ":" + port + API_PATH_V1 + ACCOUNTS_PATH + "/" + account.getId())
.then()
.statusCode(HttpStatus.OK.value())
.contentType(ContentType.JSON);
Expand All @@ -54,7 +53,7 @@ public void getAccountByFalseIdTest() {
long falseId = createAccount().getId() + 1L;

given().when()
.get(TEST_HOST + ":" + port + ACCOUNTS_PATH + "/" + falseId)
.get(TEST_HOST + ":" + port + API_PATH_V1 + ACCOUNTS_PATH + "/" + falseId)
.then()
.statusCode(HttpStatus.NOT_FOUND.value())
.contentType(ContentType.JSON)
Expand All @@ -64,7 +63,7 @@ public void getAccountByFalseIdTest() {
@Test
public void getAccountByNameTest() {
given().when()
.get(TEST_HOST + ":" + port + ACCOUNTS_PATH + "/?name=" + createAccount().getName())
.get(TEST_HOST + ":" + port + API_PATH_V1 + ACCOUNTS_PATH + "/?name=" + createAccount().getName())
.then()
.statusCode(HttpStatus.OK.value())
.contentType(ContentType.JSON);
Expand All @@ -75,7 +74,7 @@ public void getAccountByFalseNameTest() {
String falseName = createAccount().getName() + "A";

given().when()
.get(TEST_HOST + ":" + port + ACCOUNTS_PATH + "/?name=" + falseName)
.get(TEST_HOST + ":" + port + API_PATH_V1 + ACCOUNTS_PATH + "/?name=" + falseName)
.then()
.statusCode(HttpStatus.OK.value())
.contentType(ContentType.JSON);
Expand All @@ -91,7 +90,7 @@ public void postAccountTest() {
given().when()
.body(account)
.contentType(ContentType.JSON)
.post(TEST_HOST + ":" + port + ACCOUNTS_PATH)
.post(TEST_HOST + ":" + port + API_PATH_V1 + ACCOUNTS_PATH)
.then()
.statusCode(HttpStatus.CREATED.value());
}
Expand All @@ -105,7 +104,7 @@ public void postAccountNameEmptyTest() {
given().when()
.body(account)
.contentType(ContentType.JSON)
.post(TEST_HOST + ":" + port + ACCOUNTS_PATH)
.post(TEST_HOST + ":" + port + API_PATH_V1 + ACCOUNTS_PATH)
.then()
.statusCode(HttpStatus.BAD_REQUEST.value())
.body("name", equalTo("Name " + NOT_EMPTY));
Expand All @@ -120,7 +119,7 @@ public void postAccountNameTooLongTest() {
given().when()
.body(account)
.contentType(ContentType.JSON)
.post(TEST_HOST + ":" + port + ACCOUNTS_PATH)
.post(TEST_HOST + ":" + port + API_PATH_V1 + ACCOUNTS_PATH)
.then()
.statusCode(HttpStatus.BAD_REQUEST.value())
.body("name", equalTo("Name not be more than " + MAX_ACCOUNT_NAME + " characters"));
Expand All @@ -135,7 +134,7 @@ public void postAccountEmailEmptyTest() {
given().when()
.body(account)
.contentType(ContentType.JSON)
.post(TEST_HOST + ":" + port + ACCOUNTS_PATH)
.post(TEST_HOST + ":" + port + API_PATH_V1 + ACCOUNTS_PATH)
.then()
.statusCode(HttpStatus.BAD_REQUEST.value())
.body("email", equalTo("Email " + NOT_EMPTY));
Expand All @@ -151,7 +150,7 @@ public void postAccountEmailInvalidTest() {
given().when()
.body(account)
.contentType(ContentType.JSON)
.post(TEST_HOST + ":" + port + ACCOUNTS_PATH)
.post(TEST_HOST + ":" + port + API_PATH_V1 + ACCOUNTS_PATH)
.then()
.statusCode(HttpStatus.BAD_REQUEST.value())
.body("email", equalTo(INVALID_EMAIL));
Expand All @@ -162,7 +161,7 @@ public void deleteAccountTest() {
Account account = createAccount();

given().when()
.delete(TEST_HOST + ":" + port + ACCOUNTS_PATH + "/" + account.getId())
.delete(TEST_HOST + ":" + port + API_PATH_V1 + ACCOUNTS_PATH + "/" + account.getId())
.then()
.statusCode(HttpStatus.NO_CONTENT.value());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.hexlet.hexletcorrection.controller;
package io.hexlet.hexletcorrection.controller.api.v1;

import io.hexlet.hexletcorrection.domain.Account;
import io.hexlet.hexletcorrection.domain.Correction;
Expand All @@ -13,8 +13,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.test.context.junit4.SpringRunner;

import static io.hexlet.hexletcorrection.controller.ControllerConstants.CORRECTIONS_PATH;
import static io.hexlet.hexletcorrection.controller.ControllerConstants.TEST_HOST;
import static io.hexlet.hexletcorrection.controller.ControllerConstants.*;
import static io.hexlet.hexletcorrection.domain.EntityConstrainConstants.MAX_COMMENT_LENGTH;
import static io.hexlet.hexletcorrection.domain.EntityConstrainConstants.NOT_EMPTY;
import static io.hexlet.hexletcorrection.domain.EntityConstrainConstants.NOT_NULL;
Expand All @@ -37,7 +36,7 @@ public class CorrectionControllerTest {
@Test
public void getAllCorrectionsTest() {
given().when()
.get(TEST_HOST + ":" + port + CORRECTIONS_PATH)
.get(TEST_HOST + ":" + port + API_PATH_V1 + CORRECTIONS_PATH)
.then()
.statusCode(HttpStatus.OK.value())
.contentType(ContentType.JSON);
Expand All @@ -48,7 +47,7 @@ public void getCorrectionByIdTest() {
Correction savedCorrection = createCorrection(createAccount());

given().when()
.get(TEST_HOST + ":" + port + CORRECTIONS_PATH + "/" + savedCorrection.getId())
.get(TEST_HOST + ":" + port + API_PATH_V1 + CORRECTIONS_PATH + "/" + savedCorrection.getId())
.then()
.statusCode(HttpStatus.OK.value())
.contentType(ContentType.JSON);
Expand All @@ -59,7 +58,7 @@ public void getCorrectionByFalseIdTest() {
long falseId = createCorrection(createAccount()).getId() + 1L;

given().when()
.get(TEST_HOST + ":" + port + CORRECTIONS_PATH + "/" + falseId)
.get(TEST_HOST + ":" + port + API_PATH_V1 + CORRECTIONS_PATH + "/" + falseId)
.then()
.statusCode(HttpStatus.NOT_FOUND.value())
.contentType(ContentType.JSON)
Expand All @@ -71,7 +70,7 @@ public void getCorrectionByUrlTest() {
Correction savedCorrection = createCorrection(createAccount());

given().when()
.get(TEST_HOST + ":" + port + CORRECTIONS_PATH + "/?url=" + savedCorrection.getPageURL())
.get(TEST_HOST + ":" + port + API_PATH_V1 + CORRECTIONS_PATH + "/?url=" + savedCorrection.getPageURL())
.then()
.statusCode(HttpStatus.OK.value())
.contentType(ContentType.JSON);
Expand All @@ -91,7 +90,7 @@ public void postCorrectionTest() {
given().when()
.body(correction)
.contentType(ContentType.JSON)
.post(TEST_HOST + ":" + port + CORRECTIONS_PATH)
.post(TEST_HOST + ":" + port + API_PATH_V1 + CORRECTIONS_PATH)
.then()
.statusCode(HttpStatus.CREATED.value());
}
Expand All @@ -108,7 +107,7 @@ public void postCorrectionCommentEmptyTest() {
given().when()
.body(correction)
.contentType(ContentType.JSON)
.post(TEST_HOST + ":" + port + CORRECTIONS_PATH)
.post(TEST_HOST + ":" + port + API_PATH_V1 + CORRECTIONS_PATH)
.then()
.statusCode(HttpStatus.BAD_REQUEST.value())
.body("comment", equalTo("Comment " + NOT_EMPTY));
Expand All @@ -126,7 +125,7 @@ public void postCorrectionCommentTooLongTest() {
given().when()
.body(correction)
.contentType(ContentType.JSON)
.post(TEST_HOST + ":" + port + CORRECTIONS_PATH)
.post(TEST_HOST + ":" + port + API_PATH_V1 + CORRECTIONS_PATH)
.then()
.statusCode(HttpStatus.BAD_REQUEST.value())
.body("comment", equalTo("Comment not be more than " + MAX_COMMENT_LENGTH + " characters"));
Expand All @@ -144,7 +143,7 @@ public void postCorrectionHighlightTextEmptyTest() {
given().when()
.body(correction)
.contentType(ContentType.JSON)
.post(TEST_HOST + ":" + port + CORRECTIONS_PATH)
.post(TEST_HOST + ":" + port + API_PATH_V1 + CORRECTIONS_PATH)
.then()
.statusCode(HttpStatus.BAD_REQUEST.value())
.body("highlightText", equalTo("Highlight text " + NOT_EMPTY));
Expand All @@ -161,7 +160,7 @@ public void postCorrectionAccountNullTest() {
given().when()
.body(correction)
.contentType(ContentType.JSON)
.post(TEST_HOST + ":" + port + CORRECTIONS_PATH)
.post(TEST_HOST + ":" + port + API_PATH_V1 + CORRECTIONS_PATH)
.then()
.statusCode(HttpStatus.BAD_REQUEST.value())
.body("account", equalTo("Account " + NOT_NULL));
Expand All @@ -178,7 +177,7 @@ public void postCorrectionURLEmptyTest() {
given().when()
.body(correction)
.contentType(ContentType.JSON)
.post(TEST_HOST + ":" + port + CORRECTIONS_PATH)
.post(TEST_HOST + ":" + port + API_PATH_V1 + CORRECTIONS_PATH)
.then()
.statusCode(HttpStatus.BAD_REQUEST.value())
.body("pageURL", equalTo("URL " + NOT_EMPTY));
Expand All @@ -189,7 +188,7 @@ public void deleteCorrectionTest() {
Correction savedCorrection = createCorrection(createAccount());

given().when()
.delete(TEST_HOST + ":" + port + CORRECTIONS_PATH + "/" + savedCorrection.getId())
.delete(TEST_HOST + ":" + port + API_PATH_V1 + CORRECTIONS_PATH + "/" + savedCorrection.getId())
.then()
.statusCode(HttpStatus.NO_CONTENT.value());
}
Expand Down

0 comments on commit aa9314c

Please sign in to comment.