Improve artifact binary cleanup - only after commit (#2134)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2024-12-10 13:41:35 +02:00
committed by GitHub
parent d0c952f236
commit d3eeb71826
8 changed files with 128 additions and 120 deletions

View File

@@ -64,12 +64,12 @@ import org.junit.jupiter.api.Test;
*/
@Feature("Component Tests - Repository")
@Story("Artifact Management")
public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
class ArtifactManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Verifies that management get access react as specfied on calls for non existing entities by means of Optional not present.")
@ExpectEvents({ @Expect(type = SoftwareModuleCreatedEvent.class, count = 1) })
public void nonExistingEntityAccessReturnsNotPresent() {
void nonExistingEntityAccessReturnsNotPresent() {
final SoftwareModule module = testdataFactory.createSoftwareModuleOs();
assertThat(artifactManagement.get(NOT_EXIST_IDL)).isNotPresent();
@@ -85,7 +85,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
@Description("Verifies that management queries react as specfied on calls for non existing entities "
+ " by means of throwing EntityNotFoundException.")
@ExpectEvents({ @Expect(type = SoftwareModuleDeletedEvent.class, count = 0) })
public void entityQueriesReferringToNotExistingEntitiesThrowsException() throws URISyntaxException {
void entityQueriesReferringToNotExistingEntitiesThrowsException() throws URISyntaxException {
final String artifactData = "test";
final int artifactSize = artifactData.length();
@@ -110,7 +110,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Test if a local artifact can be created by API including metadata.")
public void createArtifact() throws IOException {
void createArtifact() throws IOException {
// check baseline
assertThat(softwareModuleRepository.findAll()).hasSize(0);
@@ -161,7 +161,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Verifies that artifact management does not create artifacts with illegal filename.")
public void entityQueryWithIllegalFilenameThrowsException() throws URISyntaxException {
void entityQueryWithIllegalFilenameThrowsException() throws URISyntaxException {
final String illegalFilename = "<img src=ernw onerror=alert(1)>.xml";
final String artifactData = "test";
final int artifactSize = artifactData.length();
@@ -176,7 +176,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Verifies that the quota specifying the maximum number of artifacts per software module is enforced.")
public void createArtifactsUntilQuotaIsExceeded() throws IOException {
void createArtifactsUntilQuotaIsExceeded() throws IOException {
// create a software module
final long smId = softwareModuleRepository.save(new JpaSoftwareModule(osType, "sm1", "1.0")).getId();
@@ -205,7 +205,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Verifies that the quota specifying the maximum artifact storage is enforced (across software modules).")
public void createArtifactsUntilStorageQuotaIsExceeded() throws IOException {
void createArtifactsUntilStorageQuotaIsExceeded() throws IOException {
// create as many small artifacts as possible w/o violating the storage
// quota
@@ -235,7 +235,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Verifies that you cannot create artifacts which exceed the configured maximum size.")
public void createArtifactFailsIfTooLarge() {
void createArtifactFailsIfTooLarge() {
// create a software module
final JpaSoftwareModule sm1 = softwareModuleRepository.save(new JpaSoftwareModule(osType, "sm1", "1.0"));
@@ -248,7 +248,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Tests hard delete directly on repository.")
public void hardDeleteSoftwareModule() throws IOException {
void hardDeleteSoftwareModule() throws IOException {
final JpaSoftwareModule sm = softwareModuleRepository
.save(new JpaSoftwareModule(osType, "name 1", "version 1"));
@@ -268,7 +268,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
*/
@Test
@Description("Tests the deletion of a local artifact including metadata.")
public void deleteArtifact() throws IOException {
void deleteArtifact() throws IOException {
final JpaSoftwareModule sm = softwareModuleRepository
.save(new JpaSoftwareModule(osType, "name 1", "version 1"));
final JpaSoftwareModule sm2 = softwareModuleRepository
@@ -320,7 +320,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Test the deletion of an artifact metadata where the binary is still linked to another metadata element. " +
"The expected result is that the metadata is deleted but the binary kept.")
public void deleteDuplicateArtifacts() throws IOException {
void deleteDuplicateArtifacts() throws IOException {
final JpaSoftwareModule sm = softwareModuleRepository
.save(new JpaSoftwareModule(osType, "name 1", "version 1"));
final JpaSoftwareModule sm2 = softwareModuleRepository
@@ -353,7 +353,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Verifies that you cannot delete an artifact which exists with the same hash, in the same tenant and the SoftwareModule is not deleted .")
public void deleteArtifactWithSameHashAndSoftwareModuleIsNotDeletedInSameTenants() throws IOException {
void deleteArtifactWithSameHashAndSoftwareModuleIsNotDeletedInSameTenants() throws IOException {
final JpaSoftwareModule sm = softwareModuleRepository
.save(new JpaSoftwareModule(osType, "name 1", "version 1"));
@@ -395,7 +395,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Verifies that you can not delete artifacts from another tenant which exists in another tenant with the same hash and the SoftwareModule is not deleted")
public void deleteArtifactWithSameHashAndSoftwareModuleIsNotDeletedInDifferentTenants() throws Exception {
void deleteArtifactWithSameHashAndSoftwareModuleIsNotDeletedInDifferentTenants() throws Exception {
final String tenant1 = "mytenant";
final String tenant2 = "tenant2";
@@ -422,7 +422,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Loads an local artifact based on given ID.")
public void findArtifact() throws IOException {
void findArtifact() throws IOException {
final int artifactSize = 5 * 1024;
try (final InputStream inputStream = new RandomGeneratedInputStream(artifactSize)) {
final Artifact artifact = createArtifactForSoftwareModule(
@@ -433,7 +433,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Loads an artifact binary based on given ID.")
public void loadStreamOfArtifact() throws IOException {
void loadStreamOfArtifact() throws IOException {
final int artifactSize = 5 * 1024;
final byte[] randomBytes = randomBytes(artifactSize);
try (final InputStream input = new ByteArrayInputStream(randomBytes)) {
@@ -448,7 +448,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
@Test
@WithUser(allSpPermissions = true, removeFromAllPermission = { SpPermission.DOWNLOAD_REPOSITORY_ARTIFACT })
@Description("Trys and fails to load an artifact without required permission. Checks if expected InsufficientPermissionException is thrown.")
public void loadArtifactBinaryWithoutDownloadArtifactThrowsPermissionDenied() {
void loadArtifactBinaryWithoutDownloadArtifactThrowsPermissionDenied() {
assertThatExceptionOfType(InsufficientPermissionException.class)
.as("Should not have worked with missing permission.")
.isThrownBy(() -> artifactManagement.loadArtifactBinary("123", 1, false));
@@ -456,7 +456,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Searches an artifact through the relations of a software module.")
public void findArtifactBySoftwareModule() throws IOException {
void findArtifactBySoftwareModule() throws IOException {
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
assertThat(artifactManagement.findBySoftwareModule(PAGE, sm.getId())).isEmpty();
@@ -469,7 +469,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Searches an artifact through the relations of a software module and the filename.")
public void findByFilenameAndSoftwareModule() throws IOException {
void findByFilenameAndSoftwareModule() throws IOException {
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
assertThat(artifactManagement.getByFilenameAndSoftwareModule("file1", sm.getId())).isNotPresent();
@@ -485,7 +485,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Verifies that creation of an artifact with none matching hashes fails.")
public void createArtifactWithNoneMatchingHashes() throws IOException, NoSuchAlgorithmException {
void createArtifactWithNoneMatchingHashes() throws IOException, NoSuchAlgorithmException {
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
final byte[] testData = RandomStringUtils.randomAlphanumeric(100).getBytes();
@@ -517,7 +517,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Verifies that creation of an artifact with matching hashes works.")
public void createArtifactWithMatchingHashes() throws IOException, NoSuchAlgorithmException {
void createArtifactWithMatchingHashes() throws IOException, NoSuchAlgorithmException {
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
final byte[] testData = RandomStringUtils.randomAlphanumeric(100).getBytes();
@@ -540,7 +540,7 @@ public class ArtifactManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Verifies that creation of an existing artifact returns a full hash list.")
public void createExistingArtifactReturnsFullHashList() throws IOException, NoSuchAlgorithmException {
void createExistingArtifactReturnsFullHashList() throws IOException, NoSuchAlgorithmException {
final SoftwareModule smOs = testdataFactory.createSoftwareModuleOs();
final SoftwareModule smApp = testdataFactory.createSoftwareModuleApp();

View File

@@ -57,13 +57,13 @@ import org.springframework.data.domain.PageRequest;
@Feature("Component Tests - Repository")
@Story("Software Module Management")
public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Verifies that management get access reacts as specified on calls for non existing entities by means "
+ "of Optional not present.")
@ExpectEvents({ @Expect(type = SoftwareModuleCreatedEvent.class, count = 1) })
public void nonExistingEntityAccessReturnsNotPresent() {
void nonExistingEntityAccessReturnsNotPresent() {
final SoftwareModule module = testdataFactory.createSoftwareModuleApp();
assertThat(softwareModuleManagement.get(1234L)).isNotPresent();
@@ -78,7 +78,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
@Description("Verifies that management queries react as specfied on calls for non existing entities "
+ " by means of throwing EntityNotFoundException.")
@ExpectEvents({ @Expect(type = SoftwareModuleCreatedEvent.class, count = 1) })
public void entityQueriesReferringToNotExistingEntitiesThrowsException() {
void entityQueriesReferringToNotExistingEntitiesThrowsException() {
final SoftwareModule module = testdataFactory.createSoftwareModuleApp();
verifyThrownExceptionBy(
@@ -138,7 +138,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Calling update without changing fields results in no recorded change in the repository including unchanged audit fields.")
public void updateNothingResultsInUnchangedRepository() {
void updateNothingResultsInUnchangedRepository() {
final SoftwareModule ah = testdataFactory.createSoftwareModuleOs();
final SoftwareModule updated = softwareModuleManagement
@@ -151,7 +151,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Calling update for changed fields results in change in the repository.")
public void updateSoftwareModuleFieldsToNewValue() {
void updateSoftwareModuleFieldsToNewValue() {
final SoftwareModule ah = testdataFactory.createSoftwareModuleOs();
final SoftwareModule updated = softwareModuleManagement
@@ -166,7 +166,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Create Software Module call fails when called for existing entity.")
public void createModuleCallFailsForExistingModule() {
void createModuleCallFailsForExistingModule() {
testdataFactory.createSoftwareModuleOs();
assertThatExceptionOfType(EntityAlreadyExistsException.class)
.as("Should not have worked as module already exists.")
@@ -175,7 +175,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("searched for software modules based on the various filter options, e.g. name,desc,type, version.")
public void findSoftwareModuleByFilters() {
void findSoftwareModuleByFilters() {
final SoftwareModule ah = softwareModuleManagement
.create(entityFactory.softwareModule().create().type(appType).name("agent-hub").version("1.0.1"));
final SoftwareModule jvm = softwareModuleManagement
@@ -217,7 +217,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Searches for software modules based on a list of IDs.")
public void findSoftwareModulesById() {
void findSoftwareModulesById() {
final List<Long> modules = Arrays.asList(testdataFactory.createSoftwareModuleOs().getId(),
testdataFactory.createSoftwareModuleApp().getId(), 624355263L);
@@ -227,7 +227,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Searches for software modules by type.")
public void findSoftwareModulesByType() {
void findSoftwareModulesByType() {
// found in test
final SoftwareModule one = testdataFactory.createSoftwareModuleOs("one");
final SoftwareModule two = testdataFactory.createSoftwareModuleOs("two");
@@ -242,7 +242,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Counts all software modules in the repsitory that are not marked as deleted.")
public void countSoftwareModulesAll() {
void countSoftwareModulesAll() {
// found in test
testdataFactory.createSoftwareModuleOs("one");
testdataFactory.createSoftwareModuleOs("two");
@@ -256,7 +256,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Deletes an artifact, which is not assigned to a Distribution Set")
public void hardDeleteOfNotAssignedArtifact() {
void hardDeleteOfNotAssignedArtifact() {
// [STEP1]: Create SoftwareModuleX with Artifacts
final SoftwareModule unassignedModule = createSoftwareModuleWithArtifacts(osType, "moduleX", "3.0.2", 2);
@@ -282,8 +282,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Deletes an artifact, which is assigned to a DistributionSet")
public void softDeleteOfAssignedArtifact() {
void softDeleteOfAssignedArtifact() {
// [STEP1]: Create SoftwareModuleX with ArtifactX
SoftwareModule assignedModule = createSoftwareModuleWithArtifacts(osType, "moduleX", "3.0.2", 2);
@@ -315,7 +314,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Delete an artifact, which has been assigned to a rolled out DistributionSet in the past")
public void softDeleteOfHistoricalAssignedArtifact() {
void softDeleteOfHistoricalAssignedArtifact() {
// Init target
final Target target = testdataFactory.createTarget();
@@ -355,7 +354,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Delete an software module with an artifact, which is also used by another software module.")
public void deleteSoftwareModulesWithSharedArtifact() {
void deleteSoftwareModulesWithSharedArtifact() {
// Init artifact binary data, target and DistributionSets
final int artifactSize = 1024;
@@ -401,7 +400,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Delete two assigned softwaremodules which share an artifact.")
public void deleteMultipleSoftwareModulesWhichShareAnArtifact() {
void deleteMultipleSoftwareModulesWhichShareAnArtifact() {
// Init artifact binary data, target and DistributionSets
final int artifactSize = 1024;
final byte[] source = RandomUtils.nextBytes(artifactSize);
@@ -460,7 +459,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Verifies that all undeleted software modules are found in the repository.")
public void countSoftwareModuleTypesAll() {
void countSoftwareModuleTypesAll() {
testdataFactory.createSoftwareModuleOs();
// one soft deleted
@@ -474,7 +473,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Verifies that software modules are returned that are assigned to given DS.")
public void findSoftwareModuleByAssignedTo() {
void findSoftwareModuleByAssignedTo() {
// test modules
final SoftwareModule one = testdataFactory.createSoftwareModuleOs();
testdataFactory.createSoftwareModuleOs("notassigned");
@@ -491,7 +490,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Checks that metadata for a software module can be created.")
public void createSoftwareModuleMetadata() {
void createSoftwareModuleMetadata() {
final String knownKey1 = "myKnownKey1";
final String knownValue1 = "myKnownValue1";
@@ -523,7 +522,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Verifies the enforcement of the metadata quota per software module.")
public void createSoftwareModuleMetadataUntilQuotaIsExceeded() {
void createSoftwareModuleMetadataUntilQuotaIsExceeded() {
// add meta data one by one
final SoftwareModule module = testdataFactory.createSoftwareModuleApp("m1");
@@ -569,7 +568,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Checks that metadata for a software module cannot be created for an existing key.")
public void createSoftwareModuleMetadataFailsIfKeyExists() {
void createSoftwareModuleMetadataFailsIfKeyExists() {
final String knownKey1 = "myKnownKey1";
final String knownValue1 = "myKnownValue1";
@@ -597,7 +596,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
@Test
@WithUser(allSpPermissions = true)
@Description("Checks that metadata for a software module can be updated.")
public void updateSoftwareModuleMetadata() {
void updateSoftwareModuleMetadata() {
final String knownKey = "myKnownKey";
final String knownValue = "myKnownValue";
final String knownUpdateValue = "myNewUpdatedValue";
@@ -637,7 +636,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Verifies that existing metadata can be deleted.")
public void deleteSoftwareModuleMetadata() {
void deleteSoftwareModuleMetadata() {
final String knownKey1 = "myKnownKey1";
final String knownValue1 = "myKnownValue1";
@@ -660,7 +659,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Verifies that non existing metadata find results in exception.")
public void findSoftwareModuleMetadataFailsIfEntryDoesNotExist() {
void findSoftwareModuleMetadataFailsIfEntryDoesNotExist() {
final String knownKey1 = "myKnownKey1";
final String knownValue1 = "myKnownValue1";
@@ -674,7 +673,7 @@ public class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Queries and loads the metadata related to a given software module.")
public void findAllSoftwareModuleMetadataBySwId() {
void findAllSoftwareModuleMetadataBySwId() {
final SoftwareModule sw1 = testdataFactory.createSoftwareModuleApp();
final int metadataCountSw1 = 8;