Search in sources :

Example 1 with EntityId

use of org.sonatype.nexus.common.entity.EntityId in project nexus-repository-r by sonatype-nexus-community.

the class RRoutingRuleIT method testBlockedRoutingRule.

@Test
public void testBlockedRoutingRule() throws Exception {
    String packageFileName = "agricolae_1.0-1.tar.gz";
    String allowedPackagePath = "bin/macosx/el-capitan/contrib/1.0/agricolae_1.0-1.tar.gz";
    String blockedPackagePath = "bin/macosx/el-capitan/contrib/1.1/agricolae_1.0-1.tar.gz";
    configureProxyBehaviour(allowedPackagePath, packageFileName);
    configureProxyBehaviour(blockedPackagePath, packageFileName);
    EntityId routingRuleId = createBlockedRoutingRule("r-blocking-rule", ".*/1.1/.*");
    Repository proxyRepo = repos.createRProxy("test-r-blocking-proxy", proxyServer.getUrl().toString());
    RClient client = rClient(proxyRepo);
    attachRuleToRepository(proxyRepo, routingRuleId);
    assertGetResponseStatus(client, proxyRepo, blockedPackagePath, 403);
    assertGetResponseStatus(client, proxyRepo, allowedPackagePath, 200);
    assertNoRequests(blockedPackagePath);
}
Also used : EntityId(org.sonatype.nexus.common.entity.EntityId) Repository(org.sonatype.nexus.repository.Repository) Test(org.junit.Test)

Example 2 with EntityId

use of org.sonatype.nexus.common.entity.EntityId in project nexus-repository-r by sonatype-nexus-community.

the class RComponentDirectorTest method allowMoveTest.

@Test
public void allowMoveTest() {
    RComponentDirector director = new RComponentDirector(bucketStore, repositoryManager);
    assertTrue(director.allowMoveTo(destination));
    assertTrue(director.allowMoveFrom(source));
    EntityId bucketId = mock(EntityId.class);
    when(component.bucketId()).thenReturn(bucketId);
    Bucket bucket = mock(Bucket.class);
    when(bucketStore.getById(bucketId)).thenReturn(bucket);
    when(bucket.getRepositoryName()).thenReturn("repo");
    when(repositoryManager.get("repo")).thenReturn(source);
    assertTrue(director.allowMoveTo(component, destination));
    assertTrue(director.allowMoveTo(destination));
}
Also used : EntityId(org.sonatype.nexus.common.entity.EntityId) Bucket(org.sonatype.nexus.repository.storage.Bucket) Test(org.junit.Test)

Example 3 with EntityId

use of org.sonatype.nexus.common.entity.EntityId in project nexus-repository-r by sonatype-nexus-community.

the class RComponentMaintenance method deleteAssetTx.

/**
 * Deletes the asset and its component if it's the only asset in it.
 */
@Override
@TransactionalDeleteBlob
protected Set<String> deleteAssetTx(final EntityId assetId, final boolean deleteBlob) {
    StorageTx tx = UnitOfWork.currentTx();
    final Asset asset = tx.findAsset(assetId, tx.findBucket(getRepository()));
    if (asset == null) {
        return Collections.emptySet();
    }
    final EntityId componentId = asset.componentId();
    if (componentId == null) {
        // Assets without components should be deleted on their own
        return super.deleteAssetTx(assetId, deleteBlob);
    }
    final Component component = tx.findComponent(componentId);
    if (Iterables.size(tx.browseAssets(component)) == 1) {
        // Component with only one asset should be deleted as well with its asset
        return deleteComponentTx(componentId, deleteBlob).getAssets();
    } else {
        return super.deleteAssetTx(assetId, deleteBlob);
    }
}
Also used : EntityId(org.sonatype.nexus.common.entity.EntityId) StorageTx(org.sonatype.nexus.repository.storage.StorageTx) Asset(org.sonatype.nexus.repository.storage.Asset) Component(org.sonatype.nexus.repository.storage.Component) TransactionalDeleteBlob(org.sonatype.nexus.repository.transaction.TransactionalDeleteBlob)

Aggregations

EntityId (org.sonatype.nexus.common.entity.EntityId)3 Test (org.junit.Test)2 Repository (org.sonatype.nexus.repository.Repository)1 Asset (org.sonatype.nexus.repository.storage.Asset)1 Bucket (org.sonatype.nexus.repository.storage.Bucket)1 Component (org.sonatype.nexus.repository.storage.Component)1 StorageTx (org.sonatype.nexus.repository.storage.StorageTx)1 TransactionalDeleteBlob (org.sonatype.nexus.repository.transaction.TransactionalDeleteBlob)1