Search in sources :

Example 1 with GeometryOperator

use of org.codice.alliance.libs.klv.GeometryOperator in project alliance by codice.

the class FrameCenterUpdateFieldTest method testThatGeoOperatorIsCalled.

@Test
public void testThatGeoOperatorIsCalled() throws ParseException {
    String wktChild1 = "LINESTRING (30 10, 10 30, 40 40)";
    GeometryOperator geometryOperator = mock(GeometryOperator.class);
    Geometry geometry = new WKTReader().read("LINESTRING (0 0, 1 1)");
    Context context = mock(Context.class);
    GeometryOperator.Context geometryOperatorContext = new GeometryOperator.Context();
    geometryOperatorContext.setSubsampleCount(FrameCenterUpdateField.MAX_SIZE * 2);
    when(context.getGeometryOperatorContext()).thenReturn(geometryOperatorContext);
    when(geometryOperator.apply(any(), any())).thenReturn(geometry);
    Metacard parentMetacard = mock(Metacard.class);
    Metacard childMetacard1 = mock(Metacard.class);
    when(childMetacard1.getAttribute(AttributeNameConstants.FRAME_CENTER)).thenReturn(new AttributeImpl(AttributeNameConstants.FRAME_CENTER, wktChild1));
    FrameCenterUpdateField frameCenterUpdateField = new FrameCenterUpdateField(geometryOperator, new GeometryFactory());
    frameCenterUpdateField.updateField(parentMetacard, Collections.singletonList(childMetacard1), context);
    verify(geometryOperator, never()).apply(any(), any());
    frameCenterUpdateField.end(parentMetacard, context);
    verify(geometryOperator, times(1)).apply(any(), any());
    assertThat(geometryOperatorContext.getSubsampleCount(), is(FrameCenterUpdateField.MAX_SIZE * 2));
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Context(org.codice.alliance.video.stream.mpegts.Context) Metacard(ddf.catalog.data.Metacard) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) GeometryOperator(org.codice.alliance.libs.klv.GeometryOperator) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) WKTReader(com.vividsolutions.jts.io.WKTReader) Test(org.junit.Test)

Example 2 with GeometryOperator

use of org.codice.alliance.libs.klv.GeometryOperator in project alliance by codice.

the class FrameCenterUpdateFieldTest method testThatSubsampleCountIsResetOnException.

@Test(expected = RuntimeException.class)
public void testThatSubsampleCountIsResetOnException() throws ParseException {
    String wktChild1 = "LINESTRING (30 10, 10 30, 40 40)";
    GeometryOperator geometryOperator = mock(GeometryOperator.class);
    Geometry geometry = new WKTReader().read("LINESTRING (0 0, 1 1)");
    Context context = mock(Context.class);
    GeometryOperator.Context geometryOperatorContext = new GeometryOperator.Context();
    geometryOperatorContext.setSubsampleCount(FrameCenterUpdateField.MAX_SIZE * 2);
    when(context.getGeometryOperatorContext()).thenReturn(geometryOperatorContext);
    when(geometryOperator.apply(any(), any())).thenThrow(RuntimeException.class);
    Metacard parentMetacard = mock(Metacard.class);
    Metacard childMetacard1 = mock(Metacard.class);
    when(childMetacard1.getAttribute(AttributeNameConstants.FRAME_CENTER)).thenReturn(new AttributeImpl(AttributeNameConstants.FRAME_CENTER, wktChild1));
    FrameCenterUpdateField frameCenterUpdateField = new FrameCenterUpdateField(geometryOperator, new GeometryFactory());
    frameCenterUpdateField.updateField(parentMetacard, Collections.singletonList(childMetacard1), context);
    verify(geometryOperator, never()).apply(any(), any());
    try {
        frameCenterUpdateField.end(parentMetacard, context);
        verify(geometryOperator, times(1)).apply(any(), any());
    } finally {
        assertThat(geometryOperatorContext.getSubsampleCount(), is(FrameCenterUpdateField.MAX_SIZE * 2));
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Context(org.codice.alliance.video.stream.mpegts.Context) Metacard(ddf.catalog.data.Metacard) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) GeometryOperator(org.codice.alliance.libs.klv.GeometryOperator) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) WKTReader(com.vividsolutions.jts.io.WKTReader) Test(org.junit.Test)

Example 3 with GeometryOperator

use of org.codice.alliance.libs.klv.GeometryOperator in project alliance by codice.

the class FrameCenterUpdateFieldFactoryTest method testBuild.

@Test
public void testBuild() {
    GeometryOperator geometryOperator = mock(GeometryOperator.class);
    FrameCenterUpdateFieldFactory factory = new FrameCenterUpdateFieldFactory(geometryOperator, new GeometryFactory());
    UpdateParent.UpdateField updateField = factory.build();
    assertThat(updateField, is(instanceOf(FrameCenterUpdateField.class)));
}
Also used : GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) GeometryOperator(org.codice.alliance.libs.klv.GeometryOperator) Test(org.junit.Test)

Example 4 with GeometryOperator

use of org.codice.alliance.libs.klv.GeometryOperator in project alliance by codice.

