コード例 #1
0
  /**
   * Test if the associator selects using the most important attribute first. That is, use eventId
   * before location.
   *
   * <p>This test creates 2 events, A and B, and a summary X. A and B both have eventId and location
   * information. B's location is closest to X's location, but A's eventId matches X's. The
   * associator should choose A.
   */
  @Test
  public void testAssociationOrder() {
    Date eventTime = new Date();

    // Create the first event
    ProductSummary eventSummaryA = new ProductSummary();
    eventSummaryA.setId(new ProductId("productsource", "producttype", "productcode"));
    eventSummaryA.setEventSource("source");
    eventSummaryA.setEventSourceCode("code");
    eventSummaryA.setEventLatitude(new BigDecimal("10.0"));
    eventSummaryA.setEventLongitude(new BigDecimal("10.0"));
    eventSummaryA.setEventTime(eventTime);
    Event eventA = new Event();
    eventA.addProduct(eventSummaryA);

    // Create the second event
    ProductSummary eventSummaryB = new ProductSummary();
    eventSummaryB.setId(new ProductId("productsource", "producttype", "productcode"));
    eventSummaryB.setEventSource("source2");
    eventSummaryB.setEventSourceCode("code2");
    eventSummaryB.setEventLatitude(new BigDecimal("0.0"));
    eventSummaryB.setEventLongitude(new BigDecimal("0.0"));
    eventSummaryB.setEventTime(eventTime);
    Event eventB = new Event();
    eventB.addProduct(eventSummaryB);

    // Create the test summary
    ProductSummary summaryX = new ProductSummary();
    summaryX.setId(new ProductId("productsource", "producttype", "productcode"));
    summaryX.setEventSource("source");
    summaryX.setEventSourceCode("code");
    summaryX.setEventLatitude(new BigDecimal("0.0"));
    summaryX.setEventLongitude(new BigDecimal("0.0"));
    summaryX.setEventTime(eventTime);

    // Add the events to a list
    List<Event> events = new LinkedList<Event>();
    events.add(eventA);
    events.add(eventB);

    // Test to verify event A is chosen.
    DefaultAssociator associator = new DefaultAssociator();
    Event event = associator.chooseEvent(events, summaryX);
    Assert.assertEquals("Event from same source with same code chosen", eventA, event);
  }
コード例 #2
0
 /**
  * Create an event with an origin product that has the given parameters
  *
  * @param lat
  * @param lon
  * @param d
  * @return Generated Event
  */
 private Event createEvent(String source, String code, BigDecimal lat, BigDecimal lon, Date d) {
   ProductSummary p = new ProductSummary();
   ProductId id = new ProductId("testSource", "origin", "abc123");
   p.setId(id);
   p.setEventSource(source);
   p.setEventSourceCode(code);
   p.setEventLatitude(lat);
   p.setEventLongitude(lon);
   p.setEventTime(d);
   Event event = new Event();
   event.addProduct(p);
   return event;
 }
コード例 #3
0
 private Event createDifferentEvent(
     BigDecimal lat, BigDecimal lon, Date d, String source, String type, String code) {
   ProductSummary p = new ProductSummary();
   ProductId id = new ProductId(source, type, code);
   p.setId(id);
   p.setEventLatitude(lat);
   p.setEventLongitude(lon);
   p.setEventTime(d);
   p.setEventSource(source);
   p.setEventSourceCode(code);
   Event event = new Event();
   event.addProduct(p);
   return event;
 }
コード例 #4
0
  /**
   * When an event source submits data using the same code, they refer to the same event.
   *
   * <p>The associator shouldn't filter an event when it uses the same source and code (although it
   * won't necessarily choose that event because it has the same source and code).
   */
  @Test
  public void testSameEventCodeFromSameSource() {
    ProductSummary summary = new ProductSummary();
    summary.setEventSource("source");
    summary.setEventSourceCode("code");

    // build event from same source, with same code
    ProductSummary differentSummary = new ProductSummary();
    differentSummary.setId(new ProductId("productsource", "producttype", "productcode"));
    differentSummary.setEventSource("source");
    differentSummary.setEventSourceCode("code");

    Event sameEvent = new Event();
    sameEvent.addProduct(differentSummary);

    List<Event> events = new LinkedList<Event>();
    events.add(sameEvent);

    // test to verify event is chosen
    DefaultAssociator associator = new DefaultAssociator();
    Event event = associator.chooseEvent(events, summary);

    Assert.assertEquals("Event from same source with same code chosen", sameEvent, event);
  }
