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 10:32:33 UTC

[plc4x] 01/03: test(plc4go/spi): add test for DefaultPlcConsumerRegistration

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 a7ca651288794c0f292451f86e6f260260c6c9ff
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Wed May 17 12:17:48 2023 +0200

    test(plc4go/spi): add test for DefaultPlcConsumerRegistration
---
 .../model/DefaultPlcConsumerRegistration_test.go   | 146 +++++++++++++++++++++
 1 file changed, 146 insertions(+)

diff --git a/plc4go/spi/model/DefaultPlcConsumerRegistration_test.go b/plc4go/spi/model/DefaultPlcConsumerRegistration_test.go
new file mode 100644
index 0000000000..6ad2d7fabb
--- /dev/null
+++ b/plc4go/spi/model/DefaultPlcConsumerRegistration_test.go
@@ -0,0 +1,146 @@
+/*
+ * 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"
+	"github.com/apache/plc4x/plc4go/spi"
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/mock"
+	"testing"
+)
+
+func TestDefaultPlcConsumerRegistration_GetConsumerId(t *testing.T) {
+	type fields struct {
+		consumerId    int
+		consumer      apiModel.PlcSubscriptionEventConsumer
+		plcSubscriber spi.PlcSubscriber
+		handles       []apiModel.PlcSubscriptionHandle
+	}
+	tests := []struct {
+		name   string
+		fields fields
+		want   int
+	}{
+		{
+			name: "get it",
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			d := &DefaultPlcConsumerRegistration{
+				consumerId:    tt.fields.consumerId,
+				consumer:      tt.fields.consumer,
+				plcSubscriber: tt.fields.plcSubscriber,
+				handles:       tt.fields.handles,
+			}
+			assert.Equalf(t, tt.want, d.GetConsumerId(), "GetConsumerId()")
+		})
+	}
+}
+
+func TestDefaultPlcConsumerRegistration_GetSubscriptionHandles(t *testing.T) {
+	type fields struct {
+		consumerId    int
+		consumer      apiModel.PlcSubscriptionEventConsumer
+		plcSubscriber spi.PlcSubscriber
+		handles       []apiModel.PlcSubscriptionHandle
+	}
+	tests := []struct {
+		name   string
+		fields fields
+		want   []apiModel.PlcSubscriptionHandle
+	}{
+		{
+			name: "get it",
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			d := &DefaultPlcConsumerRegistration{
+				consumerId:    tt.fields.consumerId,
+				consumer:      tt.fields.consumer,
+				plcSubscriber: tt.fields.plcSubscriber,
+				handles:       tt.fields.handles,
+			}
+			assert.Equalf(t, tt.want, d.GetSubscriptionHandles(), "GetSubscriptionHandles()")
+		})
+	}
+}
+
+func TestDefaultPlcConsumerRegistration_Unregister(t *testing.T) {
+	type fields struct {
+		consumerId    int
+		consumer      apiModel.PlcSubscriptionEventConsumer
+		plcSubscriber spi.PlcSubscriber
+		handles       []apiModel.PlcSubscriptionHandle
+	}
+	tests := []struct {
+		name   string
+		fields fields
+	}{
+		{
+			name: "unregister it",
+			fields: fields{
+				plcSubscriber: func() spi.PlcSubscriber {
+					subscriber := NewMockPlcSubscriber(t)
+					subscriber.EXPECT().Unregister(mock.Anything).Return()
+					return subscriber
+				}(),
+			},
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			d := &DefaultPlcConsumerRegistration{
+				consumerId:    tt.fields.consumerId,
+				consumer:      tt.fields.consumer,
+				plcSubscriber: tt.fields.plcSubscriber,
+				handles:       tt.fields.handles,
+			}
+			d.Unregister()
+		})
+	}
+}
+
+func TestNewDefaultPlcConsumerRegistration(t *testing.T) {
+	type args struct {
+		plcSubscriber spi.PlcSubscriber
+		consumer      apiModel.PlcSubscriptionEventConsumer
+		handles       []apiModel.PlcSubscriptionHandle
+	}
+	tests := []struct {
+		name string
+		args args
+		want apiModel.PlcConsumerRegistration
+	}{
+		{
+			name: "create it",
+			want: &DefaultPlcConsumerRegistration{},
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			got := NewDefaultPlcConsumerRegistration(tt.args.plcSubscriber, tt.args.consumer, tt.args.handles...).(*DefaultPlcConsumerRegistration)
+			tt.want.(*DefaultPlcConsumerRegistration).consumerId = got.consumerId
+			assert.Equalf(t, tt.want, got, "NewDefaultPlcConsumerRegistration(%v, func(), %v)", tt.args.plcSubscriber, tt.args.handles)
+		})
+	}
+}