Refactoring of ImageService tests.
This commit is contained in:
parent
3e4db86457
commit
d98101b8a4
@ -61,16 +61,6 @@ public class S3ImageServiceTests {
|
||||
}
|
||||
}
|
||||
|
||||
private Image createHal9000(User owner, InputStream data) throws ImageException, IOException {
|
||||
return this.imageService.create(
|
||||
owner,
|
||||
"HAL9000.svg",
|
||||
data,
|
||||
"image/svg+xml",
|
||||
27881L
|
||||
);
|
||||
}
|
||||
|
||||
private Image createHal9000(User owner) throws ImageException, IOException {
|
||||
try (final InputStream hal9000 = getHal9000()) {
|
||||
return this.imageService.create(
|
||||
@ -88,10 +78,9 @@ public class S3ImageServiceTests {
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void simpleCreate() {
|
||||
try (final InputStream hal9000 = getHal9000()) {
|
||||
public void simpleCreate() throws ImageException, IOException {
|
||||
final User owner = this.createTestUser("imageOwner");
|
||||
final Image image = this.createHal9000(owner, hal9000);
|
||||
final Image image = this.createHal9000(owner);
|
||||
assertThat(image.getOwner(), isUser(owner));
|
||||
assertThat(image.getCreated(), is(notNullValue()));
|
||||
assertThat(image.getModified(), is(nullValue()));
|
||||
@ -102,71 +91,51 @@ public class S3ImageServiceTests {
|
||||
assertThat(image.getInternalUrl(), is(notNullValue()));
|
||||
assertThat(image.isPublic(), is(false));
|
||||
assertThat(image.getViewers(), is(empty()));
|
||||
} catch (IOException | ImageException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void loadImageWithOwner() {
|
||||
try (final InputStream hal9000 = getHal9000()) {
|
||||
public void loadImageWithOwner() throws ImageException, IOException {
|
||||
final User owner = this.createTestUser("imageOwner");
|
||||
final Image image = this.createHal9000(owner, hal9000);
|
||||
final Image image = this.createHal9000(owner);
|
||||
try (final InputStream stored = this.imageService.getImageContentById(image.getId(), owner)) {
|
||||
final byte[] storedBytes = stored.readAllBytes();
|
||||
assertThat(storedBytes.length, is(27881));
|
||||
}
|
||||
} catch (IOException | ImageException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadPublicImage() {
|
||||
try (final InputStream hal9000 = getHal9000()) {
|
||||
public void loadPublicImage() throws ImageException, IOException {
|
||||
final User owner = this.createTestUser("imageOwner");
|
||||
Image image = this.createHal9000(owner, hal9000);
|
||||
Image image = this.createHal9000(owner);
|
||||
image = this.imageService.setPublic(image, owner, true);
|
||||
try (final InputStream stored = this.imageService.getImageContentById(image.getId())) {
|
||||
final byte[] storedBytes = stored.readAllBytes();
|
||||
assertThat(storedBytes.length, is(27881));
|
||||
}
|
||||
} catch (IOException | ImageException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void loadImageWithViewer() {
|
||||
try (final InputStream hal9000 = getHal9000()) {
|
||||
public void loadImageWithViewer() throws ImageException, IOException {
|
||||
final User owner = this.createTestUser("imageOwner");
|
||||
final User viewer = this.createTestUser("imageViewer");
|
||||
Image image = this.createHal9000(owner, hal9000);
|
||||
Image image = this.createHal9000(owner);
|
||||
image = this.imageService.addViewer(image, owner, viewer);
|
||||
try (final InputStream stored = this.imageService.getImageContentById(image.getId(), viewer)) {
|
||||
final byte[] storedBytes = stored.readAllBytes();
|
||||
assertThat(storedBytes.length, is(27881));
|
||||
}
|
||||
} catch (IOException | ImageException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void getImagesOwnedBy() {
|
||||
try (
|
||||
final InputStream hal9000_0 = getHal9000();
|
||||
final InputStream hal9000_1 = getHal9000();
|
||||
final InputStream hal9000_2 = getHal9000();
|
||||
) {
|
||||
public void getImagesOwnedBy() throws ImageException, IOException {
|
||||
final User owner = this.createTestUser("imageOwner");
|
||||
final User otherOwner = this.createTestUser("otherImageOwner");
|
||||
final Image image0 = this.createHal9000(owner, hal9000_0);
|
||||
final Image image1 = this.createHal9000(owner, hal9000_1);
|
||||
final Image image2 = this.createHal9000(otherOwner, hal9000_2);
|
||||
final Image image0 = this.createHal9000(owner);
|
||||
final Image image1 = this.createHal9000(owner);
|
||||
final Image image2 = this.createHal9000(otherOwner);
|
||||
|
||||
final List<Image> ownedImages = this.imageService.getImagesOwnedBy(owner);
|
||||
assertThat(ownedImages.size(), is(2));
|
||||
@ -175,24 +144,17 @@ public class S3ImageServiceTests {
|
||||
final List<Image> otherOwnedImages = this.imageService.getImagesOwnedBy(otherOwner);
|
||||
assertThat(otherOwnedImages.size(), is(1));
|
||||
assertThat(otherOwnedImages, containsImages(image2));
|
||||
} catch (IOException | ImageException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void updateOwner() {
|
||||
try (final InputStream hal9000 = getHal9000()) {
|
||||
public void updateOwner() throws ImageException, IOException {
|
||||
final User oldOwner = this.createTestUser("oldImageOwner");
|
||||
final User newOwner = this.createTestUser("newImageOwner");
|
||||
Image image = this.createHal9000(oldOwner, hal9000);
|
||||
Image image = this.createHal9000(oldOwner);
|
||||
assertThat(image.getOwner(), isUser(oldOwner));
|
||||
image = this.imageService.updateOwner(image, oldOwner, newOwner);
|
||||
assertThat(image.getOwner(), isUser(newOwner));
|
||||
} catch (ImageException | IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user