@Test
  public void testBridgeMapping() throws Exception {
    Address address = new Address();
    address.setStreet1("Peachtree Rd NE");
    address.setStreet2("JBoss");

    FullTextSession s = Search.getFullTextSession(openSession());
    Transaction tx = s.beginTransaction();
    s.persist(address);
    tx.commit();

    s.clear();

    tx = s.beginTransaction();

    QueryParser parser = new QueryParser("id", TestConstants.standardAnalyzer);
    org.apache.lucene.search.Query luceneQuery = parser.parse("street1:peac");
    FullTextQuery query = s.createFullTextQuery(luceneQuery);
    assertEquals("PrefixQuery should not be on", 0, query.getResultSize());

    luceneQuery = parser.parse("street1_abridged:peac");
    query = s.createFullTextQuery(luceneQuery);
    assertEquals("Bridge not used", 1, query.getResultSize());

    s.delete(query.list().get(0));
    tx.commit();
    s.close();
  }
  @Test
  public void testMapping() throws Exception {
    Address address = new Address();
    address.setStreet1("3340 Peachtree Rd NE");
    address.setStreet2("JBoss");

    FullTextSession s = Search.getFullTextSession(openSession());
    Transaction tx = s.beginTransaction();
    s.persist(address);
    tx.commit();

    s.clear();

    tx = s.beginTransaction();

    QueryParser parser = new QueryParser("id", TestConstants.standardAnalyzer);
    org.apache.lucene.search.Query luceneQuery = parser.parse("" + address.getAddressId());
    FullTextQuery query = s.createFullTextQuery(luceneQuery);
    assertEquals("documentId does not work properly", 1, query.getResultSize());

    luceneQuery = parser.parse("street1:peachtree");
    query = s.createFullTextQuery(luceneQuery).setProjection("idx_street2", FullTextQuery.THIS);
    assertEquals("Not properly indexed", 1, query.getResultSize());
    Object[] firstResult = (Object[]) query.list().get(0);
    assertEquals("@Field.store not respected", "JBoss", firstResult[0]);

    // Verify that AddressClassBridge was applied as well:
    luceneQuery = parser.parse("AddressClassBridge:Applied\\!");
    assertEquals(1, s.createFullTextQuery(luceneQuery).getResultSize());

    s.delete(firstResult[1]);
    tx.commit();
    s.close();
  }
  @Test
  public void testAnalyzerDef() throws Exception {
    Address address = new Address();
    address.setStreet1("3340 Peachtree Rd NE");
    address.setStreet2("JBoss");

    FullTextSession s = Search.getFullTextSession(openSession());
    Transaction tx = s.beginTransaction();
    s.persist(address);
    tx.commit();

    s.clear();

    tx = s.beginTransaction();

    QueryParser parser = new QueryParser("id", TestConstants.standardAnalyzer);
    org.apache.lucene.search.Query luceneQuery = parser.parse("street1_ngram:pea");

    final FullTextQuery query = s.createFullTextQuery(luceneQuery);
    assertEquals("Analyzer inoperant", 1, query.getResultSize());

    s.delete(query.list().get(0));
    tx.commit();
    s.close();
  }
  /**
   * Accuracy test for the method <code>getStreet2()</code>.<br>
   * The value should be properly retrieved.
   */
  @Test
  public void test_getStreet2() {
    String value = "new_value";
    instance.setStreet2(value);

    assertEquals("'getStreet2' should be correct.", value, instance.getStreet2());
  }
  @Test
  public void testFullTextFilterDefAtMappingLevel() throws Exception {
    FullTextSession s = Search.getFullTextSession(openSession());
    Transaction tx = s.beginTransaction();

    Address address = new Address();
    address.setStreet1("Peachtree Rd NE");
    address.setStreet2("Peachtnot Rd NE");
    address.setOwner("test");
    Calendar c =
        GregorianCalendar.getInstance(
            TimeZone.getTimeZone("GMT"), Locale.ROOT); // for the sake of tests
    c.set(2009, Calendar.NOVEMBER, 15);

    address.setLastUpdated(c);
    s.persist(address);

    address = new Address();

    address.setStreet1("Peachtnot Rd NE");
    address.setStreet2("Peachtree Rd NE");
    address.setLastUpdated(c);
    address.setOwner("testowner");
    s.persist(address);

    tx.commit();

    s.clear();

    tx = s.beginTransaction();

    QueryParser parser = new QueryParser("id", TestConstants.standardAnalyzer);
    org.apache.lucene.search.Query luceneQuery = parser.parse("street1:Peachtnot");
    FullTextQuery query =
        s.createFullTextQuery(luceneQuery).setProjection(FullTextQuery.THIS, FullTextQuery.SCORE);
    query.enableFullTextFilter("security").setParameter("ownerName", "testowner");
    assertEquals("expecting 1 results", 1, query.getResultSize());

    @SuppressWarnings("unchecked")
    List<Object[]> results = query.list();

    for (Object[] result : results) {
      s.delete(result[0]);
    }
    tx.commit();
    s.close();
  }
  @Test
  public void testCalendarBridgeMapping() throws Exception {
    FullTextSession s = Search.getFullTextSession(openSession());
    Transaction tx = s.beginTransaction();

    Address address = new Address();
    address.setStreet1("Peachtree Rd NE");
    address.setStreet2("Peachtnot Rd NE");
    Calendar calendar =
        GregorianCalendar.getInstance(
            TimeZone.getTimeZone("GMT"), Locale.ROOT); // for the sake of tests
    calendar.set(2009, Calendar.NOVEMBER, 15);

    address.setLastUpdated(calendar);
    s.persist(address);

    address = new Address();
    address.setStreet1("Peachtnot Rd NE");
    address.setStreet2("Peachtree Rd NE");
    address.setLastUpdated(calendar);
    s.persist(address);

    tx.commit();

    s.clear();

    tx = s.beginTransaction();

    long searchTimeStamp = DateTools.round(calendar.getTime().getTime(), DateTools.Resolution.DAY);
    org.apache.lucene.search.Query luceneQuery =
        NumericRangeQuery.newLongRange(
            "last-updated", searchTimeStamp, searchTimeStamp, true, true);

    FullTextQuery query =
        s.createFullTextQuery(luceneQuery).setProjection(FullTextQuery.THIS, FullTextQuery.SCORE);
    assertEquals("expecting 2 results", 2, query.getResultSize());

    @SuppressWarnings("unchecked")
    List<Object[]> results = query.list();

    for (Object[] result : results) {
      s.delete(result[0]);
    }
    tx.commit();
    s.close();
  }
  /**
   * Accuracy test for the method <code>setStreet2(String street2)</code>.<br>
   * The value should be properly set.
   */
  @Test
  public void test_setStreet2() {
    String value = "new_value";
    instance.setStreet2(value);

    assertEquals(
        "'setStreet2' should be correct.", value, TestsHelper.getField(instance, "street2"));
  }
 public void testGetByPositionalInvalidXPath() {
   Customer customer = new Customer();
   Address address = new Address();
   address.setStreet2(CONTROL_ADDRESS_STREET2);
   customer.setAddress(address);
   String testValue =
       xmlContext.getValueByXPath(
           customer, "contact-info/address/street[10]/text()", null, String.class);
   assertEquals(null, testValue);
 }
  @Test
  public void testBoost() throws Exception {
    FullTextSession s = Search.getFullTextSession(openSession());
    Transaction tx = s.beginTransaction();

    Address address = new Address();
    address.setStreet1("Peachtree Rd NE");
    address.setStreet2("Peachtnot Rd NE");
    s.persist(address);

    address = new Address();
    address.setStreet1("Peachtnot Rd NE");
    address.setStreet2("Peachtree Rd NE");
    s.persist(address);

    tx.commit();

    s.clear();

    tx = s.beginTransaction();

    QueryParser parser = new QueryParser("id", TestConstants.standardAnalyzer);
    org.apache.lucene.search.Query luceneQuery =
        parser.parse("street1:peachtree OR idx_street2:peachtree");
    FullTextQuery query =
        s.createFullTextQuery(luceneQuery).setProjection(FullTextQuery.THIS, FullTextQuery.SCORE);
    assertEquals("expecting two results", 2, query.getResultSize());

    @SuppressWarnings("unchecked")
    List<Object[]> results = query.list();

    assertTrue(
        "first result should be strictly higher",
        (Float) results.get(0)[1] > (Float) results.get(1)[1] * 1.9f);
    assertEquals(
        "Wrong result ordered", address.getStreet1(), ((Address) results.get(0)[0]).getStreet1());
    for (Object[] result : results) {
      s.delete(result[0]);
    }
    tx.commit();
    s.close();
  }
  @Test
  public void testBuildMessageFromMpiPatient_MultiAddress() {
    System.out.println("testBuildMessageFromMpiPatient_MultiAddress");
    II subjectId = new II();
    subjectId.setRoot("2.16.840.1.113883.3.200");
    subjectId.setExtension("1234");

    String firstExpectedName = "Joe";
    String lastExpectedName = "Smith";
    String middleExpectedName = "Middle";
    String expectedTitle = "Title";
    String expectedSuffix = "Suffix";

    PRPAIN201305UV02 query =
        TestHelper.build201305(
            firstExpectedName, lastExpectedName, "M", "March 1, 1956", subjectId);

    Identifier patId = new Identifier();
    patId.setId("1234");
    patId.setOrganizationId("2.16.840.1.113883.3.200");
    Patient patient =
        TestHelper.createMpiPatient(
            firstExpectedName, lastExpectedName, middleExpectedName, "M", "March 1, 1956", patId);

    patient.getName().setSuffix(expectedSuffix);
    patient.getName().setTitle(expectedTitle);

    Address add = new Address();
    add.setCity("Chantilly");
    add.setState("VA");
    add.setStreet1("5155 Parkstone Drive");
    add.setStreet2("Att:Developer");
    add.setZip("20151");

    Address add2 = new Address();
    add2.setCity("Melbourne");
    add2.setState("FL");
    add2.setStreet1("1025 West NASA Boulevard");
    add2.setStreet2("Att:Developer");
    add2.setZip("32919-0001");

    patient.getAddresses().add(add);
    patient.getAddresses().add(add2);
    PRPAIN201306UV02 result = HL7Parser201306.BuildMessageFromMpiPatient(patient, query);
    // TODO review the generated test code and remove the default call to fail.

    PRPAMT201310UV02Person person =
        result
            .getControlActProcess()
            .getSubject()
            .get(0)
            .getRegistrationEvent()
            .getSubject1()
            .getPatient()
            .getPatientPerson()
            .getValue();

    assertEquals(2, person.getAddr().size());
    assertEquals(5, person.getAddr().get(0).getContent().size());
    assertEquals(5, person.getAddr().get(1).getContent().size());
    // assertEquals("5155 Parkstone Drive", person.getAddr().get(0).getUse().get(0));
    // assertEquals("1025 West NASA Boulevard", person.getAddr().get(1).getUse().get(0));

  }
  @Test
  public void testDateBridgeMapping() throws Exception {
    FullTextSession s = Search.getFullTextSession(openSession());
    Transaction tx = s.beginTransaction();

    Address address = new Address();
    address.setStreet1("Peachtree Rd NE");
    address.setStreet2("Peachtnot Rd NE");
    Calendar c =
        GregorianCalendar.getInstance(
            TimeZone.getTimeZone("GMT"), Locale.ROOT); // for the sake of tests
    c.set(2009, Calendar.NOVEMBER, 15);

    Date date = new Date(c.getTimeInMillis());
    address.setDateCreated(date);
    s.persist(address);

    address = new Address();
    address.setStreet1("Peachtnot Rd NE");
    address.setStreet2("Peachtree Rd NE");
    address.setDateCreated(date);
    s.persist(address);

    BlogEntry enEntry = new BlogEntry();
    enEntry.setTitle("acknowledgment");
    enEntry.setDescription("acknowledgment");
    enEntry.setLanguage("en");
    enEntry.setDateCreated(date);
    s.persist(enEntry);

    tx.commit();

    s.clear();

    tx = s.beginTransaction();

    long searchTimeStamp = DateTools.round(date.getTime(), DateTools.Resolution.DAY);
    BooleanQuery.Builder booleanQueryBuilder = new BooleanQuery.Builder();
    booleanQueryBuilder.add(
        NumericRangeQuery.newLongRange(
            "date-created", searchTimeStamp, searchTimeStamp, true, true),
        BooleanClause.Occur.SHOULD);
    booleanQueryBuilder.add(
        NumericRangeQuery.newLongRange(
            "blog-entry-created", searchTimeStamp, searchTimeStamp, true, true),
        BooleanClause.Occur.SHOULD);

    FullTextQuery query =
        s.createFullTextQuery(booleanQueryBuilder.build())
            .setProjection(FullTextQuery.THIS, FullTextQuery.SCORE);
    assertEquals("expecting 3 results", 3, query.getResultSize());

    @SuppressWarnings("unchecked")
    List<Object[]> results = query.list();

    for (Object[] result : results) {
      s.delete(result[0]);
    }
    tx.commit();
    s.close();
  }