Here are the examples of the java api org.apache.http.HttpStatus.SC_UNPROCESSABLE_ENTITY taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
80 Examples
19
Source : ScmFileTransferServlet.java
with MIT License
from scm-manager
with MIT License
from scm-manager
/**
* Extracts the {@link LongObjectId} from the request. Finishes the request, in case the {@link LongObjectId} cannot
* be extracted with an appropriate error.
*
* @throws IOException Thrown if the response could not be completed in an error case.
*/
private AnyLongObjectId getObjectToTransfer(HttpServletRequest request, HttpServletResponse response) throws IOException {
String path = request.getPathInfo();
String objectIdFromPath = objectIdFromPath(path);
if (objectIdFromPath == null) {
// ObjectId is not retrievable from URL
sendErrorAndLog(response, HttpStatus.SC_UNPROCESSABLE_ENreplacedY, MessageFormat.format(LfsServerText.get().invalidPathInfo, path));
return null;
} else {
try {
return LongObjectId.fromString(objectIdFromPath);
} catch (InvalidLongObjectIdException e) {
sendErrorAndLog(response, HttpStatus.SC_UNPROCESSABLE_ENreplacedY, e);
return null;
}
}
}
19
Source : UsersResourceIntegrationTest.java
with MIT License
from diegocamara
with MIT License
from diegocamara
@Test
public void givenAnInvalidUser_thenReturnErrorsWith422Code() throws JsonProcessingException {
NewUserRequest newUser = new NewUserRequest();
given().contentType(MediaType.APPLICATION_JSON).body(objectMapper.writeValuereplacedtring(newUser)).when().post(USERS_RESOURCE_PATH).then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.body", hreplacedize(3), "errors.body", hasItems("username must be not blank", "email must be not blank", "preplacedword must be not blank"));
}
19
Source : UsersResourceIntegrationTest.java
with MIT License
from diegocamara
with MIT License
from diegocamara
@Test
public void givenAnInvalidEmail_thenReturnErrorsWith422Code() throws JsonProcessingException {
NewUserRequest newUser = new NewUserRequest();
newUser.setUsername("username");
newUser.setEmail("email");
newUser.setPreplacedword("user123");
given().contentType(MediaType.APPLICATION_JSON).body(objectMapper.writeValuereplacedtring(newUser)).when().post(USERS_RESOURCE_PATH).then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.body", hreplacedize(1), "errors.body", hasItems("must be a well-formed email address"));
}
19
Source : UserResourceIntegrationTest.java
with MIT License
from diegocamara
with MIT License
from diegocamara
@Test
public void givenAExistentUser_whenExecuteUpdateUserEndpointWithEmptyBody_shouldReturn422() throws JsonProcessingException {
final var user = createUserEnreplacedy("user1", "[email protected]", "bio", "image", "123");
String authorizationHeader = AUTHORIZATION_HEADER_VALUE_PREFIX + token(user);
UpdateUserRequest updateUserRequest = new UpdateUserRequest();
given().contentType(MediaType.APPLICATION_JSON).header(AUTHORIZATION_HEADER, authorizationHeader).body(objectMapper.writeValuereplacedtring(updateUserRequest)).put(USER_RESOURCE_PATH).then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.body", hasItems("At least one field must be not null"));
}
19
Source : UserResourceIntegrationTest.java
with MIT License
from diegocamara
with MIT License
from diegocamara
@Test
public void givenAExistentUser_whenExecuteUpdateUserEndpointWithInvalidEmail_shouldReturn422() throws JsonProcessingException {
final var user = createUserEnreplacedy("user1", "[email protected]", "bio", "image", "123");
String authorizationHeader = AUTHORIZATION_HEADER_VALUE_PREFIX + token(user);
UpdateUserRequest updateUserRequest = new UpdateUserRequest();
updateUserRequest.setEmail("email");
given().contentType(MediaType.APPLICATION_JSON).header(AUTHORIZATION_HEADER, authorizationHeader).body(objectMapper.writeValuereplacedtring(updateUserRequest)).put(USER_RESOURCE_PATH).then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.body", hreplacedize(1), "errors.body", hasItems("must be a well-formed email address"));
}
19
Source : UserResourceIntegrationTest.java
with MIT License
from diegocamara
with MIT License
from diegocamara
@Test
public void givenAExistentUser_whenExecuteUpdateUserEndpointWithBlankUsername_shouldReturn422() throws JsonProcessingException {
final var user = createUserEnreplacedy("user1", "[email protected]", "bio", "image", "123");
String authorizationHeader = AUTHORIZATION_HEADER_VALUE_PREFIX + token(user);
UpdateUserRequest updateUserRequest = new UpdateUserRequest();
updateUserRequest.setUsername(" ");
given().contentType(MediaType.APPLICATION_JSON).header(AUTHORIZATION_HEADER, authorizationHeader).body(objectMapper.writeValuereplacedtring(updateUserRequest)).put(USER_RESOURCE_PATH).then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.body", hasItems("username must be not blank"));
}
19
Source : UserResourceIntegrationTest.java
with MIT License
from diegocamara
with MIT License
from diegocamara
@Test
public void givenAExistentUser_whenExecuteUpdateUserEndpointWithEmptyUsername_shouldReturn422() throws JsonProcessingException {
final var user = createUserEnreplacedy("user1", "[email protected]", "bio", "image", "123");
String authorizationHeader = AUTHORIZATION_HEADER_VALUE_PREFIX + token(user);
UpdateUserRequest updateUserRequest = new UpdateUserRequest();
updateUserRequest.setUsername("");
given().contentType(MediaType.APPLICATION_JSON).header(AUTHORIZATION_HEADER, authorizationHeader).body(objectMapper.writeValuereplacedtring(updateUserRequest)).put(USER_RESOURCE_PATH).then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.body", hasItems("username must be not blank"));
}
19
Source : ReleaseControllerTest.java
with MIT License
from blocklang
with MIT License
from blocklang
@WithMockUser(username = "owner")
@Test
public void post_release_invalid_version() {
NewReleaseTaskParam release = prepareNewParam();
release.setVersion("not-a-sematic-version");
given().contentType(ContentType.JSON).body(release).when().post("/projects/{owner}/{projectName}/releases", "jack", "demo_project").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.version", hasItems("不是有效的<a href=\"https://semver.org/lang/zh-CN/\" target=\"_blank\" tabindex=\"-1\" clreplaced=\"text-white\">语义化版本</a>"));
}
19
Source : ReleaseControllerTest.java
with MIT License
from blocklang
with MIT License
from blocklang
@WithMockUser(username = "owner")
@Test
public void post_release_param_is_blank() {
NewReleaseTaskParam release = new NewReleaseTaskParam();
given().contentType(ContentType.JSON).body(release).when().post("/projects/{owner}/{projectName}/releases", "jack", "demo_project").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.version", hasItems("版本号不能为空"), "errors.replacedle", hasItems("发行版标题不能为空"), "errors.jdkReleaseId", hasItems("必须选择 JDK 版本"));
}
19
Source : ReleaseControllerTest.java
with MIT License
from blocklang
with MIT License
from blocklang
@WithMockUser(username = "owner")
@Test
public void check_version_is_blank() {
CheckReleaseVersionParam param = new CheckReleaseVersionParam();
// 有一个空格
param.setVersion(" ");
given().contentType(ContentType.JSON).body(param).when().post("/projects/{owner}/{projectName}/releases/check-version", "jack", "project").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.version", hasItem("版本号不能为空"), "errors.version.size()", is(1));
}
19
Source : ReleaseControllerTest.java
with MIT License
from blocklang
with MIT License
from blocklang
@WithMockUser(username = "owner")
@Test
public void check_version_is_not_a_valid_semantic_versioning() {
CheckReleaseVersionParam param = new CheckReleaseVersionParam();
param.setVersion("not-a-sematic-version");
given().contentType(ContentType.JSON).body(param).when().post("/projects/{owner}/{projectName}/releases/check-version", "jack", "project").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.version", hasItem("不是有效的<a href=\"https://semver.org/lang/zh-CN/\" target=\"_blank\" tabindex=\"-1\" clreplaced=\"text-white\">语义化版本</a>"), "errors.version.size()", is(1));
}
19
Source : InstallerApiTest.java
with MIT License
from blocklang
with MIT License
from blocklang
// 根据注册 token 没有找到 Deploy 配置信息
@Test
public void post_installer_no_register_token() {
String registrationToken = "not_exist_register_token";
NewRegistrationParam registration = prepareNewParam(registrationToken);
when(projectDeployService.findByRegistrationToken(eq(registrationToken))).thenReturn(Optional.empty());
given().contentType(ContentType.JSON).body(registration).when().post("/installers").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.registrationToken", hasItems("注册 Token `not_exist_register_token` 不存在"));
}
19
Source : InstallerApiTest.java
with MIT License
from blocklang
with MIT License
from blocklang
// 根据 installer token 没有找到 installer 信息
@Test
public void put_installer_no_installer_token() {
String installerToken = "installer_token_1";
UpdateRegistrationParam registration = prepareUpdateParam(installerToken);
when(installerService.findByInstallerToken(eq(installerToken))).thenReturn(Optional.empty());
given().contentType(ContentType.JSON).body(registration).when().put("/installers").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.installerToken", hasItems("安装器 Token `installer_token_1` 不存在"));
}
19
Source : InstallerApiTest.java
with MIT License
from blocklang
with MIT License
from blocklang
// 对输入参数进行校验
@Test
public void put_installer_param_not_valid() {
UpdateRegistrationParam registration = new UpdateRegistrationParam();
given().contentType(ContentType.JSON).body(registration).when().put("/installers").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.installerToken", hasItems("安装器 Token 不能为空"));
}
19
Source : InstallerApiTest.java
with MIT License
from blocklang
with MIT License
from blocklang
// 对输入参数进行校验
@Test
public void post_installer_param_not_valid() {
NewRegistrationParam registration = new NewRegistrationParam();
given().contentType(ContentType.JSON).body(registration).when().post("/installers").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.registrationToken", hasItems("注册 Token 不能为空"));
}
19
Source : RepositoryControllerTest.java
with MIT License
from blocklang
with MIT License
from blocklang
@WithMockUser(username = "owner")
@Test
public void checkNameIsInvalid() {
CheckRepositoryNameParam param = new CheckRepositoryNameParam();
param.setOwner("owner");
param.setName("中文");
given().contentType(ContentType.JSON).body(param).when().post("/repos/check-name").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.name", hasItem("只允许字母、数字、中划线(-)、下划线(_)、点(.)"), "errors.name.size()", is(1));
}
19
Source : RepositoryControllerTest.java
with MIT License
from blocklang
with MIT License
from blocklang
@WithMockUser(username = "owner")
@Test
public void checkNameIsBlank() {
CheckRepositoryNameParam param = new CheckRepositoryNameParam();
param.setOwner("owner");
param.setName(" ");
given().contentType(ContentType.JSON).body(param).when().post("/repos/check-name").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.name", hasItem("仓库名不能为空"), "errors.name.size()", is(1));
}
19
Source : ResultProcessor.java
with MIT License
from bakdata
with MIT License
from bakdata
private Response getArrowResult(Function<OutputStream, Function<VectorSchemaRoot, ArrowWriter>> writerProducer, User user, ManagedExecutionId queryId, DatasetId datasetId, DatasetRegistry datasetRegistry, boolean pretty, String fileExtension) {
ConqueryMDC.setLocation(user.getName());
log.info("Downloading results for {} on dataset {}", queryId, datasetId);
authorize(user, datasetId, Ability.READ);
ManagedExecution<?> exec = Objects.requireNonNull(datasetRegistry.getMetaStorage().getExecution(queryId));
authorize(user, exec, Ability.READ);
// Check if user is permitted to download on all datasets that were referenced by the query
authorizeDownloadDatasets(user, exec);
if (!(exec instanceof ManagedQuery || (exec instanceof ManagedForm && ((ManagedForm) exec).getSubQueries().size() == 1))) {
return Response.status(HttpStatus.SC_UNPROCESSABLE_ENreplacedY, "Execution result is not a single Table").build();
}
// Get the locale extracted by the LocaleFilter
PrintSettings settings = new PrintSettings(pretty, I18n.LOCALE.get(), datasetRegistry);
IdMappingConfig idMappingConf = config.getIdMapping();
IdMappingState mappingState = config.getIdMapping().initToExternal(user, exec);
StreamingOutput out = new StreamingOutput() {
@Override
public void write(OutputStream output) throws IOException, WebApplicationException {
renderToStream(writerProducer.apply(output), settings, exec, cer -> ResultUtil.createId(datasetRegistry.get(datasetId), cer, config.getIdMapping(), mappingState).getExternalId(), idMappingConf.getPrintIdFields(), config.getArrow().getBatchSize());
}
};
return makeResponseWithFileName(fileExtension, exec, out).build();
}
19
Source : JsonProcessingExceptionMapper.java
with MIT License
from alphagov
with MIT License
from alphagov
@Override
public Response toResponse(JsonProcessingException exception) {
LOG.warn(String.format("Unable to parse json in request body. %s", exception.getOriginalMessage()));
return Response.status(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).enreplacedy(new ErrorMessage(HttpStatus.SC_UNPROCESSABLE_ENreplacedY, exception.getOriginalMessage())).build();
}
18
Source : UsersResourceIntegrationTest.java
with MIT License
from diegocamara
with MIT License
from diegocamara
@Test
public void givenAInvalidLogin_whenExecuteLoginEndpoint_shouldReturnErrorsWith422Code() throws JsonProcessingException {
LoginRequest loginRequest = new LoginRequest();
given().contentType(MediaType.APPLICATION_JSON).body(objectMapper.writeValuereplacedtring(loginRequest)).when().post(LOGIN_PATH).then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.body", hasItems("email must be not blank", "preplacedword must be not blank"));
}
18
Source : InstallerApiTest.java
with MIT License
from blocklang
with MIT License
from blocklang
@Test
public void post_installer_no_app() {
String registrationToken = "not_exist_register_token";
NewRegistrationParam registration = prepareNewParam(registrationToken);
ProjectDeploy deploy = new ProjectDeploy();
deploy.setRegistrationToken("a");
deploy.setProjectId(1);
when(projectDeployService.findByRegistrationToken(eq(registrationToken))).thenReturn(Optional.of(deploy));
when(appService.findByProjectId(eq(1))).thenReturn(Optional.empty());
given().contentType(ContentType.JSON).body(registration).when().post("/installers").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.globalErrors", hasItems("没有找到项目(ProjectId = 1)的 APP 基本信息"));
}
18
Source : ComponentRepoControllerTest.java
with MIT License
from blocklang
with MIT License
from blocklang
@WithMockUser("jack")
@Test
public void new_component_repo_git_url_can_not_be_blank() {
NewComponentRepoParam param = new NewComponentRepoParam();
param.setGitUrl(" ");
given().contentType(ContentType.JSON).body(param).when().post("/component-repos").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.gitUrl", hasItem("Git 仓库地址不能为空"), "errors.gitUrl.size()", is(1));
}
18
Source : RepositoryControllerTest.java
with MIT License
from blocklang
with MIT License
from blocklang
@WithMockUser(username = "owner")
@Test
public void checkNameIsUsed() {
CheckRepositoryNameParam param = new CheckRepositoryNameParam();
param.setOwner("owner");
param.setName("good-name");
Repository project = new Repository();
project.setId(1);
project.setName("good-name");
when(repositoryService.find(eq("owner"), eq("good-name"))).thenReturn(Optional.of(project));
given().contentType(ContentType.JSON).body(param).when().post("/repos/check-name").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.name", hasItem("owner下已存在<strong>good-name</strong>仓库"), "errors.name.size()", is(1));
}
18
Source : RepositoryControllerTest.java
with MIT License
from blocklang
with MIT License
from blocklang
// 因为新建项目和校验项目名称中的校验逻辑完全相同
// 所以此处不再重复测试所有逻辑,而是确认其中包含测试逻辑即可。
@WithMockUser(username = "owner")
@Test
public void newRepositoryHasValidateName() {
NewRepositoryParam param = new NewRepositoryParam();
param.setOwner("owner");
param.setName("good-name");
Repository repository = new Repository();
repository.setId(1);
repository.setName("good-name");
when(repositoryService.find(eq("owner"), eq("good-name"))).thenReturn(Optional.of(repository));
given().contentType(ContentType.JSON).body(param).when().post("/repos").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.name", hasItem("owner下已存在<strong>good-name</strong>仓库"), "errors.name.size()", is(1));
}
18
Source : PageControllerTest.java
with MIT License
from blocklang
with MIT License
from blocklang
@WithMockUser(username = "jack")
@Test
public void checkNameIsUsedAtRoot() {
Repository repository = new Repository();
repository.setId(1);
when(repositoryService.find(anyString(), anyString())).thenReturn(Optional.of(repository));
when(repositoryPermissionService.canWrite(any(), any())).thenReturn(Optional.of(AccessLevel.WRITE));
RepositoryResource resource = new RepositoryResource();
when(repositoryResourceService.findByName(anyInt(), anyInt(), any(), any(), anyString())).thenReturn(Optional.of(resource));
when(repositoryResourceService.findById(anyInt())).thenReturn(Optional.of(new RepositoryResource()));
CheckPageNameParam param = new CheckPageNameParam();
param.setName("a-used-name");
param.setParentId(Constant.TREE_ROOT_ID);
param.setAppType(AppType.WEB.getKey());
given().contentType(ContentType.JSON).body(param).when().post("/repos/{owner}/{repoName}/pages/check-name", "jack", "repo").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.name", hasItem("根目录下已存在备注<strong>a-used-name</strong>"), "errors.name.size()", is(1));
}
18
Source : PageControllerTest.java
with MIT License
from blocklang
with MIT License
from blocklang
@WithMockUser(username = "jack")
@Test
public void checkKeyIsInvalid() {
Repository repository = new Repository();
repository.setId(1);
when(repositoryService.find(anyString(), anyString())).thenReturn(Optional.of(repository));
when(repositoryPermissionService.canWrite(any(), any())).thenReturn(Optional.of(AccessLevel.WRITE));
CheckPageKeyParam param = new CheckPageKeyParam();
param.setKey("中文");
given().contentType(ContentType.JSON).body(param).when().post("/repos/{owner}/{repoName}/pages/check-key", "jack", "repo").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.key", hasItem("只允许字母、数字、中划线(-)、下划线(_)"), "errors.key.size()", is(1));
}
18
Source : PageControllerTest.java
with MIT License
from blocklang
with MIT License
from blocklang
@WithMockUser(username = "jack")
@Test
public void newPageCheckKeyIsBlankAndNameIsUsed() {
NewPageParam param = new NewPageParam();
param.setParentId(Constant.TREE_ROOT_ID);
param.setAppType(AppType.WEB.getKey());
param.setKey(" ");
param.setName("a-used-name");
Repository repository = new Repository();
repository.setId(1);
when(repositoryService.find(anyString(), anyString())).thenReturn(Optional.of(repository));
when(repositoryPermissionService.canWrite(any(), any())).thenReturn(Optional.of(AccessLevel.WRITE));
RepositoryResource resource = new RepositoryResource();
when(repositoryResourceService.findByName(anyInt(), anyInt(), any(), any(), anyString())).thenReturn(Optional.of(resource));
when(repositoryResourceService.findById(anyInt())).thenReturn(Optional.of(new RepositoryResource()));
given().contentType(ContentType.JSON).body(param).when().post("/repos/{owner}/{repoName}/pages", "jack", "repo").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.key", hasItem("名称不能为空"), "errors.key.size()", is(1), "errors.name", hasItem("根目录下已存在备注<strong>a-used-name</strong>"), "errors.name.size()", is(1));
}
18
Source : PageControllerTest.java
with MIT License
from blocklang
with MIT License
from blocklang
@WithMockUser(username = "jack")
@Test
public void newPageCheckKeyIsBlankAndNamePreplaceded() {
NewPageParam param = new NewPageParam();
param.setParentId(Constant.TREE_ROOT_ID);
param.setAppType(AppType.WEB.getKey());
param.setKey(" ");
param.setName("name");
Repository repository = new Repository();
repository.setId(1);
when(repositoryService.find(anyString(), anyString())).thenReturn(Optional.of(repository));
when(repositoryPermissionService.canWrite(any(), any())).thenReturn(Optional.of(AccessLevel.WRITE));
when(repositoryResourceService.findByName(anyInt(), anyInt(), any(), any(), anyString())).thenReturn(Optional.empty());
given().contentType(ContentType.JSON).body(param).when().post("/repos/{owner}/{repoName}/pages", "jack", "repo").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.key", hasItem("名称不能为空"), "errors.key.size()", is(1), "errors.name", is(nullValue()));
}
18
Source : PageControllerTest.java
with MIT License
from blocklang
with MIT License
from blocklang
@WithMockUser(username = "jack")
@Test
public void checkNameIsUsedAtSubAndNameIsNotBlank() {
Repository repository = new Repository();
repository.setId(1);
when(repositoryService.find(anyString(), anyString())).thenReturn(Optional.of(repository));
when(repositoryPermissionService.canWrite(any(), any())).thenReturn(Optional.of(AccessLevel.WRITE));
Integer groupId = 1;
RepositoryResource resource = new RepositoryResource();
resource.setParentId(groupId);
when(repositoryResourceService.findByName(anyInt(), anyInt(), any(), any(), anyString())).thenReturn(Optional.of(resource));
RepositoryResource parentResource = new RepositoryResource();
parentResource.setId(groupId);
parentResource.setName("二级目录");
when(repositoryResourceService.findById(anyInt())).thenReturn(Optional.of(parentResource));
CheckPageNameParam param = new CheckPageNameParam();
param.setName("a-used-name");
param.setParentId(groupId);
param.setAppType(AppType.WEB.getKey());
given().contentType(ContentType.JSON).body(param).when().post("/repos/{owner}/{repoName}/pages/check-name", "jack", "repo").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.name", hasItem("二级目录下已存在备注<strong>a-used-name</strong>"), "errors.name.size()", is(1));
}
18
Source : PageControllerTest.java
with MIT License
from blocklang
with MIT License
from blocklang
@WithMockUser(username = "jack")
@Test
public void newPageCheckKeyIsUsedAndNameIsPreplaced() {
NewPageParam param = new NewPageParam();
param.setParentId(Constant.TREE_ROOT_ID);
param.setAppType(AppType.WEB.getKey());
param.setKey("a-used-key");
param.setName("name");
Repository repository = new Repository();
repository.setId(1);
when(repositoryService.find(anyString(), anyString())).thenReturn(Optional.of(repository));
when(repositoryPermissionService.canWrite(any(), any())).thenReturn(Optional.of(AccessLevel.WRITE));
RepositoryResource resource1 = new RepositoryResource();
when(repositoryResourceService.findByKey(anyInt(), anyInt(), any(), any(), anyString())).thenReturn(Optional.of(resource1));
when(repositoryResourceService.findByName(anyInt(), anyInt(), any(), any(), anyString())).thenReturn(Optional.empty());
when(repositoryResourceService.findById(anyInt())).thenReturn(Optional.of(new RepositoryResource()));
given().contentType(ContentType.JSON).body(param).when().post("/repos/{owner}/{repoName}/pages", "jack", "project").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.key", hasItem("根目录下已存在名称<strong>a-used-key</strong>"), "errors.key.size()", is(1), "errors.name", is(nullValue()));
}
18
Source : PageControllerTest.java
with MIT License
from blocklang
with MIT License
from blocklang
@WithMockUser(username = "jack")
@Test
public void checkKeyIsBlank() {
Repository repository = new Repository();
repository.setId(1);
when(repositoryService.find(anyString(), anyString())).thenReturn(Optional.of(repository));
when(repositoryPermissionService.canWrite(any(), any())).thenReturn(Optional.of(AccessLevel.WRITE));
CheckPageKeyParam param = new CheckPageKeyParam();
param.setKey(" ");
given().contentType(ContentType.JSON).body(param).when().post("/repos/{owner}/{repoName}/pages/check-key", "jack", "repo").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.key", hasItem("名称不能为空"), "errors.key.size()", is(1));
}
18
Source : PageControllerTest.java
with MIT License
from blocklang
with MIT License
from blocklang
@WithMockUser(username = "jack")
@Test
public void checkKeyIsUsedAtSubAndNameIsBlank() {
Repository repository = new Repository();
repository.setId(1);
when(repositoryService.find(anyString(), anyString())).thenReturn(Optional.of(repository));
when(repositoryPermissionService.canWrite(any(), any())).thenReturn(Optional.of(AccessLevel.WRITE));
Integer parentId = 1;
RepositoryResource resource = new RepositoryResource();
resource.setParentId(parentId);
when(repositoryResourceService.findByKey(anyInt(), anyInt(), any(), any(), anyString())).thenReturn(Optional.of(resource));
RepositoryResource parentResource = new RepositoryResource();
parentResource.setId(parentId);
parentResource.setKey("two level");
when(repositoryResourceService.findById(anyInt())).thenReturn(Optional.of(parentResource));
CheckPageKeyParam param = new CheckPageKeyParam();
param.setKey("a-used-key");
param.setParentId(parentId);
param.setAppType(AppType.WEB.getKey());
given().contentType(ContentType.JSON).body(param).when().post("/repos/{owner}/{repoName}/pages/check-key", "jack", "repo").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.key", hasItem("two level下已存在名称<strong>a-used-key</strong>"), "errors.key.size()", is(1));
}
18
Source : PageControllerTest.java
with MIT License
from blocklang
with MIT License
from blocklang
@WithMockUser(username = "jack")
@Test
public void checkKeyIsUsedAtRoot() {
Repository repository = new Repository();
repository.setId(1);
when(repositoryService.find(anyString(), anyString())).thenReturn(Optional.of(repository));
when(repositoryPermissionService.canWrite(any(), any())).thenReturn(Optional.of(AccessLevel.WRITE));
RepositoryResource resource = new RepositoryResource();
when(repositoryResourceService.findByKey(anyInt(), anyInt(), any(), any(), anyString())).thenReturn(Optional.of(resource));
when(repositoryResourceService.findById(anyInt())).thenReturn(Optional.of(new RepositoryResource()));
CheckPageKeyParam param = new CheckPageKeyParam();
param.setKey("a-used-key");
param.setParentId(Constant.TREE_ROOT_ID);
given().contentType(ContentType.JSON).body(param).when().post("/repos/{owner}/{repoName}/pages/check-key", "jack", "repo").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.key", hasItem("根目录下已存在名称<strong>a-used-key</strong>"), "errors.key.size()", is(1));
}
18
Source : PageControllerTest.java
with MIT License
from blocklang
with MIT License
from blocklang
@WithMockUser(username = "jack")
@Test
public void newPageCheckKeyIsInvalidAndNameIsPreplaceded() {
NewPageParam param = new NewPageParam();
param.setParentId(Constant.TREE_ROOT_ID);
param.setAppType(AppType.WEB.getKey());
param.setKey("中文");
param.setName("name");
Repository repository = new Repository();
repository.setId(1);
when(repositoryService.find(anyString(), anyString())).thenReturn(Optional.of(repository));
when(repositoryPermissionService.canWrite(any(), any())).thenReturn(Optional.of(AccessLevel.WRITE));
when(repositoryResourceService.findByName(anyInt(), anyInt(), any(), any(), anyString())).thenReturn(Optional.empty());
given().contentType(ContentType.JSON).body(param).when().post("/repos/{owner}/{repoName}/pages", "jack", "repo").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.key", hasItem("只允许字母、数字、中划线(-)、下划线(_)"), "errors.key.size()", is(1), "errors.name", is(nullValue()));
}
18
Source : PageControllerTest.java
with MIT License
from blocklang
with MIT License
from blocklang
@WithMockUser(username = "jack")
@Test
public void newPageCheckKeyIsNullAndNameIsNull() {
NewPageParam param = new NewPageParam();
param.setParentId(Constant.TREE_ROOT_ID);
param.setAppType(AppType.WEB.getKey());
param.setKey(null);
param.setName(null);
Repository repository = new Repository();
repository.setId(1);
when(repositoryService.find(anyString(), anyString())).thenReturn(Optional.of(repository));
when(repositoryPermissionService.canWrite(any(), any())).thenReturn(Optional.of(AccessLevel.WRITE));
when(repositoryResourceService.findByName(anyInt(), anyInt(), any(), any(), anyString())).thenReturn(Optional.empty());
given().contentType(ContentType.JSON).body(param).when().post("/repos/{owner}/{repoName}/pages", "jack", "repo").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.key", hasItem("名称不能为空"), "errors.key.size()", is(1), "errors.name", is(nullValue()));
}
18
Source : PageControllerTest.java
with MIT License
from blocklang
with MIT License
from blocklang
@WithMockUser(username = "jack")
@Test
public void checkNameIsUsedAtSubAndNameIsBlank() {
Repository repository = new Repository();
repository.setId(1);
when(repositoryService.find(anyString(), anyString())).thenReturn(Optional.of(repository));
when(repositoryPermissionService.canWrite(any(), any())).thenReturn(Optional.of(AccessLevel.WRITE));
Integer groupId = 1;
RepositoryResource resource = new RepositoryResource();
resource.setParentId(groupId);
when(repositoryResourceService.findByName(anyInt(), anyInt(), any(), any(), anyString())).thenReturn(Optional.of(resource));
RepositoryResource parentResource = new RepositoryResource();
parentResource.setId(groupId);
parentResource.setKey("Two Level");
when(repositoryResourceService.findById(anyInt())).thenReturn(Optional.of(parentResource));
CheckPageNameParam param = new CheckPageNameParam();
param.setName("a-used-name");
param.setParentId(groupId);
param.setAppType(AppType.WEB.getKey());
given().contentType(ContentType.JSON).body(param).when().post("/repos/{owner}/{repoName}/pages/check-name", "jack", "repo").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.name", hasItem("Two Level下已存在备注<strong>a-used-name</strong>"), "errors.name.size()", is(1));
}
18
Source : PageControllerTest.java
with MIT License
from blocklang
with MIT License
from blocklang
@WithMockUser(username = "jack")
@Test
public void newPageCheckKeyIsInvalidAndNameIsUsed() {
NewPageParam param = new NewPageParam();
param.setParentId(Constant.TREE_ROOT_ID);
param.setAppType(AppType.WEB.getKey());
param.setKey("中文");
param.setName("a-used-name");
Repository repository = new Repository();
repository.setId(1);
when(repositoryService.find(anyString(), anyString())).thenReturn(Optional.of(repository));
when(repositoryPermissionService.canWrite(any(), any())).thenReturn(Optional.of(AccessLevel.WRITE));
RepositoryResource resource = new RepositoryResource();
when(repositoryResourceService.findByName(anyInt(), anyInt(), any(), any(), anyString())).thenReturn(Optional.of(resource));
when(repositoryResourceService.findById(anyInt())).thenReturn(Optional.of(new RepositoryResource()));
given().contentType(ContentType.JSON).body(param).when().post("/repos/{owner}/{repoName}/pages", "jack", "repo").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.key", hasItem("只允许字母、数字、中划线(-)、下划线(_)"), "errors.key.size()", is(1), "errors.name", hasItem("根目录下已存在备注<strong>a-used-name</strong>"), "errors.name.size()", is(1));
}
18
Source : PageControllerTest.java
with MIT License
from blocklang
with MIT License
from blocklang
@WithMockUser(username = "jack")
@Test
public void checkKeyIsUsedAtSubAndNameIsNotBlank() {
Repository repository = new Repository();
repository.setId(1);
when(repositoryService.find(anyString(), anyString())).thenReturn(Optional.of(repository));
when(repositoryPermissionService.canWrite(any(), any())).thenReturn(Optional.of(AccessLevel.WRITE));
Integer parentId = 1;
RepositoryResource resource = new RepositoryResource();
resource.setParentId(parentId);
when(repositoryResourceService.findByKey(anyInt(), anyInt(), any(), any(), anyString())).thenReturn(Optional.of(resource));
RepositoryResource parentResource = new RepositoryResource();
parentResource.setId(parentId);
parentResource.setName("二级目录");
when(repositoryResourceService.findById(anyInt())).thenReturn(Optional.of(parentResource));
CheckPageKeyParam param = new CheckPageKeyParam();
param.setKey("a-used-key");
param.setParentId(parentId);
param.setAppType(AppType.WEB.getKey());
given().contentType(ContentType.JSON).body(param).when().post("/repos/{owner}/{repoName}/pages/check-key", "jack", "repo").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.key", hasItem("二级目录下已存在名称<strong>a-used-key</strong>"), "errors.key.size()", is(1));
}
18
Source : PageControllerTest.java
with MIT License
from blocklang
with MIT License
from blocklang
@WithMockUser(username = "jack")
@Test
public void newPageCheckKeyIsUsedAndNameIsUsed() {
NewPageParam param = new NewPageParam();
param.setParentId(Constant.TREE_ROOT_ID);
param.setAppType(AppType.WEB.getKey());
param.setKey("a-used-key");
param.setName("a-used-name");
Repository repository = new Repository();
repository.setId(1);
when(repositoryService.find(anyString(), anyString())).thenReturn(Optional.of(repository));
when(repositoryPermissionService.canWrite(any(), any())).thenReturn(Optional.of(AccessLevel.WRITE));
RepositoryResource resource1 = new RepositoryResource();
when(repositoryResourceService.findByKey(anyInt(), anyInt(), any(), any(), anyString())).thenReturn(Optional.of(resource1));
RepositoryResource resource2 = new RepositoryResource();
when(repositoryResourceService.findByName(anyInt(), anyInt(), any(), any(), anyString())).thenReturn(Optional.of(resource2));
when(repositoryResourceService.findById(anyInt())).thenReturn(Optional.of(new RepositoryResource()));
given().contentType(ContentType.JSON).body(param).when().post("/repos/{owner}/{repoName}/pages", "jack", "repo").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.key", hasItem("根目录下已存在名称<strong>a-used-key</strong>"), "errors.key.size()", is(1), "errors.name", hasItem("根目录下已存在备注<strong>a-used-name</strong>"), "errors.name.size()", is(1));
}
18
Source : GroupControllerTest.java
with MIT License
from blocklang
with MIT License
from blocklang
@WithMockUser(username = "jack")
@Test
public void newGroupCheckKeyIsNullAndNameIsNull() {
NewGroupParam param = new NewGroupParam();
param.setParentId(Constant.TREE_ROOT_ID);
param.setKey(null);
param.setName(null);
Repository repository = new Repository();
repository.setId(1);
when(repositoryService.find(anyString(), anyString())).thenReturn(Optional.of(repository));
when(repositoryPermissionService.canWrite(any(), any())).thenReturn(Optional.of(AccessLevel.WRITE));
when(repositoryResourceService.findByName(anyInt(), anyInt(), any(), any(), anyString())).thenReturn(Optional.empty());
given().contentType(ContentType.JSON).body(param).when().post("/repos/{owner}/{repoName}/groups", "jack", "repo").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.key", hasItem("名称不能为空"), "errors.key.size()", is(1), "errors.name", is(nullValue()));
}
18
Source : GroupControllerTest.java
with MIT License
from blocklang
with MIT License
from blocklang
@WithMockUser(username = "jack")
@Test
public void newGroupCheckKeyIsBlankAndNameIsUsed() {
NewGroupParam param = new NewGroupParam();
param.setParentId(Constant.TREE_ROOT_ID);
param.setKey(" ");
param.setName("a-used-name");
Repository repository = new Repository();
repository.setId(1);
when(repositoryService.find(anyString(), anyString())).thenReturn(Optional.of(repository));
when(repositoryPermissionService.canWrite(any(), any())).thenReturn(Optional.of(AccessLevel.WRITE));
RepositoryResource resource = new RepositoryResource();
when(repositoryResourceService.findByName(anyInt(), anyInt(), any(), any(), anyString())).thenReturn(Optional.of(resource));
when(repositoryResourceService.findById(anyInt())).thenReturn(Optional.of(new RepositoryResource()));
given().contentType(ContentType.JSON).body(param).when().post("/repos/{owner}/{repoName}/groups", "jack", "repo").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.key", hasItem("名称不能为空"), "errors.key.size()", is(1), "errors.name", hasItem("根目录下已存在备注<strong>a-used-name</strong>"), "errors.name.size()", is(1));
}
18
Source : GroupControllerTest.java
with MIT License
from blocklang
with MIT License
from blocklang
@WithMockUser(username = "jack")
@Test
public void newGroupCheckKeyIsInvalidAndNameIsUsed() {
NewGroupParam param = new NewGroupParam();
param.setParentId(Constant.TREE_ROOT_ID);
param.setKey("中文");
param.setName("a-used-name");
Repository repository = new Repository();
repository.setId(1);
when(repositoryService.find(anyString(), anyString())).thenReturn(Optional.of(repository));
when(repositoryPermissionService.canWrite(any(), any())).thenReturn(Optional.of(AccessLevel.WRITE));
RepositoryResource resource = new RepositoryResource();
when(repositoryResourceService.findByName(anyInt(), anyInt(), any(), any(), anyString())).thenReturn(Optional.of(resource));
when(repositoryResourceService.findById(anyInt())).thenReturn(Optional.of(new RepositoryResource()));
given().contentType(ContentType.JSON).body(param).when().post("/repos/{owner}/{repoName}/groups", "jack", "repo").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.key", hasItem("只允许字母、数字、中划线(-)、下划线(_)"), "errors.key.size()", is(1), "errors.name", hasItem("根目录下已存在备注<strong>a-used-name</strong>"), "errors.name.size()", is(1));
}
18
Source : GroupControllerTest.java
with MIT License
from blocklang
with MIT License
from blocklang
@WithMockUser(username = "jack")
@Test
public void newGroupCheckKeyIsInvalidAndNameIsPreplaceded() {
NewGroupParam param = new NewGroupParam();
param.setParentId(Constant.TREE_ROOT_ID);
param.setKey("中文");
param.setName("name");
Repository repository = new Repository();
repository.setId(1);
when(repositoryService.find(anyString(), anyString())).thenReturn(Optional.of(repository));
when(repositoryPermissionService.canWrite(any(), any())).thenReturn(Optional.of(AccessLevel.WRITE));
when(repositoryResourceService.findByName(anyInt(), anyInt(), any(), any(), anyString())).thenReturn(Optional.empty());
given().contentType(ContentType.JSON).body(param).when().post("/repos/{owner}/{repoName}/groups", "jack", "repo").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.key", hasItem("只允许字母、数字、中划线(-)、下划线(_)"), "errors.key.size()", is(1), "errors.name", is(nullValue()));
}
18
Source : GroupControllerTest.java
with MIT License
from blocklang
with MIT License
from blocklang
@WithMockUser(username = "jack")
@Test
public void newGroupCheckKeyIsUsedAndNameIsPreplaced() {
NewGroupParam param = new NewGroupParam();
param.setParentId(Constant.TREE_ROOT_ID);
param.setKey("a-used-key");
param.setName("name");
Repository repository = new Repository();
repository.setId(1);
when(repositoryService.find(anyString(), anyString())).thenReturn(Optional.of(repository));
when(repositoryPermissionService.canWrite(any(), any())).thenReturn(Optional.of(AccessLevel.WRITE));
RepositoryResource resource1 = new RepositoryResource();
when(repositoryResourceService.findByKey(anyInt(), anyInt(), any(), any(), anyString())).thenReturn(Optional.of(resource1));
when(repositoryResourceService.findByName(anyInt(), anyInt(), any(), any(), anyString())).thenReturn(Optional.empty());
when(repositoryResourceService.findById(anyInt())).thenReturn(Optional.of(new RepositoryResource()));
given().contentType(ContentType.JSON).body(param).when().post("/repos/{owner}/{repoName}/groups", "jack", "repo").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.key", hasItem("根目录下已存在名称<strong>a-used-key</strong>"), "errors.key.size()", is(1), "errors.name", is(nullValue()));
}
18
Source : GroupControllerTest.java
with MIT License
from blocklang
with MIT License
from blocklang
@WithMockUser(username = "jack")
@Test
public void checkNameIsUsedAtSub() {
Repository repository = new Repository();
repository.setId(1);
when(repositoryService.find(anyString(), anyString())).thenReturn(Optional.of(repository));
when(repositoryPermissionService.canWrite(any(), any())).thenReturn(Optional.of(AccessLevel.WRITE));
Integer groupId = 1;
RepositoryResource resource = new RepositoryResource();
resource.setParentId(groupId);
when(repositoryResourceService.findByName(anyInt(), anyInt(), any(), any(), anyString())).thenReturn(Optional.of(resource));
RepositoryResource parentResource = new RepositoryResource();
parentResource.setId(groupId);
parentResource.setName("二级目录");
when(repositoryResourceService.findById(anyInt())).thenReturn(Optional.of(parentResource));
CheckGroupNameParam param = new CheckGroupNameParam();
param.setName("a-used-name");
param.setParentId(groupId);
given().contentType(ContentType.JSON).body(param).when().post("/repos/{owner}/{repoName}/groups/check-name", "jack", "repo").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.name", hasItem("二级目录下已存在备注<strong>a-used-name</strong>"), "errors.name.size()", is(1));
}
18
Source : GroupControllerTest.java
with MIT License
from blocklang
with MIT License
from blocklang
@WithMockUser(username = "jack")
@Test
public void checkNameIsUsedAtRoot() {
Repository repository = new Repository();
repository.setId(1);
when(repositoryService.find(anyString(), anyString())).thenReturn(Optional.of(repository));
when(repositoryPermissionService.canWrite(any(), any())).thenReturn(Optional.of(AccessLevel.WRITE));
RepositoryResource resource = new RepositoryResource();
when(repositoryResourceService.findByName(anyInt(), anyInt(), any(), any(), anyString())).thenReturn(Optional.of(resource));
when(repositoryResourceService.findById(anyInt())).thenReturn(Optional.of(new RepositoryResource()));
CheckGroupNameParam param = new CheckGroupNameParam();
param.setName("a-used-name");
param.setParentId(Constant.TREE_ROOT_ID);
given().contentType(ContentType.JSON).body(param).when().post("/repos/{owner}/{repoName}/groups/check-name", "jack", "repo").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.name", hasItem("根目录下已存在备注<strong>a-used-name</strong>"), "errors.name.size()", is(1));
}
18
Source : GroupControllerTest.java
with MIT License
from blocklang
with MIT License
from blocklang
@WithMockUser(username = "jack")
@Test
public void checkKeyIsUsedAtRoot() {
Repository repository = new Repository();
repository.setId(1);
when(repositoryService.find(anyString(), anyString())).thenReturn(Optional.of(repository));
when(repositoryPermissionService.canWrite(any(), any())).thenReturn(Optional.of(AccessLevel.WRITE));
RepositoryResource resource = new RepositoryResource();
when(repositoryResourceService.findByKey(anyInt(), anyInt(), any(), any(), anyString())).thenReturn(Optional.of(resource));
when(repositoryResourceService.findById(anyInt())).thenReturn(Optional.of(new RepositoryResource()));
CheckGroupKeyParam param = new CheckGroupKeyParam();
param.setKey("a-used-key");
param.setParentId(Constant.TREE_ROOT_ID);
given().contentType(ContentType.JSON).body(param).when().post("/repos/{owner}/{repoName}/groups/check-key", "jack", "repo").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.key", hasItem("根目录下已存在名称<strong>a-used-key</strong>"), "errors.key.size()", is(1));
}
18
Source : GroupControllerTest.java
with MIT License
from blocklang
with MIT License
from blocklang
@WithMockUser(username = "jack")
@Test
public void newGroupCheckKeyIsBlankAndNamePreplaceded() {
NewGroupParam param = new NewGroupParam();
param.setParentId(Constant.TREE_ROOT_ID);
param.setKey(" ");
param.setName("name");
Repository repository = new Repository();
repository.setId(1);
when(repositoryService.find(anyString(), anyString())).thenReturn(Optional.of(repository));
when(repositoryPermissionService.canWrite(any(), any())).thenReturn(Optional.of(AccessLevel.WRITE));
when(repositoryResourceService.findByName(anyInt(), anyInt(), any(), any(), anyString())).thenReturn(Optional.empty());
given().contentType(ContentType.JSON).body(param).when().post("/repos/{owner}/{repoName}/groups", "jack", "repo").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.key", hasItem("名称不能为空"), "errors.key.size()", is(1), "errors.name", is(nullValue()));
}
18
Source : GroupControllerTest.java
with MIT License
from blocklang
with MIT License
from blocklang
@WithMockUser(username = "jack")
@Test
public void checkKeyIsUsedAtSub() {
Repository repository = new Repository();
repository.setId(1);
when(repositoryService.find(anyString(), anyString())).thenReturn(Optional.of(repository));
when(repositoryPermissionService.canWrite(any(), any())).thenReturn(Optional.of(AccessLevel.WRITE));
Integer groupId = 1;
RepositoryResource resource = new RepositoryResource();
resource.setParentId(groupId);
when(repositoryResourceService.findByKey(anyInt(), anyInt(), any(), any(), anyString())).thenReturn(Optional.of(resource));
RepositoryResource parentResource = new RepositoryResource();
parentResource.setId(groupId);
parentResource.setName("二级目录");
when(repositoryResourceService.findById(anyInt())).thenReturn(Optional.of(parentResource));
CheckGroupKeyParam param = new CheckGroupKeyParam();
param.setKey("a-used-key");
param.setParentId(groupId);
given().contentType(ContentType.JSON).body(param).when().post("/repos/{owner}/{repoName}/groups/check-key", "jack", "repo").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.key", hasItem("二级目录下已存在名称<strong>a-used-key</strong>"), "errors.key.size()", is(1));
}
18
Source : GroupControllerTest.java
with MIT License
from blocklang
with MIT License
from blocklang
@WithMockUser(username = "jack")
@Test
public void newGroupCheckKeyIsUsedAndNameIsUsed() {
NewGroupParam param = new NewGroupParam();
param.setParentId(Constant.TREE_ROOT_ID);
param.setKey("a-used-key");
param.setName("a-used-name");
Repository repository = new Repository();
repository.setId(1);
when(repositoryService.find(anyString(), anyString())).thenReturn(Optional.of(repository));
when(repositoryPermissionService.canWrite(any(), any())).thenReturn(Optional.of(AccessLevel.WRITE));
RepositoryResource resource1 = new RepositoryResource();
when(repositoryResourceService.findByKey(anyInt(), anyInt(), any(), any(), anyString())).thenReturn(Optional.of(resource1));
RepositoryResource resource2 = new RepositoryResource();
when(repositoryResourceService.findByName(anyInt(), anyInt(), any(), any(), anyString())).thenReturn(Optional.of(resource2));
when(repositoryResourceService.findById(anyInt())).thenReturn(Optional.of(new RepositoryResource()));
given().contentType(ContentType.JSON).body(param).when().post("/repos/{owner}/{repoName}/groups", "jack", "repo").then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENreplacedY).body("errors.key", hasItem("根目录下已存在名称<strong>a-used-key</strong>"), "errors.key.size()", is(1), "errors.name", hasItem("根目录下已存在备注<strong>a-used-name</strong>"), "errors.name.size()", is(1));
}
See More Examples