use of org.apache.archiva.repository.validation.ValidationError in project archiva by apache.
the class RemoteRepositoryHandlerTest method putWithCheck_invalid.
@Test
void putWithCheck_invalid() throws RepositoryException {
final String id = "test-repo-07";
final String name = "n-" + id;
try {
RemoteRepositoryHandler repoHandler = createHandler();
BasicRemoteRepositoryValidator checker = new BasicRemoteRepositoryValidator(configurationHandler);
checker.setRepositoryRegistry(repositoryRegistry);
RemoteRepositoryConfiguration configuration = new RemoteRepositoryConfiguration();
configuration.setId("");
configuration.setName(name);
CheckedResult<RemoteRepository, Map<String, List<ValidationError>>> result = repoHandler.putWithCheck(configuration, checker);
assertNull(repoHandler.get(id));
assertNotNull(result.getResult());
assertNotNull(result.getResult().get("id"));
assertEquals(2, result.getResult().get("id").size());
assertEquals(ISEMPTY, result.getResult().get("id").get(0).getType());
assertFalse(hasRepositoryInConfig(id));
assertFalse(hasRepositoryInConfig(""));
} finally {
removeRepositoryFromConfig(id);
}
}
use of org.apache.archiva.repository.validation.ValidationError in project archiva by apache.
the class RemoteRepositoryHandlerTest method validateRepository.
@Test
void validateRepository() throws IOException {
final String id = "test-repo-10";
RemoteRepositoryHandler repoHandler = createHandler();
EditableRemoteRepository repository = createRepository(id, "n-" + id);
CheckedResult<RemoteRepository, Map<String, List<ValidationError>>> result = repoHandler.validateRepository(repository);
assertNotNull(result);
assertEquals(0, result.getResult().size());
repository = createRepository(id, "n-test-repo-10###");
result = repoHandler.validateRepository(repository);
assertNotNull(result);
assertEquals(1, result.getResult().size());
assertNotNull(result.getResult().get("name"));
}
use of org.apache.archiva.repository.validation.ValidationError in project archiva by apache.
the class RemoteRepositoryHandlerTest method validateRepositoryIfExisting.
@Test
void validateRepositoryIfExisting() throws IOException, RepositoryException {
final String id = "test-repo-11";
try {
RemoteRepositoryHandler repoHandler = createHandler();
EditableRemoteRepository repository = createRepository(id, "n-" + id);
repoHandler.put(repository);
CheckedResult<RemoteRepository, Map<String, List<ValidationError>>> result = repoHandler.validateRepository(repository);
assertNotNull(result);
assertEquals(1, result.getResult().size());
} finally {
removeRepositoryFromConfig(id);
}
}
use of org.apache.archiva.repository.validation.ValidationError in project archiva by apache.
the class DefaultRepositoryGroupService method addRepositoryGroup.
@Override
public RepositoryGroup addRepositoryGroup(RepositoryGroup repositoryGroup) throws ArchivaRestServiceException {
final String groupId = repositoryGroup.getId();
if (StringUtils.isEmpty(groupId)) {
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_INVALID_ID, groupId), 422);
}
if (repositoryRegistry.hasRepositoryGroup(groupId)) {
httpServletResponse.setHeader("Location", uriInfo.getAbsolutePathBuilder().path(groupId).build().toString());
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_ID_EXISTS, groupId), 303);
}
try {
RepositoryGroupConfiguration configuration = toConfig(repositoryGroup);
CheckedResult<org.apache.archiva.repository.RepositoryGroup, Map<String, List<ValidationError>>> validationResult = repositoryRegistry.putRepositoryGroupAndValidate(configuration);
if (validationResult.isValid()) {
httpServletResponse.setStatus(201);
return RepositoryGroup.of(validationResult.getRepository());
} else {
throw ValidationException.of(validationResult.getResult());
}
} catch (RepositoryException e) {
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_ADD_FAILED));
}
}
Aggregations