github.com/enbility/spine-go@v0.7.0/model/deviceconfiguration_additions_test.go (about)

     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 TestDeviceConfigurationKeyValueListDataType_Update(t *testing.T) {
    11  	sut := DeviceConfigurationKeyValueListDataType{
    12  		DeviceConfigurationKeyValueData: []DeviceConfigurationKeyValueDataType{
    13  			{
    14  				KeyId: util.Ptr(DeviceConfigurationKeyIdType(0)),
    15  				Value: &DeviceConfigurationKeyValueValueType{
    16  					Boolean: util.Ptr(true),
    17  				},
    18  			},
    19  			{
    20  				KeyId:             util.Ptr(DeviceConfigurationKeyIdType(1)),
    21  				IsValueChangeable: util.Ptr(true),
    22  				Value: &DeviceConfigurationKeyValueValueType{
    23  					Boolean: util.Ptr(true),
    24  				},
    25  			},
    26  		},
    27  	}
    28  
    29  	newData := DeviceConfigurationKeyValueListDataType{
    30  		DeviceConfigurationKeyValueData: []DeviceConfigurationKeyValueDataType{
    31  			{
    32  				KeyId: util.Ptr(DeviceConfigurationKeyIdType(1)),
    33  				Value: &DeviceConfigurationKeyValueValueType{
    34  					Boolean: util.Ptr(false),
    35  				},
    36  			},
    37  		},
    38  	}
    39  
    40  	// Act
    41  	_, success := sut.UpdateList(false, true, &newData, NewFilterTypePartial(), nil)
    42  	assert.True(t, success)
    43  
    44  	data := sut.DeviceConfigurationKeyValueData
    45  	// check the non changing items
    46  	assert.Equal(t, 2, len(data))
    47  	item1 := data[0]
    48  	assert.Equal(t, 0, int(*item1.KeyId))
    49  	assert.True(t, *item1.Value.Boolean)
    50  	// check properties of updated item
    51  	item2 := data[1]
    52  	assert.Equal(t, 1, int(*item2.KeyId))
    53  	assert.False(t, *item2.Value.Boolean)
    54  }
    55  
    56  func TestDeviceConfigurationKeyValueDescriptionListDataType_Update(t *testing.T) {
    57  	sut := DeviceConfigurationKeyValueDescriptionListDataType{
    58  		DeviceConfigurationKeyValueDescriptionData: []DeviceConfigurationKeyValueDescriptionDataType{
    59  			{
    60  				KeyId:     util.Ptr(DeviceConfigurationKeyIdType(0)),
    61  				ValueType: util.Ptr(DeviceConfigurationKeyValueTypeTypeBoolean),
    62  			},
    63  			{
    64  				KeyId:     util.Ptr(DeviceConfigurationKeyIdType(1)),
    65  				ValueType: util.Ptr(DeviceConfigurationKeyValueTypeTypeBoolean),
    66  			},
    67  		},
    68  	}
    69  
    70  	newData := DeviceConfigurationKeyValueDescriptionListDataType{
    71  		DeviceConfigurationKeyValueDescriptionData: []DeviceConfigurationKeyValueDescriptionDataType{
    72  			{
    73  				KeyId:     util.Ptr(DeviceConfigurationKeyIdType(1)),
    74  				ValueType: util.Ptr(DeviceConfigurationKeyValueTypeTypeString),
    75  			},
    76  		},
    77  	}
    78  
    79  	// Act
    80  	_, success := sut.UpdateList(false, true, &newData, NewFilterTypePartial(), nil)
    81  	assert.True(t, success)
    82  
    83  	data := sut.DeviceConfigurationKeyValueDescriptionData
    84  	// check the non changing items
    85  	assert.Equal(t, 2, len(data))
    86  	item1 := data[0]
    87  	assert.Equal(t, 0, int(*item1.KeyId))
    88  	assert.Equal(t, DeviceConfigurationKeyValueTypeTypeBoolean, *item1.ValueType)
    89  	// check properties of updated item
    90  	item2 := data[1]
    91  	assert.Equal(t, 1, int(*item2.KeyId))
    92  	assert.Equal(t, DeviceConfigurationKeyValueTypeTypeString, *item2.ValueType)
    93  }
    94  
    95  func TestDeviceConfigurationKeyValueConstraintsListDataType_Update(t *testing.T) {
    96  	sut := DeviceConfigurationKeyValueConstraintsListDataType{
    97  		DeviceConfigurationKeyValueConstraintsData: []DeviceConfigurationKeyValueConstraintsDataType{
    98  			{
    99  				KeyId: util.Ptr(DeviceConfigurationKeyIdType(0)),
   100  				ValueStepSize: &DeviceConfigurationKeyValueValueType{
   101  					Boolean: util.Ptr(true),
   102  				},
   103  			},
   104  			{
   105  				KeyId: util.Ptr(DeviceConfigurationKeyIdType(1)),
   106  				ValueStepSize: &DeviceConfigurationKeyValueValueType{
   107  					Boolean: util.Ptr(true),
   108  				},
   109  			},
   110  		},
   111  	}
   112  
   113  	newData := DeviceConfigurationKeyValueConstraintsListDataType{
   114  		DeviceConfigurationKeyValueConstraintsData: []DeviceConfigurationKeyValueConstraintsDataType{
   115  			{
   116  				KeyId: util.Ptr(DeviceConfigurationKeyIdType(1)),
   117  				ValueStepSize: &DeviceConfigurationKeyValueValueType{
   118  					Boolean: util.Ptr(false),
   119  				},
   120  			},
   121  		},
   122  	}
   123  
   124  	// Act
   125  	_, success := sut.UpdateList(false, true, &newData, NewFilterTypePartial(), nil)
   126  	assert.True(t, success)
   127  
   128  	data := sut.DeviceConfigurationKeyValueConstraintsData
   129  	// check the non changing items
   130  	assert.Equal(t, 2, len(data))
   131  	item1 := data[0]
   132  	assert.Equal(t, 0, int(*item1.KeyId))
   133  	assert.Equal(t, true, *item1.ValueStepSize.Boolean)
   134  	// check properties of updated item
   135  	item2 := data[1]
   136  	assert.Equal(t, 1, int(*item2.KeyId))
   137  	assert.Equal(t, false, *item2.ValueStepSize.Boolean)
   138  }