@Test public void testResolveArgumentThrowingStorageNotFoundException() throws MissingPathVariableException { Map<String, String> uriTemplateVars = new HashMap<>(); uriTemplateVars.put("storageId", "storage-nuget"); uriTemplateVars.put("repositoryId", "pypi-releases"); nativeWebRequest.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars, RequestAttributes.SCOPE_REQUEST); mockStoragesAndRepositories(RepositoryStatusEnum.IN_SERVICE); MethodParameter uploadArtifactWithOutOfServiceRepositoryNotAllowedMethod = getMethodParameter("uploadArtifactWithOutOfServiceRepositoryNotAllowed", Repository.class); StorageNotFoundException storageNotFoundException = Assertions.assertThrows(StorageNotFoundException.class, () -> repositoryMethodArgumentResolver.resolveArgument(uploadArtifactWithOutOfServiceRepositoryNotAllowedMethod, modelAndViewContainer, nativeWebRequest, webDataBinderFactory)); assertEquals(String.format(RepositoryMethodArgumentResolver.NOT_FOUND_STORAGE_MESSAGE, uriTemplateVars.get("storageId")), storageNotFoundException.getMessage()); mockStoragesAndRepositories(RepositoryStatusEnum.OUT_OF_SERVICE); storageNotFoundException = Assertions.assertThrows(StorageNotFoundException.class, () -> repositoryMethodArgumentResolver.resolveArgument(uploadArtifactWithOutOfServiceRepositoryNotAllowedMethod, modelAndViewContainer, nativeWebRequest, webDataBinderFactory)); assertEquals(String.format(RepositoryMethodArgumentResolver.NOT_FOUND_STORAGE_MESSAGE, uriTemplateVars.get("storageId")), storageNotFoundException.getMessage()); }
@Override public Object resolveArgument(final MethodParameter parameter, final ModelAndViewContainer modelAndViewContainer, final NativeWebRequest nativeWebRequest, final WebDataBinderFactory webDataBinderFactory) throws MissingPathVariableException { final RepositoryMapping repositoryMapping = parameter.getParameterAnnotation(RepositoryMapping.class); final String storageVariableName = repositoryMapping.storageVariableName(); final String storageId = getRequiredPathVariable(parameter, nativeWebRequest, storageVariableName); final String repositoryVariableName = repositoryMapping.repositoryVariableName(); final String repositoryId = getRequiredPathVariable(parameter, nativeWebRequest, repositoryVariableName); Repository repository = (Repository) nativeWebRequest.getAttribute(REPOSITORY_REQUEST_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST); if (repository != null && Objects.equals(repository.getId(), repositoryId) && Objects.equals(repository.getStorage().getId(), storageId)) { return repository; } final Storage storage = getStorage(storageId); if (storage == null) { final String message = String.format(NOT_FOUND_STORAGE_MESSAGE, storageId); throw new StorageNotFoundException(message); } repository = getRepository(storageId, repositoryId); if (repository == null) { final String message = String.format(NOT_FOUND_REPOSITORY_MESSAGE, storageId, repositoryId); throw new RepositoryNotFoundException(message); } if (!repository.isInService() && !repositoryMapping.allowOutOfServiceRepository()) { final String message = String.format(NOT_IN_SERVICE_REPOSITORY_MESSAGE, storageId, repositoryId); throw new ServiceUnavailableException(message); } return repository; }
RepositoryMethodArgumentResolver implements HandlerMethodArgumentResolver { @Override public Object resolveArgument(final MethodParameter parameter, final ModelAndViewContainer modelAndViewContainer, final NativeWebRequest nativeWebRequest, final WebDataBinderFactory webDataBinderFactory) throws MissingPathVariableException { final RepositoryMapping repositoryMapping = parameter.getParameterAnnotation(RepositoryMapping.class); final String storageVariableName = repositoryMapping.storageVariableName(); final String storageId = getRequiredPathVariable(parameter, nativeWebRequest, storageVariableName); final String repositoryVariableName = repositoryMapping.repositoryVariableName(); final String repositoryId = getRequiredPathVariable(parameter, nativeWebRequest, repositoryVariableName); Repository repository = (Repository) nativeWebRequest.getAttribute(REPOSITORY_REQUEST_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST); if (repository != null && Objects.equals(repository.getId(), repositoryId) && Objects.equals(repository.getStorage().getId(), storageId)) { return repository; } final Storage storage = getStorage(storageId); if (storage == null) { final String message = String.format(NOT_FOUND_STORAGE_MESSAGE, storageId); throw new StorageNotFoundException(message); } repository = getRepository(storageId, repositoryId); if (repository == null) { final String message = String.format(NOT_FOUND_REPOSITORY_MESSAGE, storageId, repositoryId); throw new RepositoryNotFoundException(message); } if (!repository.isInService() && !repositoryMapping.allowOutOfServiceRepository()) { final String message = String.format(NOT_IN_SERVICE_REPOSITORY_MESSAGE, storageId, repositoryId); throw new ServiceUnavailableException(message); } return repository; } }
RepositoryMethodArgumentResolver implements HandlerMethodArgumentResolver { @Override public Object resolveArgument(final MethodParameter parameter, final ModelAndViewContainer modelAndViewContainer, final NativeWebRequest nativeWebRequest, final WebDataBinderFactory webDataBinderFactory) throws MissingPathVariableException { final RepositoryMapping repositoryMapping = parameter.getParameterAnnotation(RepositoryMapping.class); final String storageVariableName = repositoryMapping.storageVariableName(); final String storageId = getRequiredPathVariable(parameter, nativeWebRequest, storageVariableName); final String repositoryVariableName = repositoryMapping.repositoryVariableName(); final String repositoryId = getRequiredPathVariable(parameter, nativeWebRequest, repositoryVariableName); Repository repository = (Repository) nativeWebRequest.getAttribute(REPOSITORY_REQUEST_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST); if (repository != null && Objects.equals(repository.getId(), repositoryId) && Objects.equals(repository.getStorage().getId(), storageId)) { return repository; } final Storage storage = getStorage(storageId); if (storage == null) { final String message = String.format(NOT_FOUND_STORAGE_MESSAGE, storageId); throw new StorageNotFoundException(message); } repository = getRepository(storageId, repositoryId); if (repository == null) { final String message = String.format(NOT_FOUND_REPOSITORY_MESSAGE, storageId, repositoryId); throw new RepositoryNotFoundException(message); } if (!repository.isInService() && !repositoryMapping.allowOutOfServiceRepository()) { final String message = String.format(NOT_IN_SERVICE_REPOSITORY_MESSAGE, storageId, repositoryId); throw new ServiceUnavailableException(message); } return repository; }  }
RepositoryMethodArgumentResolver implements HandlerMethodArgumentResolver { @Override public Object resolveArgument(final MethodParameter parameter, final ModelAndViewContainer modelAndViewContainer, final NativeWebRequest nativeWebRequest, final WebDataBinderFactory webDataBinderFactory) throws MissingPathVariableException { final RepositoryMapping repositoryMapping = parameter.getParameterAnnotation(RepositoryMapping.class); final String storageVariableName = repositoryMapping.storageVariableName(); final String storageId = getRequiredPathVariable(parameter, nativeWebRequest, storageVariableName); final String repositoryVariableName = repositoryMapping.repositoryVariableName(); final String repositoryId = getRequiredPathVariable(parameter, nativeWebRequest, repositoryVariableName); Repository repository = (Repository) nativeWebRequest.getAttribute(REPOSITORY_REQUEST_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST); if (repository != null && Objects.equals(repository.getId(), repositoryId) && Objects.equals(repository.getStorage().getId(), storageId)) { return repository; } final Storage storage = getStorage(storageId); if (storage == null) { final String message = String.format(NOT_FOUND_STORAGE_MESSAGE, storageId); throw new StorageNotFoundException(message); } repository = getRepository(storageId, repositoryId); if (repository == null) { final String message = String.format(NOT_FOUND_REPOSITORY_MESSAGE, storageId, repositoryId); throw new RepositoryNotFoundException(message); } if (!repository.isInService() && !repositoryMapping.allowOutOfServiceRepository()) { final String message = String.format(NOT_IN_SERVICE_REPOSITORY_MESSAGE, storageId, repositoryId); throw new ServiceUnavailableException(message); } return repository; }  @Override boolean supportsParameter(final MethodParameter parameter); @Override Object resolveArgument(final MethodParameter parameter,
                                  final ModelAndViewContainer modelAndViewContainer,
                                  final NativeWebRequest nativeWebRequest,
                                  final WebDataBinderFactory webDataBinderFactory); }
