-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Description ## Changes 1. Implements Correlations API in library 2. Implements Correlations API in binary 3. Adds Correlations tests
- Loading branch information
Showing
15 changed files
with
171 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use clap::Subcommand; | ||
use serde::Deserialize; | ||
|
||
use crate::clients::client_factory::ClientFactory; | ||
|
||
#[derive(Clone, Debug, Deserialize, Subcommand)] | ||
#[serde(rename_all = "kebab-case")] | ||
pub enum CorrelationCommands { | ||
/// Gets all Correlations. | ||
GetAll, | ||
/// Gets a single Correlation by ID. | ||
GetById { | ||
/// The ID of the Correlation to retrieve. | ||
id: String, | ||
}, | ||
} | ||
|
||
pub async fn register_commands(client_factory: ClientFactory, cmd: CorrelationCommands) { | ||
let client = client_factory.create_correlation_client(); | ||
match cmd { | ||
CorrelationCommands::GetAll => match client.get_correlations().await { | ||
Ok(correlations) => println!("{:#?}", correlations), | ||
Err(e) => eprintln!("Error getting correlation: {:#?}", e), | ||
}, | ||
CorrelationCommands::GetById { id } => match client.get_correlation_by_id(&id).await { | ||
Ok(correlation) => println!("{:#?}", correlation), | ||
Err(e) => eprintln!("Error getting correlation: {:#?}", e), | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod application_info; | ||
pub mod correlation; | ||
pub mod process_definition; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct CorrelationList { | ||
pub correlations: Vec<Correlation>, | ||
pub total_count: u32, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct Correlation { | ||
#[serde(rename = "correlationId")] | ||
pub id: String, | ||
pub metadata: serde_json::Value, | ||
// TODO: pub process_instances: Vec<ProcessInstance>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use crate::clients::{api::api_client::ApiClient, error::EngineError}; | ||
|
||
use super::correlation::{Correlation, CorrelationList}; | ||
|
||
const CORRELATIONS_ENDPOINT: &str = "/correlations"; | ||
|
||
/// A client for retrieving correlations from the ProcessCube® Engine. | ||
#[derive(Clone)] | ||
pub struct CorrelationClient { | ||
api_client: ApiClient, | ||
pub correlation_url: String, | ||
} | ||
|
||
impl CorrelationClient { | ||
/// Creates a new instance of the CorrelationClient. | ||
/// | ||
/// # Arguments | ||
/// * `api_client` - The ApiClient to use for communication with the ProcessCube® Engine. | ||
/// | ||
/// # Example | ||
/// ``` | ||
/// use processcube_engine_client::clients::{api::api_client::ApiClient, correlation::correlation_client::CorrelationClient, error::EngineError}; | ||
/// const DUMMY_TOKEN: &str = "Bearer ZHVtbXlfdG9rZW4="; | ||
/// const ENGINE_URL: &str = "http://localhost:10560"; | ||
/// // Be sure to have a running ProcessCube® Engine at the given URL | ||
/// | ||
/// #[tokio::main] | ||
/// async fn main() -> Result<(), EngineError> { | ||
/// let api_client = ApiClient::new(ENGINE_URL, DUMMY_TOKEN); | ||
/// let correlation_client = CorrelationClient::new(api_client); | ||
/// // Get all correlations from the ProcessCube® Engine | ||
/// let correlations = correlation_client.get_correlations().await?; | ||
/// println!("Correlations: {:#?}", correlations); | ||
/// Ok(()) | ||
/// } | ||
/// ``` | ||
pub fn new(api_client: ApiClient) -> CorrelationClient { | ||
let correlation_url = format!( | ||
"{}{}{}", | ||
api_client.get_engine_url(), | ||
api_client.get_engine_api_endpoint(), | ||
CORRELATIONS_ENDPOINT | ||
); | ||
CorrelationClient { | ||
api_client, | ||
correlation_url, | ||
} | ||
} | ||
|
||
/// Returns all correlations from the ProcessCube® Engine. | ||
pub async fn get_correlations(&self) -> Result<CorrelationList, EngineError> { | ||
self.api_client | ||
.get::<CorrelationList>(&self.correlation_url) | ||
.await | ||
} | ||
|
||
/// Returns a correlation with the given id from the ProcessCube® Engine. | ||
pub async fn get_correlation_by_id(&self, id: &str) -> Result<Correlation, EngineError> { | ||
let url = format!("{}/{}", self.correlation_url, id); | ||
self.api_client.get::<Correlation>(&url).await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod correlation; | ||
pub mod correlation_client; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
mod get; | ||
mod create; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use processcube_engine_client::clients::client_factory::ClientFactory; | ||
|
||
const DUMMY_TOKEN: &str = "Bearer ZHVtbXlfdG9rZW4="; | ||
const ENGINE_URL: &str = "http://localhost:10560"; | ||
|
||
// Happy cases | ||
|
||
#[tokio::test] | ||
async fn get_correlations() { | ||
let client_factory = ClientFactory::new(ENGINE_URL, DUMMY_TOKEN); | ||
let client = client_factory.create_correlation_client(); | ||
let result = client.get_correlations().await; | ||
assert!(result.is_ok()); | ||
} | ||
|
||
// TODO: Add happy case test for get_correlation_by_id once ProcessInstance is implemented | ||
|
||
// Error cases | ||
|
||
#[tokio::test] | ||
async fn get_correlation_by_id_not_found() { | ||
let client_factory = ClientFactory::new(ENGINE_URL, DUMMY_TOKEN); | ||
let client = client_factory.create_correlation_client(); | ||
let result = client.get_correlation_by_id("dummy").await; | ||
|
||
assert!(result.is_err()); | ||
let error = result.unwrap_err(); | ||
assert_eq!(error.code, 404); | ||
assert_eq!(error.error_type, "NotFoundError"); | ||
assert_eq!(error.message, "Correlation with ID `dummy` not found."); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mod get; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
mod application_info_client_tests; | ||
mod client_factory_tests; | ||
mod correlation_client_tests; | ||
mod fixtures; | ||
mod process_definition_client_tests; |