remove unnecessary methods for getting artifact by id

Signed-off-by: Michael Hirsch <michael.hirsch@bosch-si.com>
This commit is contained in:
Michael Hirsch
2016-10-20 12:33:25 +02:00
committed by Kai Zimmermann
parent e97ed04c94
commit b2a16613c5
3 changed files with 0 additions and 121 deletions

View File

@@ -96,18 +96,6 @@ public class ArtifactStore implements ArtifactRepository {
return map(gridFs.findOne(new Query().addCriteria(Criteria.where(MD5).is(md5Hash))));
}
/**
* Retrieves a {@link GridFSDBFile} from the store by it's object id.
*
* @param id
* the id of the file to lookup.
* @return The gridfs file object or {@code null} if no file exists.
*/
@Override
public DbArtifact getArtifactById(final String id) {
return map(gridFs.findOne(new Query().addCriteria(Criteria.where(ID).is(id))));
}
@Override
public DbArtifact store(final InputStream content, final String filename, final String contentType) {
return store(content, filename, contentType, null);
@@ -134,15 +122,6 @@ public class ArtifactStore implements ArtifactRepository {
}
}
@Override
public void deleteById(final String artifactId) {
try {
deleteArtifact(gridFs.findOne(new Query().addCriteria(Criteria.where(ID).is(artifactId))));
} catch (final MongoException e) {
throw new ArtifactStoreException(e.getMessage(), e);
}
}
@Override
public void deleteBySha1(final String sha1Hash) {
try {
@@ -230,19 +209,6 @@ public class ArtifactStore implements ArtifactRepository {
return dbFiles.stream().map(ArtifactStore::map).collect(Collectors.toList());
}
/**
* Retrieves a list of {@link GridFSDBFile} from the store by all SHA1
* hashes.
*
* @param sha1Hashes
* the sha1-hashes of the files to lookup.
* @return list of artifacts
*/
@Override
public List<DbArtifact> getArtifactsBySha1(final List<String> sha1Hashes) {
return map(gridFs.find(new Query().addCriteria(Criteria.where(SHA1).in(sha1Hashes))));
}
/**
* Retrieves a list of {@link GridFSDBFile} from the store by all ids.
*

View File

@@ -11,27 +11,21 @@ package org.eclipse.hawkbit.artifact.repository;
import static org.fest.assertions.api.Assertions.assertThat;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Random;
import org.apache.commons.io.IOUtils;
import org.eclipse.hawkbit.artifact.TestConfiguration;
import org.eclipse.hawkbit.artifact.repository.model.DbArtifact;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.gridfs.GridFsOperations;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.google.common.io.BaseEncoding;
import com.mongodb.gridfs.GridFSDBFile;
import ru.yandex.qatools.allure.annotations.Description;
import ru.yandex.qatools.allure.annotations.Features;
@@ -50,19 +44,6 @@ public class ArtifactStoreTest {
@Autowired
private GridFsOperations gridFs;
@Test
@Description("Ensures that storage in MongoDB is correctly executed.s")
public void storeArtifactInMongoDB() {
final int filelengthBytes = 128;
final String filename = "testfile.json";
final String contentType = "application/json";
final DbArtifact storedFile = artifactStoreUnderTest.store(generateInputStream(filelengthBytes), filename,
contentType);
assertThat(storedFile).isNotNull();
assertThat(artifactStoreUnderTest.getArtifactById(storedFile.getArtifactId())).isNotNull();
}
@Test
@Description("Ensures that search by SHA1 hash (which is used by hawkBit as artifact ID) finds the expected results.")
public void findArtifactBySHA1Hash() throws NoSuchAlgorithmException {
@@ -89,43 +70,6 @@ public class ArtifactStoreTest {
BaseEncoding.base16().lowerCase().encode(digestInputStream.getMessageDigest().digest()))).isNotNull();
}
@Test
@Description("Ensures that artifact content can be read through InputStream.")
public void getInputStreamFromArtifact() throws IOException {
final int filelengthBytes = 128;
final String filename = "testfile.json";
final String contentType = "application/json";
final ByteArrayInputStream inputStream = generateInputStream(filelengthBytes);
final DbArtifact artifact = artifactStoreUnderTest
.getArtifactById(artifactStoreUnderTest.store(inputStream, filename, contentType).getArtifactId());
inputStream.reset();
final byte[] artifactBytes = new byte[filelengthBytes];
final byte[] artifactStoredBytes = new byte[filelengthBytes];
IOUtils.readFully(inputStream, artifactBytes);
IOUtils.readFully(artifact.getFileInputStream(), artifactStoredBytes);
assertThat(artifactBytes).isEqualTo(artifactStoredBytes);
}
@Test
@Description("Ensures that artifact delete actually results in deletion from database.")
public void deleteArtifact() throws NoSuchAlgorithmException {
final int filelengthBytes = 128;
final String filename = "testfile.json";
final String contentType = "application/json";
final DigestInputStream digestInputStream = digestInputStream(generateInputStream(filelengthBytes), "SHA-1");
final DbArtifact store = artifactStoreUnderTest.store(digestInputStream, filename, contentType);
artifactStoreUnderTest.deleteById(store.getArtifactId());
final GridFSDBFile findOne = gridFs
.findOne(new Query().addCriteria(Criteria.where("_id").is(store.getArtifactId())));
assertThat(findOne).isNull();
}
private static ByteArrayInputStream generateInputStream(final int length) {
final byte[] bytes = new byte[length];
new Random().nextBytes(bytes);

View File

@@ -9,7 +9,6 @@
package org.eclipse.hawkbit.artifact.repository;
import java.io.InputStream;
import java.util.List;
import org.eclipse.hawkbit.artifact.repository.model.DbArtifact;
import org.eclipse.hawkbit.artifact.repository.model.DbArtifactHash;
@@ -60,14 +59,6 @@ public interface ArtifactRepository {
*/
DbArtifact store(final InputStream content, final String filename, final String contentType, DbArtifactHash hash);
/**
* Deletes an artifact by its ID.
*
* @param artifactId
* the ID of the artifact to delete
*/
void deleteById(final String artifactId);
/**
* Deletes an artifact by its SHA1 hash.
*
@@ -84,26 +75,4 @@ public interface ArtifactRepository {
* @return The artifact file object or {@code null} if no file exists.
*/
DbArtifact getArtifactBySha1(String sha1);
/**
* Retrieves a {@link DbArtifact} from the store by it's ID.
*
* @param id
* the ID of the artifact to retrieve
* @return The artifact file object or {@code null} if no file exists.
*/
DbArtifact getArtifactById(final String id);
/**
* Retrieves a list of {@link GridFSDBFile} from the store by all SHA1
* hashes.
*
* @param tenant
* the tenant to retrieve the artifacts from, ignore case.
* @param sha1Hashes
* the sha1-hashes of the files to lookup.
* @return list of artfiacts
*/
List<DbArtifact> getArtifactsBySha1(final List<String> sha1Hashes);
}