Skip to content

Commit

Permalink
Adding notification sink and src feature
Browse files Browse the repository at this point in the history
  • Loading branch information
agosh01 committed Jul 29, 2024
1 parent e512f05 commit e71a74b
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 5 deletions.
14 changes: 9 additions & 5 deletions test_agent/cpp/src/APIWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -409,14 +412,15 @@ UStatus APIWrapper::handleNotificationSinkCommand(Document& jsonData) {
std::unique_ptr<uprotocol::communication::NotificationSink>>(
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(
Expand Down
8 changes: 8 additions & 0 deletions test_manager/features/steps/tck_step_implementations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -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 |

0 comments on commit e71a74b

Please sign in to comment.