Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/
package org.trellisldp.api;

import static java.util.Optional.empty;
import static java.util.Optional.of;
import static org.trellisldp.api.RDFUtils.TRELLIS_BNODE_PREFIX;
import static org.trellisldp.api.RDFUtils.TRELLIS_DATA_PREFIX;
Expand Down Expand Up @@ -49,7 +48,7 @@ public interface ResourceService {
* @param identifier the resource identifier
* @return the resource
*/
Optional<Resource> get(IRI identifier);
Optional<? extends Resource> get(IRI identifier);

/**
* Get a resource from the given location and time.
Expand All @@ -58,7 +57,7 @@ public interface ResourceService {
* @param time the time
* @return the resource
*/
Optional<Resource> get(IRI identifier, Instant time);
Optional<? extends Resource> get(IRI identifier, Instant time);

/**
* Put a resource into the server.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import static java.util.stream.Stream.of;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.trellisldp.vocabulary.RDF.type;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream;

Expand All @@ -43,6 +44,7 @@
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.trellisldp.vocabulary.DC;
import org.trellisldp.vocabulary.LDP;
import org.trellisldp.vocabulary.Trellis;
Expand Down Expand Up @@ -102,7 +104,7 @@ public void testExport() {
when(mockResource.getIdentifier()).thenReturn(existing);
when(mockResource.stream(eq(graphs))).thenAnswer(inv ->
Stream.of(rdf.createTriple(existing, DC.title, rdf.createLiteral("A title"))));
when(mockResourceService.get(eq(existing))).thenReturn(of(mockResource));
Mockito.<Optional<? extends Resource>>when(mockResourceService.get(eq(existing))).thenReturn(of(mockResource));

final List<Quad> export = mockResourceService.export(graphs).collect(toList());
assertEquals(1L, export.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ public void testSerializationStructure() throws Exception {
assertTrue(map.containsKey("object"));
assertTrue(map.containsKey("published"));

final List types = (List) map.get("type");
final List<?> types = (List<?>) map.get("type");
assertTrue(types.contains("Create"));
assertTrue(types.contains(Activity.getIRIString()));

assertTrue(AS.URI.contains((String) map.get("@context")));

final List actor = (List) map.get("actor");
final List<?> actor = (List<?>) map.get("actor");
assertTrue(actor.contains("info:user/test"));

assertTrue(map.get("id").equals("info:event/12345"));
Expand Down Expand Up @@ -131,7 +131,7 @@ public void testSerializationStructureNoEmptyElements() throws Exception {
assertTrue(map.containsKey("object"));
assertTrue(map.containsKey("published"));

final List types = (List) map.get("type");
final List<?> types = (List<?>) map.get("type");
assertTrue(types.contains("Create"));

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public Response createResource(@BeanParam final LdpRequest req, final File body)
final String separator = path.isEmpty() ? "" : "/";

// First check if this is a container
final Optional<Resource> parent = resourceService.get(rdf.createIRI(TRELLIS_DATA_PREFIX + path));
final Optional<? extends Resource> parent = resourceService.get(rdf.createIRI(TRELLIS_DATA_PREFIX + path));
if (parent.isPresent()) {
final Optional<IRI> ixModel = parent.map(Resource::getInteractionModel);
if (ixModel.filter(type -> ldpResourceTypes(type).anyMatch(LDP.Container::equals)).isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import static org.apache.commons.rdf.api.RDFSyntax.NTRIPLES;
import static org.apache.commons.rdf.api.RDFSyntax.TURTLE;
import static org.trellisldp.api.RDFUtils.getInstance;
import static org.trellisldp.vocabulary.LDP.Resource;

import java.time.Instant;
import java.util.ArrayList;
import java.util.Iterator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import static java.time.ZonedDateTime.parse;
import static java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME;
import static java.util.Objects.nonNull;
import static java.util.Optional.empty;
import static java.util.Optional.of;
import static java.util.Optional.ofNullable;
import static java.util.stream.Collectors.joining;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
Expand All @@ -119,7 +120,8 @@
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
import org.mockito.Mock;

import org.mockito.Mockito;
import org.mockito.stubbing.OngoingStubbing;
import org.trellisldp.api.AccessControlService;
import org.trellisldp.api.AgentService;
import org.trellisldp.api.Binary;
Expand Down Expand Up @@ -233,28 +235,33 @@ public void after() throws Exception {
super.tearDown();
}

private static OngoingStubbing<Optional<? extends Resource>> whenResource(
final Optional<? extends Resource> methodCall) {
return Mockito.<Optional<? extends Resource>>when(methodCall);
}

@BeforeEach
public void setUpMocks() {
when(mockResourceService.get(any(IRI.class), any(Instant.class)))
whenResource(mockResourceService.get(any(IRI.class), any(Instant.class)))
.thenReturn(of(mockVersionedResource));
when(mockResourceService.get(eq(identifier))).thenReturn(of(mockResource));
when(mockResourceService.get(eq(rdf.createIRI(TRELLIS_DATA_PREFIX + "repository/resource"))))
whenResource(mockResourceService.get(eq(identifier))).thenReturn(of(mockResource));
whenResource(mockResourceService.get(eq(rdf.createIRI(TRELLIS_DATA_PREFIX + "repository/resource"))))
.thenReturn(of(mockResource));
when(mockResourceService.get(eq(root))).thenReturn(of(mockResource));
whenResource(mockResourceService.get(eq(root))).thenReturn(of(mockResource));
when(mockResourceService.get(eq(childIdentifier))).thenReturn(empty());
when(mockResourceService.get(eq(childIdentifier), any(Instant.class))).thenReturn(empty());
when(mockResourceService.get(eq(binaryIdentifier))).thenReturn(of(mockBinaryResource));
when(mockResourceService.get(eq(binaryIdentifier), any(Instant.class)))
whenResource(mockResourceService.get(eq(binaryIdentifier))).thenReturn(of(mockBinaryResource));
whenResource(mockResourceService.get(eq(binaryIdentifier), any(Instant.class)))
.thenReturn(of(mockBinaryVersionedResource));
when(mockResourceService.get(eq(nonexistentIdentifier))).thenReturn(empty());
when(mockResourceService.get(eq(nonexistentIdentifier), any(Instant.class))).thenReturn(empty());
when(mockResourceService.get(eq(deletedIdentifier))).thenReturn(of(mockDeletedResource));
when(mockResourceService.get(eq(deletedIdentifier), any(Instant.class)))
whenResource(mockResourceService.get(eq(deletedIdentifier))).thenReturn(of(mockDeletedResource));
whenResource(mockResourceService.get(eq(deletedIdentifier), any(Instant.class)))
.thenReturn(of(mockDeletedResource));
when(mockResourceService.getIdentifierSupplier()).thenReturn(() -> RANDOM_VALUE);

when(mockResourceService.get(eq(userDeletedIdentifier))).thenReturn(of(mockUserDeletedResource));
when(mockResourceService.get(eq(userDeletedIdentifier), any(Instant.class)))
whenResource(mockResourceService.get(eq(userDeletedIdentifier))).thenReturn(of(mockUserDeletedResource));
whenResource(mockResourceService.get(eq(userDeletedIdentifier), any(Instant.class)))
.thenReturn(of(mockUserDeletedResource));

when(mockAgentService.asAgent(anyString())).thenReturn(agent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.time.Instant;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream;

Expand All @@ -63,7 +64,8 @@
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
import org.mockito.Mock;

import org.mockito.Mockito;
import org.mockito.stubbing.OngoingStubbing;
import org.trellisldp.api.AccessControlService;
import org.trellisldp.api.AgentService;
import org.trellisldp.api.Binary;
Expand Down Expand Up @@ -179,16 +181,21 @@ public void after() throws Exception {
super.tearDown();
}

private static OngoingStubbing<Optional<? extends Resource>> whenResource(
final Optional<? extends Resource> methodCall) {
return Mockito.<Optional<? extends Resource>>when(methodCall);
}

@BeforeEach
public void setUpMocks() {
when(mockResourceService.get(any(IRI.class), any(Instant.class)))
whenResource(mockResourceService.get(any(IRI.class), any(Instant.class)))
.thenReturn(of(mockVersionedResource));
when(mockResourceService.get(eq(identifier))).thenReturn(of(mockResource));
when(mockResourceService.get(eq(root))).thenReturn(of(mockResource));
whenResource(mockResourceService.get(eq(identifier))).thenReturn(of(mockResource));
whenResource(mockResourceService.get(eq(root))).thenReturn(of(mockResource));
when(mockResourceService.get(eq(childIdentifier))).thenReturn(empty());
when(mockResourceService.get(eq(childIdentifier), any(Instant.class))).thenReturn(empty());
when(mockResourceService.get(eq(binaryIdentifier))).thenReturn(of(mockBinaryResource));
when(mockResourceService.get(eq(binaryIdentifier), any(Instant.class)))
whenResource(mockResourceService.get(eq(binaryIdentifier))).thenReturn(of(mockBinaryResource));
whenResource(mockResourceService.get(eq(binaryIdentifier), any(Instant.class)))
.thenReturn(of(mockBinaryVersionedResource));
when(mockResourceService.get(eq(nonexistentIdentifier))).thenReturn(empty());
when(mockResourceService.get(eq(nonexistentIdentifier), any(Instant.class))).thenReturn(empty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import static org.trellisldp.http.domain.RdfMediaType.APPLICATION_SPARQL_UPDATE_TYPE;

import java.time.Instant;
import java.util.Optional;
import java.util.stream.Stream;

import javax.ws.rs.core.Application;
Expand All @@ -58,7 +59,7 @@
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
import org.mockito.Mock;

import org.mockito.Mockito;
import org.trellisldp.api.AccessControlService;
import org.trellisldp.api.AgentService;
import org.trellisldp.api.BinaryService;
Expand Down Expand Up @@ -139,8 +140,10 @@ public void after() throws Exception {

@BeforeEach
public void setUpMocks() {
when(mockResourceService.get(any(IRI.class), any(Instant.class))).thenReturn(of(mockVersionedResource));
when(mockResourceService.get(any(IRI.class))).thenReturn(of(mockResource));
Mockito.<Optional<? extends Resource>>when(mockResourceService.get(any(IRI.class), any(Instant.class)))
.thenReturn(of(mockVersionedResource));
Mockito.<Optional<? extends Resource>>when(mockResourceService.get(any(IRI.class)))
.thenReturn(of(mockResource));
when(mockResourceService.getMementos(any())).thenReturn(emptyList());

when(mockAccessControlService.getAccessModes(any(IRI.class), any(Session.class))).thenReturn(emptySet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import static org.trellisldp.http.domain.RdfMediaType.APPLICATION_SPARQL_UPDATE_TYPE;

import java.time.Instant;
import java.util.Optional;
import java.util.stream.Stream;

import javax.ws.rs.core.Application;
Expand All @@ -60,7 +61,7 @@
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
import org.mockito.Mock;

import org.mockito.Mockito;
import org.trellisldp.api.AccessControlService;
import org.trellisldp.api.BinaryService;
import org.trellisldp.api.IOService;
Expand Down Expand Up @@ -139,8 +140,10 @@ public void after() throws Exception {

@BeforeEach
public void setUpMocks() {
when(mockResourceService.get(any(IRI.class), any(Instant.class))).thenReturn(of(mockVersionedResource));
when(mockResourceService.get(any(IRI.class))).thenReturn(of(mockResource));
Mockito.<Optional<? extends Resource>>when(mockResourceService.get(any(IRI.class), any(Instant.class)))
.thenReturn(of(mockVersionedResource));
Mockito.<Optional<? extends Resource>>when(mockResourceService.get(any(IRI.class)))
.thenReturn(of(mockResource));
when(mockResourceService.getMementos(any())).thenReturn(emptyList());

when(mockAccessControlService.getAccessModes(any(IRI.class), any(Session.class))).thenReturn(emptySet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ public void setUp() {
when(mockNamespaceService.getPrefix(eq("http://purl.org/dc/dcmitype/")))
.thenReturn(Optional.of("dcmitype"));
when(mockCache.get(anyString(), any(Function.class))).thenAnswer(inv -> {
final String key = (String) inv.getArgument(0);
final Function mapper = (Function<String, String>) inv.getArgument(1);
final String key = inv.getArgument(0);
final Function<String, String> mapper = inv.getArgument(1);
return mapper.apply(key);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public String namespace() {
}

@Override
public Class vocabulary() {
public Class<ACL> vocabulary() {
return ACL.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@
*/
public class ASTest extends AbstractVocabularyTest {

@Override
public String namespace() {
return "https://www.w3.org/ns/activitystreams#";
}

public Class vocabulary() {
@Override
public Class<AS> vocabulary() {
return AS.class;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public abstract class AbstractVocabularyTest {

public abstract String namespace();

public abstract Class vocabulary();
public abstract Class<?> vocabulary();

public Boolean isStrict() {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public String namespace() {
}

@Override
public Class vocabulary() {
public Class<DC> vocabulary() {
return DC.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public String namespace() {
}

@Override
public Class vocabulary() {
public Class<FOAF> vocabulary() {
return FOAF.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public String namespace() {
}

@Override
public Class vocabulary() {
public Class<JSONLD> vocabulary() {
return JSONLD.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public String namespace() {
}

@Override
public Class vocabulary() {
public Class<LDP> vocabulary() {
return LDP.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public String namespace() {
}

@Override
public Class vocabulary() {
public Class<Memento> vocabulary() {
return Memento.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public String namespace() {
}

@Override
public Class vocabulary() {
public Class<OA> vocabulary() {
return OA.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public String namespace() {
}

@Override
public Class vocabulary() {
public Class<PROV> vocabulary() {
return PROV.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public String namespace() {
}

@Override
public Class vocabulary() {
public Class<RDFS> vocabulary() {
return RDFS.class;
}
}
Loading