Search in sources :

Example 76 with Resource

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

the class UriTemplateDispatcherTest method testValidUrlTemplate5Dispatching.

@Test(description = "Test accessing the variables parsed with URL. /products5/{productId}/reg")
public void testValidUrlTemplate5Dispatching() {
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/ecommerceservice/products5/PID125/reg?regID=RID125&para1=value1", "GET");
    HTTPCarbonMessage response = Services.invokeNew(application, TEST_EP, cMsg);
    Assert.assertNotNull(response, "Response message not found");
    // Expected Json message : {"Template":"T5","ProductID":"PID125","RegID":"RID125"}
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
    Assert.assertEquals(bJson.value().get("Template").asText(), "T5", "Resource dispatched to wrong template");
    Assert.assertEquals(bJson.value().get("ProductID").asText(), "PID125", "ProductID variable not set properly.");
    Assert.assertEquals(bJson.value().get("RegID").asText(), "RID125", "RegID variable not set properly.");
}
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 77 with Resource

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

the class UriTemplateDispatcherTest method testInValidUrlTemplateDispatching.

@Test(description = "Test resource dispatchers with invalid URL. /products/{productId}/{regId}", dataProvider = "inValidUrl")
public void testInValidUrlTemplateDispatching(String path) {
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET");
    final String xOrderIdHeadeName = "X-ORDER-ID";
    final String xOrderIdHeadeValue = "ORD12345";
    cMsg.setHeader(xOrderIdHeadeName, xOrderIdHeadeValue);
    HTTPCarbonMessage response = Services.invokeNew(application, TEST_EP, cMsg);
    Assert.assertEquals(response.getProperty(HttpConstants.HTTP_STATUS_CODE), 404, "Response code mismatch");
    // checking the exception message
    String errorMessage = StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(response).getInputStream());
    Assert.assertNotNull(errorMessage, "Message body null");
    Assert.assertTrue(errorMessage.contains("no matching resource found for path"), "Expected error not found.");
}
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) Test(org.testng.annotations.Test)

Example 78 with Resource

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

the class UriTemplateDispatcherTest method testEmptyStringResourcepath.

@Test(description = "Test empty string resource path")
public void testEmptyStringResourcepath() {
    String path = "/ecommerceservice/echo1";
    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("echo11").asText(), "echo11", "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 79 with Resource

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

the class UriTemplateDispatcherTest method testSpecialCharacterEscapedURI.

@Test(description = "Test dispatching with OPTIONS request with wildcard")
public void testSpecialCharacterEscapedURI() {
    String path = "/ech%5Bo14/ech%5Bo14/b%5Bar14";
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET", null);
    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("echo114").asText(), "b[ar14", "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 80 with Resource

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

the class ServiceTest method testGetServiceLevelString.

@Test(description = "Test accessing service level variable in resource")
public void testGetServiceLevelString() {
    HTTPTestRequest requestMsg = MessageUtils.generateHTTPMessage("/echo/getServiceLevelString", "GET");
    HTTPCarbonMessage responseMsg = Services.invokeNew(compileResult, TEST_ENDPOINT_NAME, requestMsg);
    Assert.assertNotNull(responseMsg);
    String responseMsgPayload = StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(responseMsg).getInputStream());
    StringDataSource stringDataSource = new StringDataSource(responseMsgPayload);
    Assert.assertNotNull(stringDataSource);
    Assert.assertEquals(stringDataSource.getValue(), "sample value");
}
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) StringDataSource(org.ballerinalang.runtime.message.StringDataSource) 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