You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2023/05/17 12:05:11 UTC
[plc4x] branch develop updated (7de8439f1d -> 0a14655948)
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a change to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
from 7de8439f1d fix(plc4go/spi): gracefully handle tag names not found on ReadResponse.
new 1f16e0f7be fix(plc4go/spi): gracefully handle tag names not found on SubscriptionEvent
new 794183a15d refactor(plc4go/spi): cleanup unused types
new fdce5b9aa7 fix(plc4go/spi): gracefully handle tag names not found on DefaultTag
new 0a14655948 fix(plc4go/spi): gracefully handle tag names not found on WriteResponse
The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
plc4go/spi/model/DefaultPlcSubscriptionEvent.go | 37 +-
.../spi/model/DefaultPlcSubscriptionEvent_test.go | 414 +++++++++++++++++++++
.../model/DefaultPlcSubscriptionRequestResult.go | 45 ---
...DefaultPlcSubscriptionRequestResult_plc4xgen.go | 101 -----
plc4go/spi/model/DefaultPlcTagRequest.go | 7 +-
...sponse_test.go => DefaultPlcTagRequest_test.go} | 92 +++--
plc4go/spi/model/DefaultPlcWriteRequest.go | 1 +
plc4go/spi/model/DefaultPlcWriteResponse.go | 6 +-
plc4go/spi/model/DefaultPlcWriteResponse_test.go | 51 ++-
plc4go/spi/model/render_test.go | 1 -
10 files changed, 543 insertions(+), 212 deletions(-)
create mode 100644 plc4go/spi/model/DefaultPlcSubscriptionEvent_test.go
delete mode 100644 plc4go/spi/model/DefaultPlcSubscriptionRequestResult.go
delete mode 100644 plc4go/spi/model/DefaultPlcSubscriptionRequestResult_plc4xgen.go
copy plc4go/spi/model/{DefaultPlcWriteResponse_test.go => DefaultPlcTagRequest_test.go} (50%)
[plc4x] 03/04: fix(plc4go/spi): gracefully handle tag names not found on DefaultTag
Posted by sr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit fdce5b9aa7fafe83f85c9db794fe4b826f0d35e0
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Wed May 17 13:59:43 2023 +0200
fix(plc4go/spi): gracefully handle tag names not found on DefaultTag
---
plc4go/spi/model/DefaultPlcTagRequest_test.go | 133 ++++++++++++++++++++++++++
1 file changed, 133 insertions(+)
diff --git a/plc4go/spi/model/DefaultPlcTagRequest_test.go b/plc4go/spi/model/DefaultPlcTagRequest_test.go
new file mode 100644
index 0000000000..6ac7c6daaf
--- /dev/null
+++ b/plc4go/spi/model/DefaultPlcTagRequest_test.go
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package model
+
+import (
+ "testing"
+
+ apiModel "github.com/apache/plc4x/plc4go/pkg/api/model"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestDefaultPlcTagRequest_GetTag(t *testing.T) {
+ type fields struct {
+ tags map[string]apiModel.PlcTag
+ tagNames []string
+ }
+ type args struct {
+ name string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want apiModel.PlcTag
+ }{
+ {
+ name: "get it (not found)",
+ },
+ {
+ name: "get it",
+ fields: fields{
+ tags: map[string]apiModel.PlcTag{
+ "something": nil,
+ },
+ },
+ args: args{
+ name: "something",
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ d := &DefaultPlcTagRequest{
+ tags: tt.fields.tags,
+ tagNames: tt.fields.tagNames,
+ }
+ assert.Equalf(t, tt.want, d.GetTag(tt.args.name), "GetTag(%v)", tt.args.name)
+ })
+ }
+}
+
+func TestDefaultPlcTagRequest_GetTagNames(t *testing.T) {
+ type fields struct {
+ tags map[string]apiModel.PlcTag
+ tagNames []string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ want []string
+ }{
+ // TODO: Add test cases.
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ d := &DefaultPlcTagRequest{
+ tags: tt.fields.tags,
+ tagNames: tt.fields.tagNames,
+ }
+ assert.Equalf(t, tt.want, d.GetTagNames(), "GetTagNames()")
+ })
+ }
+}
+
+func TestDefaultPlcTagRequest_IsAPlcMessage(t *testing.T) {
+ type fields struct {
+ tags map[string]apiModel.PlcTag
+ tagNames []string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ want bool
+ }{
+ // TODO: Add test cases.
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ d := &DefaultPlcTagRequest{
+ tags: tt.fields.tags,
+ tagNames: tt.fields.tagNames,
+ }
+ assert.Equalf(t, tt.want, d.IsAPlcMessage(), "IsAPlcMessage()")
+ })
+ }
+}
+
+func TestNewDefaultPlcTagRequest(t *testing.T) {
+ type args struct {
+ tags map[string]apiModel.PlcTag
+ tagNames []string
+ }
+ tests := []struct {
+ name string
+ args args
+ want *DefaultPlcTagRequest
+ }{
+ // TODO: Add test cases.
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ assert.Equalf(t, tt.want, NewDefaultPlcTagRequest(tt.args.tags, tt.args.tagNames), "NewDefaultPlcTagRequest(%v, %v)", tt.args.tags, tt.args.tagNames)
+ })
+ }
+}
[plc4x] 04/04: fix(plc4go/spi): gracefully handle tag names not found on WriteResponse
Posted by sr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit 0a14655948ed44bb2a62b4ce58a18bad652fb5f7
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Wed May 17 14:05:03 2023 +0200
fix(plc4go/spi): gracefully handle tag names not found on WriteResponse
---
plc4go/spi/model/DefaultPlcWriteResponse.go | 7 +++-
plc4go/spi/model/DefaultPlcWriteResponse_test.go | 51 +++++++++++++++++++++---
2 files changed, 50 insertions(+), 8 deletions(-)
diff --git a/plc4go/spi/model/DefaultPlcWriteResponse.go b/plc4go/spi/model/DefaultPlcWriteResponse.go
index 2198cdd648..a16d04b8b0 100644
--- a/plc4go/spi/model/DefaultPlcWriteResponse.go
+++ b/plc4go/spi/model/DefaultPlcWriteResponse.go
@@ -60,6 +60,9 @@ func (d *DefaultPlcWriteResponse) GetRequest() apiModel.PlcWriteRequest {
}
func (d *DefaultPlcWriteResponse) GetResponseCode(name string) apiModel.PlcResponseCode {
- // TODO: guard
- return d.responseCodes[name]
+ code, ok := d.responseCodes[name]
+ if !ok {
+ return apiModel.PlcResponseCode_NOT_FOUND
+ }
+ return code
}
diff --git a/plc4go/spi/model/DefaultPlcWriteResponse_test.go b/plc4go/spi/model/DefaultPlcWriteResponse_test.go
index 30c49c3244..ae7524d79a 100644
--- a/plc4go/spi/model/DefaultPlcWriteResponse_test.go
+++ b/plc4go/spi/model/DefaultPlcWriteResponse_test.go
@@ -20,9 +20,11 @@
package model
import (
+ "testing"
+
apiModel "github.com/apache/plc4x/plc4go/pkg/api/model"
+
"github.com/stretchr/testify/assert"
- "testing"
)
func TestDefaultPlcWriteResponse_GetRequest(t *testing.T) {
@@ -35,7 +37,9 @@ func TestDefaultPlcWriteResponse_GetRequest(t *testing.T) {
fields fields
want apiModel.PlcWriteRequest
}{
- // TODO: Add test cases.
+ {
+ name: "get it",
+ },
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
@@ -62,7 +66,22 @@ func TestDefaultPlcWriteResponse_GetResponseCode(t *testing.T) {
args args
want apiModel.PlcResponseCode
}{
- // TODO: Add test cases.
+ {
+ name: "get it (not found)",
+ want: apiModel.PlcResponseCode_NOT_FOUND,
+ },
+ {
+ name: "get it",
+ fields: fields{
+ responseCodes: map[string]apiModel.PlcResponseCode{
+ "something": apiModel.PlcResponseCode_OK,
+ },
+ },
+ args: args{
+ name: "something",
+ },
+ want: apiModel.PlcResponseCode_OK,
+ },
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
@@ -85,7 +104,21 @@ func TestDefaultPlcWriteResponse_GetTagNames(t *testing.T) {
fields fields
want []string
}{
- // TODO: Add test cases.
+ {
+ name: "get em (none)",
+ },
+ {
+ name: "get em",
+ fields: fields{
+ request: NewDefaultPlcWriteRequest(nil, []string{"a", "b", "c"}, nil, nil, nil),
+ responseCodes: map[string]apiModel.PlcResponseCode{
+ "a": apiModel.PlcResponseCode_OK,
+ "b": apiModel.PlcResponseCode_OK,
+ "c": apiModel.PlcResponseCode_OK,
+ },
+ },
+ want: []string{"a", "b", "c"},
+ },
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
@@ -108,7 +141,10 @@ func TestDefaultPlcWriteResponse_IsAPlcMessage(t *testing.T) {
fields fields
want bool
}{
- // TODO: Add test cases.
+ {
+ name: "is it",
+ want: true,
+ },
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
@@ -131,7 +167,10 @@ func TestNewDefaultPlcWriteResponse(t *testing.T) {
args args
want apiModel.PlcWriteResponse
}{
- // TODO: Add test cases.
+ {
+ name: "create it",
+ want: &DefaultPlcWriteResponse{},
+ },
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
[plc4x] 01/04: fix(plc4go/spi): gracefully handle tag names not found on SubscriptionEvent
Posted by sr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit 1f16e0f7beb8605e71284765bc22891bd915cd8d
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Wed May 17 13:55:20 2023 +0200
fix(plc4go/spi): gracefully handle tag names not found on SubscriptionEvent
---
plc4go/spi/model/DefaultPlcSubscriptionEvent.go | 37 +-
.../spi/model/DefaultPlcSubscriptionEvent_test.go | 414 +++++++++++++++++++++
2 files changed, 446 insertions(+), 5 deletions(-)
diff --git a/plc4go/spi/model/DefaultPlcSubscriptionEvent.go b/plc4go/spi/model/DefaultPlcSubscriptionEvent.go
index a9d8aab0f7..b4f91f4cb0 100644
--- a/plc4go/spi/model/DefaultPlcSubscriptionEvent.go
+++ b/plc4go/spi/model/DefaultPlcSubscriptionEvent.go
@@ -25,6 +25,9 @@ import (
apiModel "github.com/apache/plc4x/plc4go/pkg/api/model"
apiValues "github.com/apache/plc4x/plc4go/pkg/api/values"
"github.com/apache/plc4x/plc4go/spi/utils"
+ spiValues "github.com/apache/plc4x/plc4go/spi/values"
+
+ "github.com/rs/zerolog/log"
)
//go:generate go run ../../tools/plc4xgenerator/gen.go -type=DefaultPlcSubscriptionEvent
@@ -75,23 +78,47 @@ func (d *DefaultPlcSubscriptionEvent) GetTagNames() []string {
}
func (d *DefaultPlcSubscriptionEvent) GetResponseCode(name string) apiModel.PlcResponseCode {
- return d.values[name].GetCode()
+ item, ok := d.values[name]
+ if !ok {
+ return apiModel.PlcResponseCode_NOT_FOUND
+ }
+ return item.GetCode()
}
func (d *DefaultPlcSubscriptionEvent) GetTag(name string) apiModel.PlcTag {
- return d.values[name].GetTag()
+ item := d.values[name]
+ if item == nil {
+ log.Warn().Msgf("field for %s not found", name)
+ return nil
+ }
+ return item.GetTag()
}
func (d *DefaultPlcSubscriptionEvent) GetType(name string) SubscriptionType {
- return d.values[name].GetSubscriptionType()
+ item := d.values[name]
+ if item == nil {
+ log.Warn().Msgf("field for %s not found", name)
+ return 0
+ }
+ return item.GetSubscriptionType()
}
func (d *DefaultPlcSubscriptionEvent) GetInterval(name string) time.Duration {
- return d.values[name].GetInterval()
+ item := d.values[name]
+ if item == nil {
+ log.Warn().Msgf("field for %s not found", name)
+ return -1
+ }
+ return item.GetInterval()
}
func (d *DefaultPlcSubscriptionEvent) GetValue(name string) apiValues.PlcValue {
- return d.values[name].GetValue()
+ item := d.values[name]
+ if item == nil {
+ log.Warn().Msgf("field for %s not found", name)
+ return spiValues.PlcNull{}
+ }
+ return item.GetValue()
}
func (d *DefaultPlcSubscriptionEvent) GetAddress(name string) string {
diff --git a/plc4go/spi/model/DefaultPlcSubscriptionEvent_test.go b/plc4go/spi/model/DefaultPlcSubscriptionEvent_test.go
new file mode 100644
index 0000000000..dc8432dc09
--- /dev/null
+++ b/plc4go/spi/model/DefaultPlcSubscriptionEvent_test.go
@@ -0,0 +1,414 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package model
+
+import (
+ "github.com/stretchr/testify/mock"
+ "testing"
+ "time"
+
+ apiModel "github.com/apache/plc4x/plc4go/pkg/api/model"
+ apiValues "github.com/apache/plc4x/plc4go/pkg/api/values"
+ spiValues "github.com/apache/plc4x/plc4go/spi/values"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestDefaultPlcSubscriptionEvent_GetAddress(t *testing.T) {
+ type fields struct {
+ DefaultPlcSubscriptionEventRequirements DefaultPlcSubscriptionEventRequirements
+ values map[string]*DefaultPlcSubscriptionEventItem
+ }
+ type args struct {
+ name string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want string
+ }{
+ {
+ fields: fields{
+ DefaultPlcSubscriptionEventRequirements: func() DefaultPlcSubscriptionEventRequirements {
+ requirements := NewMockDefaultPlcSubscriptionEventRequirements(t)
+ requirements.EXPECT().GetAddress(mock.Anything).Return("anything")
+ return requirements
+ }(),
+ },
+ name: "get it",
+ want: "anything",
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ d := &DefaultPlcSubscriptionEvent{
+ DefaultPlcSubscriptionEventRequirements: tt.fields.DefaultPlcSubscriptionEventRequirements,
+ values: tt.fields.values,
+ }
+ assert.Equalf(t, tt.want, d.GetAddress(tt.args.name), "GetAddress(%v)", tt.args.name)
+ })
+ }
+}
+
+func TestDefaultPlcSubscriptionEvent_GetInterval(t *testing.T) {
+ type fields struct {
+ DefaultPlcSubscriptionEventRequirements DefaultPlcSubscriptionEventRequirements
+ values map[string]*DefaultPlcSubscriptionEventItem
+ }
+ type args struct {
+ name string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want time.Duration
+ }{
+ {
+ name: "get it (not found)",
+ want: -1,
+ },
+ {
+ name: "get it",
+ fields: fields{
+ values: map[string]*DefaultPlcSubscriptionEventItem{
+ "da field": {interval: 70},
+ },
+ },
+ args: args{
+ name: "da field",
+ },
+ want: 70,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ d := &DefaultPlcSubscriptionEvent{
+ DefaultPlcSubscriptionEventRequirements: tt.fields.DefaultPlcSubscriptionEventRequirements,
+ values: tt.fields.values,
+ }
+ assert.Equalf(t, tt.want, d.GetInterval(tt.args.name), "GetInterval(%v)", tt.args.name)
+ })
+ }
+}
+
+func TestDefaultPlcSubscriptionEvent_GetResponseCode(t *testing.T) {
+ type fields struct {
+ DefaultPlcSubscriptionEventRequirements DefaultPlcSubscriptionEventRequirements
+ values map[string]*DefaultPlcSubscriptionEventItem
+ }
+ type args struct {
+ name string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want apiModel.PlcResponseCode
+ }{
+ {
+ name: "get it (not found)",
+ want: apiModel.PlcResponseCode_NOT_FOUND,
+ },
+ {
+ name: "get it",
+ fields: fields{
+ values: map[string]*DefaultPlcSubscriptionEventItem{
+ "da field": {code: apiModel.PlcResponseCode_NOT_FOUND},
+ },
+ },
+ args: args{
+ name: "da field",
+ },
+ want: apiModel.PlcResponseCode_NOT_FOUND,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ d := &DefaultPlcSubscriptionEvent{
+ DefaultPlcSubscriptionEventRequirements: tt.fields.DefaultPlcSubscriptionEventRequirements,
+ values: tt.fields.values,
+ }
+ assert.Equalf(t, tt.want, d.GetResponseCode(tt.args.name), "GetResponseCode(%v)", tt.args.name)
+ })
+ }
+}
+
+func TestDefaultPlcSubscriptionEvent_GetSource(t *testing.T) {
+ type fields struct {
+ DefaultPlcSubscriptionEventRequirements DefaultPlcSubscriptionEventRequirements
+ values map[string]*DefaultPlcSubscriptionEventItem
+ }
+ type args struct {
+ name string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want string
+ }{
+ {
+ name: "get it (not found)",
+ fields: fields{
+ DefaultPlcSubscriptionEventRequirements: func() DefaultPlcSubscriptionEventRequirements {
+ requirements := NewMockDefaultPlcSubscriptionEventRequirements(t)
+ requirements.EXPECT().GetAddress(mock.Anything).Return("")
+ return requirements
+ }(),
+ },
+ want: "",
+ },
+ {
+ name: "get it",
+ fields: fields{
+ DefaultPlcSubscriptionEventRequirements: func() DefaultPlcSubscriptionEventRequirements {
+ requirements := NewMockDefaultPlcSubscriptionEventRequirements(t)
+ requirements.EXPECT().GetAddress(mock.Anything).Return("something")
+ return requirements
+ }(),
+ },
+ args: args{
+ name: "da field",
+ },
+ want: "something",
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ d := &DefaultPlcSubscriptionEvent{
+ DefaultPlcSubscriptionEventRequirements: tt.fields.DefaultPlcSubscriptionEventRequirements,
+ values: tt.fields.values,
+ }
+ assert.Equalf(t, tt.want, d.GetSource(tt.args.name), "GetSource(%v)", tt.args.name)
+ })
+ }
+}
+
+func TestDefaultPlcSubscriptionEvent_GetTag(t *testing.T) {
+ type fields struct {
+ DefaultPlcSubscriptionEventRequirements DefaultPlcSubscriptionEventRequirements
+ values map[string]*DefaultPlcSubscriptionEventItem
+ }
+ type args struct {
+ name string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want apiModel.PlcTag
+ }{
+ {
+ name: "get it (not found)",
+ want: nil,
+ },
+ {
+ name: "get it",
+ fields: fields{
+ values: map[string]*DefaultPlcSubscriptionEventItem{
+ "da field": {tag: nil},
+ },
+ },
+ args: args{
+ name: "da field",
+ },
+ want: nil,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ d := &DefaultPlcSubscriptionEvent{
+ DefaultPlcSubscriptionEventRequirements: tt.fields.DefaultPlcSubscriptionEventRequirements,
+ values: tt.fields.values,
+ }
+ assert.Equalf(t, tt.want, d.GetTag(tt.args.name), "GetTag(%v)", tt.args.name)
+ })
+ }
+}
+
+func TestDefaultPlcSubscriptionEvent_GetTagNames(t *testing.T) {
+ type fields struct {
+ DefaultPlcSubscriptionEventRequirements DefaultPlcSubscriptionEventRequirements
+ values map[string]*DefaultPlcSubscriptionEventItem
+ }
+ tests := []struct {
+ name string
+ fields fields
+ want []string
+ }{
+ {
+ name: "get it (not found)",
+ want: nil,
+ },
+ {
+ name: "get it",
+ fields: fields{
+ values: map[string]*DefaultPlcSubscriptionEventItem{
+ "da field": {tag: nil},
+ "da field2": {tag: nil},
+ },
+ },
+ want: []string{"da field", "da field2"},
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ d := &DefaultPlcSubscriptionEvent{
+ DefaultPlcSubscriptionEventRequirements: tt.fields.DefaultPlcSubscriptionEventRequirements,
+ values: tt.fields.values,
+ }
+ assert.Equalf(t, tt.want, d.GetTagNames(), "GetTagNames()")
+ })
+ }
+}
+
+func TestDefaultPlcSubscriptionEvent_GetType(t *testing.T) {
+ type fields struct {
+ DefaultPlcSubscriptionEventRequirements DefaultPlcSubscriptionEventRequirements
+ values map[string]*DefaultPlcSubscriptionEventItem
+ }
+ type args struct {
+ name string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want SubscriptionType
+ }{
+ {
+ name: "get it (not found)",
+ want: 0,
+ },
+ {
+ name: "get it",
+ fields: fields{
+ values: map[string]*DefaultPlcSubscriptionEventItem{
+ "da field": {subscriptionType: SubscriptionChangeOfState},
+ },
+ },
+ args: args{name: "da field"},
+ want: SubscriptionChangeOfState,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ d := &DefaultPlcSubscriptionEvent{
+ DefaultPlcSubscriptionEventRequirements: tt.fields.DefaultPlcSubscriptionEventRequirements,
+ values: tt.fields.values,
+ }
+ assert.Equalf(t, tt.want, d.GetType(tt.args.name), "GetType(%v)", tt.args.name)
+ })
+ }
+}
+
+func TestDefaultPlcSubscriptionEvent_GetValue(t *testing.T) {
+ type fields struct {
+ DefaultPlcSubscriptionEventRequirements DefaultPlcSubscriptionEventRequirements
+ values map[string]*DefaultPlcSubscriptionEventItem
+ }
+ type args struct {
+ name string
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want apiValues.PlcValue
+ }{
+ {
+ name: "get it (not found)",
+ want: spiValues.PlcNull{},
+ },
+ {
+ name: "get it",
+ fields: fields{
+ values: map[string]*DefaultPlcSubscriptionEventItem{
+ "da field": {value: spiValues.NewPlcSTRING("yeah")},
+ },
+ },
+ args: args{name: "da field"},
+ want: spiValues.NewPlcSTRING("yeah"),
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ d := &DefaultPlcSubscriptionEvent{
+ DefaultPlcSubscriptionEventRequirements: tt.fields.DefaultPlcSubscriptionEventRequirements,
+ values: tt.fields.values,
+ }
+ assert.Equalf(t, tt.want, d.GetValue(tt.args.name), "GetValue(%v)", tt.args.name)
+ })
+ }
+}
+
+func TestDefaultPlcSubscriptionEvent_IsAPlcMessage(t *testing.T) {
+ type fields struct {
+ DefaultPlcSubscriptionEventRequirements DefaultPlcSubscriptionEventRequirements
+ values map[string]*DefaultPlcSubscriptionEventItem
+ }
+ tests := []struct {
+ name string
+ fields fields
+ want bool
+ }{
+ {
+ name: "it is",
+ want: true,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ d := &DefaultPlcSubscriptionEvent{
+ DefaultPlcSubscriptionEventRequirements: tt.fields.DefaultPlcSubscriptionEventRequirements,
+ values: tt.fields.values,
+ }
+ assert.Equalf(t, tt.want, d.IsAPlcMessage(), "IsAPlcMessage()")
+ })
+ }
+}
+
+func TestNewDefaultPlcSubscriptionEvent(t *testing.T) {
+ type args struct {
+ defaultPlcSubscriptionEventRequirements DefaultPlcSubscriptionEventRequirements
+ tags map[string]apiModel.PlcTag
+ types map[string]SubscriptionType
+ intervals map[string]time.Duration
+ responseCodes map[string]apiModel.PlcResponseCode
+ values map[string]apiValues.PlcValue
+ }
+ tests := []struct {
+ name string
+ args args
+ want apiModel.PlcSubscriptionEvent
+ }{
+ {
+ name: "create it",
+ want: &DefaultPlcSubscriptionEvent{values: map[string]*DefaultPlcSubscriptionEventItem{}},
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ assert.Equalf(t, tt.want, NewDefaultPlcSubscriptionEvent(tt.args.defaultPlcSubscriptionEventRequirements, tt.args.tags, tt.args.types, tt.args.intervals, tt.args.responseCodes, tt.args.values), "NewDefaultPlcSubscriptionEvent(%v, %v, %v, %v, %v, %v)", tt.args.defaultPlcSubscriptionEventRequirements, tt.args.tags, tt.args.types, tt.args.intervals, tt.args.responseCodes, tt.args.values)
+ })
+ }
+}
[plc4x] 02/04: refactor(plc4go/spi): cleanup unused types
Posted by sr...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit 794183a15deaad0d6baa4ac8142da082a441edf8
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Wed May 17 13:56:31 2023 +0200
refactor(plc4go/spi): cleanup unused types
---
.../model/DefaultPlcSubscriptionRequestResult.go | 45 ---------
...DefaultPlcSubscriptionRequestResult_plc4xgen.go | 101 ---------------------
plc4go/spi/model/DefaultPlcTagRequest.go | 7 +-
plc4go/spi/model/DefaultPlcWriteRequest.go | 1 +
plc4go/spi/model/DefaultPlcWriteResponse.go | 1 +
plc4go/spi/model/render_test.go | 1 -
6 files changed, 6 insertions(+), 150 deletions(-)
diff --git a/plc4go/spi/model/DefaultPlcSubscriptionRequestResult.go b/plc4go/spi/model/DefaultPlcSubscriptionRequestResult.go
deleted file mode 100644
index 71a3393e5e..0000000000
--- a/plc4go/spi/model/DefaultPlcSubscriptionRequestResult.go
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package model
-
-import apiModel "github.com/apache/plc4x/plc4go/pkg/api/model"
-
-//go:generate go run ../../tools/plc4xgenerator/gen.go -type=DefaultPlcSubscriptionRequestResult
-type DefaultPlcSubscriptionRequestResult struct {
- Request apiModel.PlcSubscriptionRequest
- Response apiModel.PlcSubscriptionResponse
- Err error
-}
-
-func NewDefaultPlcSubscriptionRequestResult(Request apiModel.PlcSubscriptionRequest, Response apiModel.PlcSubscriptionResponse, Err error) apiModel.PlcSubscriptionRequestResult {
- return &DefaultPlcSubscriptionRequestResult{Request, Response, Err}
-}
-
-func (d *DefaultPlcSubscriptionRequestResult) GetRequest() apiModel.PlcSubscriptionRequest {
- return d.Request
-}
-
-func (d *DefaultPlcSubscriptionRequestResult) GetResponse() apiModel.PlcSubscriptionResponse {
- return d.Response
-}
-
-func (d *DefaultPlcSubscriptionRequestResult) GetErr() error {
- return d.Err
-}
diff --git a/plc4go/spi/model/DefaultPlcSubscriptionRequestResult_plc4xgen.go b/plc4go/spi/model/DefaultPlcSubscriptionRequestResult_plc4xgen.go
deleted file mode 100644
index dd04d7bb9f..0000000000
--- a/plc4go/spi/model/DefaultPlcSubscriptionRequestResult_plc4xgen.go
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-// Code generated by "plc4xgenerator -type=DefaultPlcSubscriptionRequestResult"; DO NOT EDIT.
-
-package model
-
-import (
- "context"
- "encoding/binary"
- "fmt"
- "github.com/apache/plc4x/plc4go/spi/utils"
-)
-
-var _ = fmt.Printf
-
-func (d *DefaultPlcSubscriptionRequestResult) Serialize() ([]byte, error) {
- wb := utils.NewWriteBufferByteBased(utils.WithByteOrderForByteBasedBuffer(binary.BigEndian))
- if err := d.SerializeWithWriteBuffer(context.Background(), wb); err != nil {
- return nil, err
- }
- return wb.GetBytes(), nil
-}
-
-func (d *DefaultPlcSubscriptionRequestResult) SerializeWithWriteBuffer(ctx context.Context, writeBuffer utils.WriteBuffer) error {
- if err := writeBuffer.PushContext("PlcSubscriptionRequestResult"); err != nil {
- return err
- }
-
- if d.Request != nil {
- if serializableField, ok := d.Request.(utils.Serializable); ok {
- if err := writeBuffer.PushContext("request"); err != nil {
- return err
- }
- if err := serializableField.SerializeWithWriteBuffer(ctx, writeBuffer); err != nil {
- return err
- }
- if err := writeBuffer.PopContext("request"); err != nil {
- return err
- }
- } else {
- stringValue := fmt.Sprintf("%v", d.Request)
- if err := writeBuffer.WriteString("request", uint32(len(stringValue)*8), "UTF-8", stringValue); err != nil {
- return err
- }
- }
- }
-
- if d.Response != nil {
- if serializableField, ok := d.Response.(utils.Serializable); ok {
- if err := writeBuffer.PushContext("response"); err != nil {
- return err
- }
- if err := serializableField.SerializeWithWriteBuffer(ctx, writeBuffer); err != nil {
- return err
- }
- if err := writeBuffer.PopContext("response"); err != nil {
- return err
- }
- } else {
- stringValue := fmt.Sprintf("%v", d.Response)
- if err := writeBuffer.WriteString("response", uint32(len(stringValue)*8), "UTF-8", stringValue); err != nil {
- return err
- }
- }
- }
-
- if d.Err != nil {
- if err := writeBuffer.WriteString("err", uint32(len(d.Err.Error())*8), "UTF-8", d.Err.Error()); err != nil {
- return err
- }
- }
- if err := writeBuffer.PopContext("PlcSubscriptionRequestResult"); err != nil {
- return err
- }
- return nil
-}
-
-func (d *DefaultPlcSubscriptionRequestResult) String() string {
- writeBuffer := utils.NewWriteBufferBoxBasedWithOptions(true, true)
- if err := writeBuffer.WriteSerializable(context.Background(), d); err != nil {
- return err.Error()
- }
- return writeBuffer.GetBox().String()
-}
diff --git a/plc4go/spi/model/DefaultPlcTagRequest.go b/plc4go/spi/model/DefaultPlcTagRequest.go
index d5c5654814..da56bd6fa0 100644
--- a/plc4go/spi/model/DefaultPlcTagRequest.go
+++ b/plc4go/spi/model/DefaultPlcTagRequest.go
@@ -42,8 +42,9 @@ func (d *DefaultPlcTagRequest) GetTagNames() []string {
}
func (d *DefaultPlcTagRequest) GetTag(name string) apiModel.PlcTag {
- if tag, ok := d.tags[name]; ok {
- return tag
+ tag, ok := d.tags[name]
+ if !ok {
+ return nil
}
- return nil
+ return tag
}
diff --git a/plc4go/spi/model/DefaultPlcWriteRequest.go b/plc4go/spi/model/DefaultPlcWriteRequest.go
index f065fc5764..35e114f300 100644
--- a/plc4go/spi/model/DefaultPlcWriteRequest.go
+++ b/plc4go/spi/model/DefaultPlcWriteRequest.go
@@ -194,5 +194,6 @@ func (d *DefaultPlcWriteRequest) GetWriteRequestInterceptor() interceptors.Write
}
func (d *DefaultPlcWriteRequest) GetValue(name string) apiValues.PlcValue {
+ // TODO: guard
return d.values[name]
}
diff --git a/plc4go/spi/model/DefaultPlcWriteResponse.go b/plc4go/spi/model/DefaultPlcWriteResponse.go
index 5bf7e3fd7b..2198cdd648 100644
--- a/plc4go/spi/model/DefaultPlcWriteResponse.go
+++ b/plc4go/spi/model/DefaultPlcWriteResponse.go
@@ -60,5 +60,6 @@ func (d *DefaultPlcWriteResponse) GetRequest() apiModel.PlcWriteRequest {
}
func (d *DefaultPlcWriteResponse) GetResponseCode(name string) apiModel.PlcResponseCode {
+ // TODO: guard
return d.responseCodes[name]
}
diff --git a/plc4go/spi/model/render_test.go b/plc4go/spi/model/render_test.go
index 4d6eb82895..e6987e58f4 100644
--- a/plc4go/spi/model/render_test.go
+++ b/plc4go/spi/model/render_test.go
@@ -55,7 +55,6 @@ func TestRenderTest(t *testing.T) {
&DefaultPlcSubscriptionEventItem{},
&DefaultPlcSubscriptionHandle{},
&DefaultPlcSubscriptionRequest{DefaultPlcTagRequest: NewDefaultPlcTagRequest(nil, nil)},
- &DefaultPlcSubscriptionRequestResult{},
&DefaultPlcSubscriptionResponse{},
&DefaultPlcSubscriptionResponseItem{},
&DefaultPlcTagRequest{},