// unloadItems removes items from the items collection and the graph. func unloadItems(context interface{}, db *db.DB, store *cayley.Handle) error { items, err := itemfix.Get() if err != nil { return err } for _, itm := range items { if err := sponge.Remove(context, db, store, itm.ID); err != nil { return err } } return nil }
// Remove removes the specified Item from the items collection and removes any // relevant quads from the graph database. // 200 Success, 400 Bad Request, 404 Not Found, 500 Internal func (itemHandle) Remove(c *web.Context) error { db := c.Ctx["DB"].(*db.DB) graphHandle, err := db.GraphHandle(c.SessionID) if err != nil { return err } if err := sponge.Remove(c.SessionID, db, graphHandle, c.Params["id"]); err != nil { return err } c.Respond(nil, http.StatusNoContent) return nil }
// TestImportRemoveItem tests the insert and update of an item. func TestImportRemoveItem(t *testing.T) { db, store := setup(t) defer teardown(t, db, store) t.Log("Given the need to import an item.") { //---------------------------------------------------------------------- // Get the fixture. items, err := itemfix.Get() if err != nil { t.Fatalf("\t%s\tShould be able to retrieve the fixture : %v", tests.Failed, err) } t.Logf("\t%s\tShould be able to retrieve the fixture.", tests.Success) //---------------------------------------------------------------------- // Import the Item. if err := sponge.Import(tests.Context, db, store, &items[0]); err != nil { t.Fatalf("\t%s\tShould be able to import an item : %s", tests.Failed, err) } t.Logf("\t%s\tShould be able to import an item", tests.Success) //---------------------------------------------------------------------- // Check the inferred relationship. p := cayley.StartPath(store, quad.String("ITEST_80aa936a-f618-4234-a7be-df59a14cf8de")).Out(quad.String("authored")) it, _ := p.BuildIterator().Optimize() defer it.Close() for it.Next() { token := it.Result() value := store.NameOf(token) if quad.NativeOf(value) != "ITEST_d1dfa366-d2f7-4a4a-a64f-af89d4c97d82" { t.Fatalf("\t%s\tShould be able to get the inferred relationships from the graph", tests.Failed) } } if err := it.Err(); err != nil { t.Fatalf("\t%s\tShould be able to get the inferred relationships from the graph : %s", tests.Failed, err) } it.Close() t.Logf("\t%s\tShould be able to get the inferred relationships from the graph.", tests.Success) //---------------------------------------------------------------------- // Import the Item again to test for duplicate imports. if err := sponge.Import(tests.Context, db, store, &items[0]); err != nil { t.Fatalf("\t%s\tShould be able to import a duplicate item : %s", tests.Failed, err) } t.Logf("\t%s\tShould be able to import a duplicate item", tests.Success) //---------------------------------------------------------------------- // Remove the item. if err := sponge.Remove(tests.Context, db, store, items[0].ID); err != nil { t.Fatalf("\t%s\tShould be able to remove the item : %s", tests.Failed, err) } t.Logf("\t%s\tShould be able to remove the item", tests.Success) //---------------------------------------------------------------------- // Check the inferred relationships. p = cayley.StartPath(store, quad.String("ITEST_80aa936a-f618-4234-a7be-df59a14cf8de")).Out(quad.String("authored")) it, _ = p.BuildIterator().Optimize() defer it.Close() var count int for it.Next() { count++ } if err := it.Err(); err != nil { t.Fatalf("\t%s\tShould be able to confirm removed relationships : %s", tests.Failed, err) } if count > 0 { t.Fatalf("\t%s\tShould be able to confirm removed relationships.", tests.Failed) } t.Logf("\t%s\tShould be able to confirm removed relationships.", tests.Success) } }