Search in sources :

Example 11 with ValidationError

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);
    }
}
Also used : RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) RemoteRepository(org.apache.archiva.repository.RemoteRepository) EditableRemoteRepository(org.apache.archiva.repository.EditableRemoteRepository) ValidationError(org.apache.archiva.repository.validation.ValidationError) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 12 with ValidationError

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"));
}
Also used : RemoteRepository(org.apache.archiva.repository.RemoteRepository) EditableRemoteRepository(org.apache.archiva.repository.EditableRemoteRepository) ValidationError(org.apache.archiva.repository.validation.ValidationError) Map(java.util.Map) EditableRemoteRepository(org.apache.archiva.repository.EditableRemoteRepository) Test(org.junit.jupiter.api.Test)

Example 13 with ValidationError

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);
    }
}
Also used : RemoteRepository(org.apache.archiva.repository.RemoteRepository) EditableRemoteRepository(org.apache.archiva.repository.EditableRemoteRepository) ValidationError(org.apache.archiva.repository.validation.ValidationError) Map(java.util.Map) EditableRemoteRepository(org.apache.archiva.repository.EditableRemoteRepository) Test(org.junit.jupiter.api.Test)

Example 14 with ValidationError

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));
    }
}
Also used : RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup) RepositoryGroup(org.apache.archiva.rest.api.v2.model.RepositoryGroup) ArchivaRestServiceException(org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException) RepositoryException(org.apache.archiva.repository.RepositoryException) ValidationError(org.apache.archiva.repository.validation.ValidationError) Map(java.util.Map)

Aggregations

Map (java.util.Map)14 ValidationError (org.apache.archiva.repository.validation.ValidationError)14 Test (org.junit.jupiter.api.Test)12 EditableRepositoryGroup (org.apache.archiva.repository.EditableRepositoryGroup)6 EditableManagedRepository (org.apache.archiva.repository.EditableManagedRepository)4 EditableRemoteRepository (org.apache.archiva.repository.EditableRemoteRepository)4 ManagedRepository (org.apache.archiva.repository.ManagedRepository)4 RemoteRepository (org.apache.archiva.repository.RemoteRepository)4 RepositoryGroup (org.apache.archiva.repository.RepositoryGroup)4 RepositoryGroupConfiguration (org.apache.archiva.configuration.model.RepositoryGroupConfiguration)3 RepositoryException (org.apache.archiva.repository.RepositoryException)2 RepositoryGroup (org.apache.archiva.rest.api.v2.model.RepositoryGroup)2 ArchivaRestServiceException (org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException)2 ArrayList (java.util.ArrayList)1 ManagedRepositoryConfiguration (org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)1 RemoteRepositoryConfiguration (org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)1