001/** 002 * Copyright 2015 DuraSpace, Inc. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.fcrepo.sword.integration; 017 018import org.apache.abdera.model.Service; 019import org.apache.http.HttpResponse; 020import org.apache.http.HttpStatus; 021import org.junit.Test; 022 023import java.io.IOException; 024 025import static org.fcrepo.sword.integration.Assert.assertContentType; 026import static org.fcrepo.sword.integration.Assert.assertStatusCode; 027import static org.junit.Assert.assertEquals; 028import static org.junit.Assert.assertNotNull; 029import static org.junit.Assert.fail; 030 031/** 032 * @author claussni 033 */ 034public class ServiceDocumentIT extends BaseServiceProviderIT { 035 036 @Test 037 public void returnsAtomServiceDocumentMediaType() throws IOException { 038 final HttpResponse response = requestServiceDocument(); 039 assertStatusCode(200, response); 040 assertContentType("application/atomsvc+xml", response); 041 } 042 043 @Test 044 public void specifiesSwordVersion2() throws IOException { 045 final HttpResponse response = requestServiceDocument(); 046 final Service service = serviceDocumentFromStream(response.getEntity().getContent()); 047 assertEquals("2.0", service.getSimpleExtension( 048 "http://purl.org/net/sword/terms/", 049 "version", 050 "sword")); 051 } 052 053 @Test 054 public void specifiesMaxUploadSizeAsInteger() throws IOException { 055 final HttpResponse response = requestServiceDocument(); 056 final Service service = serviceDocumentFromStream(response.getEntity().getContent()); 057 try { 058 final int maxUploadSize = Integer.parseUnsignedInt(service.getSimpleExtension( 059 "http://purl.org/net/sword/terms/", 060 "maxUploadSize", 061 "sword")); 062 assertEquals("Expected default value for sword:maxUploadSize", Integer.MAX_VALUE, maxUploadSize); 063 } catch (NumberFormatException e) { 064 fail("sword:maxUploadSize is not an Integer"); 065 } 066 } 067 068 @Test 069 public void canCreateNewWorkspace() throws IOException { 070 final HttpResponse response = createWorkspaceNode("Test Workspace"); 071 assertEquals("Expect 201 Created response", HttpStatus.SC_CREATED, response.getStatusLine().getStatusCode()); 072 } 073 074 @Test 075 public void definedWorkspaceGetsListetInServiceDocument() throws IOException { 076 final String title = "Test Workspace"; 077 createWorkspaceNode(title); 078 final HttpResponse response = requestServiceDocument(); 079 final Service service = serviceDocumentFromStream(response.getEntity().getContent()); 080 assertNotNull("Expect workspace to be defined.", service.getWorkspace(title)); 081 assertEquals(title, service.getWorkspace(title).getTitle()); 082 } 083 084} 085