Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CUSTCOM-199 Test For Admin Command JSON Invocation #4531

Merged
merged 1 commit into from
Feb 21, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,59 @@
*/
package fish.payara.samples.rest.management;

import static java.lang.String.format;
import static javax.ws.rs.client.Entity.entity;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.util.HashMap;
import java.util.Map;

import javax.json.JsonObject;
import javax.ws.rs.core.Response;

import org.junit.Test;

/**
* Test the REST management interface for it's basic HTTP responses
*/
public class HttpResponsesTest extends RestManagementTest {
public class HttpSemanticsTest extends RestManagementTest {

/**
* Tests that when deleting a non-existent resource a 404 is returned instead of
* a 415. See CUSTCOM-13 for details.
*/
@Test
public void when_DELETE_non_existent_resource_expect_404() {
int status = target
.path("servers/server/server/application-ref/non-existent-application-ref")
Response response = target.path("servers/server/server/application-ref/non-existent-application-ref")
.request()
.delete()
.getStatus();
assertEquals("A non-existent resource should return a 404.", 404, status);
.delete();
assertEquals("A non-existent resource should return a 404.", 404, response.getStatus());
}

/**
* Tests that when invoking an asadmin command using the REST management
* interface with a JSON request, the parameters are unwrapped correctly (and
* without quotation marks). See CUSTCOM-199 for details.
*/
@Test
public void when_JSON_parameters_in_request_expect_correct_parsing() {
Map<String, String> parameters = new HashMap<>();
parameters.put("node", "invalid-node");

JsonObject response = target.path("create-instance")
.request()
.post(entity(parameters, APPLICATION_JSON))
.readEntity(JsonObject.class);

String commandLog = response
.getJsonObject("extraProperties")
.getJsonArray("commandLog")
.toString();

assertTrue(format("The \"node\" parameter was unwrapped incorrectly. command log: %s", commandLog),
commandLog.contains("--node invalid-node"));
}

}