@Test public void testError() throws JMSException { doThrow(JMSException.class).when(mockProducer).send(eq(mockMessage)); final EventService svc = new JmsPublisher(mockSession, queueName); svc.emit(mockEvent); verify(mockProducer).send(eq(mockMessage)); } }
@Test public void testJms() throws JMSException { final EventService svc = new JmsPublisher(mockConnection); svc.emit(mockEvent); verify(mockProducer).send(eq(mockMessage)); }
notifications.emit(new Notification(toExternal(identifier, baseUrl).getIRIString(), dataset));
@Test public void testPostIndirectContainer() { final EventService myEventService = mock(EventService.class); when(mockBundler.getEventService()).thenReturn(myEventService); when(mockRootResource.getInteractionModel()).thenReturn(LDP.IndirectContainer); when(mockRootResource.getMembershipResource()).thenReturn(of(newresourceIdentifier)); when(mockResourceService.get(eq(rdf.createIRI(TRELLIS_DATA_PREFIX + RANDOM_VALUE)))) .thenAnswer(inv -> completedFuture(MISSING_RESOURCE)); final Response res = target().request() .post(entity("<> <http://purl.org/dc/terms/title> \"An indirect container\" .", TEXT_TURTLE_TYPE)); assertEquals(SC_CREATED, res.getStatus(), "Unexpected response code!"); verify(myEventService, times(2)).emit(any()); }
@Test public void testPutUncontainedIndirectContainer() { final EventService myEventService = mock(EventService.class); when(mockBundler.getEventService()).thenReturn(myEventService); when(mockRootResource.getInteractionModel()).thenReturn(LDP.IndirectContainer); when(mockRootResource.getMembershipResource()).thenReturn(of(newresourceIdentifier)); when(mockResource.getContainer()).thenReturn(empty()); final Response res = target(RESOURCE_PATH).request() .put(entity("<> <http://purl.org/dc/terms/title> \"A title\" .", TEXT_TURTLE_TYPE)); assertEquals(SC_NO_CONTENT, res.getStatus(), "Unexpected response code!"); verify(myEventService, times(1)).emit(any()); }
@Test public void testPutIndirectContainerSelf() { final EventService myEventService = mock(EventService.class); when(mockBundler.getEventService()).thenReturn(myEventService); when(mockRootResource.getInteractionModel()).thenReturn(LDP.IndirectContainer); when(mockRootResource.getMembershipResource()).thenReturn(of(root)); final Response res = target(RESOURCE_PATH).request() .put(entity("<> <http://purl.org/dc/terms/title> \"A title\" .", TEXT_TURTLE_TYPE)); assertEquals(SC_NO_CONTENT, res.getStatus(), "Unexpected response code!"); verify(myEventService, times(2)).emit(any()); }
@Test public void testPutDirectContainerResource() { final EventService myEventService = mock(EventService.class); when(mockBundler.getEventService()).thenReturn(myEventService); when(mockRootResource.getInteractionModel()).thenReturn(LDP.DirectContainer); when(mockRootResource.getMembershipResource()).thenReturn(of(identifier)); final Response res = target(RESOURCE_PATH).request() .put(entity("<> <http://purl.org/dc/terms/title> \"A title\" .", TEXT_TURTLE_TYPE)); assertEquals(SC_NO_CONTENT, res.getStatus(), "Unexpected response code!"); verify(myEventService, times(1)).emit(any()); }
private CompletionStage<Void> emitMembershipUpdateEvent() { final IRI membershipResource = getParentMembershipResource(); if (nonNull(membershipResource)) { return allOf(getServices().getResourceService().touch(membershipResource).toCompletableFuture(), getServices().getResourceService().get(membershipResource).thenAccept(res -> { if (nonNull(res.getIdentifier())) { getServices().getEventService().emit(new SimpleEvent(getUrl(res.getIdentifier()), getSession().getAgent(), asList(PROV.Activity, AS.Update), asList(res.getInteractionModel()))); } }).toCompletableFuture()); } return completedFuture(null); }
@Test public void testPutIndirectContainer() { final EventService myEventService = mock(EventService.class); when(mockBundler.getEventService()).thenReturn(myEventService); when(mockRootResource.getInteractionModel()).thenReturn(LDP.IndirectContainer); when(mockRootResource.getMembershipResource()).thenReturn(of(newresourceIdentifier)); final Response res = target(RESOURCE_PATH).request() .put(entity("<> <http://purl.org/dc/terms/title> \"A title\" .", TEXT_TURTLE_TYPE)); assertEquals(SC_NO_CONTENT, res.getStatus(), "Unexpected response code!"); verify(myEventService, times(1)).emit(any()); }
@Test public void testPutDirectContainerSelf() { final EventService myEventService = mock(EventService.class); when(mockBundler.getEventService()).thenReturn(myEventService); when(mockRootResource.getInteractionModel()).thenReturn(LDP.DirectContainer); when(mockRootResource.getMembershipResource()).thenReturn(of(root)); final Response res = target(RESOURCE_PATH).request() .put(entity("<> <http://purl.org/dc/terms/title> \"A title\" .", TEXT_TURTLE_TYPE)); assertEquals(SC_NO_CONTENT, res.getStatus(), "Unexpected response code!"); verify(myEventService, times(1)).emit(any()); }
@Test public void testPutUncontainedIndirectContainerSelf() { final EventService myEventService = mock(EventService.class); when(mockBundler.getEventService()).thenReturn(myEventService); when(mockRootResource.getInteractionModel()).thenReturn(LDP.IndirectContainer); when(mockRootResource.getMembershipResource()).thenReturn(of(root)); when(mockResource.getContainer()).thenReturn(empty()); final Response res = target(RESOURCE_PATH).request() .put(entity("<> <http://purl.org/dc/terms/title> \"A title\" .", TEXT_TURTLE_TYPE)); assertEquals(SC_NO_CONTENT, res.getStatus(), "Unexpected response code!"); verify(myEventService, times(1)).emit(any()); }
@Test public void testPutDirectContainer() { final EventService myEventService = mock(EventService.class); when(mockBundler.getEventService()).thenReturn(myEventService); when(mockRootResource.getInteractionModel()).thenReturn(LDP.DirectContainer); when(mockRootResource.getMembershipResource()).thenReturn(of(newresourceIdentifier)); final Response res = target(RESOURCE_PATH).request() .put(entity("<> <http://purl.org/dc/terms/title> \"A title\" .", TEXT_TURTLE_TYPE)); assertEquals(SC_NO_CONTENT, res.getStatus(), "Unexpected response code!"); verify(myEventService, times(1)).emit(any()); }
@Test public void testPostIndirectContainerSelf() { final EventService myEventService = mock(EventService.class); when(mockBundler.getEventService()).thenReturn(myEventService); when(mockRootResource.getInteractionModel()).thenReturn(LDP.IndirectContainer); when(mockRootResource.getMembershipResource()).thenReturn(of(root)); when(mockResourceService.get(eq(rdf.createIRI(TRELLIS_DATA_PREFIX + RANDOM_VALUE)))) .thenAnswer(inv -> completedFuture(MISSING_RESOURCE)); final Response res = target().request() .post(entity("<> <http://purl.org/dc/terms/title> \"A self-contained LDP-IC\" .", TEXT_TURTLE_TYPE)); assertEquals(SC_CREATED, res.getStatus(), "Unexpected response code!"); verify(myEventService, times(2)).emit(any()); }
@Test public void testPostIndirectContainerResource() { final EventService myEventService = mock(EventService.class); when(mockBundler.getEventService()).thenReturn(myEventService); when(mockRootResource.getInteractionModel()).thenReturn(LDP.IndirectContainer); when(mockRootResource.getMembershipResource()).thenReturn(of(identifier)); when(mockResourceService.get(eq(rdf.createIRI(TRELLIS_DATA_PREFIX + RANDOM_VALUE)))) .thenAnswer(inv -> completedFuture(MISSING_RESOURCE)); final Response res = target().request() .post(entity("<> <http://purl.org/dc/terms/title> \"An LDP-IC\" .", TEXT_TURTLE_TYPE)); assertEquals(SC_CREATED, res.getStatus(), "Unexpected response code!"); verify(myEventService, times(3)).emit(any()); }
@Test public void testPostDirectContainerResource() { final EventService myEventService = mock(EventService.class); when(mockBundler.getEventService()).thenReturn(myEventService); when(mockRootResource.getInteractionModel()).thenReturn(LDP.DirectContainer); when(mockRootResource.getMembershipResource()).thenReturn(of(identifier)); when(mockResourceService.get(eq(rdf.createIRI(TRELLIS_DATA_PREFIX + RANDOM_VALUE)))) .thenAnswer(inv -> completedFuture(MISSING_RESOURCE)); final Response res = target().request() .post(entity("<> <http://purl.org/dc/terms/title> \"An LDP-DC resource\" .", TEXT_TURTLE_TYPE)); assertEquals(SC_CREATED, res.getStatus(), "Unexpected response code!"); verify(myEventService, times(3)).emit(any()); }
@Test public void testPostDirectContainer() { final EventService myEventService = mock(EventService.class); when(mockBundler.getEventService()).thenReturn(myEventService); when(mockRootResource.getInteractionModel()).thenReturn(LDP.DirectContainer); when(mockRootResource.getMembershipResource()).thenReturn(of(newresourceIdentifier)); when(mockResourceService.get(eq(rdf.createIRI(TRELLIS_DATA_PREFIX + RANDOM_VALUE)))) .thenAnswer(inv -> completedFuture(MISSING_RESOURCE)); final Response res = target().request() .post(entity("<> <http://purl.org/dc/terms/title> \"An LDP-DC\" .", TEXT_TURTLE_TYPE)); assertEquals(SC_CREATED, res.getStatus(), "Unexpected response code!"); verify(myEventService, times(2)).emit(any()); }
@Test public void testPostDirectContainerSelf() { final EventService myEventService = mock(EventService.class); when(mockBundler.getEventService()).thenReturn(myEventService); when(mockRootResource.getInteractionModel()).thenReturn(LDP.DirectContainer); when(mockRootResource.getMembershipResource()).thenReturn(of(root)); when(mockResourceService.get(eq(rdf.createIRI(TRELLIS_DATA_PREFIX + RANDOM_VALUE)))) .thenAnswer(inv -> completedFuture(MISSING_RESOURCE)); final Response res = target().request() .post(entity("<> <http://purl.org/dc/terms/title> \"A self-contained LDP-DC\" .", TEXT_TURTLE_TYPE)); assertEquals(SC_CREATED, res.getStatus(), "Unexpected response code!"); verify(myEventService, times(2)).emit(any()); }
@Test public void testPutUncontainedIndirectContainerResource() { final EventService myEventService = mock(EventService.class); final Resource mockChildResource = mock(Resource.class); when(mockBundler.getEventService()).thenReturn(myEventService); when(mockResourceService.get(childIdentifier)).thenAnswer(inv -> completedFuture(mockChildResource)); when(mockRootResource.getInteractionModel()).thenReturn(LDP.IndirectContainer); when(mockRootResource.getMembershipResource()).thenReturn(of(childIdentifier)); when(mockResource.getContainer()).thenReturn(empty()); final Response res = target(RESOURCE_PATH).request() .put(entity("<> <http://purl.org/dc/terms/title> \"A title\" .", TEXT_TURTLE_TYPE)); assertEquals(SC_NO_CONTENT, res.getStatus(), "Unexpected response code!"); verify(myEventService, times(1)).emit(any()); }
@Test public void testError() throws IOException { doThrow(IOException.class).when(mockChannel).basicPublish(eq(exchangeName), eq(queueName), anyBoolean(), anyBoolean(), any(BasicProperties.class), any(byte[].class)); final EventService svc = new AmqpPublisher(mockChannel, exchangeName, queueName, true, true); svc.emit(mockEvent); verify(mockChannel).basicPublish(eq(exchangeName), eq(queueName), anyBoolean(), anyBoolean(), any(BasicProperties.class), any(byte[].class)); } }
@Test public void testPutIndirectContainerResource() { final EventService myEventService = mock(EventService.class); final Resource mockChildResource = mock(Resource.class); when(mockBundler.getEventService()).thenReturn(myEventService); when(mockResourceService.get(childIdentifier)).thenAnswer(inv -> completedFuture(mockChildResource)); when(mockChildResource.getIdentifier()).thenReturn(childIdentifier); when(mockChildResource.getInteractionModel()).thenReturn(LDP.RDFSource); when(mockRootResource.getInteractionModel()).thenReturn(LDP.IndirectContainer); when(mockRootResource.getMembershipResource()).thenReturn(of(childIdentifier)); final Response res = target(RESOURCE_PATH).request() .put(entity("<> <http://purl.org/dc/terms/title> \"A title\" .", TEXT_TURTLE_TYPE)); assertEquals(SC_NO_CONTENT, res.getStatus(), "Unexpected response code!"); verify(myEventService, times(2)).emit(any()); }