|
| 1 | +package org.commonjava.indy.folo.ftest.content.admin; |
| 2 | + |
| 3 | +import org.commonjava.indy.client.core.IndyClientModule; |
| 4 | +import org.commonjava.indy.folo.client.IndyFoloAdminClientModule; |
| 5 | +import org.commonjava.indy.folo.client.IndyFoloContentClientModule; |
| 6 | +import org.commonjava.indy.ftest.core.AbstractContentManagementTest; |
| 7 | +import org.commonjava.indy.model.core.BatchDeleteRequest; |
| 8 | +import org.commonjava.indy.model.core.HostedRepository; |
| 9 | +import org.commonjava.indy.model.core.StoreKey; |
| 10 | +import org.commonjava.indy.model.core.io.IndyObjectMapper; |
| 11 | +import org.commonjava.indy.pkg.npm.model.PackageMetadata; |
| 12 | +import org.commonjava.indy.pkg.npm.model.VersionMetadata; |
| 13 | +import org.junit.Test; |
| 14 | + |
| 15 | +import java.io.InputStream; |
| 16 | +import java.util.*; |
| 17 | + |
| 18 | +import static org.commonjava.indy.pkg.npm.model.NPMPackageTypeDescriptor.NPM_PKG_KEY; |
| 19 | +import static org.hamcrest.CoreMatchers.equalTo; |
| 20 | +import static org.hamcrest.CoreMatchers.notNullValue; |
| 21 | +import static org.junit.Assert.assertThat; |
| 22 | +import static org.junit.Assert.assertTrue; |
| 23 | + |
| 24 | +/** |
| 25 | + * <b>GIVEN:</b> |
| 26 | + * <ul> |
| 27 | + * <li>HostedRepository and the NPM packages with two versions</li> |
| 28 | + * </ul> |
| 29 | + * |
| 30 | + * <br/> |
| 31 | + * <b>WHEN:</b> |
| 32 | + * <ul> |
| 33 | + * <li>Store the package with version 1.5.1 through the FOLO id into the repository</li> |
| 34 | + * <li>Store the package with version 1.6.2 without FOLO id into the repository</li> |
| 35 | + * <li>Seal the record</li> |
| 36 | + * <li>Specifying the FOLO id to batch delete the artifacts from the repository</li> |
| 37 | + * </ul> |
| 38 | + * |
| 39 | + * <br/> |
| 40 | + * <b>THEN:</b> |
| 41 | + * <ul> |
| 42 | + * <li>The package with version 1.5.1 does not exist in the repository</li> |
| 43 | + * <li>The package with version 1.6.2 still exists in the repository</li> |
| 44 | + * </ul> |
| 45 | + */ |
| 46 | +public class BatchDeletionOfNPMPackagesTest extends AbstractContentManagementTest |
| 47 | +{ |
| 48 | + |
| 49 | + @Test |
| 50 | + public void test() throws Exception |
| 51 | + { |
| 52 | + |
| 53 | + final String trackingId = newName(); |
| 54 | + |
| 55 | + final InputStream content1 = |
| 56 | + Thread.currentThread().getContextClassLoader().getResourceAsStream( "package-1.5.1.json" ); |
| 57 | + |
| 58 | + final InputStream content2 = |
| 59 | + Thread.currentThread().getContextClassLoader().getResourceAsStream( "package-1.6.2.json" ); |
| 60 | + |
| 61 | + final String path = "jquery"; |
| 62 | + |
| 63 | + final String firstTarballPath = "jquery/-/jquery-1.5.1.tgz"; |
| 64 | + final String firstVersionPath = "jquery/1.5.1"; |
| 65 | + |
| 66 | + final String secondTarballPath = "jquery/-/jquery-1.6.2.tgz"; |
| 67 | + final String secondVersionPath = "jquery/1.6.2"; |
| 68 | + |
| 69 | + HostedRepository repo = client.stores().create(new HostedRepository(NPM_PKG_KEY, STORE), "adding npm hosted repo", HostedRepository.class); |
| 70 | + |
| 71 | + StoreKey storeKey = repo.getKey(); |
| 72 | + |
| 73 | + client.module( IndyFoloContentClientModule.class ).store( trackingId, storeKey, path, content1 ); |
| 74 | + client.content().store( storeKey, path, content2 ); |
| 75 | + |
| 76 | + IndyFoloAdminClientModule adminModule = client.module( IndyFoloAdminClientModule.class ); |
| 77 | + boolean success = adminModule.sealTrackingRecord( trackingId ); |
| 78 | + assertTrue( success ); |
| 79 | + |
| 80 | + final InputStream is = client.content().get( storeKey, path ); |
| 81 | + |
| 82 | + IndyObjectMapper mapper = new IndyObjectMapper( true ); |
| 83 | + PackageMetadata packageMetadata = mapper.readValue( is, PackageMetadata.class ); |
| 84 | + |
| 85 | + Map<String, VersionMetadata> versions = packageMetadata.getVersions(); |
| 86 | + assertThat( versions, notNullValue() ); |
| 87 | + assertThat( versions.size(), equalTo( 2 ) ); |
| 88 | + assertThat( versions.get( "1.5.1" ).getVersion(), equalTo( "1.5.1" ) ); |
| 89 | + assertThat( versions.get( "1.6.2" ).getVersion(), equalTo( "1.6.2" ) ); |
| 90 | + |
| 91 | + assertThat( client.content().exists( storeKey, firstTarballPath ), equalTo( true ) ); |
| 92 | + assertThat( client.content().exists( storeKey, firstVersionPath ), equalTo( true ) ); |
| 93 | + |
| 94 | + assertThat( client.content().exists( storeKey, secondTarballPath ), equalTo( true ) ); |
| 95 | + assertThat( client.content().exists( storeKey, secondVersionPath ), equalTo( true ) ); |
| 96 | + |
| 97 | + content1.close(); |
| 98 | + content2.close(); |
| 99 | + |
| 100 | + BatchDeleteRequest request = new BatchDeleteRequest(); |
| 101 | + request.setStoreKey( storeKey ); |
| 102 | + request.setTrackingID( trackingId ); |
| 103 | + |
| 104 | + adminModule.deleteFilesFromStoreByTrackingID( request ); |
| 105 | + |
| 106 | + final InputStream is_2 = client.content().get( storeKey, path ); |
| 107 | + |
| 108 | + packageMetadata = mapper.readValue( is_2, PackageMetadata.class ); |
| 109 | + |
| 110 | + versions = packageMetadata.getVersions(); |
| 111 | + assertThat( versions, notNullValue() ); |
| 112 | + assertThat( versions.size(), equalTo( 1 ) ); |
| 113 | + assertThat( versions.get( "1.6.2" ).getVersion(), equalTo( "1.6.2" ) ); |
| 114 | + |
| 115 | + assertThat( client.content().exists( storeKey, firstTarballPath ), equalTo( false ) ); |
| 116 | + assertThat( client.content().exists( storeKey, firstVersionPath ), equalTo( false ) ); |
| 117 | + |
| 118 | + assertThat( client.content().exists( storeKey, secondTarballPath ), equalTo( true ) ); |
| 119 | + assertThat( client.content().exists( storeKey, secondVersionPath ), equalTo( true ) ); |
| 120 | + |
| 121 | + } |
| 122 | + |
| 123 | + @Override |
| 124 | + protected Collection<IndyClientModule> getAdditionalClientModules() |
| 125 | + { |
| 126 | + return Arrays.asList( new IndyFoloContentClientModule(), new IndyFoloAdminClientModule() ); |
| 127 | + } |
| 128 | +} |
0 commit comments