UpdateParent implements FindChildrenStreamEndPlugin.Handler { @Override public void end(Context context, Metacard parentMetacard) { updateField.end(parentMetacard, context); UpdateRequest updateRequest = createUpdateRequest(parentMetacard); update(context, parentMetacard, updateRequest); } UpdateParent(UpdateField updateField); void setCatalogUpdateRetry(CatalogUpdateRetry catalogUpdateRetry); @Override void handle(Context context, Metacard parent, List<Metacard> children); @Override void end(Context context, Metacard parentMetacard);  }
@Test public void testEnd() throws SourceUnavailableException, IngestException { UpdateParent.UpdateField updateField = mock(UpdateParent.UpdateField.class); UpdateParent updateParent = new UpdateParent(updateField); UdpStreamProcessor udpStreamProcessor = mock(UdpStreamProcessor.class); CatalogFramework catalogFramework = mock(CatalogFramework.class); when(udpStreamProcessor.getCatalogFramework()).thenReturn(catalogFramework); when(udpStreamProcessor.getMetacardUpdateInitialDelay()).thenReturn(1L); Context context = mock(Context.class); when(context.getUdpStreamProcessor()).thenReturn(udpStreamProcessor); Metacard parent = mock(Metacard.class); UpdateResponse updateResponse = mock(UpdateResponse.class); Update update = mock(Update.class); when(update.getNewMetacard()).thenReturn(parent); when(updateResponse.getUpdatedMetacards()).thenReturn(Collections.singletonList(update)); when(catalogFramework.update(any(UpdateRequest.class))).thenReturn(updateResponse); updateParent.end(context, parent); verify(updateField).end(parent, context); ArgumentCaptor<UpdateRequest> captor = ArgumentCaptor.forClass(UpdateRequest.class); verify(catalogFramework).update(captor.capture()); assertThat(captor.getValue().getUpdates().get(0).getValue(), is(parent)); }
@Test(expected = IllegalStateException.class) public void testCallUpdateAfterEnd() { UpdateParent.UpdateField updateField = new UpdateParent.BaseUpdateField() { @Override protected void doEnd(Metacard parent, Context context) {} @Override protected void doUpdateField(Metacard parent, List<Metacard> children, Context context) {} }; Context context = mock(Context.class); Metacard parent = mock(Metacard.class); Metacard child = mock(Metacard.class); updateField.end(parent, context); updateField.updateField(parent, Collections.singletonList(child), context); }