Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change scope from testScope to device #630

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
232 changes: 116 additions & 116 deletions device/thunder_ripple_sdk/src/tests/contracts/thunder_browser_pacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,124 +15,124 @@
// SPDX-License-Identifier: Apache-2.0
//

use crate::get_pact_with_params;
use crate::processors::thunder_browser::ThunderBrowserRequestProcessor;
use crate::ripple_sdk::extn::client::extn_processor::ExtnRequestProcessor;
use crate::tests::contracts::contract_utils::*;
use crate::thunder_state::ThunderConnectionState;
use crate::{client::thunder_client_pool::ThunderClientPool, thunder_state::ThunderState};
use pact_consumer::mock_server::StartMockServerAsync;
use ripple_sdk::{
api::device::{
device_browser::{BrowserLaunchParams, BrowserRequest},
device_request::DeviceRequest,
},
async_channel::unbounded,
extn::extn_client_message::{ExtnPayload, ExtnRequest},
serde_json,
};
use serde_json::json;
use std::collections::HashMap;
use std::sync::Arc;
// use crate::get_pact_with_params;
// use crate::processors::thunder_browser::ThunderBrowserRequestProcessor;
// use crate::ripple_sdk::extn::client::extn_processor::ExtnRequestProcessor;
// use crate::tests::contracts::contract_utils::*;
// use crate::thunder_state::ThunderConnectionState;
// use crate::{client::thunder_client_pool::ThunderClientPool, thunder_state::ThunderState};
// use pact_consumer::mock_server::StartMockServerAsync;
// use ripple_sdk::{
// api::device::{
// device_browser::{BrowserLaunchParams, BrowserRequest},
// device_request::DeviceRequest,
// },
// async_channel::unbounded,
// extn::extn_client_message::{ExtnPayload, ExtnRequest},
// serde_json,
// };
// use serde_json::json;
// use std::collections::HashMap;
// use std::sync::Arc;
// #[tokio::test(flavor = "multi_thread")]
// #[cfg_attr(not(feature = "contract_tests"), ignore)]
#[allow(dead_code)]
async fn test_device_launch_html_app() {
let mut pact_builder_async = get_pact_builder_async_obj().await;

let mut params = HashMap::new();
params.insert(
"callsign".into(),
ContractMatcher::MatchType("Html-0".into()),
);
params.insert("type".into(), ContractMatcher::MatchType("HtmlApp".into()));
params.insert(
"uri".into(),
ContractMatcher::MatchRegex(
r"^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?".into(),
"https://google.com".into(),
),
);
params.insert("x".into(), ContractMatcher::MatchNumber(0));
params.insert("y".into(), ContractMatcher::MatchNumber(0));
params.insert("w".into(), ContractMatcher::MatchNumber(1920));
params.insert("h".into(), ContractMatcher::MatchNumber(1080));
params.insert("suspend".into(), ContractMatcher::MatchBool(false));
params.insert("visible".into(), ContractMatcher::MatchBool(true));
params.insert("focused".into(), ContractMatcher::MatchBool(true));

let mut result = HashMap::new();
result.insert(
"launchType".into(),
ContractMatcher::MatchType("activate".into()),
);
result.insert("success".into(), ContractMatcher::MatchBool(true));

pact_builder_async
.synchronous_message_interaction("A request to launch an application", |mut i| async move {
i.contents_from(get_pact_with_params!(
"org.rdk.RDKShell.1.launch",
ContractResult { result },
ContractParams { params }
))
.await;
i.test_name("lanuch_html_application");
i
})
.await;

let mock_server = pact_builder_async
.start_mock_server_async(Some("websockets/transport/websockets"))
.await;

let browser_name = "Html-0";
let uri = "https://google.com";
let _type = "HtmlApp";
let visible = true;
let suspend = false;
let focused = true;
let name = "Html-0";
let x = 0;
let y = 0;
let w = 1920;
let h = 1080;
let start_params = BrowserLaunchParams {
browser_name: browser_name.to_string(),
uri: uri.to_string(),
_type: _type.to_string(),
visible,
suspend,
focused,
name: name.to_string(),
x,
y,
w,
h,
properties: None,
};
let payload = ExtnPayload::Request(ExtnRequest::Device(DeviceRequest::Browser(
BrowserRequest::Start(start_params.clone()),
)));
let msg = get_extn_msg(payload);

let url = url::Url::parse(mock_server.path("/jsonrpc").as_str()).unwrap();
let thunder_client =
ThunderClientPool::start(url, None, Arc::new(ThunderConnectionState::new()), 1)
.await
.unwrap();

let (s, r) = unbounded();
let extn_client = get_extn_client(s.clone(), r.clone());

let state: ThunderState = ThunderState::new(extn_client, thunder_client);

let _ = ThunderBrowserRequestProcessor::process_request(
state,
msg,
BrowserRequest::Start(start_params.clone()),
)
.await;
}
// #[allow(dead_code)]
// async fn test_device_launch_html_app() {
// let mut pact_builder_async = get_pact_builder_async_obj().await;

