Navigation Menu

Skip to content

Commit

Permalink
Add support to the web UI to trigger the file picker when no file att…
Browse files Browse the repository at this point in the history
…ached for datastream creation.

Resolves: https://www.pivotaltracker.com/story/show/78847348
  • Loading branch information
lsitu authored and Andrew Woods committed Oct 31, 2014
1 parent a97d8b0 commit 1e1282b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
Expand Up @@ -58,7 +58,7 @@
</label>
<input type="file" name="file" id="binary_payload"/>
</div>
<button type="submit" class="btn btn-primary">Add</button>
<button id="btn_action_create" class="btn btn-primary">Add</button>
<hr />
</form>

Expand Down
12 changes: 11 additions & 1 deletion fcrepo-http-api/src/main/resources/views/common.js
Expand Up @@ -106,7 +106,17 @@ $(function() {
}
});

$('#action_create').submit(addChild);
$('#btn_action_create').click(function (e) {
if ($("#new_mixin").val() == 'binary') {
var file = $("#binary_payload").val();
if (file.length == 0) {
$('#binary_payload').click();
return false;
}
}
$('#action_create').submit(addChild);
});

$('#action_sparql_update').submit(sendSparqlUpdate);
$('#action_register_namespace').submit(registerNamespace);
$('#action_delete').submit(deleteItem);
Expand Down
Expand Up @@ -15,6 +15,7 @@
*/
package org.fcrepo.integration;

import static javax.ws.rs.core.Response.Status.NOT_FOUND;
import static com.gargoylesoftware.htmlunit.BrowserVersion.FIREFOX_24;
import static com.google.common.collect.Lists.transform;
import static java.util.UUID.randomUUID;
Expand Down Expand Up @@ -120,7 +121,7 @@ private HtmlPage createAndVerifyObjectWithIdFromRootPage(final String pid) throw
@Test
public void testCreateNewNodeWithGeneratedId() throws IOException {

final HtmlPage page = javascriptlessWebClient.getPage(serverAddress);
final HtmlPage page = webClient.getPage(serverAddress);
final HtmlForm form = (HtmlForm)page.getElementById("action_create");
final HtmlSelect type = (HtmlSelect)page.getElementById("new_mixin");
type.getOptionByValue("object").setSelected(true);
Expand Down Expand Up @@ -158,6 +159,29 @@ public void testCreateNewDatastream() throws IOException {
assertEquals(serverAddress + pid, page1.getTitleText());
}

@Test
public void testCreateNewDatastreamWithNoFileAttached() throws IOException {

final String pid = randomUUID().toString();

// can't do this with javascript, because HTMLUnit doesn't speak the HTML5 file api
final HtmlPage page = webClient.getPage(serverAddress);
final HtmlForm form = (HtmlForm)page.getElementById("action_create");

final HtmlInput slug = form.getInputByName("slug");
slug.setValueAttribute(pid);

final HtmlSelect type = (HtmlSelect)page.getElementById("new_mixin");
type.getOptionByValue("binary").setSelected(true);

final HtmlButton button = form.getFirstByXPath("button");
button.click();

javascriptlessWebClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
final int status = javascriptlessWebClient.getPage(serverAddress + pid).getWebResponse().getStatusCode();
assertEquals(NOT_FOUND.getStatusCode(), status);
}

@Test
public void testCreateNewObjectAndDeleteIt() throws IOException {
final boolean throwExceptionOnFailingStatusCode = webClient.getOptions().isThrowExceptionOnFailingStatusCode();
Expand Down

0 comments on commit 1e1282b

Please sign in to comment.