Example #1
0
  @Test
  public void validate_given_id_then_ok() {
    Node node = Node.newNode().id(EntityId.from("abc")).build();

    final Collection<IndexDocument> indexDocuments =
        NodeIndexDocumentFactory.create(node, TEST_WORKSPACE);

    assertNotNull(indexDocuments);
  }
Example #2
0
  @Test
  public void index_node_document_created() throws Exception {
    Node node = Node.newNode().id(EntityId.from("abc")).build();

    final Collection<IndexDocument> indexDocuments =
        NodeIndexDocumentFactory.create(node, TEST_WORKSPACE);

    assertNotNull(indexDocuments);
    assertNotNull(getIndexDocumentOfType(indexDocuments, IndexType.NODE));
  }
Example #3
0
  @Test
  public void validate_given_no_id_then_exception() throws Exception {
    Node node = Node.newNode().build();

    try {
      NodeIndexDocumentFactory.create(node, TEST_WORKSPACE);
    } catch (NullPointerException e) {
      assertEquals("Id must be set", e.getMessage());
      return;
    }

    fail("Expected exception");
  }
Example #4
0
  @Test
  public void node_index_document_meta_data_values() throws Exception {
    final String myAnalyzerName = "myAnalyzer";

    Instant modifiedDateTime = LocalDateTime.of(2013, 1, 2, 3, 4, 5).toInstant(ZoneOffset.UTC);

    Node node =
        Node.newNode()
            .id(EntityId.from("myId"))
            .parent(NodePath.ROOT)
            .name(NodeName.from("my-name"))
            .createdTime(Instant.now())
            .creator(UserKey.from("test:creator"))
            .modifier(UserKey.from("test:modifier").asUser())
            .modifiedTime(modifiedDateTime)
            .entityIndexConfig(
                EntityPropertyIndexConfig.newEntityIndexConfig().analyzer(myAnalyzerName).build())
            .build();

    final Collection<IndexDocument> indexDocuments =
        NodeIndexDocumentFactory.create(node, TEST_WORKSPACE);

    final IndexDocument indexDocument = getIndexDocumentOfType(indexDocuments, IndexType.NODE);

    assertEquals(myAnalyzerName, indexDocument.getAnalyzer());
    assertEquals(TEST_WORKSPACE.getSearchIndexName(), indexDocument.getIndexName());
    assertEquals(IndexType.NODE.getName(), indexDocument.getIndexTypeName());

    final AbstractIndexDocumentItem createdTimeItem =
        getItemWithName(
            indexDocument, NodeIndexDocumentFactory.CREATED_TIME_PROPERTY, IndexValueType.DATETIME);

    assertEquals(Date.from(node.getCreatedTime()), createdTimeItem.getValue());

    final AbstractIndexDocumentItem creator =
        getItemWithName(
            indexDocument, NodeIndexDocumentFactory.CREATOR_PROPERTY_PATH, IndexValueType.STRING);

    assertEquals("test:creator", creator.getValue());

    final AbstractIndexDocumentItem modifier =
        getItemWithName(
            indexDocument, NodeIndexDocumentFactory.MODIFIER_PROPERTY_PATH, IndexValueType.STRING);

    assertEquals("test:modifier", modifier.getValue());
  }
Example #5
0
  @Test
  public void set_analyzer() throws Exception {
    final String myAnalyzerName = "myAnalyzer";

    final Node node =
        Node.newNode()
            .id(EntityId.from("abc"))
            .entityIndexConfig(
                EntityPropertyIndexConfig.newEntityIndexConfig().analyzer(myAnalyzerName).build())
            .build();

    final Collection<IndexDocument> indexDocuments =
        NodeIndexDocumentFactory.create(node, TEST_WORKSPACE);

    final IndexDocument indexDocument = getIndexDocumentOfType(indexDocuments, IndexType.NODE);

    assertEquals(myAnalyzerName, indexDocument.getAnalyzer());
  }
Example #6
0
  @Test
  public void create_for_properties_with_multiple_values() throws Exception {
    RootDataSet rootDataSet = new RootDataSet();
    rootDataSet.addProperty(DataPath.from("a.b.c"), Value.newDouble(2.0));
    rootDataSet.addProperty(DataPath.from("a.b.c"), Value.newDouble(3.0));

    Node node = Node.newNode().id(EntityId.from("myId")).rootDataSet(rootDataSet).build();

    final Collection<IndexDocument> indexDocuments =
        NodeIndexDocumentFactory.create(node, TEST_WORKSPACE);

    assertTrue(indexDocuments.iterator().hasNext());
    final IndexDocument next = indexDocuments.iterator().next();

    final Set<AbstractIndexDocumentItem> numberItems =
        getItemsWithName(next, IndexDocumentItemPath.from("a_b_c"), IndexValueType.NUMBER);

    assertEquals(2, numberItems.size());
  }
Example #7
0
  @Test
  public void add_properties_then_index_document_items_created_for_each_property()
      throws Exception {
    RootDataSet rootDataSet = new RootDataSet();
    rootDataSet.addProperty(DataPath.from("a.b.c"), Value.newDouble(2.0));
    rootDataSet.setProperty(DataPath.from("a.b.d"), Value.newLocalDate(LocalDate.now()));

    Node node = Node.newNode().id(EntityId.from("myId")).rootDataSet(rootDataSet).build();

    final Collection<IndexDocument> indexDocuments =
        NodeIndexDocumentFactory.create(node, TEST_WORKSPACE);

    final IndexDocument indexDocument = getIndexDocumentOfType(indexDocuments, IndexType.NODE);

    assertNotNull(
        getItemWithName(indexDocument, IndexDocumentItemPath.from("a_b_c"), IndexValueType.NUMBER));
    assertNotNull(
        getItemWithName(
            indexDocument, IndexDocumentItemPath.from("a_b_d"), IndexValueType.DATETIME));
  }