Search in sources :

Example 41 with Annotation

use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.

the class ProducesConsumesAnnotationTest method testWithoutProducesConsumeAnnotation.

@Test(description = "Test without Pro-Con annotation with URL. /echo67/echo1 ")
public void testWithoutProducesConsumeAnnotation() {
    String path = "/echo67/echo1";
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET");
    cMsg.setHeader(HttpHeaderNames.CONTENT_TYPE.toString(), "text/plain; charset=ISO-8859-4");
    cMsg.setHeader(HttpHeaderNames.ACCEPT.toString(), "text/*;q=0.3, text/html;Level=1;q=0.7");
    HTTPCarbonMessage response = Services.invokeNew(compileResult, TEST_EP, cMsg);
    Assert.assertNotNull(response, "Response message not found");
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
    Assert.assertEquals(bJson.value().get("echo33").asText(), "echo1", "No media types");
}
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 42 with Annotation

use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.

the class ProducesConsumesAnnotationTest method testProducesAnnotation.

@Test(description = "Test Produces annotation with URL. /echo66/test2 ")
public void testProducesAnnotation() {
    String path = "/echo66/test2";
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET");
    cMsg.setHeader(HttpHeaderNames.ACCEPT.toString(), "text/xml;q=0.3, multipart/*;Level=1;q=0.7");
    HTTPCarbonMessage response = Services.invokeNew(compileResult, TEST_EP, cMsg);
    Assert.assertNotNull(response, "Response message not found");
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
    Assert.assertEquals(bJson.value().get("msg").asText(), "wso22", "media type matched");
}
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 43 with Annotation

use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.

the class ProducesConsumesAnnotationTest method testIncorrectConsumesAnnotation.

@Test(description = "Test incorrect Consumes annotation with URL. /echo66/test1 ")
public void testIncorrectConsumesAnnotation() {
    String path = "/echo66/test1";
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "POST", "Test");
    cMsg.setHeader(HttpHeaderNames.CONTENT_TYPE.toString(), "compileResult/json");
    HTTPCarbonMessage response = Services.invokeNew(compileResult, TEST_EP, cMsg);
    Assert.assertNotNull(response, "Response message not found");
    int trueResponse = (int) response.getProperty(HttpConstants.HTTP_STATUS_CODE);
    Assert.assertEquals(trueResponse, 415, "Unsupported media type");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) Test(org.testng.annotations.Test)

Example 44 with Annotation

use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.

the class ProducesConsumesAnnotationTest method testBogusConsumesAnnotation.

@Test(description = "Test bogus Consumes annotation with URL. /echo66/test1 ")
public void testBogusConsumesAnnotation() {
    String path = "/echo66/test1";
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "POST", "Test");
    cMsg.setHeader(HttpHeaderNames.CONTENT_TYPE.toString(), ",:vhjv");
    HTTPCarbonMessage response = Services.invokeNew(compileResult, TEST_EP, cMsg);
    Assert.assertNotNull(response, "Response message not found");
    int trueResponse = (int) response.getProperty(HttpConstants.HTTP_STATUS_CODE);
    Assert.assertEquals(trueResponse, 415, "Unsupported media type");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) Test(org.testng.annotations.Test)

Example 45 with Annotation

use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.

the class UriTemplateDefaultDispatcherTest method testServiceNameDispatchingWhenAnnotationUnavailable.

@Test(description = "Test dispatching with Service name when annotation is not available")
public void testServiceNameDispatchingWhenAnnotationUnavailable() {
    String path = "/serviceWithNoAnnotation/test1";
    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("echo").asText(), "dispatched to a service without an annotation", "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

Test (org.testng.annotations.Test)29 ArrayList (java.util.ArrayList)14 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)12 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)11 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)11 HashMap (java.util.HashMap)9 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)9 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)9 List (java.util.List)8 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)8 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)8 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)8 Annotation (org.wso2.siddhi.query.api.annotation.Annotation)8 BLangConnector (org.wso2.ballerinalang.compiler.tree.BLangConnector)7 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)7 BLangResource (org.wso2.ballerinalang.compiler.tree.BLangResource)7 BLangService (org.wso2.ballerinalang.compiler.tree.BLangService)7 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)7 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)7 HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)7