コード例 #5
0
  @Test
  public void testDateTimeLine() {

    Date eventTime = new Date();
    DefaultAssociator associator = new DefaultAssociator();

    // Create the first event
    ProductSummary eventSummaryA = new ProductSummary();
    eventSummaryA.setId(new ProductId("us", "origin", "1234abcd"));
    eventSummaryA.setEventSource("us");
    eventSummaryA.setEventSourceCode("1234abcd");
    eventSummaryA.setEventLatitude(new BigDecimal("0.0"));
    eventSummaryA.setEventLongitude(new BigDecimal("179.80"));
    eventSummaryA.setEventTime(eventTime);
    Event eventA = new Event();
    eventA.addProduct(eventSummaryA);

    // Create the second event
    ProductSummary eventSummaryB = new ProductSummary();
    eventSummaryB.setId(new ProductId("ci", "origin", "5678efgh"));
    eventSummaryB.setEventSource("ci");
    eventSummaryB.setEventSourceCode("5678efgh");
    eventSummaryB.setEventLatitude(new BigDecimal("0.0"));
    eventSummaryB.setEventLongitude(new BigDecimal("179.50"));
    eventSummaryB.setEventTime(eventTime);
    Event eventB = new Event();
    eventB.addProduct(eventSummaryB);

    /*
     * Verify that events associate (0.3 degrees apart) when the points are
     * not crossing date line
     */

    Assert.assertTrue(associator.eventsAssociated(eventA, eventB));

    // Create the third event
    ProductSummary eventSummaryC = new ProductSummary();
    eventSummaryC.setId(new ProductId("us", "origin", "1234abcd"));
    eventSummaryC.setEventSource("us");
    eventSummaryC.setEventSourceCode("1234abcd");
    eventSummaryC.setEventLatitude(new BigDecimal("0.0"));
    eventSummaryC.setEventLongitude(new BigDecimal("179.85"));
    eventSummaryC.setEventTime(eventTime);
    Event eventC = new Event();
    eventC.addProduct(eventSummaryC);

    // Create the fourth event
    ProductSummary eventSummaryD = new ProductSummary();
    eventSummaryD.setId(new ProductId("ci", "origin", "5678efgh"));
    eventSummaryD.setEventSource("ci");
    eventSummaryD.setEventSourceCode("5678efgh");
    eventSummaryD.setEventLatitude(new BigDecimal("0.0"));
    eventSummaryD.setEventLongitude(new BigDecimal("-179.85"));
    eventSummaryD.setEventTime(eventTime);
    Event eventD = new Event();
    eventD.addProduct(eventSummaryD);

    /*
     * Verify that events associate (0.3 degrees apart) when the points do
     * cross the date line
     */

    Assert.assertTrue(associator.eventsAssociated(eventC, eventD));

    // Create the fifth event
    ProductSummary eventSummaryE = new ProductSummary();
    eventSummaryE.setId(new ProductId("us", "origin", "1234abcd"));
    eventSummaryE.setEventSource("us");
    eventSummaryE.setEventSourceCode("1234abcd");
    eventSummaryE.setEventLatitude(new BigDecimal("0.0"));
    eventSummaryE.setEventLongitude(new BigDecimal("-179.85"));
    eventSummaryE.setEventTime(eventTime);
    Event eventE = new Event();
    eventE.addProduct(eventSummaryE);

    // Create the sixth event
    ProductSummary eventSummaryF = new ProductSummary();
    eventSummaryF.setId(new ProductId("ci", "origin", "5678efgh"));
    eventSummaryF.setEventSource("ci");
    eventSummaryF.setEventSourceCode("5678efgh");
    eventSummaryF.setEventLatitude(new BigDecimal("0.0"));
    eventSummaryF.setEventLongitude(new BigDecimal("179.85"));
    eventSummaryF.setEventTime(eventTime);
    Event eventF = new Event();
    eventF.addProduct(eventSummaryF);

    /*
     * Verify that events associate (0.3 degrees apart) when the points do
     * cross the date line, reversing the order. This checks that
     * jdbcProductIndex.normalizeLongitude is working in both directions
     * across the dateline.
     */

    Assert.assertTrue(associator.eventsAssociated(eventE, eventF));

    // Create the seventh event
    ProductSummary eventSummaryG = new ProductSummary();
    eventSummaryG.setId(new ProductId("us", "origin", "1234abcd"));
    eventSummaryG.setEventSource("us");
    eventSummaryG.setEventSourceCode("1234abcd");
    eventSummaryG.setEventLatitude(new BigDecimal("0.0"));
    eventSummaryG.setEventLongitude(new BigDecimal("50"));
    eventSummaryG.setEventTime(eventTime);
    Event eventG = new Event();
    eventG.addProduct(eventSummaryG);

    // Create the eighth event
    ProductSummary eventSummaryH = new ProductSummary();
    eventSummaryH.setId(new ProductId("ci", "origin", "5678efgh"));
    eventSummaryH.setEventSource("ci");
    eventSummaryH.setEventSourceCode("5678efgh");
    eventSummaryH.setEventLatitude(new BigDecimal("0.0"));
    eventSummaryH.setEventLongitude(new BigDecimal("100"));
    eventSummaryH.setEventTime(eventTime);
    Event eventH = new Event();
    eventH.addProduct(eventSummaryH);

    /*
     * Verify that events do NOT associate, when they are more than 100km
     * apart
     */

    Assert.assertFalse(associator.eventsAssociated(eventG, eventH));
  }