RepositoryMethodArgumentResolver implements HandlerMethodArgumentResolver { @Override public Object resolveArgument(final MethodParameter parameter, final ModelAndViewContainer modelAndViewContainer, final NativeWebRequest nativeWebRequest, final WebDataBinderFactory webDataBinderFactory) throws MissingPathVariableException { final RepositoryMapping repositoryMapping = parameter.getParameterAnnotation(RepositoryMapping.class); final String storageVariableName = repositoryMapping.storageVariableName(); final String storageId = getRequiredPathVariable(parameter, nativeWebRequest, storageVariableName); final String repositoryVariableName = repositoryMapping.repositoryVariableName(); final String repositoryId = getRequiredPathVariable(parameter, nativeWebRequest, repositoryVariableName); Repository repository = (Repository) nativeWebRequest.getAttribute(REPOSITORY_REQUEST_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST); if (repository != null && Objects.equals(repository.getId(), repositoryId) && Objects.equals(repository.getStorage().getId(), storageId)) { return repository; } final Storage storage = getStorage(storageId); if (storage == null) { final String message = String.format(NOT_FOUND_STORAGE_MESSAGE, storageId); throw new StorageNotFoundException(message); } repository = getRepository(storageId, repositoryId); if (repository == null) { final String message = String.format(NOT_FOUND_REPOSITORY_MESSAGE, storageId, repositoryId); throw new RepositoryNotFoundException(message); } if (!repository.isInService() && !repositoryMapping.allowOutOfServiceRepository()) { final String message = String.format(NOT_IN_SERVICE_REPOSITORY_MESSAGE, storageId, repositoryId); throw new ServiceUnavailableException(message); } return repository; }  @Override boolean supportsParameter(final MethodParameter parameter); @Override Object resolveArgument(final MethodParameter parameter,
                                  final ModelAndViewContainer modelAndViewContainer,
                                  final NativeWebRequest nativeWebRequest,
                                  final WebDataBinderFactory webDataBinderFactory); static final String NOT_FOUND_STORAGE_MESSAGE; static final String NOT_FOUND_REPOSITORY_MESSAGE; static final String NOT_IN_SERVICE_REPOSITORY_MESSAGE; }