Skip to content

Commit

Permalink
fix up rss and webhooks mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Jun 11, 2013
1 parent 5f1cb1b commit c786508
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 27 deletions.
10 changes: 10 additions & 0 deletions fcrepo-http-commons/src/main/java/org/fcrepo/AbstractResource.java
Expand Up @@ -260,4 +260,14 @@ public void setObjectService(final ObjectService objectService) {
public void setDatastreamService(final DatastreamService datastreamService) {
this.datastreamService = datastreamService;
}


/**
* Set the Event Bus, used primary for testing without spring
* @param eventBus
*/
public void setEventBus(final EventBus eventBus) {
this.eventBus = eventBus;
}

}
Expand Up @@ -26,19 +26,19 @@ public void setUp() {
@Test
public void testGetFeed() throws Exception {
EventBus mockBus = mock(EventBus.class);
setField("eventBus", testObj, mockBus);
testObj.setEventBus(mockBus);
UriInfo mockUris = mock(UriInfo.class);
URI mockUri = new URI("http://localhost.info");
when(mockUris.getBaseUri()).thenReturn(mockUri);
setField("uriInfo", AbstractResource.class,testObj, mockUris);
testObj.setUriInfo(mockUris);
testObj.initialize();
testObj.getFeed();
}

@Test
public void testInitialize() throws Exception {
EventBus mockBus = mock(EventBus.class);
setField("eventBus", testObj, mockBus);
testObj.setEventBus(mockBus);
testObj.initialize();
verify(mockBus).register(testObj);
}
Expand All @@ -48,16 +48,5 @@ public void testNewEvent() {
Event mockEvent = mock(Event.class);
testObj.newEvent(mockEvent);
}

private static void setField(String name, Class<?> type, RSSPublisher obj, Object val)
throws Exception {
Field field = type.getDeclaredField(name);
field.setAccessible(true);
field.set(obj, val);
}

private static void setField(String name, RSSPublisher obj, Object val)
throws Exception {
setField(name, RSSPublisher.class, obj, val);
}
}
Expand Up @@ -51,13 +51,13 @@ public void setUp() throws Exception {
when(mockSessions.getSession()).thenReturn(mockSession);
when(mockSessions.getSession(any(SecurityContext.class), any(HttpServletRequest.class)))
.thenReturn(mockSession);
setField("sessions", AbstractResource.class, testObj, mockSessions);
testObj.setSessionFactory(mockSessions);
}

@Test
public void testInitialize() throws Exception {
EventBus mockBus = mock(EventBus.class);
setField("eventBus", testObj, mockBus);
testObj.setEventBus(mockBus);
testObj.initialize();
verify(mockBus).register(testObj);
}
Expand Down Expand Up @@ -116,15 +116,4 @@ public void testSessions() {
verify(mockSession).logout();
}

private static void setField(String name, Class<?> type, FedoraWebhooks obj, Object val)
throws Exception {
Field field = type.getDeclaredField(name);
field.setAccessible(true);
field.set(obj, val);
}

private static void setField(String name, FedoraWebhooks obj, Object val)
throws Exception {
setField(name, FedoraWebhooks.class, obj, val);
}
}

0 comments on commit c786508

Please sign in to comment.