/** * Delegates call to {@link Mockito#description(String)}. * * @since 2.0.0 */ default VerificationMode description(String description) { return Mockito.description(description); } }
/** * Delegates call to {@link Mockito#description(String)}. * * @since 2.0.0 */ default VerificationMode description(String description) { return Mockito.description(description); } }
private Stream<Executable> checkBinaryEntityResponse() { return Stream.of( () -> verify(mockResourceService, description("ResourceService::create not called!")) .create(any(Metadata.class), any(Dataset.class)), () -> verify(mockIoService, never().description("entity shouldn't be read!")).read(any(), any(), any()), () -> verify(mockBinaryService, description("content not set on binary service!")) .setContent(metadataArgument.capture(), any(InputStream.class)), () -> assertEquals(of("text/plain"), metadataArgument.getValue().getMimeType(), "Invalid content-type"), () -> assertTrue(metadataArgument.getValue().getIdentifier().getIRIString().startsWith("file:///"), "Invalid binary ID!")); } }
private Stream<Executable> verifyInteractions(final ResourceService svc) { return of( () -> verify(svc, never().description("Don't re-initialize the root if it already exists")) .create(any(Metadata.class), any(Dataset.class)), () -> verify(svc, never().description("Don't re-initialize the root if it already exists")) .replace(any(Metadata.class), any(Dataset.class)), () -> verify(svc, description("Verify that the root resource is fetched only once")).get(root)); } }
private Stream<Executable> checkRdfPut(final Response res) { return Stream.of( () -> assertAll("Check LDP type Link headers", checkLdpType(res, LDP.RDFSource)), () -> verify(mockBinaryService, never().description("Binary service shouldn't have been called!")) .setContent(any(BinaryMetadata.class), any(InputStream.class), any()), () -> verify(mockIoService, description("IOService should have been called with an RDF resource")) .read(any(InputStream.class), any(RDFSyntax.class), anyString())); }
private Stream<Executable> checkBinaryPut(final Response res) { return Stream.of( () -> assertAll("Check LDP type Link headers", checkLdpType(res, LDP.NonRDFSource)), () -> verify(mockBinaryService, description("BinaryService should have been called to set content!")) .setContent(any(BinaryMetadata.class), any(InputStream.class)), () -> verify(mockIoService, never().description("IOService shouldn't have been called with a Binary!")) .read(any(InputStream.class), any(RDFSyntax.class), anyString())); } }
@Test public void testInitializeoDeletedLdpResource() throws Exception { final ResourceService mockService = mock(ResourceService.class); when(mockBundler.getResourceService()).thenReturn(mockService); when(mockService.get(eq(root))).thenAnswer(inv -> completedFuture(DELETED_RESOURCE)); when(mockService.create(any(Metadata.class), any(Dataset.class))).thenReturn(completedFuture(null)); final TrellisHttpResource matcher = new TrellisHttpResource(mockBundler); matcher.initialize(); verify(mockService, description("A previously deleted root resource should be re-created upon initialization")) .create(any(Metadata.class), any(Dataset.class)); verify(mockService, never().description("replace shouldn't be called when re-initializing a deleted root")) .replace(any(Metadata.class), any(Dataset.class)); verify(mockService, description("Verify that the root resource is fetched only once")).get(root); }
@Test public void testInitializeoNoLdpResource() throws Exception { final ResourceService mockService = mock(ResourceService.class); when(mockBundler.getResourceService()).thenReturn(mockService); when(mockService.get(eq(root))).thenAnswer(inv -> completedFuture(MISSING_RESOURCE)); when(mockService.create(any(Metadata.class), any(Dataset.class))).thenReturn(completedFuture(null)); final TrellisHttpResource matcher = new TrellisHttpResource(mockBundler); matcher.initialize(); verify(mockService, description("Re-create a missing root resource on initialization")) .create(any(Metadata.class), any(Dataset.class)); verify(mockService, never().description("Don't try to replace a non-existent root on initialization")) .replace(any(Metadata.class), any(Dataset.class)); verify(mockService, description("Verify that the root resource is fetched only once")).get(root); }
@Test public void testInitializeExistingLdpResourceWithNoACL() throws Exception { final ResourceService mockService = mock(ResourceService.class); when(mockBundler.getResourceService()).thenReturn(mockService); when(mockService.get(eq(root))).thenAnswer(inv -> completedFuture(mockRootResource)); when(mockRootResource.hasAcl()).thenReturn(false); when(mockService.replace(any(Metadata.class), any(Dataset.class))).thenReturn(completedFuture(null)); final TrellisHttpResource matcher = new TrellisHttpResource(mockBundler); matcher.initialize(); verify(mockService, never().description("When re-initializing the root ACL, create should not be called")) .create(any(Metadata.class), any(Dataset.class)); verify(mockService, description("Use replace when re-initializing the root ACL")) .replace(any(Metadata.class), any(Dataset.class)); verify(mockService, description("Verify that the root resource is fetched only once")).get(root); }