Search in sources :

Example 86 with Resource

use of org.wso2.carbon.registry.core.Resource in project ballerina by ballerina-lang.

the class UriTemplateBestMatchTest method testServiceRoot.

@Test(description = "Test dispatching with URL. /hello")
public void testServiceRoot() {
    String path = "/echo1?foo=zzz";
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET");
    HTTPCarbonMessage response = Services.invokeNew(application, TEST_EP, cMsg);
    Assert.assertNotNull(response, "Response message not found");
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
    Assert.assertEquals(bJson.value().get("third").asText(), "zzz", "Resource dispatched to wrong template");
    Assert.assertEquals(bJson.value().get("echo33").asText(), "echo1", "Resource dispatched to wrong template");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 87 with Resource

use of org.wso2.carbon.registry.core.Resource in project ballerina by ballerina-lang.

the class UriTemplateBestMatchTest method testBestMatchWithCapitalizedPathSegments.

@Test(description = "Test whether requests get dispatched to the capitalized resource path.")
public void testBestMatchWithCapitalizedPathSegments() {
    String path = "/uri/Go";
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "POST");
    HTTPCarbonMessage response = Services.invokeNew(application, TEST_EP, cMsg);
    Assert.assertNotNull(response, "Response message not found.");
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
    Assert.assertEquals(bJson.value().get("value").asText(), "capitalized", "Request dispatched to wrong resource");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 88 with Resource

use of org.wso2.carbon.registry.core.Resource in project ballerina by ballerina-lang.

the class UriTemplateBestMatchTest method testLeastSpecificURITemplate.

@Test(description = "Test dispatching with URL. /hello/echo2/shafreen+anfar/foo/bar")
public void testLeastSpecificURITemplate() {
    String path = "/hello/echo2/shafreen+anfar/foo/bar";
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET");
    HTTPCarbonMessage response = Services.invokeNew(application, TEST_EP, cMsg);
    Assert.assertNotNull(response, "Response message not found");
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
    Assert.assertEquals(bJson.value().get("echo5").asText(), "any", "Resource dispatched to wrong template");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 89 with Resource

use of org.wso2.carbon.registry.core.Resource in project ballerina by ballerina-lang.

the class UriTemplateBestMatchTest method testMostSpecificServiceDispatch.

@Test(description = "Test dispatching with URL. /hello/echo2?regid=abc")
public void testMostSpecificServiceDispatch() {
    String path = "/hello/echo2?regid=abc";
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET");
    HTTPCarbonMessage response = Services.invokeNew(application, TEST_EP, cMsg);
    Assert.assertNotNull(response, "Response message not found");
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
    Assert.assertEquals(bJson.value().get("echo5").asText(), "echo5", "Resource dispatched to wrong template");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 90 with Resource

use of org.wso2.carbon.registry.core.Resource in project ballerina by ballerina-lang.

the class UriTemplateBestMatchTest method testParamDefaultValues.

@Test(description = "Test dispatching with URL. /hello/echo2/shafreen+anfar/bar")
public void testParamDefaultValues() {
    String path = "/hello/echo3/shafreen+anfar?foo=bar";
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET");
    HTTPCarbonMessage response = Services.invokeNew(application, TEST_EP, cMsg);
    Assert.assertNotNull(response, "Response message not found");
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
    Assert.assertEquals(bJson.value().get("first").asText(), "shafreen anfar", "Resource dispatched to wrong template");
    Assert.assertEquals(bJson.value().get("second").asText(), "bar", "Resource dispatched to wrong template");
    Assert.assertEquals(bJson.value().get("echo9").asText(), "echo9", "Resource dispatched to wrong template");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)111 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)102 HashMap (java.util.HashMap)91 Test (org.testng.annotations.Test)64 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)59 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)56 HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)53 BJSON (org.ballerinalang.model.values.BJSON)46 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)38 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)29 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)27 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)24 CharonException (org.wso2.charon3.core.exceptions.CharonException)24 IOException (java.io.IOException)23 Map (java.util.Map)20 SCIMResponse (org.wso2.charon3.core.protocol.SCIMResponse)20 NotFoundException (org.wso2.charon3.core.exceptions.NotFoundException)17 SCIMResourceTypeSchema (org.wso2.charon3.core.schema.SCIMResourceTypeSchema)17 ArrayList (java.util.ArrayList)15 InternalErrorException (org.wso2.charon3.core.exceptions.InternalErrorException)15