Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zhongl/websockit
Provide stub and driver for testing WebSocket application
https://github.com/zhongl/websockit
Last synced: 3 days ago
JSON representation
Provide stub and driver for testing WebSocket application
- Host: GitHub
- URL: https://github.com/zhongl/websockit
- Owner: zhongl
- License: apache-2.0
- Created: 2013-07-17T09:48:31.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2013-09-28T06:31:50.000Z (about 11 years ago)
- Last Synced: 2024-11-05T10:57:29.346Z (about 2 months ago)
- Language: Scala
- Size: 723 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
**websockit** provide stub and driver for testing [WebSocket](http://www.websocket.org) applicaiton.
## Install
### Install
- install [SBT](http://www.scala-sbt.org/release/docs/Getting-Started/Setup.html)
- clone [websockit](https://github.com/zhongl/websocket-kit)
```
> git clone [email protected]:zhongl/websockit.git
```## Usage
- start websockit server
```
> cd websockit
> sbt run
```- start websockit server at special port
```
> sbt "run 12306"
```- `ws://localhost:12306/websocket` should be the url for your application to connect.
- use workbench page, click
- left-top panel can update mock rules, press `Cmd|Ctrl + Enter` to submit
- left-bottom panel can drive a message to your websocket client, press `Cmd|Ctrl + Enter` to submit
- right panel is a console, which could display all the operation logs.![websockit-workbench](websockit.png)
## Mock Rule Syntax
Suppose your application use [JSON](http://json.org) string base on [WebSocket](http://www.websocket.org).
An mock rule contains `filter` and `result`, with `>>` in the middle, like:
```
($".to" =~ "allen" || $".seq" > 25) >> json"""{"code":200, "seq":${ $".seq" }}"""
```it means, `{"to":"allen", "seq":26}` was sent to websockit, and then `{"code":200, "seq":26}` would return from websockit.
### [JSONPath](http://goessner.net/articles/JsonPath/)
```scala
// {"name":"websockit"}$".name" // return "websockit"
```### Equal
```scala
// {"name":"websockit", "age": 1}$".name" =~ "websockit" // return true
$".age" =~ 1 // return true
```### Regex
```scala
// {"name":"websockit"}$".name" =* "\\w+" // return true
$".name" =* """\w+""" // same as above
```### Great and Less
```scala
// {"age":"18"}$".age" > 17 // return true
$".age" < 19 // return true
```### `||` and `&&`
```scala
// {"name":"websockit", "age": 1}$".name" =~ "websockit" && $".age" > 0 // return true
```### JSON result with variables
```scala
json"""{"code":200, "seq":${ $".seq" }}""" // ${ $".seq" } get `seq` value of the input json
```## Copyright and license
Copyright 2013 zhongl
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 athttp://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.