Skip to content

Commit

Permalink
Merge branch 'master'
Browse files Browse the repository at this point in the history
  • Loading branch information
anhashia committed Mar 23, 2017
2 parents 3fb12fc + 60a3f0b commit a626d1e
Show file tree
Hide file tree
Showing 76 changed files with 6,314 additions and 476 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ Method is representation of a single Direct Method access collection with a Json
*/
public class Method
{
public Method(String name, Long timeout, Object payload) throws IllegalArgumentException;
public Method();
public Method(String name, Long responseTimeout, Long connectTimeout, Object payload) throws IllegalArgumentException;
public Method(Object payload);
public Method(String json) throws IllegalArgumentException;

public synchronized void fromJson(String json) throws IllegalArgumentException;

public Integer getStatus();
public Integer getStatus() throws IllegalArgumentException;
public Object getPayload();

public String toJson();
Expand All @@ -36,6 +38,7 @@ public Method();
```
**SRS_METHOD_21_029: [**The constructor shall create an instance of the method.**]**
**SRS_METHOD_21_030: [**The constructor shall initialize all data in the collection as null.**]**
**SRS_METHOD_21_022: [**The constructor shall initialize the method operation as `none`.**]**

### Method
```java
Expand All @@ -44,70 +47,75 @@ public Method();
* Create a Method instance with provided values.
*
* @param name - method name [required].
* @param timeout - maximum interval of time, in seconds, that the Direct Method will wait for answer.
* @param payload - Object that contains the payload defined by the user.
* @param responseTimeout - maximum interval of time, in seconds, that the Direct Method will wait for answer. It can be {@code null}.
* @param connectTimeout - maximum interval of time, in seconds, that the Direct Method will wait for the connection. It can be {@code null}.
* @param payload - Object that contains the payload defined by the user. It can be {@code null}.
* @throws IllegalArgumentException This exception is thrown if the one of the provided information do not fits the requirements.
*/
public Method(String name, Long timeout, Object payload) throws IllegalArgumentException;
public Method(String name, Long responseTimeout, Long connectTimeout, Object payload) throws IllegalArgumentException;
```
**SRS_METHOD_21_001: [**The constructor shall create an instance of the method.**]**
**SRS_METHOD_21_002: [**The constructor shall update the method collection using the provided information.**]**
**SRS_METHOD_21_023: [**The constructor shall initialize the method operation as `invoke`.**]**
**SRS_METHOD_21_003: [**All Strings are case sensitive.**]**
**SRS_METHOD_21_004: [**If the `name` is null, empty, contains more than 128 chars, or illegal char (`$`, `.`, space), the constructor shall throw IllegalArgumentException.**]**
**SRS_METHOD_21_005: [**If the timeout is a negative number, the constructor shall throw IllegalArgumentException.**]**
**SRS_METHOD_21_005: [**If the responseTimeout is a negative number, the constructor shall throw IllegalArgumentException.**]**
**SRS_METHOD_21_033: [**If the connectTimeout is a negative number, the constructor shall throw IllegalArgumentException.**]**


```java
/**
* CONSTRUCTOR
* Create a Method instance with provided values.
*
* @param payload - Object that contains the payload defined by the user.
* @param payload - Object that contains the payload defined by the user. It can be {@code null}.
*/
public Method(Object payload);
```
**SRS_METHOD_21_020: [**The constructor shall create an instance of the method.**]**
**SRS_METHOD_21_021: [**The constructor shall update the method collection using the provided information.**]**
**SRS_METHOD_21_034: [**The constructor shall set the method operation as `payload`.**]**


### fromJson
```java
/**
* Create a Method instance with the provided information in the json.
* Set the Method collection with the provided information in the json.
*
* @param json - Json with the information to change the collection.
* - If contains `methodName`, it is a full method including `methodName`, `responseTimeoutInSeconds`, and `payload`.
* - If contains `methodName`, it is a full method including `methodName`, `responseTimeoutInSeconds`, `connectTimeoutInSeconds`, and `payload`.
* - If contains `status`, it is a response with `status` and `payload`.
* - Otherwise, it is only `payload`.
* @throws IllegalArgumentException This exception is thrown if the one of the provided information do not fits the requirements.
*/
public fromJson(String json) throws IllegalArgumentException
public synchronized void fromJson(String json) throws IllegalArgumentException;
```
**SRS_METHOD_21_006: [**The fromJson shall create an instance of the method.**]**
**SRS_METHOD_21_007: [**The fromJson shall parse the json and fill the status and payload.**]**
**SRS_METHOD_21_006: [**The fromJson shall parse the json and fill the method collection.**]**
**SRS_METHOD_21_007: [**The json can contain values `null`, `"null"`, and `""`, which represents null, the string null, and empty string respectively.**]**
**SRS_METHOD_21_008: [**If the provided json is null, empty, or not valid, the fromJson shall throws IllegalArgumentException.**]**
**SRS_METHOD_21_009: [**If the json contains the `methodName` identification, the fromJson shall parser the full method.**]**
**SRS_METHOD_21_009: [**If the json contains the `methodName` identification, the fromJson shall parse the full method, and set the operation as `invoke`.**]**
Ex:
```json
{
"methodName": "reboot",
"responseTimeoutInSeconds": 200,
"connectTimeoutInSeconds": 5,
"payload":
{
"input1": "someInput",
"input2": "anotherInput"
}
}
```
**SRS_METHOD_21_010: [**If the json contains any payload without status identification, the fromJson shall parser only the payload.**]**
**SRS_METHOD_21_010: [**If the json contains any payload without `methodName` or `status` identification, the fromJson shall parse only the payload, and set the operation as `payload`**]**
Ex:
```json
{
"input1": "someInput",
"input2": "anotherInput"
}
```
**SRS_METHOD_21_011: [**If the json contains the `status` and `payload` identification, the fromJson shall parser both status and payload.**]**
**SRS_METHOD_21_011: [**If the json contains the `status` identification, the fromJson shall parse both status and payload, and set the operation as `response`.**]**
Ex:
```json
{
Expand All @@ -121,19 +129,21 @@ Ex:
/**
* Return an Integer with the response status.
*
* @return An integer with the status of the response (it can be null).
* @return An integer with the status of the response. It can be {@code null}.
* @throws IllegalArgumentException This exception is thrown if the operation is not type of `response`.
*/
public Integer getStatus()
public Integer getStatus() throws IllegalArgumentException
```
**SRS_METHOD_21_012: [**The getStatus shall return an Integer with the status in the parsed json.**]**
**SRS_METHOD_21_035: [**If the operation is not `response`, the getStatus shall throws IllegalArgumentException.**]**


### getPayload
```java
/**
* Return an Object with the payload.
*
* @return An Object with the payload(it can be null).
* @return An Object with the payload. It can be {@code null}.
*/
public Object getPayload()
```
Expand All @@ -152,37 +162,41 @@ public String toJson()
```
**SRS_METHOD_21_014: [**The toJson shall create a String with the full information in the method collection using json format.**]**
**SRS_METHOD_21_015: [**The toJson shall include name as `methodName` in the json.**]**
**SRS_METHOD_21_016: [**The toJson shall include timeout in seconds as `responseTimeoutInSeconds` in the json.**]**
**SRS_METHOD_21_017: [**If the timeout is null, the toJson shall not include the `responseTimeoutInSeconds` in the json.**]**
**SRS_METHOD_21_016: [**The toJson shall include responseTimeout in seconds as `responseTimeoutInSeconds` in the json.**]**
**SRS_METHOD_21_017: [**If the responseTimeout is null, the toJson shall not include the `responseTimeoutInSeconds` in the json.**]**
**SRS_METHOD_21_031: [**The toJson shall include connectTimeout in seconds as `connectTimeoutInSeconds` in the json.**]**
**SRS_METHOD_21_032: [**If the connectTimeout is null, the toJson shall not include the `connectTimeoutInSeconds` in the json.**]**
**SRS_METHOD_21_018: [**The class toJson include payload as `payload` in the json.**]**
**SRS_METHOD_21_019: [**If the payload is null, the toJson shall not include `payload` for parameters in the json.**]**
**SRS_METHOD_21_019: [**If the payload is null, the toJson shall include `payload` with value `null`.**]**
**SRS_METHOD_21_024: [**The class toJson include status as `status` in the json.**]**
**SRS_METHOD_21_025: [**If the status is null, the toJson shall not include `status` for parameters in the json.**]**
**SRS_METHOD_21_026: [**If the method contains a name, the toJson shall include the full method information in the json.**]**
**SRS_METHOD_21_025: [**If the status is null, the toJson shall include `status` as `null`.**]**
**SRS_METHOD_21_026: [**If the method operation is `invoke`, the toJson shall include the full method information in the json.**]**
Ex:
```json
{
"methodName": "reboot",
"responseTimeoutInSeconds": 200,
"connectTimeoutInSeconds": 5,
"payload": {
"input1": "someInput",
"input2": "anotherInput"
}
}
```
**SRS_METHOD_21_027: [**If the method contains the status, the toJson shall parser both status and payload.**]**
**SRS_METHOD_21_027: [**If the method operation is `response`, the toJson shall parse both status and payload.**]**
Ex:
```json
{
"status": 201,
"payload": {"AnyValidPayload" : "" }
}
```
**SRS_METHOD_21_028: [**If the method do not contains name or status, the toJson shall parser only the payload.**]**
**SRS_METHOD_21_028: [**If the method operation is `payload`, the toJson shall parse only the payload.**]**
Ex:
```json
{
"input1": "someInput",
"input2": "anotherInput"
}
```
**SRS_METHOD_21_036: [**If the method operation is `none`, the toJson shall throw IllegalArgumentException.**]**
Loading

0 comments on commit a626d1e

Please sign in to comment.