dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts@v1.0.2/clients/http/deviceservicecallback_test.go (about)

     1  //
     2  // Copyright (C) 2020-2022 IOTech Ltd
     3  // Copyright (C) 2023 Intel Corporation
     4  //
     5  // SPDX-License-Identifier: Apache-2.0
     6  
     7  package http
     8  
     9  import (
    10  	"context"
    11  	"net/http"
    12  	"path"
    13  	"testing"
    14  
    15  	"dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts/common"
    16  	dtoCommon "dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts/dtos/common"
    17  	"dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts/dtos/requests"
    18  
    19  	"github.com/google/uuid"
    20  	"github.com/stretchr/testify/assert"
    21  	"github.com/stretchr/testify/require"
    22  )
    23  
    24  func TestAddDeviceCallback(t *testing.T) {
    25  	requestId := uuid.New().String()
    26  	expectedResponse := dtoCommon.NewBaseResponse(requestId, "", http.StatusOK)
    27  	ts := newTestServer(http.MethodPost, common.ApiDeviceCallbackRoute, expectedResponse)
    28  	defer ts.Close()
    29  
    30  	client := NewDeviceServiceCallbackClient(ts.URL, NewNullAuthenticationInjector(), false)
    31  	res, err := client.AddDeviceCallback(context.Background(), requests.AddDeviceRequest{})
    32  
    33  	require.NoError(t, err)
    34  	assert.Equal(t, requestId, res.RequestId)
    35  }
    36  
    37  func TestValidateDeviceCallback(t *testing.T) {
    38  	requestId := uuid.New().String()
    39  	expectedResponse := dtoCommon.NewBaseResponse(requestId, "", http.StatusOK)
    40  	ts := newTestServer(http.MethodPost, common.ApiDeviceValidationRoute, expectedResponse)
    41  	defer ts.Close()
    42  
    43  	client := NewDeviceServiceCallbackClient(ts.URL, NewNullAuthenticationInjector(), false)
    44  	res, err := client.ValidateDeviceCallback(context.Background(), requests.AddDeviceRequest{})
    45  
    46  	require.NoError(t, err)
    47  	assert.Equal(t, requestId, res.RequestId)
    48  }
    49  
    50  func TestUpdateDeviceCallback(t *testing.T) {
    51  	requestId := uuid.New().String()
    52  	expectedResponse := dtoCommon.NewBaseResponse(requestId, "", http.StatusOK)
    53  	ts := newTestServer(http.MethodPut, common.ApiDeviceCallbackRoute, expectedResponse)
    54  	defer ts.Close()
    55  
    56  	client := NewDeviceServiceCallbackClient(ts.URL, NewNullAuthenticationInjector(), false)
    57  	res, err := client.UpdateDeviceCallback(context.Background(), requests.UpdateDeviceRequest{})
    58  
    59  	require.NoError(t, err)
    60  	assert.Equal(t, requestId, res.RequestId)
    61  }
    62  
    63  func TestDeleteDeviceCallback(t *testing.T) {
    64  	testDeviceName := "testName"
    65  	requestId := uuid.New().String()
    66  	urlPath := path.Join(common.ApiDeviceCallbackRoute, common.Name, testDeviceName)
    67  	expectedResponse := dtoCommon.NewBaseResponse(requestId, "", http.StatusOK)
    68  	ts := newTestServer(http.MethodDelete, urlPath, expectedResponse)
    69  	defer ts.Close()
    70  
    71  	client := NewDeviceServiceCallbackClient(ts.URL, NewNullAuthenticationInjector(), false)
    72  	res, err := client.DeleteDeviceCallback(context.Background(), testDeviceName)
    73  
    74  	require.NoError(t, err)
    75  	assert.Equal(t, requestId, res.RequestId)
    76  }
    77  
    78  func TestUpdateDeviceProfileCallback(t *testing.T) {
    79  	requestId := uuid.New().String()
    80  	expectedResponse := dtoCommon.NewBaseResponse(requestId, "", http.StatusOK)
    81  	ts := newTestServer(http.MethodPut, common.ApiProfileCallbackRoute, expectedResponse)
    82  	defer ts.Close()
    83  
    84  	client := NewDeviceServiceCallbackClient(ts.URL, NewNullAuthenticationInjector(), false)
    85  	res, err := client.UpdateDeviceProfileCallback(context.Background(), requests.DeviceProfileRequest{})
    86  
    87  	require.NoError(t, err)
    88  	assert.Equal(t, requestId, res.RequestId)
    89  }
    90  
    91  func TestAddProvisionWatcherCallback(t *testing.T) {
    92  	requestId := uuid.New().String()
    93  	expectedResponse := dtoCommon.NewBaseResponse(requestId, "", http.StatusOK)
    94  	ts := newTestServer(http.MethodPost, common.ApiWatcherCallbackRoute, expectedResponse)
    95  	defer ts.Close()
    96  
    97  	client := NewDeviceServiceCallbackClient(ts.URL, NewNullAuthenticationInjector(), false)
    98  	res, err := client.AddProvisionWatcherCallback(context.Background(), requests.AddProvisionWatcherRequest{})
    99  
   100  	require.NoError(t, err)
   101  	assert.Equal(t, requestId, res.RequestId)
   102  }
   103  
   104  func TestUpdateProvisionWatcherCallback(t *testing.T) {
   105  	requestId := uuid.New().String()
   106  	expectedResponse := dtoCommon.NewBaseResponse(requestId, "", http.StatusOK)
   107  	ts := newTestServer(http.MethodPut, common.ApiWatcherCallbackRoute, expectedResponse)
   108  	defer ts.Close()
   109  
   110  	client := NewDeviceServiceCallbackClient(ts.URL, NewNullAuthenticationInjector(), false)
   111  	res, err := client.UpdateProvisionWatcherCallback(context.Background(), requests.UpdateProvisionWatcherRequest{})
   112  
   113  	require.NoError(t, err)
   114  	assert.Equal(t, requestId, res.RequestId)
   115  }
   116  
   117  func TestDeleteProvisionWatcherCallback(t *testing.T) {
   118  	testWatcherName := "testName"
   119  	requestId := uuid.New().String()
   120  	urlPath := path.Join(common.ApiWatcherCallbackRoute, common.Name, testWatcherName)
   121  	expectedResponse := dtoCommon.NewBaseResponse(requestId, "", http.StatusOK)
   122  	ts := newTestServer(http.MethodDelete, urlPath, expectedResponse)
   123  	defer ts.Close()
   124  
   125  	client := NewDeviceServiceCallbackClient(ts.URL, NewNullAuthenticationInjector(), false)
   126  	res, err := client.DeleteProvisionWatcherCallback(context.Background(), testWatcherName)
   127  
   128  	require.NoError(t, err)
   129  	assert.Equal(t, requestId, res.RequestId)
   130  }
   131  
   132  func TestUpdateDeviceServiceCallback(t *testing.T) {
   133  	requestId := uuid.New().String()
   134  	expectedResponse := dtoCommon.NewBaseResponse(requestId, "", http.StatusOK)
   135  	ts := newTestServer(http.MethodPut, common.ApiServiceCallbackRoute, expectedResponse)
   136  	defer ts.Close()
   137  
   138  	client := NewDeviceServiceCallbackClient(ts.URL, NewNullAuthenticationInjector(), false)
   139  	res, err := client.UpdateDeviceServiceCallback(context.Background(), requests.UpdateDeviceServiceRequest{})
   140  
   141  	require.NoError(t, err)
   142  	assert.Equal(t, requestId, res.RequestId)
   143  }