001/* 002 * Licensed to DuraSpace under one or more contributor license agreements. 003 * See the NOTICE file distributed with this work for additional information 004 * regarding copyright ownership. 005 * 006 * DuraSpace licenses this file to you under the Apache License, 007 * Version 2.0 (the "License"); you may not use this file except in 008 * compliance with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.fcrepo.http.api.url; 019 020import static org.apache.jena.rdf.model.ResourceFactory.createResource; 021import static org.fcrepo.http.commons.test.util.TestHelpers.getUriInfoImpl; 022import static org.fcrepo.kernel.api.FedoraTypes.FCR_METADATA; 023import static org.fcrepo.kernel.api.RdfLexicon.HAS_FIXITY_SERVICE; 024import static org.fcrepo.kernel.api.RdfLexicon.HAS_TRANSACTION_SERVICE; 025import static org.fcrepo.kernel.api.RdfLexicon.REPOSITORY_ROOT; 026import static org.junit.Assert.assertTrue; 027import static org.mockito.Mockito.when; 028 029import org.apache.jena.rdf.model.Model; 030import org.apache.jena.rdf.model.Resource; 031 032import org.fcrepo.kernel.api.identifiers.FedoraId; 033import org.fcrepo.kernel.api.models.Binary; 034import org.fcrepo.kernel.api.models.FedoraResource; 035import org.fcrepo.kernel.api.models.NonRdfSourceDescription; 036import org.junit.Before; 037import org.junit.Test; 038import org.junit.runner.RunWith; 039import org.mockito.Mock; 040import org.mockito.junit.MockitoJUnitRunner; 041 042import javax.ws.rs.core.UriInfo; 043 044import java.util.UUID; 045 046/** 047 * <p>HttpApiResourcesTest class.</p> 048 * 049 * @author awoods 050 * @author ajs6f 051 * @author whikloj 052 */ 053 054@RunWith(MockitoJUnitRunner.Silent.class) 055public class HttpApiResourcesTest { 056 057 private HttpApiResources testObj; 058 059 private UriInfo uriInfo; 060 061 @Mock 062 private FedoraResource mockResource; 063 064 @Mock 065 private Binary mockBinary; 066 067 @Mock 068 private NonRdfSourceDescription mockDescription; 069 070 private FedoraId resourceId; 071 072 @Before 073 public void setUp() { 074 testObj = new HttpApiResources(); 075 uriInfo = getUriInfoImpl(); 076 resourceId = FedoraId.create(UUID.randomUUID().toString()); 077 } 078 079 @Test 080 public void shouldDecorateModeRootNodesWithRepositoryWideLinks() { 081 when(mockResource.hasType(REPOSITORY_ROOT.getURI())).thenReturn(true); 082 when(mockResource.getFedoraId()).thenReturn(resourceId); 083 084 final Resource graphSubject = createResource(resourceId.getFullId()); 085 086 final Model model = 087 testObj.createModelForResource(mockResource, uriInfo); 088 089 assertTrue(model.contains(graphSubject, HAS_TRANSACTION_SERVICE)); 090 } 091 092 @Test 093 public void shouldDecorateDescriptionWithLinksToFixityChecks() { 094 final var descriptionId = resourceId.resolve(FCR_METADATA); 095 when(mockDescription.getDescribedResource()).thenReturn(mockBinary); 096 when(mockDescription.getFedoraId()).thenReturn(descriptionId); 097 when(mockBinary.getDescribedResource()).thenReturn(mockBinary); 098 when(mockBinary.getFedoraId()).thenReturn(resourceId); 099 final Resource graphSubject = createResource(resourceId.getFullId()); 100 101 final Model model = 102 testObj.createModelForResource(mockDescription, uriInfo); 103 104 assertTrue(model.contains(graphSubject, HAS_FIXITY_SERVICE)); 105 } 106}