bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford * The contents of this file are subject to the terms of the Common Development and
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford * Distribution License (the License). You may not use this file except in compliance with the
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford * specific language governing permission and limitations under the License.
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford * When distributing Covered Software, include this CDDL Header Notice in each file and include
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford * Header, with the fields enclosed by brackets [] replaced by your own identifying
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford * information: "Portions copyright [year] [name of copyright owner]".
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford * Copyright 2016 ForgeRock AS.
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamfordimport static org.assertj.core.api.Assertions.*;
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford * Test the RESTEndpoint class.
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford RESTEndpoint endpoint = new RESTEndpoint.RESTEndpointBuilder()
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford assertThat(toStringValue).startsWith("path+params=" + path);
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford RESTEndpoint endpoint = new RESTEndpoint.RESTEndpointBuilder()
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford assertThat(toStringValue).startsWith("path+params=" + path + "/" + append);
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford assertThat(toPathValue).startsWith(path + "/" + append);
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford public void shouldAppendTwoPathsWithExtraSeparators() {
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford RESTEndpoint endpoint = new RESTEndpoint.RESTEndpointBuilder()
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford assertThat(toStringValue).startsWith("path+params=" + path + "/" + append);
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford assertThat(toPathValue).startsWith(path + "/" + append);
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford public void shouldAppendThreePathsWithExtraSeparators() {
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford RESTEndpoint endpoint = new RESTEndpoint.RESTEndpointBuilder()
e80c6451e400ef4956af170a3efaa0423aede68cTony Bamford public void shouldCorrectlySubstituteEmptyRealm() {
e80c6451e400ef4956af170a3efaa0423aede68cTony Bamford RESTEndpoint endpoint = new RESTEndpoint.RESTEndpointBuilder()
e80c6451e400ef4956af170a3efaa0423aede68cTony Bamford assertThat(toPathValue).contains("<path>/<append>");
e80c6451e400ef4956af170a3efaa0423aede68cTony Bamford public void shouldCorrectlySubstituteEmptyRealmAlt() {
e80c6451e400ef4956af170a3efaa0423aede68cTony Bamford RESTEndpoint endpoint = new RESTEndpoint.RESTEndpointBuilder()
e80c6451e400ef4956af170a3efaa0423aede68cTony Bamford assertThat(toPathValue).contains("<path>/<append>");
e80c6451e400ef4956af170a3efaa0423aede68cTony Bamford public void shouldCorrectlySubstituteNonEmptyRealm() {
e80c6451e400ef4956af170a3efaa0423aede68cTony Bamford RESTEndpoint endpoint = new RESTEndpoint.RESTEndpointBuilder()
e80c6451e400ef4956af170a3efaa0423aede68cTony Bamford assertThat(toPathValue).contains("<path>/<realm>/<append>");
e80c6451e400ef4956af170a3efaa0423aede68cTony Bamford public void shouldCorrectlySubstituteNonEmptyRealmAlt() {
e80c6451e400ef4956af170a3efaa0423aede68cTony Bamford RESTEndpoint endpoint = new RESTEndpoint.RESTEndpointBuilder()
e80c6451e400ef4956af170a3efaa0423aede68cTony Bamford assertThat(toPathValue).contains("<path>/<realm>/<append>");
e80c6451e400ef4956af170a3efaa0423aede68cTony Bamford public void shouldCorrectlySubstituteDeliberatelySpecifiedRootRealm() {
e80c6451e400ef4956af170a3efaa0423aede68cTony Bamford RESTEndpoint endpoint = new RESTEndpoint.RESTEndpointBuilder()
e80c6451e400ef4956af170a3efaa0423aede68cTony Bamford assertThat(toPathValue).contains("<path>/<append>");
e80c6451e400ef4956af170a3efaa0423aede68cTony Bamford public void shouldCorrectlySubstituteDeliberatelySpecifiedRootRealmAlt() {
e80c6451e400ef4956af170a3efaa0423aede68cTony Bamford RESTEndpoint endpoint = new RESTEndpoint.RESTEndpointBuilder()
e80c6451e400ef4956af170a3efaa0423aede68cTony Bamford assertThat(toPathValue).contains("<path>/<append>");
e80c6451e400ef4956af170a3efaa0423aede68cTony Bamford public void shouldNotContainRealmEvenThoughSpecified() {
e80c6451e400ef4956af170a3efaa0423aede68cTony Bamford RESTEndpoint endpoint = new RESTEndpoint.RESTEndpointBuilder()
e80c6451e400ef4956af170a3efaa0423aede68cTony Bamford assertThat(toPathValue).doesNotContain("<wibble>");
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford public void shouldHandleMultipleParametersInCorrectOrder() {
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford RESTEndpoint endpoint = new RESTEndpoint.RESTEndpointBuilder()
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford assertThat(toStringValue).contains("?" + param1name + "=" + param1value);
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford assertThat(toPathValue).contains("?" + param1name + "=" + param1value);
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford assertThat(toStringValue).contains("&" + param2name + "=" + param2value);
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford assertThat(toPathValue).contains("&" + param2name + "=" + param2value);
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford // Ordering should be preserved with the parameters, even though it probably doesn't make a difference
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford // in real life.
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford assertThat(toStringValue.indexOf(param1name)).isLessThan(toStringValue.indexOf(param2name));
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford * Note that this actually checks the output of the toString function, which could be made to lie without effecting
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford * the remainder of the functionality within the class. However, using toString means we don't have to introduce
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford * any other functions to access the http method.
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford RESTEndpoint endpoint = new RESTEndpoint.RESTEndpointBuilder().build();
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford // Check the default is POST
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford assertThat(toStringValue).contains("method: POST");
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford assertThat(toStringValue).doesNotContain("method: GET");
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford endpoint = new RESTEndpoint.RESTEndpointBuilder()
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford assertThat(toStringValue).contains("method: GET");
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford assertThat(toStringValue).doesNotContain("method: POST");
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford endpoint = new RESTEndpoint.RESTEndpointBuilder()
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford assertThat(toStringValue).contains("method: POST");
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford assertThat(toStringValue).doesNotContain("method: GET");
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford public void checkToStringHidesPasswordsInPostData() {
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford RESTEndpoint endpoint = new RESTEndpoint.RESTEndpointBuilder()
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford // Check there is no post data
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford assertThat(toStringValue).doesNotContain(" post data ");
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford endpoint = new RESTEndpoint.RESTEndpointBuilder()
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford assertThat(toStringValue).contains(" post data " + postData);
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford endpoint = new RESTEndpoint.RESTEndpointBuilder()
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford assertThat(toStringValue).doesNotContain(" post data " + postData);
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford RESTEndpoint endpoint = new RESTEndpoint.RESTEndpointBuilder()
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford int indexHeaders = toStringValue.indexOf("headers:");
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford int indexValue1 = toStringValue.indexOf(value1);
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford int indexValue2 = toStringValue.indexOf(value2);
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford assertThat(indexName1).isGreaterThan(indexHeaders);
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford assertThat(indexValue1).isGreaterThan(indexName1);
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford assertThat(indexName2).isGreaterThan(indexName1);
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford assertThat(indexName2).isGreaterThan(indexValue1);
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford assertThat(indexValue2).isGreaterThan(indexName2);
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford assertThat(toStringValue).contains(name1 + ": " + value1);
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford assertThat(toStringValue).contains(name2 + ": " + value2);
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford RESTEndpoint endpoint = new RESTEndpoint.RESTEndpointBuilder()
bbe59b9e7b19daeef0e63ffa77aaefb67aceb85eTony Bamford assertThat(toStringValue).contains(name1 + ": " + value1);