-
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
package tests
import (
"testing"
"activitypub"
"jsonld"
"strings"
)
func TestAcceptSerialization(t *testing.T) {
obj := activitypub.AcceptNew("https://localhost/myactivity", nil)
obj.Name = make(activitypub.NaturalLanguageValue, 1)
obj.Name["en"] = "test"
ctx := jsonld.Context{URL: "https://www.w3.org/ns/activitystreams"}
data, err := jsonld.Marshal(obj, &ctx)
if err != nil {
t.Errorf("Error: %v", err)
}
if !strings.Contains(string(data), string(ctx.URL)) {
t.Errorf("Could not find context url %#v in output %s", ctx.URL, 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["en"])) {
t.Errorf("Could not find name %#v in output %s", string(obj.Name["en"]), 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 := activitypub.ObjectId("test_object")
obj := activitypub.AcceptNew(id, nil)
obj.Name["en"] = "Accept New"
baseUri := string(activitypub.ActivityBaseURI)
ctx := jsonld.Context{
URL: jsonld.Ref(baseUri + string(obj.Type)),
}
data, err := jsonld.Marshal(obj, &ctx)
if err != nil {
t.Error(err)
}
if !strings.Contains(string(data), string(ctx.URL)) {
t.Errorf("Could not find context url %#v in output %s", ctx.URL, 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["en"])) {
t.Errorf("Could not find name %#v in output %s", string(obj.Name["en"]), data)
}
if !strings.Contains(string(data), string(obj.Type)) {
t.Errorf("Could not find activity type %#v in output %s", obj.Type, data)
}
}