Skip to content

Commit

Permalink
Model updates
Browse files Browse the repository at this point in the history
- Fixed data model typos
- Removed update support for Sensing, as it uses TimeStamps which is not supported yet by the update logic
- Added more tests for other update supported models
  • Loading branch information
DerAndereAndi committed Jan 26, 2024
1 parent f620739 commit 3c3270e
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 19 deletions.
6 changes: 3 additions & 3 deletions model/electricalconnection.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ type ElectricalConnectionIdType uint

type ElectricalConnectionParameterIdType uint

type ElectricalConnectionCharaceteristicsIdType uint
type ElectricalConnectionCharaceteristicIdType uint

type ElectricalConnectionMeasurandVariantType string

Expand Down Expand Up @@ -211,7 +211,7 @@ type ElectricalConnectionDescriptionListDataSelectorsType struct {
type ElectricalConnectionCharacteristicDataType struct {
ElectricalConnectionId *ElectricalConnectionIdType `json:"electricalConnectionId,omitempty" eebus:"key"`
ParameterId *ElectricalConnectionParameterIdType `json:"parameterId,omitempty" eebus:"key"`
CharacteristicId *ElectricalConnectionCharaceteristicsIdType `json:"characteristicId,omitempty" eebus:"key"`
CharacteristicId *ElectricalConnectionCharaceteristicIdType `json:"characteristicId,omitempty" eebus:"key"`
CharacteristicContext *ElectricalConnectionCharacteristicContextType `json:"characteristicContext,omitempty"`
CharacteristicType *ElectricalConnectionCharacteristicTypeType `json:"characteristicType,omitempty"`
Value *ScaledNumberType `json:"value,omitempty"`
Expand All @@ -235,7 +235,7 @@ type ElectricalConnectionCharacteristicListDataType struct {
type ElectricalConnectionCharacteristicListDataSelectorsType struct {
ElectricalConnectionId *ElectricalConnectionIdType `json:"electricalConnectionId,omitempty"`
ParameterId *ElectricalConnectionParameterIdType `json:"parameterId,omitempty"`
CharacteristicId *ElectricalConnectionCharaceteristicsIdType `json:"characteristicId,omitempty"`
CharacteristicId *ElectricalConnectionCharaceteristicIdType `json:"characteristicId,omitempty"`
CharacteristicContext *ElectricalConnectionCharacteristicContextType `json:"characteristicContext,omitempty"`
CharacteristicType *ElectricalConnectionCharacteristicTypeType `json:"characteristicType,omitempty"`
}
44 changes: 44 additions & 0 deletions model/electricalconnection_additions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,50 @@ func TestElectricalConnectionDescriptionListDataType_Update(t *testing.T) {
assert.Equal(t, ElectricalConnectionVoltageTypeTypeDc, *item2.PowerSupplyType)
}

func TestElectricalConnectionCharacteristicListDataType_Update(t *testing.T) {
sut := ElectricalConnectionCharacteristicListDataType{
ElectricalConnectionCharacteristicListData: []ElectricalConnectionCharacteristicDataType{
{
ElectricalConnectionId: util.Ptr(ElectricalConnectionIdType(0)),
ParameterId: util.Ptr(ElectricalConnectionParameterIdType(0)),
CharacteristicId: util.Ptr(ElectricalConnectionCharaceteristicIdType(0)),
CharacteristicType: util.Ptr(ElectricalConnectionCharacteristicTypeTypeApparentPowerConsumptionNominalMax),
},
{
ElectricalConnectionId: util.Ptr(ElectricalConnectionIdType(1)),
ParameterId: util.Ptr(ElectricalConnectionParameterIdType(0)),
CharacteristicId: util.Ptr(ElectricalConnectionCharaceteristicIdType(1)),
CharacteristicType: util.Ptr(ElectricalConnectionCharacteristicTypeTypePowerConsumptionMax),
},
},
}

newData := ElectricalConnectionCharacteristicListDataType{
ElectricalConnectionCharacteristicListData: []ElectricalConnectionCharacteristicDataType{
{
ElectricalConnectionId: util.Ptr(ElectricalConnectionIdType(1)),
ParameterId: util.Ptr(ElectricalConnectionParameterIdType(0)),
CharacteristicId: util.Ptr(ElectricalConnectionCharaceteristicIdType(1)),
CharacteristicType: util.Ptr(ElectricalConnectionCharacteristicTypeTypeEnergyCapacityNominalMax),
},
},
}

// Act
sut.UpdateList(&newData, NewFilterTypePartial(), nil)

data := sut.ElectricalConnectionCharacteristicListData
// check the non changing items
assert.Equal(t, 2, len(data))
item1 := data[0]
assert.Equal(t, 0, int(*item1.ElectricalConnectionId))
assert.Equal(t, ElectricalConnectionCharacteristicTypeTypeApparentPowerConsumptionNominalMax, *item1.CharacteristicType)
// check properties of updated item
item2 := data[1]
assert.Equal(t, 1, int(*item2.ElectricalConnectionId))
assert.Equal(t, ElectricalConnectionCharacteristicTypeTypeEnergyCapacityNominalMax, *item2.CharacteristicType)
}

func TestElectricalConnectionParameterDescriptionListDataType_Update(t *testing.T) {
sut := ElectricalConnectionParameterDescriptionListDataType{
ElectricalConnectionParameterDescriptionData: []ElectricalConnectionParameterDescriptionDataType{
Expand Down
85 changes: 85 additions & 0 deletions model/identification_additions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,88 @@ func TestIdentificationListDataType_Update(t *testing.T) {
assert.Equal(t, 1, int(*item2.IdentificationId))
assert.Equal(t, IdentificationTypeTypeEui64, *item2.IdentificationType)
}

func TestSessionIdentificationListDataType_Update(t *testing.T) {
sut := SessionIdentificationListDataType{
SessionIdentificationData: []SessionIdentificationDataType{
{
IdentificationId: util.Ptr(IdentificationIdType(0)),
SessionId: util.Ptr(SessionIdType(1)),
IsLatestSession: util.Ptr(false),
},
{
IdentificationId: util.Ptr(IdentificationIdType(1)),
SessionId: util.Ptr(SessionIdType(2)),
IsLatestSession: util.Ptr(true),
},
},
}

newData := SessionIdentificationListDataType{
SessionIdentificationData: []SessionIdentificationDataType{
{
IdentificationId: util.Ptr(IdentificationIdType(1)),
SessionId: util.Ptr(SessionIdType(2)),
IsLatestSession: util.Ptr(false),
},
},
}

// Act
sut.UpdateList(&newData, NewFilterTypePartial(), nil)

data := sut.SessionIdentificationData
// check the non changing items
assert.Equal(t, 2, len(data))
item1 := data[0]
assert.Equal(t, 0, int(*item1.IdentificationId))
assert.Equal(t, false, *item1.IsLatestSession)
// check properties of updated item
item2 := data[1]
assert.Equal(t, 1, int(*item2.IdentificationId))
assert.Equal(t, false, *item2.IsLatestSession)
}

func TestSessionMeasurementRelationListDataType_Update(t *testing.T) {
sut := SessionMeasurementRelationListDataType{
SessionMeasurementRelationData: []SessionMeasurementRelationDataType{
{
SessionId: util.Ptr(SessionIdType(0)),
MeasurementId: []MeasurementIdType{
0, 1,
},
},
{
SessionId: util.Ptr(SessionIdType(1)),
MeasurementId: []MeasurementIdType{
2, 3,
},
},
},
}

newData := SessionMeasurementRelationListDataType{
SessionMeasurementRelationData: []SessionMeasurementRelationDataType{
{
SessionId: util.Ptr(SessionIdType(1)),
MeasurementId: []MeasurementIdType{
2, 3, 4,
},
},
},
}

// Act
sut.UpdateList(&newData, NewFilterTypePartial(), nil)

data := sut.SessionMeasurementRelationData
// check the non changing items
assert.Equal(t, 2, len(data))
item1 := data[0]
assert.Equal(t, 0, int(*item1.SessionId))
assert.Equal(t, []MeasurementIdType{0, 1}, item1.MeasurementId)
// check properties of updated item
item2 := data[1]
assert.Equal(t, 1, int(*item2.SessionId))
assert.Equal(t, []MeasurementIdType{2, 3, 4}, item2.MeasurementId)
}
4 changes: 2 additions & 2 deletions model/measurement.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ type MeasurementValueTypeType string
const (
MeasurementValueTypeTypeValue MeasurementValueTypeType = "value"
MeasurementValueTypeTypeAverageValue MeasurementValueTypeType = "averageValue"
MeasurementValueTypeTypeMinvValue MeasurementValueTypeType = "minValue"
MeasurementValueTypeTypeMaxvVlue MeasurementValueTypeType = "maxValue"
MeasurementValueTypeTypeMinValue MeasurementValueTypeType = "minValue"
MeasurementValueTypeTypeMaxValue MeasurementValueTypeType = "maxValue"
MeasurementValueTypeTypeStandardDeviation MeasurementValueTypeType = "standardDeviation"
)

Expand Down
41 changes: 41 additions & 0 deletions model/measurement_additions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,47 @@ func TestMeasurementListDataType_Update_Replace(t *testing.T) {
assert.Equal(t, 10.0, item2.Value.GetValue())
}

func TestMeasurementSeriesListDataType_Update(t *testing.T) {
sut := MeasurementSeriesListDataType{
MeasurementSeriesData: []MeasurementSeriesDataType{
{
MeasurementId: util.Ptr(MeasurementIdType(0)),
ValueType: util.Ptr(MeasurementValueTypeTypeMinValue),
Value: NewScaledNumberType(1),
},
{
MeasurementId: util.Ptr(MeasurementIdType(1)),
ValueType: util.Ptr(MeasurementValueTypeTypeMaxValue),
Value: NewScaledNumberType(10),
},
},
}

newData := MeasurementSeriesListDataType{
MeasurementSeriesData: []MeasurementSeriesDataType{
{
MeasurementId: util.Ptr(MeasurementIdType(1)),
ValueType: util.Ptr(MeasurementValueTypeTypeMaxValue),
Value: NewScaledNumberType(100),
},
},
}

// Act
sut.UpdateList(&newData, NewFilterTypePartial(), nil)

data := sut.MeasurementSeriesData
// check the non changing items
assert.Equal(t, 2, len(data))
item1 := data[0]
assert.Equal(t, 0, int(*item1.MeasurementId))
assert.Equal(t, 1.0, item1.Value.GetValue())
// check properties of updated item
item2 := data[1]
assert.Equal(t, 1, int(*item2.MeasurementId))
assert.Equal(t, 100.0, item2.Value.GetValue())
}

func TestMeasurementConstraintsListDataType_Update(t *testing.T) {
sut := MeasurementConstraintsListDataType{
MeasurementConstraintsData: []MeasurementConstraintsDataType{
Expand Down
14 changes: 0 additions & 14 deletions model/sensing_additions.go

This file was deleted.

46 changes: 46 additions & 0 deletions model/stateinformation_additions_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package model

import (
"testing"

"github.com/enbility/spine-go/util"
"github.com/stretchr/testify/assert"
)

func TestStateInformationListDataType_Update(t *testing.T) {
sut := StateInformationListDataType{
StateInformationData: []StateInformationDataType{
{
StateInformationId: util.Ptr(StateInformationIdType(0)),
IsActive: util.Ptr(true),
},
{
StateInformationId: util.Ptr(StateInformationIdType(1)),
IsActive: util.Ptr(false),
},
},
}

newData := StateInformationListDataType{
StateInformationData: []StateInformationDataType{
{
StateInformationId: util.Ptr(StateInformationIdType(1)),
IsActive: util.Ptr(true),
},
},
}

// Act
sut.UpdateList(&newData, NewFilterTypePartial(), nil)

data := sut.StateInformationData
// check the non changing items
assert.Equal(t, 2, len(data))
item1 := data[0]
assert.Equal(t, 0, int(*item1.StateInformationId))
assert.Equal(t, true, *item1.IsActive)
// check properties of updated item
item2 := data[1]
assert.Equal(t, 1, int(*item2.StateInformationId))
assert.Equal(t, true, *item2.IsActive)
}

0 comments on commit 3c3270e

Please sign in to comment.