Search for answers or browse our knowledge base.
Testing the Source Tutorial
0 out of 5 stars
5 Stars | 0% | |
4 Stars | 0% | |
3 Stars | 0% | |
2 Stars | 0% | |
1 Stars | 0% |
Prerequisites
This tutorial assumes you have completed the entirety of the Source Tutorial.
Please complete the tutorial if you have not done so already, then return to this page to learn how to test it.
Testing Sources Rules
We will now create a Unit Test to ensure that our Rule always works as we expect. A Unit Test is preferable to an Integration Test for this case because we are only testing the functionality of a single Rule rather than of a whole Project or App.
A Vantiq Test is driven by a sequence of ordered input events and expects a collection of output events. We want to create a Test that
- creates a Source event from the Weather Source as an input and
- expects an UPDATE on the
weatherReading
Type as an output.
Navigate to the weatherReading
Rule and click the Create Test button.
Set the name of the test to weatherReading0
.
Click on the pencil button to edit the Event Object. The event object is the message that will arrive from the Source to trigger the Rule during the Test run.
The following JSON Object is a sample event received from the weather
Source. It was captured and copied during step 2 of the Source Tutorial using the Test Data Receipt feature. It is important for the Test data to resemble real data as closely as possible, to accurately test the system under the correct conditions.
Copy and paste the following Source message into the JSON editor and then click OK.
{
"coord": {
"lon": -122.12,
"lat": 37.89
},
"weather": [
{
"id": 800,
"main": "Clear",
"description": "clear sky",
"icon": "01d"
}
],
"base": "stations",
"main": {
"temp": 294.78,
"feels_like": 290.57,
"temp_min": 292.59,
"temp_max": 297.15,
"pressure": 1023,
"humidity": 23
},
"visibility": 16093,
"wind": {
"speed": 3.1,
"deg": 80
},
"clouds": {
"all": 1
},
"dt": 1582680753,
"sys": {
"type": 1,
"id": 3581,
"country": "US",
"sunrise": 1582641979,
"sunset": 1582682233
},
"timezone": -28800,
"id": 5364226,
"name": "My Address",
"cod": 200
}
A new Test pane opens with all of the General properties on the test already set.
Navigate to the Inputs tab and verify that there is one input in the Inputs list.
The Test expects one output: The UPDATE to the weatherReading
Type performed by the Rule.
To accomplish this, navigate to the Outputs tab and click the Add Output Button.
The weather
Rule performs an UPDATE on the weatherReading with the matching location.
It is assumed that the Test pre-populates the Namespace with an instance of weatherReading to be UPDATED. We will include this later using a Setup Procedure. The existing instance includes the zipCode and location properties. The Rule updates the instance to include the tempK property.
Set types as the Resource, weatherReading as the ResourceId and UPDATE as the Operation.
Click on the Click to Edit button to open the Expected Object Editor and create a JSON Object with the following contents:
{
"location": "My Address",
"tempK": 294.78,
"zipCode": "94609"
}
Click OK to close the Event Object Editor, then OK again to save exit the Edit Output popup.
Because one of the Test outputs is an expected UPDATE event, it is implied that there will already be an existing instance of the weatherReading
Type to be UPDATED. The Test therefore requires Setup and Cleanup Procedures.
Use the Add button in the IDE Navigation Bar, hover over Advanced, and select Procedures. Click the New Procedure button to create a new Procedure.
Name the Procedure createWeatherData
. This Procedure is the Test Setup Procedure. The Procedure sets the weather
Source into Mock Mode and
INSERTS the necessary instance of the weatherReading
Type.
To learn more about Source Mock Mode, reference the Testing Reference Guide.
Copy and paste the following into the new Procedure Pane:
PROCEDURE createWeatherData()
Test.startSourceMocking("weather", null, null)
INSERT weatherReading(location:"My Address", zipCode:"94609")
Click Save to save the Procedure.
Add a second procedure, and name it deleteWeatherData
. This Procedure is the Cleanup Procedure. The Procedure turns off Mock Mode on the weather
Source and DELETES the created instance of the weatherReading
Type.
Copy and paste the following into the new Procedure Pane:
PROCEDURE deleteWeatherData()
DELETE weatherReading WHERE zipCode == "94609"
Test.stopSourceMocking("weather")
Click Save to save the Procedure.
Navigate back to the Test pane in which we were defining the weatherReading0
test and click on the General tab.
Select createWeatherData as the Setup Procedure and deleteWeatherData as the Cleanup Procedure. Save the Test.
Navigate back to the weatherReading
Rule. Select the new test weatherReading0
from the Execute droplist and then click Run.
Navigate back to the Test pane for weatherReading0
and click Show Test History.
Expect one entry with a green check showing that the test run was a success.
Adding Source Query Mocking
You can also use a Procedure to supply test data for the Source when running the test. This is called mocking the Source.
In this section, we will add a Procedure querySourceAndInsert
that uses our Source, and then add a Procedure to supply mock data for that source, which will be used in testing the querySourceAndInsert
Procedure.
First, let’s create the Procedure querySourceAndInsert
.
Click the Add button, hover over Advanced, and click Procedure… Click the New Procedure button to create a new Procedure.
The querySourceAndInsert
Procedure queries the weather
Source and then INSERTS an instance of the weatherReading
Type.
We will use this Procedure in our Test to show Mocking a query to a Source.
Copy and paste the following into the new Procedure Pane:
PROCEDURE querySourceAndInsert()
var weatherReading = SELECT FROM SOURCE weather
weatherReading = weatherReading[0]
INSERT weatherReading(tempK:weatherReading.main.temp, location: weatherReading.name, zipCode = "94609")
Click Save to save the Procedure.
Now let’s create our Mocking Procedure. Click the Add button, hover over Advanced, and click Procedure… Click the New Procedure button to create a new Procedure.
The queryProcedureOverride
Procedure mocks the weather
Source’s query functionality by always returning the same object.
Procedure queryProcedureOverride(queryDesc)
return {
"coord": {
"lon": -122.12,
"lat": 37.89
},
"weather": [
{
"id": 800,
"main": "Clear",
"description": "clear sky",
"icon": "01d"
}
],
"base": "stations",
"main": {
"temp": 75,
"feels_like": 290.57,
"temp_min": 292.59,
"temp_max": 297.15,
"pressure": 1023,
"humidity": 23
},
"visibility": 16093,
"wind": {
"speed": 3.1,
"deg": 80
},
"clouds": {
"all": 1
},
"dt": 1582680753,
"sys": {
"type": 1,
"id": 3581,
"country": "US",
"sunrise": 1582641979,
"sunset": 1582682233
},
"timezone": -28800,
"id": 5364226,
"name": "Walnut Creek",
"cod": 200
}
Click Save to save the Procedure.
Navigate back to the createWeatherData
Procedure and update the Test.startSourceMocking
Procedure to set the Query
Mock Procedure to the new Procedure we just created.
PROCEDURE createWeatherData()
Test.startSourceMocking("weather", "queryProcedureOverride", null)
INSERT weatherReading(location:"My Address", zipCode:"94609")
Click Save to save the Procedure.
Navigate back to the querySourceAndInsert
Procedure. Click the Create Test button. Confirm by clicking Create Unit Test
then type querySourceAndInsert0 as the test name and click OK.
A new Test called querySourceAndInsert0
opens.
Navigate to the Inputs tab and you will see this test has a single input, running the querySourceAndInsert
Procedure.
Right click this input and click Edit.
In the test input, an expected Return Value is automatically generated. This is normally quite helpful, but in this case we want to override the return value with the mock data we created in the queryProcedureOverride
Procedure. Therefore, open the Expected Return Value editor by clicking the Click to Edit button, and delete the contents of the editor. This will cause the test to ignore the return value of the Procedure. Close Event Object Editor by clicking OK, then exit the Edit Test Input popup by clicking OK.
Click on the Outputs tab. Click the Add Output Button.
For the output, set types as the Resource, weatherReading as the ResourceId and INSERT as the Operation. This captures the INSERT produced by the querySourceAndInsert Procedure.
Click on the Click to Edit button to open the Expected Object Editor and create a JSON Object with the following contents:
{
"location": "Walnut Creek",
"tempK": 75,
"zipCode": "94609"
}
Click OK to close the Event Object Editor.
Navigate to the General Tab. Select createWeatherData as the Setup Procedure and deleteWeatherData as the Cleanup Procedure. Save the
Test.
Navigate back to the querySourceAndInsert
Procedure. Select the new test querySourceAndInsert0
from the Execute droplist and then click Run.
Navigate back to the Test pane for querySourceAndInsert0
and click Show Test History
.
Expect one entry with a green check showing that the test run was a success.
Conclusion
After successfully navigating through this tutorial, the user should be familiar with:
- Creating Unit Tests for Rules and Procedures
- Running Unit Tests from the Rule/Procedure Pane
- Setting a Source to Mock Mode and overriding Source behavior with Mock Procedures
0 out of 5 stars
5 Stars | 0% | |
4 Stars | 0% | |
3 Stars | 0% | |
2 Stars | 0% | |
1 Stars | 0% |
-
Getting Started
-
- Advanced Collaborations
- Analytics
- App Components
- Assemblies
- Catalogs Tutorial
- Client Builder
- Client Components
- Deployment Tutorial
- Floor Plan
- Introduction to Collaboration
- Natural Language Tutorial
- Sources
- Stateful Services
- System Modeler
- Testing the Debugging Tutorial
- Testing the Introductory Tutorial
- Testing the Source Tutorial
- User and Namespace Administration
- Show Remaining Articles ( 3 ) Collapse Articles
-
Product Documentation
-
-
-
- Accessing Documents
- Automatic Document Caching
- Client Resources
- Client Startup
- Control Widgets in the "Views" Portion of Client Builder
- Controllers
- Creating A Client
- Data Objects
- Data Stream Widgets in the “Views” Portion of Client Builder
- Data Streams
- Debugging
- Field Validation
- Introduction
- Launching Clients from a browser
- Layout Widgets in the “Views” Portion of Client Builder
- Localizing Clients
- Navigation Between Pages
- Offline Operation
- On Start Events
- Public Clients
- Server Requests
- Terminating The Client
- The Client Builder Concepts
- The Client Builder's Canvas Section
- The Client Builder's Control Dock
- The Client Builder's Palette Area
- The Client Builder's Slideout Section
- Uploading data to the Server
- Show Remaining Articles ( 13 ) Collapse Articles
-
- abort()
- cancelSpeaking()
- clearInterval()
- clearTimeout()
- clone()
- closePopup()
- confirmCustom()
- confirmCustomEx()
- createClientEventDataStream()
- createDataChangedDataStream()
- createOutboundServiceEventDataStream()
- createPagedQueryDataStream()
- createPublishEventDataStream()
- createResourceEventDataStream()
- createResponseObject()
- createSourceEventDataStream()
- createTimedQueryDataStream()
- data
- deleteOne()
- errorDialog()
- execute()
- executePublic()
- executeStreamed()
- executeStreamedPublic()
- formatMsg()
- generateUUID()
- getCollaborationContext()
- getCurrentPage()
- getCurrentPopup()
- getDataStreamByName()
- getDataStreamByUUID()
- getDeviceId()
- getDeviceName()
- getDocumentAssetLabelList()
- getDocumentAssetList()
- getDocumentUrl()
- getGroupNames()
- getLocation()
- getName()
- getProfileNames()
- getRequestParameters()
- getStateObject()
- getUsername()
- getUserRecord()
- getWidget()
- goToPage()
- infoDialog()
- insert()
- instance
- isNetworkActive
- isPublic
- localeCountryCode
- localeLanguageCode
- localeVariantCode
- logout()
- markupImage()
- modifyClientEvent()
- modifyDataChanged()
- modifyPagedQuery()
- modifyPublishEvent()
- modifyResourceEvent()
- modifyServiceEvent()
- modifySourceEvent()
- modifyTimedQuery()
- navBarBackgroundColor
- navBarForegroundColor
- navBarIcon
- navBarIconHeight
- navBarIconWidth
- navBarShowControls
- navBarTitle
- navBarTitleFontFamily
- navBarTitleFontSize
- navBarTitleFontWeight
- Show Remaining Articles ( 59 ) Collapse Articles
-
-
-
- Accessing Namespaces in the Organization
- Active Resource Control Center
- Adding a New User to an Organization
- Adding a New User to the Application Namespace
- Administrators' Concepts and Terminology
- Authorizing Users to Access the Application
- Creating a Developer Namespace for the Organization Administrator
- Creating a New Application Namespace
- Creating Resources for New Namespaces
- Custom User Invites
- Deploying the GenAI Flow Service Connector
- Developer Tasks
- Handling Administrators Leaving
- Related Configuration
- Removing Namespace Administrators
- Self-Administration Tasks
- System Administration Tasks
- Viewing Lists of Users
- Show Remaining Articles ( 3 ) Collapse Articles
-
- Deploy Results Tab
- Deploying the same application to different environments
- Deployment
- Deployment Tool - Introduction
- Environment
- Environment Tab
- Node
- Project Partitions
- Redeploy On A Failed Node
- Reliable Deployment
- Settings Tab
- The Graph View
- The Tree View
- Undeploy
- Update Partitions
- Verify Application After Deployment
- Show Remaining Articles ( 1 ) Collapse Articles
-
- CheckedInsert/CheckedUpsert Command
- Command Line Options
- Delete Command
- Execute Command
- Export Command
- Find Command
- Help Command
- Import Command
- Insert Command
- Installation - Prerequisites
- Installation - Profile
- List Command
- Load Command
- Recommend Command
- Run Command
- Select Command
- Stop Command
- The Vantiq Command Line Interface (CLI) - Overview
- Upsert Command
- Show Remaining Articles ( 4 ) Collapse Articles
-
- App Execution Dashboard
- App With Split Dashboard
- Dashboard Navigation Bar
- Deprecated Dashboards
- Event Processing Dashboard
- General Dashboard Behavior
- Getting Started with Grafana
- Grafana Usage
- Monitoring Namespaces with Grafana
- Most Commonly Used Dashboards
- Namespace Monitoring Dashboards
- Organization Level Behavior
- Procedure and Rule Execution Dashboards
- Profiling Dashboards
- Reliable Event Dashboard
- Resource Usage Dashboard
- Service Execution Dashboard
- Service Handler Dashboard
- Source Activity Dashboard
- Storage Manager Dashboard
- Tensorflow Model Dashboard
- Type Storage Dashboard
- Show Remaining Articles ( 7 ) Collapse Articles
-
- Access to a Kubernetes Cluster
- Creating a K8s Cluster
- Delayed Processing
- Deploying K8s Installations to a Kubernetes Cluster
- Deploying the K8s Worker
- External Lifecycle Management Guide - Overview
- K8s Worker
- Kubernetes Components of a K8s Installation
- Kubernetes Namespaces
- Loading Images into a Kubernetes Cluster
- Managing K8s Installations
- Other Configuration Options
- System View
- Use of the self Cluster
- Using a Kubernetes Cluster
- Using Templates to Deploy the K8s Worker
- Vantiq Namespaces
- Verify Installation
- Show Remaining Articles ( 3 ) Collapse Articles
-
- Changing the System Password
- Creating a GenAIFlowService Service Connector
- Creating a New Organization and Namespace
- Deployment Methods
- Docker Deployment
- Edge Installation Management
- Edge Vision Server
- Executable JAR Deployment
- MongoDB
- Requirements
- Running the Vantiq Executable
- Setting the default LLMs API key
- Setting Up Vantiq Edge
- Vantiq Edge Reference Guide - Overview
- Vantiq Edge Self Node
- Windows bat file
- Show Remaining Articles ( 1 ) Collapse Articles
-
- Additional Buffer Semantics
- Applicability
- auditFrequency Quota
- Background
- Default Quotas
- Detailed Credit Quotas
- errorBreaker Quota
- errorReportingFrequency Quota
- Execution Credit Quota
- Execution Credit Quota - Diagnostics
- Execution Credit Quota - Mitigation
- Execution Rate Quota
- Execution Rate Quota - Diagnostics
- Execution Rate Quota - Mitigations
- executionTime Quota
- k8sResources Quota
- Quota Interactions
- receiveMessage Quota
- receiveMessage Quota - Diagnostics
- receiveMessage Quota - Mitigation
- reservedGroups Quota
- stackDepth Quota
- Stream Quota
- Terminology
- Workload Management
- Workload Management Conceptual Model
- Show Remaining Articles ( 11 ) Collapse Articles
-
-
-
- Accumulate State
- Analytics
- Answer Question
- App Activity Tasks
- App Builder Guide - Introduction
- App Builder Overview
- Assign
- Build and Predict Path
- Cached Enrich
- Chat
- Close Collaboration
- Collaborations in Apps
- Compute Statistics
- Convert Coordinates
- Creating an App
- DBScan
- Delay
- Dependency Management
- Dwell
- Enrich
- Error Handling
- Escalate
- EscalateState
- Establish Collaboration
- Event Redelivery
- Event Stream
- Filter
- GenAI Flow
- Get Collaboration
- Interpret Conversational Language
- Join
- K-Means Cluster
- Limit
- Linear Regression
- Log Stream
- Loop While
- Merge
- Notify
- Optional Imports
- Polynomial Fitter
- Predict Paths By Age
- Procedure
- Process Intent
- PublishToService
- PublishToSource
- PublishToTopic
- Rate
- Recommend
- RecordEvent
- Reliable Apps
- Run TensorFlow Model On Document
- Run TensorFlow Model On Image
- Run TensorFlow Model On Tensors
- Sample
- SaveToType
- Split By Group
- Submit Prompt
- Threshold
- Time Difference
- Track
- Track Motion
- Tracking Progress
- Transformation
- Unwind
- VAIL
- VisionScript
- Window
- Within Tracking Region
- YOLO From Images
- Show Remaining Articles ( 54 ) Collapse Articles
-
-
-
- Broker Service
- Catalog Operations
- Catalog Procedures
- Connect to Catalog
- Create Entry
- Create Entry
- Custom Operations
- Disconnect from Catalog
- Host Catalog
- Integrating Applications With the Catalog
- Managing Catalog
- Managing Event Types
- Publisher Service
- Register
- Remove Entry
- Repair Catalog
- Resolve
- Subscriber Service
- Unhost Catalog
- Unregister
- Utilities
- Show Remaining Articles ( 6 ) Collapse Articles
-
-
-
- Advanced Use Cases
- Data Manipulation
- Defining Types
- Discovery from External Data Store
- Error Handling
- Installation and Use
- Native Language Implementation
- Restricting Capabilities
- Service Connectors
- Storage Manager Assembly Contents
- Storage Manager Service API
- Storage Manager Transactions
- Storage Managers - Introduction
- Transaction Support
-
-
-
- App Pane
- Autopsies
- Defining a Run Policy
- Defining a Test Suite - Properties
- Defining an Input
- Defining an Output
- Error Pane
- Integration Tests
- Populate Testing Namespace With Data
- Procedure Pane
- Rule Pane
- Running a Test in the IDE
- Running a Test through the REST Interface
- Source Mocking For Tests
- Unit Tests
- Vantiq Testing Reference Guide - Introduction
- Show Remaining Articles ( 1 ) Collapse Articles
-
-
-
- Assign
- Branch
- Categorize
- CodeBlock
- Consensus
- Content Ingestion Flows
- Conversation
- GenAI Builder Guide Introduction
- GenAI Builder Layout
- GenAI Components
- GenAI Flow Properties
- GenAI Flow Tracing and Auditing
- Launching the GenAI Builder
- LLM
- Memory and Conversations
- Merging Task Outputs
- NativeLCEL
- Optional
- PromptFromTemplate
- RAG
- Repeat
- Runtime Configuration
- Semantic Index
- Sub-Flows
- Supported VAIL Language Features
- Using GenAI Components
- Vantiq Provided GenAI Components
- Show Remaining Articles ( 12 ) Collapse Articles
-
- AWS
- Azure OpenAI
- Bedrock
- Configuration
- Function Authorizer
- Gemini
- LLM Playground
- Main Chatting Area
- Navigation Panel
- NVIDIA NIM
- OpenAI
- SageMaker
- Settings Panel
- Testing Semantic Index
- Tool Authorizer
- Tools
- Show Remaining Articles ( 1 ) Collapse Articles
-
-
-
-
- Assembly Configs
- Audits
- Catalog Members
- Catalogs
- Debug Configs
- Delegated Requests
- Documents
- Event Generators
- Groups
- Images
- K8s Clusters
- K8s Installations
- K8s Workitems
- LLMs
- Logs
- Namespaces
- Nodes
- Organizations
- Procedures
- Profiles
- Projects
- Resource Definition
- Resource Events
- Resource Relationship Model
- Resource Security Model
- Rules
- Scheduled Events
- Secrets
- Semantic Indexes
- Service Connectors
- Services
- Sources
- StorageManagers
- TensorFlowModels
- Test Reports
- Test Suites
- Tests
- Tokens
- Topics
- TrackingRegions
- Types
- Users
- Vantiq Resources
- Videos
- Show Remaining Articles ( 29 ) Collapse Articles
-
- Before Rules
- Built-In Services
- Data Manipulation
- Data Model Declarations
- Declaring Packages
- Defining Remote Connections
- Distributed Processing
- Error Handling
- Event Sending
- External State
- Flow Control
- General Use Procedures
- In-Memory State Management
- Iteration
- Logging
- Operators
- Package Scoping and Name Resolution
- Packages
- Packages
- Persistent State
- Procedure Execution
- Procedures
- PROCESSED BY Clause
- Resource Definition
- RETURN
- Rules
- Services
- Syntax
- Type Specific Procedures
- VAIL Declarations
- VAIL Types
- Variables
- Show Remaining Articles ( 17 ) Collapse Articles
-
-
-
Articles
-
- How To Video Shorts: Client Layouts
- How To Video Shorts: AI Functions
- How To Video Shorts: Analytics and ComputeStatistics
- How To Video Shorts: Calling Procedures by Properties
- How To Video Shorts: Client CSS
- How To Video Shorts: Invite Other Users to Your Namespace
- How To Video Shorts: SplitByGroup
- How To Video Shorts: The Vantiq API
- How To Video Shorts: The Vantiq IDE
- How To Video Shorts: The Vantiq Version Control System
- How To Video Shorts: Using Generative AI in Applications
- How-To Video Shorts: Managing AI Conversations
- How-To Videos: AI Design Model Assistant
- How-To Videos: AI Documentation Search
- Production Applications Best Practices