use of org.codice.alliance.video.stream.mpegts.Context in project alliance by codice.
the class UpdateParentTest method testEnd.
/**
* Test that #end calls the catalog framework
*/
@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));
}
use of org.codice.alliance.video.stream.mpegts.Context in project alliance by codice.
the class LineStringMetacardUpdaterTest method testChildOnly.
@Test
public void testChildOnly() throws ParseException {
String childWkt = normalize("LINESTRING(0 0, 1 1)");
when(childAttr.getValue()).thenReturn(childWkt);
when(childMetacard.getAttribute(attrName)).thenReturn(childAttr);
Context context = mock(Context.class);
lineStringMetacardUpdater.update(parentMetacard, childMetacard, context);
ArgumentCaptor<Attribute> argumentCaptor = ArgumentCaptor.forClass(Attribute.class);
verify(parentMetacard).setAttribute(argumentCaptor.capture());
assertThat(argumentCaptor.getValue().getValue(), is(childWkt));
}
use of org.codice.alliance.video.stream.mpegts.Context in project alliance by codice.
the class LocationUpdateField method doUpdateField.
@Override
protected void doUpdateField(Metacard parent, List<Metacard> children, Context context) {
WKTReader wktReader = new WKTReader();
List<String> childLocations = extractChildLocations(children);
List<Geometry> geometries = childLocations.stream().map(s -> GeometryUtility.wktToGeometry(s, wktReader)).filter(Optional::isPresent).map(Optional::get).map(geometry -> preUnionGeometryOperator.apply(geometry, context.getGeometryOperatorContext())).collect(Collectors.toList());
if (intermediateGeometry != null) {
geometries.add(intermediateGeometry);
}
geometries.stream().reduce(Geometry::union).ifPresent(geometry -> intermediateGeometry = geometry);
}
use of org.codice.alliance.video.stream.mpegts.Context in project alliance by codice.
the class FrameCenterUpdateField method doUpdateField.
@Override
protected void doUpdateField(Metacard parent, List<Metacard> children, Context context) {
WKTReader wktReader = new WKTReader();
List<String> childLocations = extractChildFrameCenters(children);
List<Geometry> geometries = new LinkedList<>();
if (intermediateGeometry != null) {
geometries.add(intermediateGeometry);
}
geometries.addAll(childLocations.stream().map(s -> GeometryUtility.wktToGeometry(s, wktReader)).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList()));
List<Coordinate> coordinates = geometries.stream().flatMap(geometry -> Stream.of(geometry.getCoordinates())).collect(Collectors.toList());
intermediateGeometry = geometryFactory.createLineString(coordinates.toArray(new Coordinate[coordinates.size()]));
}
use of org.codice.alliance.video.stream.mpegts.Context in project alliance by codice.
the class FrameCenterUpdateFieldTest method testLineString.
@Test
public void testLineString() {
String wktChild1 = "LINESTRING (30 10, 10 30, 40 40)";
String wktChild2 = "LINESTRING (50 50, 60 60, 70 70)";
String wktChild3 = "LINESTRING (80 80, 85 85)";
String wktExpected = "LINESTRING (30 10, 10 30, 40 40, 50 50, 60 60, 70 70, 80 80, 85 85)";
Metacard parentMetacard = mock(Metacard.class);
Metacard childMetacard1 = mock(Metacard.class);
when(childMetacard1.getAttribute(AttributeNameConstants.FRAME_CENTER)).thenReturn(new AttributeImpl(AttributeNameConstants.FRAME_CENTER, wktChild1));
Metacard childMetacard2 = mock(Metacard.class);
when(childMetacard2.getAttribute(AttributeNameConstants.FRAME_CENTER)).thenReturn(new AttributeImpl(AttributeNameConstants.FRAME_CENTER, wktChild2));
Metacard childMetacard3 = mock(Metacard.class);
when(childMetacard3.getAttribute(AttributeNameConstants.FRAME_CENTER)).thenReturn(new AttributeImpl(AttributeNameConstants.FRAME_CENTER, wktChild3));
FrameCenterUpdateField frameCenterUpdateField = new FrameCenterUpdateField(GeometryOperator.IDENTITY, new GeometryFactory());
Context context = mock(Context.class);
GeometryOperator.Context geometryOperatorContext = new GeometryOperator.Context();
geometryOperatorContext.setSubsampleCount(FrameCenterUpdateField.MAX_SIZE * 2);
when(context.getGeometryOperatorContext()).thenReturn(geometryOperatorContext);
frameCenterUpdateField.updateField(parentMetacard, Collections.singletonList(childMetacard1), context);
frameCenterUpdateField.updateField(parentMetacard, Arrays.asList(childMetacard2, childMetacard3), context);
frameCenterUpdateField.end(parentMetacard, context);
ArgumentCaptor<Attribute> captor = ArgumentCaptor.forClass(Attribute.class);
verify(parentMetacard).setAttribute(captor.capture());
assertThat(captor.getValue().getValue(), is(wktExpected));
assertThat(geometryOperatorContext.getSubsampleCount(), is(FrameCenterUpdateField.MAX_SIZE * 2));
}
Aggregations