Skip to content

Commit

Permalink
Specify sword:maxUploadSize
Browse files Browse the repository at this point in the history
  • Loading branch information
claussni committed Jul 10, 2015
1 parent 78d63ae commit 02ab03f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
Expand Up @@ -158,6 +158,8 @@ private void registerNamespace(final Session session) {
public Service serviceDocument() {
final Service service = abdera.newService();
service.addSimpleExtension(NS_SWORD_TERMS, "version", "sword", SWORD_VERSION);
service.addSimpleExtension(NS_SWORD_TERMS, "maxUploadSize", "sword",
String.valueOf(SWORD_MAX_UPLOAD_SIZE_KB));
return service;
}

Expand Down
Expand Up @@ -70,4 +70,9 @@ public void fedoraRepositoryIsResponding() throws IOException {
assertStatusCode(200, response);
}

protected HttpResponse requestServiceDocument() throws IOException {
final HttpGet get = new HttpGet(serverAddress);
get.setHeader("Content-Type", "application/svc+xml");
return httpClient.execute(get);
}
}
30 changes: 21 additions & 9 deletions src/test/java/org/fcrepo/sword/integration/ServiceDocumentIT.java
Expand Up @@ -17,14 +17,14 @@

import org.apache.abdera.model.Service;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.junit.Test;

import java.io.IOException;

import static org.fcrepo.sword.integration.Assert.assertContentType;
import static org.fcrepo.sword.integration.Assert.assertStatusCode;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

/**
* @author claussni
Expand All @@ -33,23 +33,35 @@ public class ServiceDocumentIT extends BaseProviderServiceIT {

@Test
public void returnsAtomServiceDocumentMediaType() throws IOException {
final HttpGet get = new HttpGet(serverAddress);
get.setHeader("Content-Type", "application/svc+xml");
final HttpResponse response = httpClient.execute(get);
final HttpResponse response = requestServiceDocument();
assertStatusCode(200, response);
assertContentType("application/atomsvc+xml", response);
}

@Test
public void hasSwordVersion2() throws IOException {
final HttpGet get = new HttpGet(serverAddress);
get.setHeader("Content-Type", "application/svc+xml");
final HttpResponse response = httpClient.execute(get);
final Service service = serviceDocumentFromStream(response.getEntity().getContent());
public void specifiesSwordVersion2() throws IOException {
final HttpResponse response = requestServiceDocument();
final Service service = serviceDocumentFromStream(response.getEntity().getContent());
assertEquals("2.0", service.getSimpleExtension(
"http://purl.org/net/sword/terms/",
"version",
"sword"));
}

@Test
public void specifiesMaxUploadSizeAsInteger() throws IOException {
final HttpResponse response = requestServiceDocument();
final Service service = serviceDocumentFromStream(response.getEntity().getContent());
try {
final int maxUploadSize = Integer.parseUnsignedInt(service.getSimpleExtension(
"http://purl.org/net/sword/terms/",
"maxUploadSize",
"sword"));
assertEquals("Expected default value for sword:maxUploadSize", Integer.MAX_VALUE, maxUploadSize);
} catch (NumberFormatException e) {
fail("sword:maxUploadSize is not an Integer");
}
}

}

0 comments on commit 02ab03f

Please sign in to comment.