the class LocationUpdateFieldFactoryTest method testBuild.

@Test
public void testBuild() {
    GeometryOperator preUnionGeometryOperator = mock(GeometryOperator.class);
    GeometryOperator postUnionGeometryOperator = mock(GeometryOperator.class);
    LocationUpdateFieldFactory factory = new LocationUpdateFieldFactory(preUnionGeometryOperator, postUnionGeometryOperator);
    UpdateParent.UpdateField updateField = factory.build();
    assertThat(updateField, is(instanceOf(LocationUpdateField.class)));
    LocationUpdateField locationUpdateField = (LocationUpdateField) updateField;
    assertThat(locationUpdateField.getPreUnionGeometryOperator(), is(preUnionGeometryOperator));
    assertThat(locationUpdateField.getPostUnionGeometryOperator(), is(postUnionGeometryOperator));
}
Also used : GeometryOperator(org.codice.alliance.libs.klv.GeometryOperator) Test(org.junit.Test)

Example 5 with GeometryOperator

use of org.codice.alliance.libs.klv.GeometryOperator in project alliance by codice.

the class CatalogRolloverActionTest method setup.

@Before
public void setup() throws SourceUnavailableException, IngestException {
    FilenameGenerator filenameGenerator = mock(FilenameGenerator.class);
    String filenameTemplate = "filenameTemplate";
    StreamProcessor streamProcessor = mock(StreamProcessor.class);
    when(streamProcessor.getMetacardUpdateInitialDelay()).thenReturn(1L);
    catalogFramework = mock(CatalogFramework.class);
    MetacardType metacardType = mock(MetacardType.class);
    tempFile = new File("someTempFile");
    URI uri = URI.create("udp://127.0.0.1:10000");
    String title = "theTitleString";
    childWkt = "POLYGON (( 0.5 0.5, 1.5 0.5, 1.5 1.5, 0.5 1.5, 0.5 0.5 ))";
    when(metacardType.getAttributeDescriptor(AttributeNameConstants.TEMPORAL_START)).thenReturn(mock(AttributeDescriptor.class));
    when(metacardType.getAttributeDescriptor(AttributeNameConstants.TEMPORAL_END)).thenReturn(mock(AttributeDescriptor.class));
    UdpStreamProcessor udpStreamProcessor = mock(UdpStreamProcessor.class);
    when(udpStreamProcessor.getSubject()).thenReturn(new SimpleSubject());
    Context context = new Context(udpStreamProcessor);
    when(udpStreamProcessor.getMetacardTypeList()).thenReturn(Collections.singletonList(metacardType));
    when(udpStreamProcessor.getStreamUri()).thenReturn(Optional.of(uri));
    when(udpStreamProcessor.getTitle()).thenReturn(Optional.of(title));
    Security security = mock(Security.class);
    Subject subject = mock(Subject.class);
    when(security.getSystemSubject()).thenReturn(subject);
    GeometryOperator postUnionGeometryOperator = new GeometryOperatorList(Arrays.asList(new SimplifyGeometryFunction(), new NormalizeGeometry()));
    UuidGenerator uuidGenerator = mock(UuidGenerator.class);
    when(uuidGenerator.generateUuid()).thenReturn("anId");
    catalogRolloverAction = new CatalogRolloverAction(filenameGenerator, filenameTemplate, catalogFramework, context, new ListMetacardUpdater(Arrays.asList(new LocationMetacardUpdater(postUnionGeometryOperator, GeometryOperator.IDENTITY), new TemporalStartMetacardUpdater(), new TemporalEndMetacardUpdater(), new ModifiedDateMetacardUpdater(), new FrameCenterMetacardUpdater(postUnionGeometryOperator))), uuidGenerator);
    createdParentMetacard = mock(Metacard.class);
    when(createdParentMetacard.getMetacardType()).thenReturn(metacardType);
    context.setParentMetacard(createdParentMetacard);
    context.getGeometryOperatorContext().setDistanceTolerance(0.0025);
    createdChildMetacard = mock(Metacard.class);
    when(createdChildMetacard.getMetacardType()).thenReturn(metacardType);
    Metacard updatedParentMetacard = mock(Metacard.class);
    when(updatedParentMetacard.getMetacardType()).thenReturn(metacardType);
    Metacard updatedChildMetacard = mock(Metacard.class);
    when(updatedChildMetacard.getMetacardType()).thenReturn(metacardType);
    CreateResponse createResponse = mock(CreateResponse.class);
    CreateResponse storageCreateResponse = mock(CreateResponse.class);
    Update childUpdate = mock(Update.class);
    childUpdateResponse = mock(UpdateResponse.class);
    Update parentUpdate = mock(Update.class);
    parentUpdateResponse = mock(UpdateResponse.class);
    when(createResponse.getCreatedMetacards()).thenReturn(Collections.singletonList(createdParentMetacard));
    when(storageCreateResponse.getCreatedMetacards()).thenReturn(Collections.singletonList(createdChildMetacard));
    when(childUpdate.getNewMetacard()).thenReturn(updatedChildMetacard);
    when(childUpdateResponse.getUpdatedMetacards()).thenReturn(Collections.singletonList(childUpdate));
    when(parentUpdate.getNewMetacard()).thenReturn(updatedParentMetacard);
    when(parentUpdateResponse.getUpdatedMetacards()).thenReturn(Collections.singletonList(parentUpdate));
    when(filenameGenerator.generateFilename(any())).thenReturn("someFileName");
    when(streamProcessor.getStreamUri()).thenReturn(Optional.of(uri));
    when(streamProcessor.getTitle()).thenReturn(Optional.of(title));
    when(catalogFramework.create(any(CreateRequest.class))).thenReturn(createResponse);
    when(catalogFramework.create(any(CreateStorageRequest.class))).thenReturn(storageCreateResponse);
    when(catalogFramework.update(any(UpdateRequest.class))).thenReturn(childUpdateResponse).thenReturn(parentUpdateResponse);
    when(createdChildMetacard.getLocation()).thenReturn(childWkt);
    when(createdChildMetacard.getAttribute(AttributeNameConstants.TEMPORAL_START)).thenReturn(new AttributeImpl(AttributeNameConstants.TEMPORAL_START, TEMPORAL_START_DATE));
    when(createdChildMetacard.getAttribute(AttributeNameConstants.TEMPORAL_END)).thenReturn(new AttributeImpl(AttributeNameConstants.TEMPORAL_END, TEMPORAL_END_DATE));
}
Also used : UuidGenerator(org.codice.ddf.platform.util.uuidgenerator.UuidGenerator) ModifiedDateMetacardUpdater(org.codice.alliance.video.stream.mpegts.metacard.ModifiedDateMetacardUpdater) CreateResponse(ddf.catalog.operation.CreateResponse) CreateRequest(ddf.catalog.operation.CreateRequest) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) TemporalEndMetacardUpdater(org.codice.alliance.video.stream.mpegts.metacard.TemporalEndMetacardUpdater) SimpleSubject(org.codice.alliance.video.stream.mpegts.SimpleSubject) Security(org.codice.ddf.security.common.Security) Update(ddf.catalog.operation.Update) URI(java.net.URI) TemporalStartMetacardUpdater(org.codice.alliance.video.stream.mpegts.metacard.TemporalStartMetacardUpdater) UpdateResponse(ddf.catalog.operation.UpdateResponse) GeometryOperator(org.codice.alliance.libs.klv.GeometryOperator) NormalizeGeometry(org.codice.alliance.libs.klv.NormalizeGeometry) CatalogFramework(ddf.catalog.CatalogFramework) SimplifyGeometryFunction(org.codice.alliance.libs.klv.SimplifyGeometryFunction) UdpStreamProcessor(org.codice.alliance.video.stream.mpegts.netty.UdpStreamProcessor) Context(org.codice.alliance.video.stream.mpegts.Context) UdpStreamProcessor(org.codice.alliance.video.stream.mpegts.netty.UdpStreamProcessor) StreamProcessor(org.codice.alliance.video.stream.mpegts.netty.StreamProcessor) ListMetacardUpdater(org.codice.alliance.video.stream.mpegts.metacard.ListMetacardUpdater) FrameCenterMetacardUpdater(org.codice.alliance.video.stream.mpegts.metacard.FrameCenterMetacardUpdater) MetacardType(ddf.catalog.data.MetacardType) SimpleSubject(org.codice.alliance.video.stream.mpegts.SimpleSubject) Subject(ddf.security.Subject) LocationMetacardUpdater(org.codice.alliance.video.stream.mpegts.metacard.LocationMetacardUpdater) GeometryOperatorList(org.codice.alliance.libs.klv.GeometryOperatorList) Metacard(ddf.catalog.data.Metacard) FilenameGenerator(org.codice.alliance.video.stream.mpegts.filename.FilenameGenerator) File(java.io.File) CreateStorageRequest(ddf.catalog.content.operation.CreateStorageRequest) Before(org.junit.Before)

Aggregations

GeometryOperator (org.codice.alliance.libs.klv.GeometryOperator)7 Test (org.junit.Test)6 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)3 Metacard (ddf.catalog.data.Metacard)3 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)3 Context (org.codice.alliance.video.stream.mpegts.Context)3 Geometry (com.vividsolutions.jts.geom.Geometry)2 WKTReader (com.vividsolutions.jts.io.WKTReader)2 CatalogFramework (ddf.catalog.CatalogFramework)1 CreateStorageRequest (ddf.catalog.content.operation.CreateStorageRequest)1 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)1 MetacardType (ddf.catalog.data.MetacardType)1 CreateRequest (ddf.catalog.operation.CreateRequest)1 CreateResponse (ddf.catalog.operation.CreateResponse)1 Update (ddf.catalog.operation.Update)1 UpdateResponse (ddf.catalog.operation.UpdateResponse)1 Subject (ddf.security.Subject)1 File (java.io.File)1 URI (java.net.URI)1 GeometryOperatorList (org.codice.alliance.libs.klv.GeometryOperatorList)1