1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
package tests
import (
"strings"
"testing"
j "github.com/go-ap/jsonld"
pub "github.com/go-ap/activitypub"
)
func TestAcceptSerialization(t *testing.T) {
obj := pub.AcceptNew("https://localhost/myactivity", nil)
obj.Name = make(pub.NaturalLanguageValues, 1)
obj.Name.Set("en", pub.Content("test"))
obj.Name.Set("fr", pub.Content("teste"))
uri := "https://www.w3.org/ns/activitystreams"
p := j.WithContext(j.IRI(uri))
data, err := p.Marshal(obj)
if err != nil {
t.Errorf("Error: %v", err)
}
if !strings.Contains(string(data), uri) {
t.Errorf("Could not find context url %#v in output %s", p.Context, data)
}
if !strings.Contains(string(data), string(obj.ID)) {
t.Errorf("Could not find id %#v in output %s", string(obj.ID), data)
}
if !strings.Contains(string(data), string(obj.Name.Get("en"))) {
t.Errorf("Could not find name %#v in output %s", string(obj.Name.Get("en")), data)
}
if !strings.Contains(string(data), string(obj.Name.Get("fr"))) {
t.Errorf("Could not find name %#v in output %s", string(obj.Name.Get("fr")), data)
}
if !strings.Contains(string(data), string(obj.Type)) {
t.Errorf("Could not find activity type %#v in output %s", obj.Type, data)
}
}
func TestCreateActivityHTTPSerialization(t *testing.T) {
id := pub.ID("test_object")
obj := pub.AcceptNew(id, nil)
obj.Name.Set("en", pub.Content("Accept New"))
uri := string(pub.ActivityBaseURI)
data, err := j.WithContext(j.IRI(uri)).Marshal(obj)
if err != nil {
t.Errorf("Error: %v", err)
}
if !strings.Contains(string(data), uri) {
t.Errorf("Could not find context url %#v in output %s", j.GetContext(), data)
}
if !strings.Contains(string(data), string(obj.ID)) {
t.Errorf("Could not find id %#v in output %s", string(obj.ID), data)
}
if !strings.Contains(string(data), obj.Name.Get("en").String()) {
t.Errorf("Could not find name %s in output %s", obj.Name.Get("en"), data)
}
if !strings.Contains(string(data), string(obj.Type)) {
t.Errorf("Could not find activity type %#v in output %s", obj.Type, data)
}
}
|