@Test public void checkArtifactSizeTest() throws IOException { long size = multipartFile.getSize(); configurationManagementService.setArtifactMaxSize(STORAGE_ID, REPOSITORY_ID, size + 1000L); try { artifactOperationsValidator.checkArtifactSize(STORAGE_ID, REPOSITORY_ID, multipartFile); } catch (ArtifactResolutionException e) { } configurationManagementService.setArtifactMaxSize(STORAGE_ID, REPOSITORY_ID, size - 10L); try { artifactOperationsValidator.checkArtifactSize(STORAGE_ID, REPOSITORY_ID, multipartFile); fail("Should have thrown an ArtifactResolutionException."); } catch (ArtifactResolutionException e) { assertThat(true).isTrue(); } configurationManagementService.setArtifactMaxSize(STORAGE_ID, REPOSITORY_ID, 0L); try { artifactOperationsValidator.checkArtifactSize(STORAGE_ID, REPOSITORY_ID, multipartFile); } catch (ArtifactResolutionException e) { } Path path = Paths.get(REPOSITORY_BASEDIR, "validate-test.jar"); Files.createDirectories(path.getParent()); Files.createFile(path); MockMultipartFile emptyFile = new MockMultipartFile("artifact", "strongbox-validate-empty.jar", MediaType.APPLICATION_OCTET_STREAM_VALUE, Files.newInputStream(path)); try { artifactOperationsValidator.checkArtifactSize(STORAGE_ID, REPOSITORY_ID, emptyFile); fail("Should have thrown an ArtifactResolutionException."); } catch (ArtifactResolutionException e) { assertThat(true).isTrue(); } Files.delete(path); }
public void checkArtifactSize(String storageId, String repositoryId, MultipartFile uploadedFile) throws ArtifactResolutionException { if (uploadedFile.isEmpty() || uploadedFile.getSize() == 0) { throw new ArtifactResolutionException("Uploaded file is empty."); } Repository repository = getConfiguration().getStorage(storageId).getRepository(repositoryId); long artifactMaxSize = repository.getArtifactMaxSize(); if (artifactMaxSize > 0 && uploadedFile.getSize() > artifactMaxSize) { throw new ArtifactResolutionException("The size of the artifact exceeds the maximum size accepted by " + "this repository (" + uploadedFile.getSize() + "/" + artifactMaxSize + ")."); } }
ArtifactOperationsValidator { public void checkArtifactSize(String storageId, String repositoryId, MultipartFile uploadedFile) throws ArtifactResolutionException { if (uploadedFile.isEmpty() || uploadedFile.getSize() == 0) { throw new ArtifactResolutionException("Uploaded file is empty."); } Repository repository = getConfiguration().getStorage(storageId).getRepository(repositoryId); long artifactMaxSize = repository.getArtifactMaxSize(); if (artifactMaxSize > 0 && uploadedFile.getSize() > artifactMaxSize) { throw new ArtifactResolutionException("The size of the artifact exceeds the maximum size accepted by " + "this repository (" + uploadedFile.getSize() + "/" + artifactMaxSize + ")."); } } }
ArtifactOperationsValidator { public void checkArtifactSize(String storageId, String repositoryId, MultipartFile uploadedFile) throws ArtifactResolutionException { if (uploadedFile.isEmpty() || uploadedFile.getSize() == 0) { throw new ArtifactResolutionException("Uploaded file is empty."); } Repository repository = getConfiguration().getStorage(storageId).getRepository(repositoryId); long artifactMaxSize = repository.getArtifactMaxSize(); if (artifactMaxSize > 0 && uploadedFile.getSize() > artifactMaxSize) { throw new ArtifactResolutionException("The size of the artifact exceeds the maximum size accepted by " + "this repository (" + uploadedFile.getSize() + "/" + artifactMaxSize + ")."); } } ArtifactOperationsValidator(); }
ArtifactOperationsValidator { public void checkArtifactSize(String storageId, String repositoryId, MultipartFile uploadedFile) throws ArtifactResolutionException { if (uploadedFile.isEmpty() || uploadedFile.getSize() == 0) { throw new ArtifactResolutionException("Uploaded file is empty."); } Repository repository = getConfiguration().getStorage(storageId).getRepository(repositoryId); long artifactMaxSize = repository.getArtifactMaxSize(); if (artifactMaxSize > 0 && uploadedFile.getSize() > artifactMaxSize) { throw new ArtifactResolutionException("The size of the artifact exceeds the maximum size accepted by " + "this repository (" + uploadedFile.getSize() + "/" + artifactMaxSize + ")."); } } ArtifactOperationsValidator(); void validate(RepositoryPath repositoryPath); void checkStorageExists(String storageId); void checkRepositoryExists(String storageId,
                                      String repositoryId); void checkArtifactPath(RepositoryPath repositoryPath); void checkAllowsDeployment(Repository repository); void checkAllowsRedeployment(Repository repository,
                                        ArtifactCoordinates coordinates); void checkAllowsDeletion(Repository repository); void checkArtifactSize(String storageId,
                                  String repositoryId,
                                  MultipartFile uploadedFile); Configuration getConfiguration(); }
ArtifactOperationsValidator { public void checkArtifactSize(String storageId, String repositoryId, MultipartFile uploadedFile) throws ArtifactResolutionException { if (uploadedFile.isEmpty() || uploadedFile.getSize() == 0) { throw new ArtifactResolutionException("Uploaded file is empty."); } Repository repository = getConfiguration().getStorage(storageId).getRepository(repositoryId); long artifactMaxSize = repository.getArtifactMaxSize(); if (artifactMaxSize > 0 && uploadedFile.getSize() > artifactMaxSize) { throw new ArtifactResolutionException("The size of the artifact exceeds the maximum size accepted by " + "this repository (" + uploadedFile.getSize() + "/" + artifactMaxSize + ")."); } } ArtifactOperationsValidator(); void validate(RepositoryPath repositoryPath); void checkStorageExists(String storageId); void checkRepositoryExists(String storageId,
                                      String repositoryId); void checkArtifactPath(RepositoryPath repositoryPath); void checkAllowsDeployment(Repository repository); void checkAllowsRedeployment(Repository repository,
                                        ArtifactCoordinates coordinates); void checkAllowsDeletion(Repository repository); void checkArtifactSize(String storageId,
                                  String repositoryId,
                                  MultipartFile uploadedFile); Configuration getConfiguration();  }