// let mut params = HashMap::new();
// params.insert(
// "callsign".into(),
// ContractMatcher::MatchType("Html-0".into()),
// );
// params.insert("type".into(), ContractMatcher::MatchType("HtmlApp".into()));
// params.insert(
// "uri".into(),
// ContractMatcher::MatchRegex(
// r"^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?".into(),
// "https://google.com".into(),
// ),
// );
// params.insert("x".into(), ContractMatcher::MatchNumber(0));
// params.insert("y".into(), ContractMatcher::MatchNumber(0));
// params.insert("w".into(), ContractMatcher::MatchNumber(1920));
// params.insert("h".into(), ContractMatcher::MatchNumber(1080));
// params.insert("suspend".into(), ContractMatcher::MatchBool(false));
// params.insert("visible".into(), ContractMatcher::MatchBool(true));
// params.insert("focused".into(), ContractMatcher::MatchBool(true));

// let mut result = HashMap::new();
// result.insert(
// "launchType".into(),
// ContractMatcher::MatchType("activate".into()),
// );
// result.insert("success".into(), ContractMatcher::MatchBool(true));

// pact_builder_async
// .synchronous_message_interaction("A request to launch an application", |mut i| async move {
// i.contents_from(get_pact_with_params!(
// "org.rdk.RDKShell.1.launch",
// ContractResult { result },
// ContractParams { params }
// ))
// .await;
// i.test_name("lanuch_html_application");
// i
// })
// .await;

// let mock_server = pact_builder_async
// .start_mock_server_async(Some("websockets/transport/websockets"))
// .await;

// let browser_name = "Html-0";
// let uri = "https://google.com";
// let _type = "HtmlApp";
// let visible = true;
// let suspend = false;
// let focused = true;
// let name = "Html-0";
// let x = 0;
// let y = 0;
// let w = 1920;
// let h = 1080;
// let start_params = BrowserLaunchParams {
// browser_name: browser_name.to_string(),
// uri: uri.to_string(),
// _type: _type.to_string(),
// visible,
// suspend,
// focused,
// name: name.to_string(),
// x,
// y,
// w,
// h,
// properties: None,
// };
// let payload = ExtnPayload::Request(ExtnRequest::Device(DeviceRequest::Browser(
// BrowserRequest::Start(start_params.clone()),
// )));
// let msg = get_extn_msg(payload);

// let url = url::Url::parse(mock_server.path("/jsonrpc").as_str()).unwrap();
// let thunder_client =
// ThunderClientPool::start(url, None, Arc::new(ThunderConnectionState::new()), 1)
// .await
// .unwrap();

// let (s, r) = unbounded();
// let extn_client = get_extn_client(s.clone(), r.clone());

// let state: ThunderState = ThunderState::new(extn_client, thunder_client);

// let _ = ThunderBrowserRequestProcessor::process_request(
// state,
// msg,
// BrowserRequest::Start(start_params.clone()),
// )
// .await;
// }

// #[tokio::test(flavor = "multi_thread")]
// #[cfg_attr(not(feature = "contract_tests"), ignore)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async fn test_device_set_persistent_value(with_scope: bool) {
.await;

let scope = if with_scope {
"matching(type, 'testScope')"
"matching(type, 'device')"
} else {
"matching(type, '')"
};
Expand Down Expand Up @@ -116,7 +116,7 @@ async fn test_device_set_persistent_value(with_scope: bool) {
};
let mut scope = None;
if with_scope {
scope = Some("testScope".to_string());
scope = Some("device".to_string());
}
let set_params = SetStorageProperty {
namespace: namespace.to_string(),
Expand Down Expand Up @@ -171,15 +171,12 @@ async fn test_device_get_persistent_value(with_scope: bool) {
);
params.insert("key".into(), ContractMatcher::MatchType("testKey".into()));
if with_scope {
params.insert(
"scope".into(),
ContractMatcher::MatchType("testScope".into()),
);
params.insert("scope".into(), ContractMatcher::MatchType("device".into()));
}

let given_statement = format!(
"\"key:{}\", \"namespace:{}\", \"scope:{}\" is retrieved from persistentStore with value \"{}\"",
"testKey", "testNamespace", if with_scope { "testScope" } else { "" }, "testValue1"
"testKey", "testNamespace", if with_scope { "device" } else { "" }, "testValue1"
);

pact_builder_async
Expand Down Expand Up @@ -207,7 +204,7 @@ async fn test_device_get_persistent_value(with_scope: bool) {
let key = "testKey";
let mut scope = None;
if with_scope {
scope = Some("testScope".to_string());
scope = Some("device".to_string());
}
let get_params = GetStorageProperty {
namespace: namespace.to_string(),
Expand Down Expand Up @@ -261,17 +258,14 @@ async fn test_device_delete_persistent_value_by_key(with_scope: bool) {
);
params.insert("key".into(), ContractMatcher::MatchType("testKey".into()));
if with_scope {
params.insert(
"scope".into(),
ContractMatcher::MatchType("testScope".into()),
);
params.insert("scope".into(), ContractMatcher::MatchType("device".into()));
}

let given_statement = format!(
"\"key:{}\", \"namespace:{}\", \"scope:{}\" is deleted from persistentStore",
"testKey",
"testNamespace",
if with_scope { "testScope" } else { "" }
if with_scope { "device" } else { "" }
);

pact_builder_async
Expand Down Expand Up @@ -299,7 +293,7 @@ async fn test_device_delete_persistent_value_by_key(with_scope: bool) {
let key = "testKey";
let mut scope = None;
if with_scope {
scope = Some("testScope".to_string());
scope = Some("device".to_string());
}
let delete_params = DeleteStorageProperty {
namespace: namespace.to_string(),
Expand Down
Loading
Loading