Skip to content

Commit

Permalink
feat: stub local list messages
Browse files Browse the repository at this point in the history
  • Loading branch information
subnova committed Mar 20, 2024
1 parent 9f5b969 commit 6f9ca00
Show file tree
Hide file tree
Showing 14 changed files with 384 additions and 0 deletions.
24 changes: 24 additions & 0 deletions manager/handlers/ocpp201/clear_cache.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: Apache-2.0

package ocpp201

import (
"context"
"github.com/thoughtworks/maeve-csms/manager/ocpp"
types "github.com/thoughtworks/maeve-csms/manager/ocpp/ocpp201"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
)

type ClearCacheResultHandler struct{}

func (h ClearCacheResultHandler) HandleCallResult(ctx context.Context, chargeStationId string, request ocpp.Request, response ocpp.Response, state any) error {
resp := response.(*types.ClearCacheResponseJson)

span := trace.SpanFromContext(ctx)

span.SetAttributes(
attribute.String("clear_cache.status", string(resp.Status)))

return nil
}
37 changes: 37 additions & 0 deletions manager/handlers/ocpp201/clear_cache_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: Apache-2.0

package ocpp201_test

import (
"context"
"github.com/stretchr/testify/require"
"github.com/thoughtworks/maeve-csms/manager/handlers/ocpp201"
types "github.com/thoughtworks/maeve-csms/manager/ocpp/ocpp201"
"github.com/thoughtworks/maeve-csms/manager/testutil"
"testing"
)

func TestClearCacheResultHandler(t *testing.T) {
handler := ocpp201.ClearCacheResultHandler{}

tracer, exporter := testutil.GetTracer()

ctx := context.Background()

func() {
ctx, span := tracer.Start(ctx, `test`)
defer span.End()

req := &types.ClearCacheRequestJson{}
resp := &types.ClearCacheResponseJson{
Status: types.ClearCacheStatusEnumTypeAccepted,
}

err := handler.HandleCallResult(ctx, "cs001", req, resp, nil)
require.NoError(t, err)
}()

testutil.AssertSpan(t, &exporter.GetSpans()[0], "test", map[string]any{
"clear_cache.status": "Accepted",
})
}
24 changes: 24 additions & 0 deletions manager/handlers/ocpp201/get_local_list_version_result.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: Apache-2.0

package ocpp201

import (
"context"
"github.com/thoughtworks/maeve-csms/manager/ocpp"
types "github.com/thoughtworks/maeve-csms/manager/ocpp/ocpp201"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
)

type GetLocalListVersionResultHandler struct{}

func (h GetLocalListVersionResultHandler) HandleCallResult(ctx context.Context, chargeStationId string, request ocpp.Request, response ocpp.Response, state any) error {
resp := response.(*types.GetLocalListVersionResponseJson)

span := trace.SpanFromContext(ctx)

span.SetAttributes(
attribute.Int("get_local_list_version.version_number", resp.VersionNumber))

return nil
}
37 changes: 37 additions & 0 deletions manager/handlers/ocpp201/get_local_list_version_result_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: Apache-2.0

package ocpp201_test

import (
"context"
"github.com/stretchr/testify/require"
"github.com/thoughtworks/maeve-csms/manager/handlers/ocpp201"
types "github.com/thoughtworks/maeve-csms/manager/ocpp/ocpp201"
"github.com/thoughtworks/maeve-csms/manager/testutil"
"testing"
)

