Skip to content

Commit

Permalink
Merge pull request #6335 from seadowg/test-improvements
Browse files Browse the repository at this point in the history
Use IDs for media files in StubOpenRosaServer
  • Loading branch information
grzesiek2010 authored Aug 12, 2024
2 parents 3669ada + f01c7f1 commit 52a69bb
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;

public class StubOpenRosaServer implements OpenRosaHttpInterface {
Expand Down Expand Up @@ -291,7 +292,7 @@ private InputStream getManifestResponse(@NonNull URI uri) throws IOException {
}

stringBuilder
.append("<downloadUrl>" + getURL() + "/mediaFile/" + formID + "/" + mediaFile.getName() + "</downloadUrl>\n")
.append("<downloadUrl>" + getURL() + "/mediaFile/" + formID + "/" + mediaFile.getId() + "</downloadUrl>\n")
.append("</mediaFile>\n");
}

Expand All @@ -309,9 +310,9 @@ private InputStream getFormXML(String formID) throws IOException {
@NotNull
private InputStream getMediaFile(URI uri) throws IOException {
String formID = uri.getPath().split("/mediaFile/")[1].split("/")[0];
String mediaFileName = uri.getPath().split("/mediaFile/")[1].split("/")[1];
String id = uri.getPath().split("/mediaFile/")[1].split("/")[1];
XFormItem xformItem = forms.get(Integer.parseInt(formID));
String actualFileName = xformItem.getMediaFiles().stream().filter(mediaFile -> mediaFile.getName().equals(mediaFileName)).findFirst().get().getFile();
String actualFileName = xformItem.getMediaFiles().stream().filter(mediaFile -> mediaFile.getId().equals(id)).findFirst().get().getFile();
return getResourceAsStream("media/" + actualFileName);
}

Expand Down Expand Up @@ -393,6 +394,7 @@ public List<MediaFileItem> getMediaFiles() {
public static class MediaFileItem {
private final String name;
private final String file;
private final String id = UUID.randomUUID().toString();

private final String hash;

Expand Down Expand Up @@ -421,6 +423,10 @@ public String getFile() {
public String getHash() {
return hash;
}

public String getId() {
return id;
}
}

public static class EntityListItem extends MediaFileItem {
Expand Down

0 comments on commit 52a69bb

Please sign in to comment.