From e71a74bd1958c7c7a94159b663b9174720359bfd Mon Sep 17 00:00:00 2001 From: Agosh Singh Date: Sun, 28 Jul 2024 19:36:37 -0400 Subject: [PATCH] Adding notification sink and src feature --- test_agent/cpp/src/APIWrapper.cpp | 14 +++-- .../steps/tck_step_implementations.py | 8 +++ .../notification_sink_and_source.feature | 52 +++++++++++++++++++ 3 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 test_manager/features/tests/L2_APIs/notification_sink_and_source.feature diff --git a/test_agent/cpp/src/APIWrapper.cpp b/test_agent/cpp/src/APIWrapper.cpp index ceea8796..817b955a 100644 --- a/test_agent/cpp/src/APIWrapper.cpp +++ b/test_agent/cpp/src/APIWrapper.cpp @@ -349,16 +349,19 @@ UStatus APIWrapper::handleSubscriberCommand(Document& jsonData) { UStatus APIWrapper::handleNotificationSourceCommand(Document& jsonData) { Value& data = jsonData[Constants::DATA]; - auto uriSource = def_src_uuri_; - // Build attributes auto attributes = ProtoConverter::distToAttributes( data[Constants::ATTRIBUTES], jsonData.GetAllocator()); + auto uriSource = attributes.source(); auto uriSink = attributes.sink(); auto format = attributes.payload_format(); auto priority = attributes.priority(); - // Build payload + spdlog::debug( + "APIWrapper::handleNotificationSourceCommand(), Source URI: {}, Sink " + "URI: {}", + uriSource.DebugString(), uriSink.DebugString()); + auto payloadValueStr = std::string(data[Constants::PAYLOAD].GetString()); uprotocol::datamodel::builder::Payload payload(payloadValueStr, format); @@ -409,14 +412,15 @@ UStatus APIWrapper::handleNotificationSinkCommand(Document& jsonData) { std::unique_ptr>( uriCallbackMap_, serializedUri)) { status.set_code(UCode::ALREADY_EXISTS); - status.set_message("RPC Server already exists for the given URI."); + status.set_message( + "Notification Sink already exists for the given URI."); return status; } // Create NotificationSink object auto NotificationSinkHandle = uprotocol::communication::NotificationSink::create( - transportPtr_, std::move(uri), std::move(callback), std::nullopt); + transportPtr_, std::move(callback), std::move(uri)); return NotificationSinkHandle.has_value() ? addHandleToUriCallbackMap( diff --git a/test_manager/features/steps/tck_step_implementations.py b/test_manager/features/steps/tck_step_implementations.py index 5d7685cf..f30423c2 100644 --- a/test_manager/features/steps/tck_step_implementations.py +++ b/test_manager/features/steps/tck_step_implementations.py @@ -343,6 +343,14 @@ def set_key_to_bytes(context, key: str, value: str): context.json_dict[key] = "BYTES:" + value +@given('sets "{key}" to entity URI of "{ue}"') +@when('sets "{key}" to entity URI of "{ue}"') +def set_key_to_ue_uri(context: Context, key: str, ue: str): + ue_number = ue.replace("uE", "") + if key not in context.json_dict: + context.json_dict[key] = context.ue_tracker[int(ue_number) - 1][2] + + @given('sends "{command}" request') @when('sends "{command}" request') def send_command_request(context, command: str): diff --git a/test_manager/features/tests/L2_APIs/notification_sink_and_source.feature b/test_manager/features/tests/L2_APIs/notification_sink_and_source.feature new file mode 100644 index 00000000..77cc3e0b --- /dev/null +++ b/test_manager/features/tests/L2_APIs/notification_sink_and_source.feature @@ -0,0 +1,52 @@ +# ------------------------------------------------------------------------- +# +# SPDX-FileCopyrightText: Copyright (c) 2024 Contributors to +# the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# Licensed 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 +# +# http: *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. +# SPDX-FileType: SOURCE +# SPDX-License-Identifier: Apache-2.0 +# +# ------------------------------------------------------------------------- + +Feature: Testing Publish and Subscribe Functionality + + Scenario Outline: To test the rpc server and client apis + Given "uE1" creates data for "notificationsink" + And sets "authority_name" to "me_authority" + And sets "ue_id" to "65538" + And sets "ue_version_major" to "1" + And sets "resource_id" to "32770" + + And sends "notificationsink" request + Then the status received with "code" is "OK" + + When "uE2" creates data for "notificationsource" + And sets "attributes.source.authority_name" to "me_authority" + And sets "attributes.source.ue_id" to "65538" + And sets "attributes.source.ue_version_major" to "1" + And sets "attributes.source.resource_id" to "32770" + And sets "attributes.sink" to entity URI of "uE1" + And sets "attributes.payload_format" to "UPAYLOAD_FORMAT_PROTOBUF_WRAPPED_IN_ANY" + And sets "payload" to b".type.googleapis.com/google.protobuf.Int32Value\x12\x02\x08\x03" + And sends "notificationsource" request + + Then the status received with "code" is "OK" + And "uE1" sends onreceive message with field "payload" as b"type.googleapis.com/google.protobuf.Int32Value\x12\x02\x08\x03" + + Examples: + | ignore | ignore | + | ignore | ignore | \ No newline at end of file