Skip to content

Commit

Permalink
1) failure execution on missing object id 2) success test on execute …
Browse files Browse the repository at this point in the history
…with parameters 3) test cases name correction from write_only to read_only

Signed-off-by: Kiran Pradeep <kiran.happy@gmail.com>
  • Loading branch information
kiranpradeep authored and Kai Hudalla committed Jan 4, 2016
1 parent a667c8f commit 45fe8e4
Showing 1 changed file with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.eclipse.leshan.core.response.ExecuteResponse;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

public class ExecuteTest {
Expand All @@ -46,7 +47,7 @@ public void stop() {
}

@Test
public void cannot_execute_write_only_resource() {
public void cannot_execute_read_only_resource() {
// client registration
helper.client.send(new RegisterRequest(ENDPOINT_IDENTIFIER));

Expand All @@ -57,6 +58,45 @@ public void cannot_execute_write_only_resource() {
assertEquals(ResponseCode.METHOD_NOT_ALLOWED, response.getCode());
}

@Test
public void cannot_execute_read_write_resource() {
// client registration
helper.client.send(new RegisterRequest(ENDPOINT_IDENTIFIER));

// execute current time resource on device
ExecuteResponse response = helper.server.send(helper.getClient(), new ExecuteRequest(3, 0, 13));

// verify result
assertEquals(ResponseCode.METHOD_NOT_ALLOWED, response.getCode());
}

//TODO: Does this has to be implemented ?
@Ignore
@Test
public void cannot_execute_nonexisting_resource_on_existing_object() {
// client registration
helper.client.send(new RegisterRequest(ENDPOINT_IDENTIFIER));

final int nonExistingResourceId = 9999;
// execute non existing resource on device
ExecuteResponse response = helper.server.send(helper.getClient(), new ExecuteRequest(3, 0, nonExistingResourceId));

// verify result
assertEquals(ResponseCode.NOT_FOUND, response.getCode());
}

@Test
public void cannot_execute_nonexisting_resource_on_non_existing_object() {
// client registration
helper.client.send(new RegisterRequest(ENDPOINT_IDENTIFIER));

final int nonExistingObjectId = 9999;
ExecuteResponse response = helper.server.send(helper.getClient(), new ExecuteRequest(nonExistingObjectId, 0, 0));

// verify result
assertEquals(ResponseCode.NOT_FOUND, response.getCode());
}

@Test
public void can_execute_resource() {
// client registration
Expand All @@ -69,4 +109,16 @@ public void can_execute_resource() {
assertEquals(ResponseCode.CHANGED, response.getCode());
}

@Test
public void can_execute_resource_with_parameters() {
// client registration
helper.client.send(new RegisterRequest(ENDPOINT_IDENTIFIER));

// execute reboot after 60 seconds on device
ExecuteResponse response = helper.server.send(helper.getClient(), new ExecuteRequest(3, 0, 4, "60"));

// verify result
assertEquals(ResponseCode.CHANGED, response.getCode());
}

}

0 comments on commit 45fe8e4

Please sign in to comment.