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.integration; 019 020import com.hp.hpl.jena.rdf.model.Resource; 021import org.fcrepo.kernel.api.RdfStream; 022import org.fcrepo.kernel.api.models.Container; 023import org.fcrepo.kernel.api.services.ContainerService; 024import org.fcrepo.kernel.modeshape.rdf.impl.DefaultIdentifierTranslator; 025import org.fcrepo.transform.transformations.LDPathTransform; 026import org.junit.Before; 027import org.junit.Test; 028import org.junit.runner.RunWith; 029import org.springframework.test.annotation.DirtiesContext; 030import org.springframework.test.annotation.DirtiesContext.ClassMode; 031import org.springframework.test.context.ContextConfiguration; 032import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 033 034import javax.inject.Inject; 035import javax.jcr.Repository; 036import javax.jcr.RepositoryException; 037import javax.jcr.Session; 038import java.io.ByteArrayInputStream; 039import java.io.InputStream; 040import java.util.Collection; 041import java.util.Map; 042import java.util.List; 043 044import static org.fcrepo.kernel.api.RequiredRdfContext.PROPERTIES; 045import static org.fcrepo.kernel.api.RdfLexicon.REPOSITORY_NAMESPACE; 046import static org.fcrepo.kernel.modeshape.utils.FedoraTypesUtils.getJcrNode; 047import static org.junit.Assert.assertEquals; 048import static org.junit.Assert.assertNotNull; 049import static org.junit.Assert.assertTrue; 050 051 052/** 053 * <p>LDPathServiceIT class.</p> 054 * 055 * @author cbeer 056 */ 057@RunWith(SpringJUnit4ClassRunner.class) 058@ContextConfiguration({"/spring-test/master.xml"}) 059@DirtiesContext(classMode = ClassMode.AFTER_CLASS) 060public class LDPathServiceIT { 061 062 @Inject 063 Repository repo; 064 065 @Inject 066 ContainerService containerService; 067 private LDPathTransform testObj; 068 069 @Before 070 public void setUp() { 071 072 } 073 074 @Test 075 public void shouldDoStuff() throws RepositoryException { 076 final Session session = repo.login(); 077 078 final Container object = containerService.findOrCreate(session, "/testObject"); 079 getJcrNode(object).setProperty("dc:title", "some-title"); 080 081 final String s = "@prefix dces : <http://purl.org/dc/elements/1.1/>\n" + 082 "@prefix fcrepo : <" + REPOSITORY_NAMESPACE + ">\n" + 083 "id = . :: xsd:string ;\n" + 084 "title = dc:title :: xsd:string ;"; 085 final InputStream stringReader = new ByteArrayInputStream(s.getBytes()); 086 087 testObj = new LDPathTransform(stringReader); 088 089 final DefaultIdentifierTranslator subjects = new DefaultIdentifierTranslator(session); 090 final Resource topic = subjects.reverse().convert(object); 091 final RdfStream triples = object.getTriples(subjects, PROPERTIES); 092 final List<Map<String, Collection<Object>>> list = testObj.apply(triples); 093 094 assertNotNull("Failed to retrieve results!", list); 095 096 assertTrue("List didn't contain a result", list.size() == 1); 097 098 final Map<String, Collection<Object>> stuff = list.get(0); 099 100 assertTrue("Results didn't contain an identifier!", stuff.containsKey("id")); 101 assertTrue("Results didn't contain a title!", stuff.containsKey("title")); 102 103 assertEquals("Received more than one identifier!", 1, stuff.get("id").size()); 104 assertEquals("Got wrong subject in identifier!", subjects.toDomain("/testObject").getURI(), stuff.get( 105 "id").iterator().next()); 106 assertEquals("Got wrong title!", "some-title", stuff.get("title").iterator().next()); 107 } 108}