Skip to content

Commit e958834

Browse files
committed
Add missing files
1 parent 461264c commit e958834

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-0
lines changed

model/surrogate.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package model
2+
3+
type SurrogateIdType uint
4+
5+
type SurrogateScopeEnumType string
6+
7+
type SurrogateScopeType string
8+
9+
type SurrogateOtherSourceType string
10+
11+
type SurrogateSourcesType struct {
12+
SpineSource []EntityAddressType `json:"spineSource,omitempty"`
13+
OtherSource []SurrogateOtherSourceType `json:"otherSource,omitempty"`
14+
}
15+
16+
type SurrogateDescriptionDataType struct {
17+
SurrogateId *SurrogateIdType `json:"surrogateId,omitempty" eebus:"key"`
18+
SurrogateScope *SurrogateScopeType `json:"surrogateScope,omitempty"`
19+
SurrogateSources *SurrogateSourcesType `json:"surrogateSources,omitempty"`
20+
Label *LabelType `json:"label,omitempty"`
21+
Description *DescriptionType `json:"description,omitempty"`
22+
}
23+
24+
type SurrogateSourcesElementsType struct {
25+
SpineSource *EntityAddressElementsType `json:"spineSource,omitempty"`
26+
OtherSource *ElementTagType `json:"otherSource,omitempty"`
27+
}
28+
29+
type SurrogateDescriptionDataElementsType struct {
30+
SurrogateId *ElementTagType `json:"surrogateId,omitempty"`
31+
SurrogateScope *ElementTagType `json:"surrogateScope,omitempty"`
32+
SurrogateSources *SurrogateSourcesElementsType `json:"surrogateSources,omitempty"`
33+
Label *ElementTagType `json:"label,omitempty"`
34+
Description *ElementTagType `json:"description,omitempty"`
35+
}
36+
37+
type SurrogateDescriptionListDataType struct {
38+
SurrogateDescriptionData []SurrogateDescriptionDataType `json:"surrogateDescriptionData,omitempty"`
39+
}
40+
41+
type SurrogateDescriptionListDataSelectorsSourcesType struct {
42+
SpineSource *EntityAddressType `json:"spineSource,omitempty"`
43+
OtherSource *string `json:"otherSource,omitempty"`
44+
}
45+
46+
type SurrogateDescriptionListDataSelectorsType struct {
47+
SurrogateId *SurrogateIdType `json:"surrogateId,omitempty"`
48+
SurrogateScope *SurrogateScopeType `json:"surrogateScope,omitempty"`
49+
SurrogateSources *SurrogateDescriptionListDataSelectorsSourcesType `json:"surrogateSources,omitempty"`
50+
}

model/surrogate_additions.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package model
2+
3+
// SurrogateDescriptionListDataType
4+
5+
var _ Updater = (*SurrogateDescriptionListDataType)(nil)
6+
7+
func (r *SurrogateDescriptionListDataType) UpdateList(remoteWrite, persist bool, newList any, filterPartial, filterDelete *FilterType) (any, bool) {
8+
var newData []SurrogateDescriptionDataType
9+
if newList != nil {
10+
newData = newList.(*SurrogateDescriptionListDataType).SurrogateDescriptionData
11+
}
12+
13+
data, success := UpdateList(remoteWrite, r.SurrogateDescriptionData, newData, filterPartial, filterDelete)
14+
15+
if success && persist {
16+
r.SurrogateDescriptionData = data
17+
}
18+
19+
return data, success
20+
}

model/surrogate_additions_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package model
2+
3+
import (
4+
"testing"
5+
6+
"github.com/enbility/spine-go/util"
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
func TestSurrogateDescriptionListDataType_Update(t *testing.T) {
11+
sut := SurrogateDescriptionListDataType{
12+
SurrogateDescriptionData: []SurrogateDescriptionDataType{
13+
{
14+
SurrogateId: util.Ptr(SurrogateIdType(0)),
15+
SurrogateScope: util.Ptr(SurrogateScopeType("old")),
16+
},
17+
{
18+
SurrogateId: util.Ptr(SurrogateIdType(1)),
19+
SurrogateScope: util.Ptr(SurrogateScopeType("test")),
20+
},
21+
},
22+
}
23+
24+
newData := SurrogateDescriptionListDataType{
25+
SurrogateDescriptionData: []SurrogateDescriptionDataType{
26+
{
27+
SurrogateId: util.Ptr(SurrogateIdType(1)),
28+
SurrogateScope: util.Ptr(SurrogateScopeType("new")),
29+
},
30+
},
31+
}
32+
33+
// Act
34+
_, success := sut.UpdateList(false, true, &newData, NewFilterTypePartial(), nil)
35+
assert.True(t, success)
36+
37+
data := sut.SurrogateDescriptionData
38+
// check the non changing items
39+
assert.Equal(t, 2, len(data))
40+
item1 := data[0]
41+
assert.Equal(t, 0, int(*item1.SurrogateId))
42+
assert.Equal(t, "old", string(*item1.SurrogateScope))
43+
// check properties of updated item
44+
item2 := data[1]
45+
assert.Equal(t, 1, int(*item2.SurrogateId))
46+
assert.Equal(t, "new", string(*item2.SurrogateScope))
47+
}

0 commit comments

Comments
 (0)