2018-10-11 09:26:00 +00:00
|
|
|
package activitystreams
|
2017-09-11 21:16:43 +00:00
|
|
|
|
2018-04-09 11:10:27 +00:00
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
2017-09-11 21:16:43 +00:00
|
|
|
|
2017-10-01 12:55:39 +00:00
|
|
|
func TestCollectionNew(t *testing.T) {
|
2018-03-27 13:06:06 +00:00
|
|
|
var testValue = ObjectID("test")
|
2017-09-11 21:16:43 +00:00
|
|
|
|
|
|
|
c := CollectionNew(testValue)
|
|
|
|
|
2018-04-08 16:55:25 +00:00
|
|
|
if c.ID != testValue {
|
|
|
|
t.Errorf("APObject Id '%v' different than expected '%v'", c.ID, testValue)
|
2017-09-11 21:16:43 +00:00
|
|
|
}
|
|
|
|
if c.Type != CollectionType {
|
2017-10-05 10:38:11 +00:00
|
|
|
t.Errorf("APObject Type '%v' different than expected '%v'", c.Type, CollectionType)
|
2017-09-11 21:16:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-01 12:55:39 +00:00
|
|
|
func TestOrderedCollectionNew(t *testing.T) {
|
2018-03-27 13:06:06 +00:00
|
|
|
var testValue = ObjectID("test")
|
2017-09-11 21:16:43 +00:00
|
|
|
|
|
|
|
c := OrderedCollectionNew(testValue)
|
|
|
|
|
2018-04-08 16:55:25 +00:00
|
|
|
if c.ID != testValue {
|
|
|
|
t.Errorf("APObject Id '%v' different than expected '%v'", c.ID, testValue)
|
2017-09-11 21:16:43 +00:00
|
|
|
}
|
|
|
|
if c.Type != OrderedCollectionType {
|
2017-10-05 10:38:11 +00:00
|
|
|
t.Errorf("APObject Type '%v' different than expected '%v'", c.Type, OrderedCollectionType)
|
2017-09-11 21:16:43 +00:00
|
|
|
}
|
|
|
|
}
|
2017-09-12 15:47:49 +00:00
|
|
|
|
|
|
|
func TestCollectionPageNew(t *testing.T) {
|
2018-03-27 13:06:06 +00:00
|
|
|
var testValue = ObjectID("test")
|
2017-09-12 15:47:49 +00:00
|
|
|
|
|
|
|
c := CollectionNew(testValue)
|
|
|
|
p := CollectionPageNew(c)
|
2018-10-18 08:45:10 +00:00
|
|
|
if reflect.DeepEqual(p.Collection, c) {
|
|
|
|
t.Errorf("Invalid collection parent '%v'", p.PartOf)
|
|
|
|
}
|
|
|
|
if p.PartOf != c.GetLink() {
|
2017-09-12 15:47:49 +00:00
|
|
|
t.Errorf("Invalid collection '%v'", p.PartOf)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestOrderedCollectionPageNew(t *testing.T) {
|
2018-03-27 13:06:06 +00:00
|
|
|
var testValue = ObjectID("test")
|
2017-09-12 15:47:49 +00:00
|
|
|
|
|
|
|
c := OrderedCollectionNew(testValue)
|
|
|
|
p := OrderedCollectionPageNew(c)
|
2018-10-18 08:45:10 +00:00
|
|
|
if reflect.DeepEqual(p.OrderedCollection, c) {
|
|
|
|
t.Errorf("Invalid ordered collection parent '%v'", p.PartOf)
|
|
|
|
}
|
|
|
|
if p.PartOf != c.GetLink() {
|
2017-09-12 15:47:49 +00:00
|
|
|
t.Errorf("Invalid collection '%v'", p.PartOf)
|
|
|
|
}
|
2017-09-16 18:38:09 +00:00
|
|
|
}
|
|
|
|
|
2018-04-09 11:10:27 +00:00
|
|
|
func Test_OrderedCollection_Append(t *testing.T) {
|
|
|
|
id := ObjectID("test")
|
|
|
|
|
2018-06-09 12:05:46 +00:00
|
|
|
val := Object{ID: ObjectID("grrr")}
|
2018-04-09 11:10:27 +00:00
|
|
|
|
|
|
|
c := OrderedCollectionNew(id)
|
|
|
|
c.Append(val)
|
|
|
|
|
2019-06-02 14:45:37 +00:00
|
|
|
if c.Count() != 1 {
|
|
|
|
t.Errorf("Inbox collection of %q should have one element", *c.GetID())
|
|
|
|
}
|
2018-06-09 12:05:46 +00:00
|
|
|
if !reflect.DeepEqual(c.OrderedItems[0], val) {
|
2018-04-09 11:10:27 +00:00
|
|
|
t.Errorf("First item in Inbox is does not match %q", val.ID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-04 18:06:46 +00:00
|
|
|
func TestCollection_Append(t *testing.T) {
|
2018-04-09 11:10:27 +00:00
|
|
|
id := ObjectID("test")
|
|
|
|
|
2018-06-09 12:05:46 +00:00
|
|
|
val := Object{ID: ObjectID("grrr")}
|
2018-04-09 11:10:27 +00:00
|
|
|
|
|
|
|
c := CollectionNew(id)
|
|
|
|
c.Append(val)
|
|
|
|
|
2019-06-02 14:45:37 +00:00
|
|
|
if c.Count() != 1 {
|
|
|
|
t.Errorf("Inbox collection of %q should have one element", *c.GetID())
|
|
|
|
}
|
2018-06-09 12:05:46 +00:00
|
|
|
if !reflect.DeepEqual(c.Items[0], val) {
|
2018-04-09 11:10:27 +00:00
|
|
|
t.Errorf("First item in Inbox is does not match %q", val.ID)
|
|
|
|
}
|
|
|
|
}
|
2018-11-04 18:06:46 +00:00
|
|
|
|
|
|
|
func TestCollectionPage_Append(t *testing.T) {
|
|
|
|
id := ObjectID("test")
|
|
|
|
|
|
|
|
val := Object{ID: ObjectID("grrr")}
|
|
|
|
|
|
|
|
c := CollectionNew(id)
|
|
|
|
|
|
|
|
p := CollectionPageNew(c)
|
|
|
|
p.Append(val)
|
|
|
|
|
|
|
|
if p.PartOf != c.GetLink() {
|
|
|
|
t.Errorf("Collection page should point to collection %q", c.GetLink())
|
|
|
|
}
|
2019-06-02 14:45:37 +00:00
|
|
|
if p.Count() != 1 {
|
|
|
|
t.Errorf("Collection page of %q should have exactly one element", *p.GetID())
|
|
|
|
}
|
2018-11-04 18:06:46 +00:00
|
|
|
if !reflect.DeepEqual(p.Items[0], val) {
|
|
|
|
t.Errorf("First item in Inbox is does not match %q", val.ID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCollection_Collection(t *testing.T) {
|
|
|
|
id := ObjectID("test")
|
|
|
|
|
|
|
|
c := CollectionNew(id)
|
|
|
|
|
2019-12-01 18:27:45 +00:00
|
|
|
if !reflect.DeepEqual(c.Collection(), c.Items) {
|
|
|
|
t.Errorf("Collection items should be equal %v %v", c.Collection(), c.Items)
|
2018-11-04 18:06:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCollection_GetID(t *testing.T) {
|
|
|
|
id := ObjectID("test")
|
|
|
|
|
|
|
|
c := CollectionNew(id)
|
|
|
|
|
|
|
|
if *c.GetID() != id {
|
|
|
|
t.Errorf("GetID should return %s, received %s", id, *c.GetID())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCollection_GetLink(t *testing.T) {
|
|
|
|
id := ObjectID("test")
|
|
|
|
link := IRI(id)
|
|
|
|
|
|
|
|
c := CollectionNew(id)
|
|
|
|
|
|
|
|
if c.GetLink() != link {
|
|
|
|
t.Errorf("GetLink should return %q, received %q", link, c.GetLink())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCollection_GetType(t *testing.T) {
|
|
|
|
id := ObjectID("test")
|
|
|
|
|
|
|
|
c := CollectionNew(id)
|
|
|
|
|
|
|
|
if c.GetType() != CollectionType {
|
|
|
|
t.Errorf("Collection Type should be %q, received %q", CollectionType, c.GetType())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCollection_IsLink(t *testing.T) {
|
|
|
|
id := ObjectID("test")
|
|
|
|
|
|
|
|
c := CollectionNew(id)
|
|
|
|
|
|
|
|
if c.IsLink() != false {
|
|
|
|
t.Errorf("Collection should not be a link, received %t", c.IsLink())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCollection_IsObject(t *testing.T) {
|
|
|
|
id := ObjectID("test")
|
|
|
|
|
|
|
|
c := CollectionNew(id)
|
|
|
|
|
|
|
|
if c.IsObject() != true {
|
|
|
|
t.Errorf("Collection should be an object, received %t", c.IsObject())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCollection_UnmarshalJSON(t *testing.T) {
|
2018-11-04 19:07:26 +00:00
|
|
|
c := Collection{}
|
2018-11-04 18:06:46 +00:00
|
|
|
|
2018-11-04 19:07:26 +00:00
|
|
|
dataEmpty := []byte("{}")
|
|
|
|
c.UnmarshalJSON(dataEmpty)
|
|
|
|
if c.ID != "" {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty ID, received %q", c.ID)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if c.Type != "" {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty Type, received %q", c.Type)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if c.AttributedTo != nil {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty AttributedTo, received %q", c.AttributedTo)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if len(c.Name) != 0 {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty Name, received %q", c.Name)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if len(c.Summary) != 0 {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty Summary, received %q", c.Summary)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if len(c.Content) != 0 {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty Content, received %q", c.Content)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if c.TotalItems != 0 {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty TotalItems, received %d", c.TotalItems)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if len(c.Items) > 0 {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty Items, received %v", c.Items)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if c.URL != nil {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty URL, received %v", c.URL)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if !c.Published.IsZero() {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty Published, received %q", c.Published)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if !c.StartTime.IsZero() {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty StartTime, received %q", c.StartTime)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if !c.Updated.IsZero() {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty Updated, received %q", c.Updated)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
2018-11-04 18:06:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCollectionPage_UnmarshalJSON(t *testing.T) {
|
2018-11-04 19:07:26 +00:00
|
|
|
p := CollectionPage{}
|
2018-11-04 18:06:46 +00:00
|
|
|
|
2018-11-04 19:07:26 +00:00
|
|
|
dataEmpty := []byte("{}")
|
|
|
|
p.UnmarshalJSON(dataEmpty)
|
|
|
|
if p.ID != "" {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty ID, received %q", p.ID)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if p.Type != "" {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty Type, received %q", p.Type)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if p.AttributedTo != nil {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty AttributedTo, received %q", p.AttributedTo)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if len(p.Name) != 0 {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty Name, received %q", p.Name)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if len(p.Summary) != 0 {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty Summary, received %q", p.Summary)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if len(p.Content) != 0 {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty Content, received %q", p.Content)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if p.TotalItems != 0 {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty TotalItems, received %d", p.TotalItems)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if len(p.Items) > 0 {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty Items, received %v", p.Items)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if p.URL != nil {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty URL, received %v", p.URL)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if !p.Published.IsZero() {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty Published, received %q", p.Published)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if !p.StartTime.IsZero() {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty StartTime, received %q", p.StartTime)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if !p.Updated.IsZero() {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty Updated, received %q", p.Updated)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if p.PartOf != nil {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty PartOf, received %q", p.PartOf)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if p.Current != nil {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty Current, received %q", p.Current)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if p.First != nil {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty First, received %q", p.First)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if p.Last != nil {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty Last, received %q", p.Last)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if p.Next != nil {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty Next, received %q", p.Next)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if p.Prev != nil {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty Prev, received %q", p.Prev)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
2018-11-04 18:06:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestOrderedCollection_Append(t *testing.T) {
|
|
|
|
id := ObjectID("test")
|
|
|
|
|
|
|
|
val := Object{ID: ObjectID("grrr")}
|
|
|
|
|
|
|
|
c := OrderedCollectionNew(id)
|
|
|
|
|
|
|
|
p := OrderedCollectionPageNew(c)
|
|
|
|
p.Append(val)
|
|
|
|
|
|
|
|
if p.PartOf != c.GetLink() {
|
|
|
|
t.Errorf("Ordereed collection page should point to ordered collection %q", c.GetLink())
|
|
|
|
}
|
2019-06-02 14:45:37 +00:00
|
|
|
if p.Count() != 1 {
|
|
|
|
t.Errorf("Ordered collection page of %q should have exactly one element", *p.GetID())
|
|
|
|
}
|
2018-11-04 18:06:46 +00:00
|
|
|
if !reflect.DeepEqual(p.OrderedItems[0], val) {
|
|
|
|
t.Errorf("First item in Inbox is does not match %q", val.ID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestOrderedCollection_Collection(t *testing.T) {
|
|
|
|
id := ObjectID("test")
|
|
|
|
|
2019-12-01 18:27:45 +00:00
|
|
|
o := OrderedCollectionNew(id)
|
2018-11-04 18:06:46 +00:00
|
|
|
|
2019-12-01 18:27:45 +00:00
|
|
|
if !reflect.DeepEqual(o.Collection(), o.OrderedItems) {
|
|
|
|
t.Errorf("Collection items should be equal %v %v", o.Collection(), o.OrderedItems)
|
2018-11-04 18:06:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestOrderedCollection_GetID(t *testing.T) {
|
|
|
|
id := ObjectID("test")
|
|
|
|
|
|
|
|
c := OrderedCollectionNew(id)
|
|
|
|
|
|
|
|
if *c.GetID() != id {
|
|
|
|
t.Errorf("GetID should return %q, received %q", id, *c.GetID())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestOrderedCollection_GetLink(t *testing.T) {
|
|
|
|
id := ObjectID("test")
|
|
|
|
link := IRI(id)
|
|
|
|
|
|
|
|
c := OrderedCollectionNew(id)
|
|
|
|
|
|
|
|
if c.GetLink() != link {
|
|
|
|
t.Errorf("GetLink should return %q, received %q", link, c.GetLink())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestOrderedCollection_GetType(t *testing.T) {
|
|
|
|
id := ObjectID("test")
|
|
|
|
|
|
|
|
c := OrderedCollectionNew(id)
|
|
|
|
|
|
|
|
if c.GetType() != OrderedCollectionType {
|
|
|
|
t.Errorf("OrderedCollection Type should be %q, received %q", OrderedCollectionType, c.GetType())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestOrderedCollection_IsLink(t *testing.T) {
|
|
|
|
id := ObjectID("test")
|
|
|
|
|
|
|
|
c := OrderedCollectionNew(id)
|
|
|
|
|
|
|
|
if c.IsLink() != false {
|
|
|
|
t.Errorf("OrderedCollection should not be a link, received %t", c.IsLink())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestOrderedCollection_IsObject(t *testing.T) {
|
|
|
|
id := ObjectID("test")
|
|
|
|
|
|
|
|
c := OrderedCollectionNew(id)
|
|
|
|
|
|
|
|
if c.IsObject() != true {
|
|
|
|
t.Errorf("OrderedCollection should be an object, received %t", c.IsObject())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestOrderedCollection_UnmarshalJSON(t *testing.T) {
|
2018-11-04 19:07:26 +00:00
|
|
|
c := OrderedCollection{}
|
2018-11-04 18:06:46 +00:00
|
|
|
|
2018-11-04 19:07:26 +00:00
|
|
|
dataEmpty := []byte("{}")
|
|
|
|
c.UnmarshalJSON(dataEmpty)
|
|
|
|
if c.ID != "" {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty ID, received %q", c.ID)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if c.Type != "" {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty Type, received %q", c.Type)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if c.AttributedTo != nil {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty AttributedTo, received %q", c.AttributedTo)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if len(c.Name) != 0 {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty Name, received %q", c.Name)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if len(c.Summary) != 0 {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty Summary, received %q", c.Summary)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if len(c.Content) != 0 {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty Content, received %q", c.Content)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if c.TotalItems != 0 {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty TotalItems, received %d", c.TotalItems)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if len(c.OrderedItems) > 0 {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty OrderedItems, received %v", c.OrderedItems)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if c.URL != nil {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty URL, received %v", c.URL)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if !c.Published.IsZero() {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty Published, received %q", c.Published)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if !c.StartTime.IsZero() {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty StartTime, received %q", c.StartTime)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if !c.Updated.IsZero() {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty Updated, received %q", c.Updated)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
2018-11-04 18:06:46 +00:00
|
|
|
}
|
|
|
|
|
2018-11-04 19:07:26 +00:00
|
|
|
func TestOrderedCollectionPage_UnmarshalJSON(t *testing.T) {
|
|
|
|
p := OrderedCollectionPage{}
|
2018-11-04 18:06:46 +00:00
|
|
|
|
2018-11-04 19:07:26 +00:00
|
|
|
dataEmpty := []byte("{}")
|
|
|
|
p.UnmarshalJSON(dataEmpty)
|
|
|
|
if p.ID != "" {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty ID, received %q", p.ID)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if p.Type != "" {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty Type, received %q", p.Type)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if p.AttributedTo != nil {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty AttributedTo, received %q", p.AttributedTo)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if len(p.Name) != 0 {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty Name, received %q", p.Name)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if len(p.Summary) != 0 {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty Summary, received %q", p.Summary)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if len(p.Content) != 0 {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty Content, received %q", p.Content)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if p.TotalItems != 0 {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty TotalItems, received %d", p.TotalItems)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if len(p.OrderedItems) > 0 {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty OrderedItems, received %v", p.OrderedItems)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if p.URL != nil {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty URL, received %v", p.URL)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if !p.Published.IsZero() {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty Published, received %q", p.Published)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if !p.StartTime.IsZero() {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty StartTime, received %q", p.StartTime)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if !p.Updated.IsZero() {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty Updated, received %q", p.Updated)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if p.PartOf != nil {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty PartOf, received %q", p.PartOf)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if p.Current != nil {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty Current, received %q", p.Current)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if p.First != nil {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty First, received %q", p.First)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if p.Last != nil {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty Last, received %q", p.Last)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if p.Next != nil {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty Next, received %q", p.Next)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
|
|
|
if p.Prev != nil {
|
2019-11-23 19:36:16 +00:00
|
|
|
t.Errorf("Unmarshaled object should have empty Prev, received %q", p.Prev)
|
2018-11-04 19:07:26 +00:00
|
|
|
}
|
2018-11-04 18:06:46 +00:00
|
|
|
}
|
|
|
|
|
2018-11-04 19:07:26 +00:00
|
|
|
func TestOrderedCollectionPage_Append(t *testing.T) {
|
2018-11-04 18:06:46 +00:00
|
|
|
id := ObjectID("test")
|
|
|
|
|
|
|
|
val := Object{ID: ObjectID("grrr")}
|
|
|
|
|
|
|
|
c := OrderedCollectionNew(id)
|
|
|
|
|
|
|
|
p := OrderedCollectionPageNew(c)
|
|
|
|
p.Append(val)
|
|
|
|
|
|
|
|
if p.PartOf != c.GetLink() {
|
|
|
|
t.Errorf("OrderedCollection page should point to OrderedCollection %q", c.GetLink())
|
|
|
|
}
|
2019-06-02 14:45:37 +00:00
|
|
|
if p.Count() != 1 {
|
|
|
|
t.Errorf("OrderedCollection page of %q should have exactly one element", *p.GetID())
|
|
|
|
}
|
2018-11-04 18:06:46 +00:00
|
|
|
if !reflect.DeepEqual(p.OrderedItems[0], val) {
|
|
|
|
t.Errorf("First item in Inbox is does not match %q", val.ID)
|
|
|
|
}
|
|
|
|
}
|
2019-05-11 08:31:19 +00:00
|
|
|
|
|
|
|
func TestOrderedCollectionPage_Collection(t *testing.T) {
|
2019-07-09 11:30:02 +00:00
|
|
|
id := ObjectID("test")
|
|
|
|
|
|
|
|
c := OrderedCollectionNew(id)
|
|
|
|
p := OrderedCollectionPageNew(c)
|
|
|
|
|
2019-12-01 18:27:45 +00:00
|
|
|
if !reflect.DeepEqual(p.Collection(), p.OrderedItems) {
|
|
|
|
t.Errorf("Collection items should be equal %v %v", p.Collection(), p.OrderedItems)
|
2019-07-09 11:30:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCollectionPage_Collection(t *testing.T) {
|
|
|
|
id := ObjectID("test")
|
|
|
|
|
|
|
|
c := CollectionNew(id)
|
|
|
|
p := CollectionPageNew(c)
|
|
|
|
|
2019-12-01 18:27:45 +00:00
|
|
|
if !reflect.DeepEqual(p.Collection(), p.Items) {
|
|
|
|
t.Errorf("Collection items should be equal %v %v", p.Collection(), p.Items)
|
2019-07-09 11:30:02 +00:00
|
|
|
}
|
2019-05-11 08:31:19 +00:00
|
|
|
}
|
|
|
|
|
2019-06-02 14:45:37 +00:00
|
|
|
func TestCollection_Count(t *testing.T) {
|
2019-07-09 11:30:02 +00:00
|
|
|
id := ObjectID("test")
|
|
|
|
|
|
|
|
c := CollectionNew(id)
|
|
|
|
|
|
|
|
if c.TotalItems != 0 {
|
|
|
|
t.Errorf("Empty object should have empty TotalItems, received %d", c.TotalItems)
|
|
|
|
}
|
|
|
|
if len(c.Items) > 0 {
|
|
|
|
t.Errorf("Empty object should have empty Items, received %v", c.Items)
|
|
|
|
}
|
|
|
|
if c.Count() != uint(len(c.Items)) {
|
|
|
|
t.Errorf("%T.Count() returned %d, expected %d", c, c.Count(), len(c.Items))
|
|
|
|
}
|
|
|
|
|
|
|
|
c.Append(IRI("test"))
|
|
|
|
if c.TotalItems != 0 {
|
|
|
|
t.Errorf("Empty object should have empty TotalItems, received %d", c.TotalItems)
|
|
|
|
}
|
|
|
|
if c.Count() != uint(len(c.Items)) {
|
|
|
|
t.Errorf("%T.Count() returned %d, expected %d", c, c.Count(), len(c.Items))
|
|
|
|
}
|
2019-06-02 14:45:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCollectionPage_Count(t *testing.T) {
|
2019-07-09 11:30:02 +00:00
|
|
|
id := ObjectID("test")
|
|
|
|
|
|
|
|
c := CollectionNew(id)
|
|
|
|
p := CollectionPageNew(c)
|
|
|
|
|
|
|
|
if p.TotalItems != 0 {
|
|
|
|
t.Errorf("Empty object should have empty TotalItems, received %d", p.TotalItems)
|
|
|
|
}
|
|
|
|
if len(p.Items) > 0 {
|
|
|
|
t.Errorf("Empty object should have empty Items, received %v", p.Items)
|
|
|
|
}
|
|
|
|
if p.Count() != uint(len(p.Items)) {
|
|
|
|
t.Errorf("%T.Count() returned %d, expected %d", c, p.Count(), len(p.Items))
|
|
|
|
}
|
|
|
|
|
|
|
|
p.Append(IRI("test"))
|
|
|
|
if p.TotalItems != 0 {
|
|
|
|
t.Errorf("Empty object should have empty TotalItems, received %d", p.TotalItems)
|
|
|
|
}
|
|
|
|
if p.Count() != uint(len(p.Items)) {
|
|
|
|
t.Errorf("%T.Count() returned %d, expected %d", c, p.Count(), len(p.Items))
|
|
|
|
}
|
2019-06-02 14:45:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestOrderedCollection_Count(t *testing.T) {
|
2019-07-09 11:30:02 +00:00
|
|
|
id := ObjectID("test")
|
|
|
|
|
|
|
|
c := OrderedCollectionNew(id)
|
|
|
|
|
|
|
|
if c.TotalItems != 0 {
|
|
|
|
t.Errorf("Empty object should have empty TotalItems, received %d", c.TotalItems)
|
|
|
|
}
|
|
|
|
if len(c.OrderedItems) > 0 {
|
|
|
|
t.Errorf("Empty object should have empty Items, received %v", c.OrderedItems)
|
|
|
|
}
|
|
|
|
if c.Count() != uint(len(c.OrderedItems)) {
|
|
|
|
t.Errorf("%T.Count() returned %d, expected %d", c, c.Count(), len(c.OrderedItems))
|
|
|
|
}
|
|
|
|
|
|
|
|
c.Append(IRI("test"))
|
|
|
|
if c.TotalItems != 0 {
|
|
|
|
t.Errorf("Empty object should have empty TotalItems, received %d", c.TotalItems)
|
|
|
|
}
|
|
|
|
if c.Count() != uint(len(c.OrderedItems)) {
|
|
|
|
t.Errorf("%T.Count() returned %d, expected %d", c, c.Count(), len(c.OrderedItems))
|
|
|
|
}
|
2019-06-02 14:45:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestOrderedCollectionPage_Count(t *testing.T) {
|
2019-07-09 11:30:02 +00:00
|
|
|
id := ObjectID("test")
|
|
|
|
|
|
|
|
c := OrderedCollectionNew(id)
|
|
|
|
p := OrderedCollectionPageNew(c)
|
|
|
|
|
|
|
|
if p.TotalItems != 0 {
|
|
|
|
t.Errorf("Empty object should have empty TotalItems, received %d", p.TotalItems)
|
|
|
|
}
|
|
|
|
if len(p.OrderedItems) > 0 {
|
|
|
|
t.Errorf("Empty object should have empty Items, received %v", p.OrderedItems)
|
|
|
|
}
|
|
|
|
if p.Count() != uint(len(p.OrderedItems)) {
|
|
|
|
t.Errorf("%T.Count() returned %d, expected %d", c, p.Count(), len(p.OrderedItems))
|
|
|
|
}
|
|
|
|
|
|
|
|
p.Append(IRI("test"))
|
|
|
|
if p.TotalItems != 0 {
|
|
|
|
t.Errorf("Empty object should have empty TotalItems, received %d", p.TotalItems)
|
|
|
|
}
|
|
|
|
if p.Count() != uint(len(p.OrderedItems)) {
|
|
|
|
t.Errorf("%T.Count() returned %d, expected %d", c, p.Count(), len(p.OrderedItems))
|
|
|
|
}
|
2019-05-11 08:31:19 +00:00
|
|
|
}
|
2019-08-21 20:21:32 +00:00
|
|
|
|
|
|
|
func TestToCollection(t *testing.T) {
|
|
|
|
t.Skipf("TODO")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestToCollectionPage(t *testing.T) {
|
|
|
|
t.Skipf("TODO")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestToOrderedCollection(t *testing.T) {
|
|
|
|
t.Skipf("TODO")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestToOrderedCollectionPage(t *testing.T) {
|
|
|
|
t.Skipf("TODO")
|
|
|
|
}
|
2019-08-23 18:39:28 +00:00
|
|
|
|
|
|
|
func TestCollection_Contains(t *testing.T) {
|
|
|
|
t.Skipf("TODO")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCollectionPage_Contains(t *testing.T) {
|
|
|
|
t.Skipf("TODO")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestOrderedCollection_Contains(t *testing.T) {
|
|
|
|
t.Skipf("TODO")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestOrderedCollectionPage_Contains(t *testing.T) {
|
|
|
|
t.Skipf("TODO")
|
|
|
|
}
|