Skip to content

Commit

Permalink
Add integration tests for actions on simple resources with explicit r…
Browse files Browse the repository at this point in the history
…esource levels.
  • Loading branch information
haroldl committed Nov 15, 2021
1 parent a133830 commit 0a9eb23
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@
"type" : "int"
} ],
"returns" : "int"
}, {
"name" : "exampleActionThatIsExplicitlyAnyLevel",
"doc" : "An example action on the greeting which is explicitly set to any-level.",
"parameters" : [ {
"name" : "param1",
"type" : "int"
} ],
"returns" : "int"
}, {
"name" : "exampleActionThatIsExplicitlyEntityLevel",
"doc" : "An example action on the greeting which is explicitly set to entity-level.",
"parameters" : [ {
"name" : "param1",
"type" : "int"
} ],
"returns" : "int"
}, {
"name" : "exceptionTest",
"doc" : "An example action throwing an exception."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@
"type" : "int"
} ],
"returns" : "int"
}, {
"name" : "exampleActionThatIsExplicitlyAnyLevel",
"doc" : "An example action on the greeting which is explicitly set to any-level.",
"parameters" : [ {
"name" : "param1",
"type" : "int"
} ],
"returns" : "int"
}, {
"name" : "exampleActionThatIsExplicitlyEntityLevel",
"doc" : "An example action on the greeting which is explicitly set to entity-level.",
"parameters" : [ {
"name" : "param1",
"type" : "int"
} ],
"returns" : "int"
}, {
"name" : "exceptionTest",
"doc" : "An example action throwing an exception."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.linkedin.restli.common.PatchRequest;
import com.linkedin.restli.examples.greetings.api.Greeting;
import com.linkedin.restli.examples.greetings.api.Tone;
import com.linkedin.restli.server.ResourceLevel;
import com.linkedin.restli.server.RestLiServiceException;
import com.linkedin.restli.server.UpdateResponse;
import com.linkedin.restli.server.annotations.Action;
Expand Down Expand Up @@ -96,6 +97,24 @@ public int exampleAction(@ActionParam("param1") int param1)
return param1 * 10;
}

/**
* An example action on the greeting which is explicitly set to entity-level.
*/
@Action(name="exampleActionThatIsExplicitlyEntityLevel", resourceLevel=ResourceLevel.ENTITY)
public int exampleActionThatIsExplicitlyEntityLevel(@ActionParam("param1") int param1)
{
return param1 * 11;
}

/**
* An example action on the greeting which is explicitly set to any-level.
*/
@Action(name="exampleActionThatIsExplicitlyAnyLevel", resourceLevel=ResourceLevel.ANY)
public int exampleActionThatIsExplicitlyAnyLevel(@ActionParam("param1") int param1)
{
return param1 * 12;
}

/**
* An example action throwing an exception.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,24 @@ public void testRootSimpleResourceIntAction(RootBuilderWrapper<Void, Greeting> b
Assert.assertEquals(responseFuture.getResponse().getEntity().intValue(), 10);
}

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testRootSimpleResourceEntityAction(RootBuilderWrapper<Void, Greeting> builders) throws RemoteInvocationException
{
Request<Integer> request = builders.<Integer>action("ExampleActionThatIsExplicitlyEntityLevel").setActionParam("Param1", 3).build();
ResponseFuture<Integer> responseFuture = getClient().sendRequest(request);
Assert.assertEquals(responseFuture.getResponse().getStatus(), 200);
Assert.assertEquals(responseFuture.getResponse().getEntity().intValue(), 33);
}

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testRootSimpleResourceAnyAction(RootBuilderWrapper<Void, Greeting> builders) throws RemoteInvocationException
{
Request<Integer> request = builders.<Integer>action("ExampleActionThatIsExplicitlyAnyLevel").setActionParam("Param1", 3).build();
ResponseFuture<Integer> responseFuture = getClient().sendRequest(request);
Assert.assertEquals(responseFuture.getResponse().getStatus(), 200);
Assert.assertEquals(responseFuture.getResponse().getEntity().intValue(), 36);
}

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testRootSimpleResourceActionException(RootBuilderWrapper<Void, Greeting> builders) throws RemoteInvocationException
{
Expand Down

0 comments on commit 0a9eb23

Please sign in to comment.