广汽安道拓Acura项目MES后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

126 lines
3.2 KiB

package container
import (
"LAPP_ACURA_MOM_BACKEND/global"
"fmt"
"testing"
)
func TestNewSessionBrokerBuilder_New(t *testing.T) {
builder := NewNewSessionBrokerBuilder()
if builder == nil {
t.Fatalf("创建失败!")
}
}
func TestNewSessionBrokerBuilder_Check(t *testing.T) {
methodName := "StringWithContext"
method, ok := testServiceType.MethodByName(methodName)
if !ok {
t.Fatalf("意外的没找到方法:%s", methodName)
}
builder := NewNewSessionBrokerBuilder()
err := builder.Check(method.Type)
if err != nil {
t.Fatalf("意外错误:%s", err.Error())
}
}
func TestNewSessionBrokerBuilder_Check_Less(t *testing.T) {
methodName := "String"
method, ok := testServiceType.MethodByName(methodName)
if !ok {
t.Fatalf("意外的没找到方法:%s", methodName)
}
builder := NewNewSessionBrokerBuilder()
err := builder.Check(method.Type)
if err == nil {
t.Fatalf("意外的没有错误!")
}
if err.Error() != fmt.Sprintf("参数太少!实际数量:0") {
t.Fatalf("意外错误:%s", err.Error())
}
}
func TestNewSessionBrokerBuilder_Check_FirstNotSession(t *testing.T) {
methodName := "StringNotFirstContext"
method, ok := testServiceType.MethodByName(methodName)
if !ok {
t.Fatalf("意外的没找到方法:%s", methodName)
}
builder := NewNewSessionBrokerBuilder()
err := builder.Check(method.Type)
if err == nil {
t.Fatalf("意外的没有错误!")
}
if err.Error() != fmt.Sprintf("第一个参数必须是*RequestContext") {
t.Fatalf("意外错误:%s", err.Error())
}
}
func TestNewSessionBrokerBuilder_Check_OtherSession(t *testing.T) {
methodName := "String3"
method, ok := testServiceType.MethodByName(methodName)
if !ok {
t.Fatalf("意外的没找到方法:%s", methodName)
}
builder := NewNewSessionBrokerBuilder()
err := builder.Check(method.Type)
if err == nil {
t.Fatalf("意外的没有错误!")
}
if err.Error() != fmt.Sprintf("第2个参数不能是*RequestContext") {
t.Fatalf("意外错误:%s", err.Error())
}
}
func TestNewSessionBrokerBuilder_Check_NullMethodType(t *testing.T) {
builder := NewNewSessionBrokerBuilder()
err := builder.Check(nil)
if err == nil {
t.Fatalf("意外的没有错误!")
}
if err.Error() != fmt.Sprintf("方法类型不能为空!") {
t.Fatalf("意外错误:%s", err.Error())
}
}
func TestNewSessionBrokerBuilder_Build_NullCaller(t *testing.T) {
userId := "userId"
user := &global.User{UserId: userId}
sessionContext, err := NewSessionContext(user, transactionHandlerFactoryMock)
if err != nil {
t.Fatalf("意外错误:%s", err.Error())
}
builder := NewNewSessionBrokerBuilder()
_, err = builder.Build(sessionContext, nil)
if err == nil {
t.Fatalf("意外的没有错误!")
}
if err.Error() != fmt.Sprintf("调用器不能为空!") {
t.Fatalf("意外错误:%s", err.Error())
}
}
func TestNewSessionBrokerBuilder_Build_NullSession(t *testing.T) {
caller, err := serviceInstance.GetCaller("String")
if err != nil {
t.Fatalf("意外错误:%s", err.Error())
}
builder := NewNewSessionBrokerBuilder()
_, err = builder.Build(nil, caller)
if err == nil {
t.Fatalf("意外的没有错误!")
}
if err.Error() != fmt.Sprintf("会话上下文不能为空!") {
t.Fatalf("意外错误:%s", err.Error())
}
}