forked from lorenzodonini/ocpp-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchange_configuration_test.go
84 lines (77 loc) · 4.17 KB
/
change_configuration_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
75
76
77
78
79
80
81
82
83
84
package ocpp16_test
import (
"fmt"
"github.com/lorenzodonini/ocpp-go/ocpp1.6/core"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)
// Test
func (suite *OcppV16TestSuite) TestChangeConfigurationRequestValidation() {
t := suite.T()
var requestTable = []GenericTestEntry{
{core.ChangeConfigurationRequest{Key: "someKey", Value: "someValue"}, true},
{core.ChangeConfigurationRequest{Key: "someKey"}, false},
{core.ChangeConfigurationRequest{Value: "someValue"}, false},
{core.ChangeConfigurationRequest{}, false},
{core.ChangeConfigurationRequest{Key: ">50................................................", Value: "someValue"}, false},
{core.ChangeConfigurationRequest{Key: "someKey", Value: ">500................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................."}, false},
}
ExecuteGenericTestTable(t, requestTable)
}
func (suite *OcppV16TestSuite) TestChangeConfigurationConfirmationValidation() {
t := suite.T()
var confirmationTable = []GenericTestEntry{
{core.ChangeConfigurationConfirmation{Status: core.ConfigurationStatusAccepted}, true},
{core.ChangeConfigurationConfirmation{Status: core.ConfigurationStatusRejected}, true},
{core.ChangeConfigurationConfirmation{Status: core.ConfigurationStatusRebootRequired}, true},
{core.ChangeConfigurationConfirmation{Status: core.ConfigurationStatusNotSupported}, true},
{core.ChangeConfigurationConfirmation{Status: "invalidConfigurationStatus"}, false},
}
ExecuteGenericTestTable(t, confirmationTable)
}
func (suite *OcppV16TestSuite) TestChangeConfigurationE2EMocked() {
t := suite.T()
wsId := "test_id"
messageId := defaultMessageId
wsUrl := "someUrl"
key := "someKey"
value := "someValue"
status := core.ConfigurationStatusAccepted
requestJson := fmt.Sprintf(`[2,"%v","%v",{"key":"%v","value":"%v"}]`, messageId, core.ChangeConfigurationFeatureName, key, value)
responseJson := fmt.Sprintf(`[3,"%v",{"status":"%v"}]`, messageId, status)
changeConfigurationConfirmation := core.NewChangeConfigurationConfirmation(status)
channel := NewMockWebSocket(wsId)
coreListener := &MockChargePointCoreListener{}
coreListener.On("OnChangeConfiguration", mock.Anything).Return(changeConfigurationConfirmation, nil).Run(func(args mock.Arguments) {
request, ok := args.Get(0).(*core.ChangeConfigurationRequest)
require.NotNil(t, request)
require.True(t, ok)
assert.Equal(t, key, request.Key)
assert.Equal(t, value, request.Value)
})
setupDefaultCentralSystemHandlers(suite, nil, expectedCentralSystemOptions{clientId: wsId, rawWrittenMessage: []byte(requestJson), forwardWrittenMessage: true})
setupDefaultChargePointHandlers(suite, coreListener, expectedChargePointOptions{serverUrl: wsUrl, clientId: wsId, createChannelOnStart: true, channel: channel, rawWrittenMessage: []byte(responseJson), forwardWrittenMessage: true})
// Run Test
suite.centralSystem.Start(8887, "somePath")
err := suite.chargePoint.Start(wsUrl)
require.Nil(t, err)
resultChannel := make(chan bool, 1)
err = suite.centralSystem.ChangeConfiguration(wsId, func(confirmation *core.ChangeConfigurationConfirmation, err error) {
require.Nil(t, err)
require.NotNil(t, confirmation)
assert.Equal(t, status, confirmation.Status)
resultChannel <- true
}, key, value)
require.Nil(t, err)
result := <-resultChannel
assert.True(t, result)
}
func (suite *OcppV16TestSuite) TestChangeConfigurationInvalidEndpoint() {
messageId := defaultMessageId
key := "someKey"
value := "someValue"
changeConfigurationRequest := core.NewChangeConfigurationRequest(key, value)
requestJson := fmt.Sprintf(`[2,"%v","%v",{"key":"%v","value":"%v"}]`, messageId, core.ChangeConfigurationFeatureName, key, value)
testUnsupportedRequestFromChargePoint(suite, changeConfigurationRequest, requestJson, messageId)
}