-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext_test.go
74 lines (55 loc) · 2.38 KB
/
context_test.go
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
68
69
70
71
72
73
74
package context
import (
core "github.com/procyon-projects/procyon-core"
"github.com/stretchr/testify/assert"
"testing"
)
type testConfigurableContextAdapter struct {
}
func (adapter testConfigurableContextAdapter) Configure() {
}
func (adapter testConfigurableContextAdapter) OnConfigure() {
}
func (adapter testConfigurableContextAdapter) FinishConfigure() {
}
func TestBaseApplicationContext_WithNilConfigurableContextAdapter(t *testing.T) {
assert.Panics(t, func() {
NewBaseApplicationContext("app-id", "context-id", nil)
})
}
func TestBaseApplicationContext_SetLogger(t *testing.T) {
baseApplicationContext := NewBaseApplicationContext("app-id", "context-id", testConfigurableContextAdapter{})
logger := NewSimpleLogger()
baseApplicationContext.SetLogger(logger)
assert.Panics(t, func() {
baseApplicationContext.SetLogger(logger)
})
baseApplicationContext.AddApplicationListener(testApplicationListener1{})
baseApplicationContext.AddApplicationListener(testApplicationListener2{})
assert.Equal(t, 2, len(baseApplicationContext.GetApplicationListeners()))
}
func TestBaseApplicationContext_AddApplicationListener(t *testing.T) {
baseApplicationContext := NewBaseApplicationContext("app-id", "context-id", testConfigurableContextAdapter{})
assert.Panics(t, func() {
baseApplicationContext.AddApplicationListener(nil)
})
}
func TestBaseApplicationContext(t *testing.T) {
baseApplicationContext := NewBaseApplicationContext("app-id", "context-id", testConfigurableContextAdapter{})
baseApplicationContext.Get("")
baseApplicationContext.AddApplicationListener(testApplicationListener1{})
baseApplicationContext.AddApplicationListener(testApplicationListener2{})
logger := NewSimpleLogger()
baseApplicationContext.SetLogger(logger)
assert.Equal(t, logger, baseApplicationContext.GetLogger())
baseApplicationContext.SetApplicationName("app-name")
assert.Equal(t, "app-name", baseApplicationContext.GetApplicationName())
assert.Equal(t, ApplicationId("app-id"), baseApplicationContext.GetAppId())
assert.Equal(t, ContextId("context-id"), baseApplicationContext.GetContextId())
baseApplicationContext.Put("test-key", "test-value")
assert.Equal(t, "test-value", baseApplicationContext.Get("test-key"))
env := core.NewStandardEnvironment()
baseApplicationContext.SetEnvironment(env)
assert.Equal(t, env, baseApplicationContext.GetEnvironment())
baseApplicationContext.Configure()
}