Skip to content

Commit

Permalink
Merge branch 'master' into seehamrun-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
pablomd314 authored Jan 28, 2020
2 parents edab7d3 + 0dd8986 commit ee1bdc3
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private String createOneDriveFolder(PhotoAlbum album) throws IOException {
if (code < 200 || code > 299) {
throw new IOException(
"Got error code: " + code + " message: " + response.message() + " body: " + response
.body());
.body().string());
}
if (body == null) {
throw new IOException("Got null body");
Expand Down Expand Up @@ -225,7 +225,7 @@ private String importSinglePhoto(
if (code < 200 || code > 299) {
throw new IOException(
"Got error code: " + code + " message: " + response.message() + " body: " + response
.body());
.body().string());
}

// Extract photo ID from response body
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ public void cleanName(String forbiddenCharacters, char replacementCharacter, int
.mapToObj(c -> (char) c)
.map(c -> forbiddenCharacters.contains(Character.toString(c)) ? replacementCharacter : c)
.map(Object::toString)
.collect(Collectors.joining(""));
.collect(Collectors.joining("")).trim();
if (maxLength <= 0) {
return;
}
name = name.substring(0, maxLength);
name = name.substring(0, Math.min(maxLength, name.length())).trim();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ public void cleanTitle(String forbiddenCharacters, char replacementCharacter, in
.mapToObj(c -> (char) c)
.map(c -> forbiddenCharacters.contains(Character.toString(c)) ? replacementCharacter : c)
.map(Object::toString)
.collect(Collectors.joining(""));
.collect(Collectors.joining("")).trim();
if (maxLength <= 0) {
return;
}
title = title.substring(0, Math.min(maxLength, title.length()));
title = title.substring(0, Math.min(maxLength, title.length())).trim();
}

public boolean isInTempStore() { return inTempStore; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.datatransferproject.types.common.models.TransmogrificationConfig;
import org.junit.Test;

import java.util.stream.Collectors;
import java.util.List;

public class PhotosContainerResourceTest {
Expand Down Expand Up @@ -163,7 +164,6 @@ public void verifyTransmogrifyAlbums_NoRootPhotos() throws Exception {
}

@Test

public void verifyTransmogrifyAlbums_NameForbiddenCharacters() throws Exception {
TransmogrificationConfig config = new TransmogrificationConfig() {
public String getAlbumNameForbiddenCharacters() {
Expand Down Expand Up @@ -192,6 +192,7 @@ public char getAlbumNameReplacementCharacter() {
Truth.assertThat(Iterables.get(data.getAlbums(),0).getName()).isEqualTo("This?a fake album?");
}

@Test
public void verifyTransmogrifyAlbums_oddDivisionWithoutLoosePhotos() throws Exception {
TransmogrificationConfig config = new TransmogrificationConfig() {
public boolean getAlbumAllowRootPhotos() {
Expand All @@ -201,24 +202,23 @@ public int getAlbumMaxSize() {
return 2;
}
};
List<PhotoAlbum> albums =
ImmutableList.of(new PhotoAlbum("id1", "albumb1", "This is a fake album"));
List<PhotoAlbum> albums = ImmutableList.of();
List<PhotoModel> photos =
ImmutableList.of(
new PhotoModel("Pic1", "http://fake.com/1.jpg", "A pic", "image/jpg", "p1", "id1",
false),
new PhotoModel("Pic3", "http://fake.com/2.jpg", "A pic", "image/jpg", "p3", "id1",
false),
new PhotoModel("Pic2", "https://fake.com/pic2.png", "fine art", "image/png", "p2", null, false),
new PhotoModel(
"Pic2", "https://fake.com/pic2.png", "fine art", "image/png", "p2", null, false),
new PhotoModel(
"Pic5", "https://fake.com/pic5.png", "fine art", "image/png", "p5", null, false),
new PhotoModel(
"Pic6", "https://fake.com/pic6.png", "fine art", "image/png", "p6", null, false));

PhotosContainerResource data = new PhotosContainerResource(albums, photos);
data.transmogrify(config);
Truth.assertThat(data.getAlbums()).hasSize(3);
Truth.assertThat(data.getPhotos()).hasSize(5);
Truth.assertThat(data.getAlbums()).hasSize(2);
Truth.assertThat(
data.getAlbums().stream().map(thing -> thing.getName()).collect(Collectors.toList()))
.isEqualTo(ImmutableList.of("Transferred Photos (1/2)", "Transferred Photos (2/2)"));
Truth.assertThat(data.getPhotos()).hasSize(3);
}


Expand All @@ -243,6 +243,26 @@ public void verifyTransmogrifyAlbums_NameNoForbiddenCharacters() throws Exceptio
Truth.assertThat(Iterables.get(data.getAlbums(),0).getName()).isEqualTo("This:a fake album!");
}

@Test
public void verifyTransmogrifyAlbums_stripName() throws Exception {
TransmogrificationConfig config = new TransmogrificationConfig();
List<PhotoAlbum> albums =
ImmutableList.of(new PhotoAlbum("id1", "This:a fake album! ", "This:a fake album!"));

List<PhotoModel> photos =
ImmutableList.of(
new PhotoModel("Pic1", "http://fake.com/1.jpg", "A pic", "image/jpg", "p1", "id1",
false),
new PhotoModel("Pic3", "http://fake.com/2.jpg", "A pic", "image/jpg", "p3", "id1",
false),
new PhotoModel(
"Pic2", "https://fake.com/pic.png", "fine art", "image/png", "p2", null, false));

PhotosContainerResource data = new PhotosContainerResource(albums, photos);
data.transmogrify(config);
Truth.assertThat(Iterables.get(data.getAlbums(),0).getName()).isEqualTo("This:a fake album!");
}


@Test
public void verifyTransmogrifyAlbums_NameTooLong() throws Exception {
Expand Down Expand Up @@ -390,4 +410,24 @@ public void verifyTransmogrifyPhotos_TitleNoLengthLimit() throws Exception {
Truth.assertThat(Iterables.get(data.getPhotos(),2).getTitle()).hasLength(4);

}

@Test
public void verifyTransmogrifyPhotos_stripTitle() throws Exception {
TransmogrificationConfig config = new TransmogrificationConfig();
List<PhotoAlbum> albums =
ImmutableList.of(new PhotoAlbum("id1", "albumb1", "This:a fake album!"));

List<PhotoModel> photos =
ImmutableList.of(
new PhotoModel("Pic1 ", "http://fake.com/1.jpg", "A pic", "image/jpg", "p1", "id1",
false),
new PhotoModel("Pic3 ", "http://fake.com/2.jpg", "A pic", "image/jpg", "p3", "id1",
false));

PhotosContainerResource data = new PhotosContainerResource(albums, photos);
data.transmogrify(config);
Truth.assertThat(Iterables.get(data.getPhotos(),0).getTitle()).isEqualTo("Pic1");
Truth.assertThat(Iterables.get(data.getPhotos(),1).getTitle()).isEqualTo("Pic3");

}
}

0 comments on commit ee1bdc3

Please sign in to comment.