コード例 #1
0
ファイル: relationship_test.go プロジェクト: jadengore/neoism
// 18.5.12. Get typed relationships
func TestGetTypedRelationships(t *testing.T) {
	db := connectTest(t)
	defer cleanup(t, db)
	// Create
	relType0 := rndStr(t)
	relType1 := rndStr(t)
	n0, _ := db.CreateNode(Props{})
	n1, _ := db.CreateNode(Props{})
	r0, _ := n0.Relate(relType0, n1.Id(), Props{})
	r1, _ := n0.Relate(relType1, n1.Id(), Props{})
	// Check one type of relationship
	rels, err := n0.Relationships(relType0)
	if err != nil {
		t.Error(err)
	}
	assert.Equalf(t, len(rels), 1, "Wrong number of relationships")
	_, present := rels.Map()[r0.Id()]
	assert.Tf(t, present, "Missing expected relationship")
	// Check two types of relationship together
	rels, err = n0.Relationships(relType0, relType1)
	if err != nil {
		t.Error(err)
	}
	assert.Equalf(t, len(rels), 2, "Wrong number of relationships")
	for _, r := range []*Relationship{r0, r1} {
		_, present := rels.Map()[r.Id()]
		assert.Tf(t, present, "Missing expected relationship")
	}
}
コード例 #2
0
ファイル: node_test.go プロジェクト: jadengore/neoism
// 18.7.7. Delete a named property from a node
func TestDeleteNamedPropertyFromNode(t *testing.T) {
	db := connectTest(t)
	defer cleanup(t, db)
	// Create
	props0 := Props{"foo": "bar"}
	props1 := Props{"foo": "bar", "spam": "eggs"}
	n0, _ := db.CreateNode(props1)
	// Delete
	err := n0.DeleteProperty("spam")
	if err != nil {
		t.Error(err)
	}
	// Confirm
	checkProps, _ := n0.Properties()
	assert.Equalf(t, props0, checkProps, "Failed to remove named property with DeleteProperty().")
	//
	// Delete non-existent property
	//
	err = n0.DeleteProperty("eggs")
	assert.NotEqual(t, nil, err)
	//
	// Delete and check 404
	//
	n0.Delete()
	err = n0.DeleteProperty("spam")
	assert.Equal(t, NotFound, err)
}
コード例 #3
0
ファイル: relationship_test.go プロジェクト: jadengore/neoism
// 18.5.13. Get relationships on a node without relationships
func TestGetRelationshipsOnNodeWithoutRelationships(t *testing.T) {
	db := connectTest(t)
	n0, _ := db.CreateNode(Props{})
	defer n0.Delete()
	rels, err := n0.Relationships()
	if err != nil {
		t.Error(err)
	}
	assert.Equalf(t, len(rels), 0, "Node with no relationships should return empty slice of relationships")
}
コード例 #4
0
ファイル: node_test.go プロジェクト: jadengore/neoism
// 18.4.6. Nodes with relationships can not be deleted;
func TestDeleteNodeWithRelationships(t *testing.T) {
	db := connectTest(t)
	defer cleanup(t, db)
	// Create
	n0, _ := db.CreateNode(Props{})
	n1, _ := db.CreateNode(Props{})
	n0.Relate("knows", n1.Id(), Props{})
	// Attempt to delete node without deleting relationship
	err := n0.Delete()
	assert.Equalf(t, err, CannotDelete, "Should not be possible to delete node with relationship.")
}
コード例 #5
0
ファイル: node_test.go プロジェクト: jadengore/neoism
// 18.7.3. Get properties for node
func TestGetPropertiesForNode(t *testing.T) {
	db := connectTest(t)
	defer cleanup(t, db)
	// Create
	props := Props{rndStr(t): rndStr(t)}
	n0, _ := db.CreateNode(props)
	// Get properties & confirm
	checkProps, err := n0.Properties()
	if err != nil {
		t.Error(err)
	}
	assert.Equalf(t, props, checkProps, "Did not return expected properties.")
}
コード例 #6
0
ファイル: node_test.go プロジェクト: jadengore/neoism
// 18.4.3. Get node
func TestGetNode(t *testing.T) {
	db := connectTest(t)
	defer cleanup(t, db)
	// Create
	n0, _ := db.CreateNode(Props{})
	// Get Node
	n1, err := db.Node(n0.Id())
	if err != nil {
		t.Error(err)
	}
	// Confirm nodes are the same
	assert.Equalf(t, n0.Id(), n1.Id(), "Nodes do not have same ID")
}
コード例 #7
0
ファイル: node_index_test.go プロジェクト: jadengore/neoism
// 18.9.10. Find node by query
func TestFindNodeByQuery(t *testing.T) {
	db := connectTest(t)
	defer cleanup(t, db)
	// Create
	idx0, _ := db.CreateLegacyNodeIndex("test index", "", "")
	defer idx0.Delete()
	key0 := rndStr(t)
	key1 := rndStr(t)
	value0 := rndStr(t)
	value1 := rndStr(t)
	n0, _ := db.CreateNode(Props{})
	idx0.Add(n0, key0, value0)
	idx0.Add(n0, key1, value1)
	n1, _ := db.CreateNode(Props{})
	idx0.Add(n1, key0, value0)
	n2, _ := db.CreateNode(Props{})
	idx0.Add(n2, rndStr(t), rndStr(t))
	// Retrieve
	luceneQuery0 := fmt.Sprintf("%v:%v AND %v:%v", key0, value0, key1, value1) // Retrieve n0 only
	luceneQuery1 := fmt.Sprintf("%v:%v", key0, value0)                         // Retrieve n0 and n1
	nodes0, err := idx0.Query(luceneQuery0)
	if err != nil {
		t.Error(err)
	}
	nodes1, err := idx0.Query(luceneQuery1)
	if err != nil {
		t.Error(err)
	}
	// Confirm
	assert.Equalf(t, len(nodes0), 1, "Query should have returned only one Node.")
	_, present := nodes0[n0.Id()]
	assert.Tf(t, present, "Query() failed to return node with id "+strconv.Itoa(n0.Id()))
	assert.Equalf(t, len(nodes1), 2, "Query should have returned exactly 2 Nodes.")
	_, present = nodes1[n0.Id()]
	assert.Tf(t, present, "Query() failed to return node with id "+strconv.Itoa(n0.Id()))
	_, present = nodes1[n1.Id()]
	assert.Tf(t, present, "Query() failed to return node with id "+strconv.Itoa(n1.Id()))
}
コード例 #8
0
ファイル: relationship_test.go プロジェクト: jadengore/neoism
// 18.5.8. Set single property on a relationship
func TestSetSinglePropertyOnRelationship(t *testing.T) {
	db := connectTest(t)
	defer cleanup(t, db)
	// Create
	n0, _ := db.CreateNode(Props{})
	n1, _ := db.CreateNode(Props{})
	r0, _ := n0.Relate("knows", n1.Id(), Props{})
	// Set property
	r0.SetProperty("foo", "bar")
	// Confirm
	expected := Props{"foo": "bar"}
	props, _ := r0.Properties()
	assert.Equalf(t, props, expected, "Failed to set single property on relationship.")
}
コード例 #9
0
ファイル: relationship_test.go プロジェクト: jadengore/neoism
// 18.5.6. Set all properties on a relationship
func TestSetAllPropertiesOnRelationship(t *testing.T) {
	db := connectTest(t)
	defer cleanup(t, db)
	props0 := Props{"foo": "bar"}
	props1 := Props{"spam": "eggs"}
	// Create
	n0, _ := db.CreateNode(Props{})
	n1, _ := db.CreateNode(Props{})
	r0, _ := n0.Relate("knows", n1.Id(), props0)
	// Set all properties
	r0.SetProperties(props1)
	// Confirm
	checkProps, _ := r0.Properties()
	assert.Equalf(t, checkProps, props1, "Failed to set all properties on relationship")
}
コード例 #10
0
ファイル: relationship_test.go プロジェクト: jadengore/neoism
// 18.5.4. Delete relationship
func TestDeleteRelationship(t *testing.T) {
	db := connectTest(t)
	defer cleanup(t, db)
	// Create
	n0, _ := db.CreateNode(Props{})
	n1, _ := db.CreateNode(Props{})
	r0, err := n0.Relate("knows", n1.Id(), Props{})
	if err != nil {
		t.Error(err)
	}
	// Delete and confirm
	r0.Delete()
	_, err = db.Relationship(r0.Id())
	assert.Equalf(t, err, NotFound, "Should not be able to Get() a deleted relationship.")
}
コード例 #11
0
ファイル: relationship_test.go プロジェクト: jadengore/neoism
// 18.5.7. Get single property on a relationship
func TestGetSinglePropertyOnRelationship(t *testing.T) {
	db := connectTest(t)
	defer cleanup(t, db)
	// Create
	props := Props{"foo": "bar"}
	n0, _ := db.CreateNode(Props{})
	n1, _ := db.CreateNode(Props{})
	r0, _ := n0.Relate("knows", n1.Id(), props)
	// Get property
	value, err := r0.Property("foo")
	if err != nil {
		t.Error(err)
	}
	assert.Equalf(t, value, "bar", "Incorrect value when getting single property.")
}
コード例 #12
0
ファイル: relationship_test.go プロジェクト: jadengore/neoism
// 18.5.3. Create a relationship with properties
func TestCreateRelationshipWithProperties(t *testing.T) {
	db := connectTest(t)
	defer cleanup(t, db)
	// Create
	props0 := Props{"foo": "bar", "spam": "eggs"}
	n0, _ := db.CreateNode(Props{})
	n1, _ := db.CreateNode(Props{})
	r0, err := n0.Relate("knows", n1.Id(), props0)
	if err != nil {
		t.Error(err)
	}
	// Confirm relationship was created with specified properties.
	props1, _ := r0.Properties()
	assert.Equalf(t, props0, props1, "Properties queried from relationship do not match properties it was created with.")
}
コード例 #13
0
ファイル: relationship_test.go プロジェクト: jadengore/neoism
// 18.5.5. Get all properties on a relationship
func TestGetAllPropertiesOnRelationship(t *testing.T) {
	db := connectTest(t)
	defer cleanup(t, db)
	// Create
	props0 := Props{"foo": "bar", "spam": "eggs"}
	n0, _ := db.CreateNode(Props{})
	n1, _ := db.CreateNode(Props{})
	r0, _ := n0.Relate("knows", n1.Id(), props0)
	// Confirm relationship was created with specified properties.  No need to
	// check success of creation itself, as that is handled by TestCreateRelationship().
	props1, err := r0.Properties()
	if err != nil {
		t.Error(err)
	}
	assert.Equalf(t, props0, props1, "Properties queried from relationship do not match properties it was created with.")
}
コード例 #14
0
ファイル: node_test.go プロジェクト: jadengore/neoism
// 18.7.2. Update node properties
func TestUpdatePropertyOnNode(t *testing.T) {
	db := connectTest(t)
	defer cleanup(t, db)
	// Create
	props0 := Props{rndStr(t): rndStr(t)}
	props1 := Props{rndStr(t): rndStr(t)}
	n0, _ := db.CreateNode(props0)
	// Update
	err := n0.SetProperties(props1)
	if err != nil {
		t.Error(err)
	}
	// Confirm
	checkProps, _ := n0.Properties()
	assert.Equalf(t, props1, checkProps, "Did not recover expected properties after updating with SetProperties().")
}
コード例 #15
0
ファイル: node_test.go プロジェクト: jadengore/neoism
func TestNodeProperty(t *testing.T) {
	db := connectTest(t)
	defer cleanup(t, db)
	props := Props{"foo": "bar"}
	n0, _ := db.CreateNode(props)
	value, err := n0.Property("foo")
	if err != nil {
		t.Error(err)
	}
	assert.Equalf(t, value, "bar", "Incorrect value when getting single property.")
	//
	// Check Not Found
	//
	n0.Delete()
	_, err = n0.Property("foo")
	assert.Equal(t, NotFound, err)
}
コード例 #16
0
ファイル: relationship_test.go プロジェクト: jadengore/neoism
// 18.5.10. Get incoming relationships
func TestGetIncomingRelationships(t *testing.T) {
	db := connectTest(t)
	defer cleanup(t, db)
	// Create
	n0, _ := db.CreateNode(Props{})
	n1, _ := db.CreateNode(Props{})
	n0.Relate("knows", n1.Id(), Props{})
	r1, _ := n1.Relate("knows", n0.Id(), Props{})
	n0.Relate("knows", n1.Id(), Props{})
	// Check relationships
	rels, err := n0.Incoming()
	if err != nil {
		t.Error(err)
	}
	assert.Equalf(t, len(rels), 1, "Wrong number of relationships")
	_, present := rels.Map()[r1.Id()]
	assert.Tf(t, present, "Missing expected relationship")
}
コード例 #17
0
ファイル: node_test.go プロジェクト: jadengore/neoism
// 18.4.2. Create Node with properties
func TestCreateNodeWithProperties(t *testing.T) {
	db := connectTest(t)
	defer cleanup(t, db)
	// Create
	props0 := Props{}
	props0["foo"] = "bar"
	props0["spam"] = "eggs"
	n0, err := db.CreateNode(props0)
	if err != nil {
		t.Error(err)
	}
	// Confirm creation
	_, err = db.Node(n0.Id())
	if err != nil {
		t.Error(err)
	}
	// Confirm properties
	props1, _ := n0.Properties()
	assert.Equalf(t, props0, props1, "Node properties not as expected")
}
コード例 #18
0
ファイル: node_test.go プロジェクト: jadengore/neoism
// 18.7.6. Delete all properties from node
func TestDeleteAllPropertiesFromNode(t *testing.T) {
	db := connectTest(t)
	defer cleanup(t, db)
	// Create
	props := Props{
		rndStr(t): rndStr(t),
		rndStr(t): rndStr(t),
	}
	n0, _ := db.CreateNode(props)
	// Delete properties
	err := n0.DeleteProperties()
	if err != nil {
		t.Error(err)
	}
	// Confirm deletion
	checkProps, _ := n0.Properties()
	assert.Equalf(t, Props{}, checkProps, "Properties should be empty after call to DeleteProperties()")
	n0.Delete()
	err = n0.DeleteProperties()
	assert.Equal(t, NotFound, err)
}