func TestGetLocalListVersionResultHandler(t *testing.T) {
handler := ocpp201.GetLocalListVersionResultHandler{}

tracer, exporter := testutil.GetTracer()

ctx := context.Background()

func() {
ctx, span := tracer.Start(ctx, `test`)
defer span.End()

req := &types.GetLocalListVersionRequestJson{}
resp := &types.GetLocalListVersionResponseJson{
VersionNumber: 42,
}

err := handler.HandleCallResult(ctx, "cs001", req, resp, nil)
require.NoError(t, err)
}()

testutil.AssertSpan(t, &exporter.GetSpans()[0], "test", map[string]any{
"get_local_list_version.version_number": 42,
})
}
24 changes: 24 additions & 0 deletions manager/handlers/ocpp201/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ func NewRouter(emitter transport.Emitter,
ResponseSchema: "ocpp201/ChangeAvailabilityResponse.json",
Handler: ChangeAvailabilityResultHandler{},
},
"ClearCache": {
NewRequest: func() ocpp.Request { return new(ocpp201.ClearCacheRequestJson) },
NewResponse: func() ocpp.Response { return new(ocpp201.ClearCacheResponseJson) },
RequestSchema: "ocpp201/ClearCacheRequest.json",
ResponseSchema: "ocpp201/ClearCacheResponse.json",
Handler: ClearCacheResultHandler{},
},
"DeleteCertificate": {
NewRequest: func() ocpp.Request { return new(ocpp201.DeleteCertificateRequestJson) },
NewResponse: func() ocpp.Response { return new(ocpp201.DeleteCertificateResponseJson) },
Expand All @@ -166,6 +173,13 @@ func NewRouter(emitter transport.Emitter,
ResponseSchema: "ocpp201/GetInstalledCertificateIdsResponse.json",
Handler: GetInstalledCertificateIdsResultHandler{},
},
"GetLocalListVersion": {
NewRequest: func() ocpp.Request { return new(ocpp201.GetLocalListVersionRequestJson) },
NewResponse: func() ocpp.Response { return new(ocpp201.GetLocalListVersionResponseJson) },
RequestSchema: "ocpp201/GetLocalListVersionRequest.json",
ResponseSchema: "ocpp201/GetLocalListVersionResponse.json",
Handler: GetLocalListVersionResultHandler{},
},
"GetReport": {
NewRequest: func() ocpp.Request { return new(ocpp201.GetReportRequestJson) },
NewResponse: func() ocpp.Response { return new(ocpp201.GetReportResponseJson) },
Expand Down Expand Up @@ -217,6 +231,13 @@ func NewRouter(emitter transport.Emitter,
ResponseSchema: "ocpp201/ResetResponse.json",
Handler: ResetResultHandler{},
},
"SendLocalList": {
NewRequest: func() ocpp.Request { return new(ocpp201.SendLocalListRequestJson) },
NewResponse: func() ocpp.Response { return new(ocpp201.SendLocalListResponseJson) },
RequestSchema: "ocpp201/SendLocalListRequest.json",
ResponseSchema: "ocpp201/SendLocalListResponse.json",
Handler: SendLocalListResultHandler{},
},
"SetNetworkProfile": {
NewRequest: func() ocpp.Request { return new(ocpp201.SetNetworkProfileRequestJson) },
NewResponse: func() ocpp.Response { return new(ocpp201.SetNetworkProfileResponseJson) },
Expand Down Expand Up @@ -260,16 +281,19 @@ func NewCallMaker(e transport.Emitter) *handlers.OcppCallMaker {
Actions: map[reflect.Type]string{
reflect.TypeOf(&ocpp201.CertificateSignedRequestJson{}): "CertificateSigned",
reflect.TypeOf(&ocpp201.ChangeAvailabilityRequestJson{}): "ChangeAvailability",
reflect.TypeOf(&ocpp201.ClearCacheRequestJson{}): "ClearCache",
reflect.TypeOf(&ocpp201.DeleteCertificateRequestJson{}): "DeleteCertificate",
reflect.TypeOf(&ocpp201.GetBaseReportRequestJson{}): "GetBaseReport",
reflect.TypeOf(&ocpp201.GetInstalledCertificateIdsRequestJson{}): "GetInstalledCertificateIds",
reflect.TypeOf(&ocpp201.GetLocalListVersionRequestJson{}): "GetLocalListVersion",
reflect.TypeOf(&ocpp201.GetReportRequestJson{}): "GetReport",
reflect.TypeOf(&ocpp201.GetTransactionStatusRequestJson{}): "GetTransactionStatus",
reflect.TypeOf(&ocpp201.GetVariablesRequestJson{}): "GetVariables",
reflect.TypeOf(&ocpp201.InstallCertificateRequestJson{}): "InstallCertificate",
reflect.TypeOf(&ocpp201.RequestStartTransactionRequestJson{}): "RequestStartTransaction",
reflect.TypeOf(&ocpp201.RequestStopTransactionRequestJson{}): "RequestStopTransaction",
reflect.TypeOf(&ocpp201.ResetRequestJson{}): "Reset",
reflect.TypeOf(&ocpp201.SendLocalListRequestJson{}): "SendLocalList",
reflect.TypeOf(&ocpp201.SetNetworkProfileRequestJson{}): "SetNetworkProfile",
reflect.TypeOf(&ocpp201.SetVariablesRequestJson{}): "SetVariables",
reflect.TypeOf(&ocpp201.TriggerMessageRequestJson{}): "TriggerMessage",
Expand Down
43 changes: 43 additions & 0 deletions manager/handlers/ocpp201/routing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ func TestRoutingCallResults(t *testing.T) {
Status: types.ChangeAvailabilityStatusEnumTypeAccepted,
},
},
"ClearCache": {
request: &types.ClearCacheRequestJson{},
response: &types.ClearCacheResponseJson{
Status: types.ClearCacheStatusEnumTypeAccepted,
},
},
"DeleteCertificate": {
request: &types.DeleteCertificateRequestJson{
CertificateHashData: types.CertificateHashDataType{
Expand Down Expand Up @@ -307,6 +313,12 @@ func TestRoutingCallResults(t *testing.T) {
},
},
},
"GetLocalListVersion": {
request: &types.GetLocalListVersionRequestJson{},
response: &types.GetLocalListVersionResponseJson{
VersionNumber: 17,
},
},
"GetReport": {
request: &types.GetReportRequestJson{
RequestId: 18,
Expand Down Expand Up @@ -389,6 +401,23 @@ func TestRoutingCallResults(t *testing.T) {
Status: types.ResetStatusEnumTypeScheduled,
},
},
"SendLocalList": {
request: &types.SendLocalListRequestJson{
LocalAuthorizationList: []types.AuthorizationData{
{
IdToken: types.IdTokenType{
Type: types.IdTokenEnumTypeEMAID,
IdToken: "XYZ12345",
},
},
},
VersionNumber: 22,
UpdateType: types.UpdateEnumTypeFull,
},
response: &types.SendLocalListResponseJson{
Status: types.SendLocalListStatusEnumTypeAccepted,
},
},
"SetNetworkProfile": {
request: &types.SetNetworkProfileRequestJson{
ConfigurationSlot: 1,
Expand Down Expand Up @@ -488,6 +517,7 @@ func TestCallMaker(t *testing.T) {
"ChangeAvailability": &types.ChangeAvailabilityRequestJson{
OperationalStatus: types.OperationalStatusEnumTypeInoperative,
},
"ClearCache": &types.ClearCacheRequestJson{},
"DeleteCertificate": &types.DeleteCertificateRequestJson{
CertificateHashData: types.CertificateHashDataType{
HashAlgorithm: types.HashAlgorithmEnumTypeSHA256,
Expand All @@ -505,6 +535,7 @@ func TestCallMaker(t *testing.T) {
types.GetCertificateIdUseEnumTypeCSMSRootCertificate,
},
},
"GetLocalListVersion": &types.GetLocalListVersionRequestJson{},
"GetReport": &types.GetReportRequestJson{
RequestId: 42,
},
Expand Down Expand Up @@ -540,6 +571,18 @@ func TestCallMaker(t *testing.T) {
"Reset": &types.ResetRequestJson{
Type: types.ResetEnumTypeImmediate,
},
"SendLocalList": &types.SendLocalListRequestJson{
LocalAuthorizationList: []types.AuthorizationData{
{
IdToken: types.IdTokenType{
Type: types.IdTokenEnumTypeISO14443,
IdToken: "ABCD1234",
},
},
},
UpdateType: types.UpdateEnumTypeDifferential,
VersionNumber: 12,
},
"SetNetworkProfile": &types.SetNetworkProfileRequestJson{
ConfigurationSlot: 1,
ConnectionData: types.NetworkConnectionProfileType{
Expand Down
27 changes: 27 additions & 0 deletions manager/handlers/ocpp201/send_local_list_result.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: Apache-2.0

package ocpp201

import (
"context"
"github.com/thoughtworks/maeve-csms/manager/ocpp"
types "github.com/thoughtworks/maeve-csms/manager/ocpp/ocpp201"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
)

type SendLocalListResultHandler struct{}

func (h SendLocalListResultHandler) HandleCallResult(ctx context.Context, chargeStationId string, request ocpp.Request, response ocpp.Response, state any) error {
req := request.(*types.SendLocalListRequestJson)
resp := response.(*types.SendLocalListResponseJson)

span := trace.SpanFromContext(ctx)

span.SetAttributes(
attribute.String("send_local_list.update_type", string(req.UpdateType)),
attribute.Int("send_local_list.version_number", req.VersionNumber),
attribute.String("send_local_list.status", string(resp.Status)))

return nil
}
50 changes: 50 additions & 0 deletions manager/handlers/ocpp201/send_local_list_result_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// SPDX-License-Identifier: Apache-2.0

package ocpp201_test

import (
"context"
"github.com/stretchr/testify/require"
"github.com/thoughtworks/maeve-csms/manager/handlers/ocpp201"
types "github.com/thoughtworks/maeve-csms/manager/ocpp/ocpp201"
"github.com/thoughtworks/maeve-csms/manager/testutil"
"testing"
)

func TestSendLocalListResultHandler(t *testing.T) {
handler := ocpp201.SendLocalListResultHandler{}

tracer, exporter := testutil.GetTracer()

ctx := context.Background()

func() {
ctx, span := tracer.Start(ctx, `test`)
defer span.End()

req := &types.SendLocalListRequestJson{
LocalAuthorizationList: []types.AuthorizationData{
{
IdToken: types.IdTokenType{
Type: types.IdTokenEnumTypeISO14443,
IdToken: "ABCD1234",
},
},
},
UpdateType: types.UpdateEnumTypeFull,
VersionNumber: 42,
}
resp := &types.SendLocalListResponseJson{
Status: types.SendLocalListStatusEnumTypeAccepted,
}

err := handler.HandleCallResult(ctx, "cs001", req, resp, nil)
require.NoError(t, err)
}()

testutil.AssertSpan(t, &exporter.GetSpans()[0], "test", map[string]any{
"send_local_list.update_type": "Full",
"send_local_list.version_number": 42,
"send_local_list.status": "Accepted",
})
}
10 changes: 10 additions & 0 deletions manager/ocpp/ocpp201/clear_cache_request.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: Apache-2.0

package ocpp201

type ClearCacheRequestJson struct {
// CustomData corresponds to the JSON schema field "customData".
CustomData *CustomDataType `json:"customData,omitempty" yaml:"customData,omitempty" mapstructure:"customData,omitempty"`
}

func (*ClearCacheRequestJson) IsRequest() {}
21 changes: 21 additions & 0 deletions manager/ocpp/ocpp201/clear_cache_response.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: Apache-2.0

package ocpp201

type ClearCacheStatusEnumType string

const ClearCacheStatusEnumTypeAccepted ClearCacheStatusEnumType = "Accepted"
const ClearCacheStatusEnumTypeRejected ClearCacheStatusEnumType = "Rejected"

type ClearCacheResponseJson struct {
// CustomData corresponds to the JSON schema field "customData".
CustomData *CustomDataType `json:"customData,omitempty" yaml:"customData,omitempty" mapstructure:"customData,omitempty"`

// Status corresponds to the JSON schema field "status".
Status ClearCacheStatusEnumType `json:"status" yaml:"status" mapstructure:"status"`

// StatusInfo corresponds to the JSON schema field "statusInfo".
StatusInfo *StatusInfoType `json:"statusInfo,omitempty" yaml:"statusInfo,omitempty" mapstructure:"statusInfo,omitempty"`
}

func (*ClearCacheResponseJson) IsResponse() {}
10 changes: 10 additions & 0 deletions manager/ocpp/ocpp201/get_local_list_version_request.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: Apache-2.0

package ocpp201

type GetLocalListVersionRequestJson struct {
// CustomData corresponds to the JSON schema field "customData".
CustomData *CustomDataType `json:"customData,omitempty" yaml:"customData,omitempty" mapstructure:"customData,omitempty"`
}

func (*GetLocalListVersionRequestJson) IsRequest() {}
Loading

0 comments on commit 6f9ca00

Please sign in to comment.