-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
384 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
37
manager/handlers/ocpp201/get_local_list_version_result_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} |
Oops, something went wrong.