use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.
the class ProducesConsumesAnnotationTest method testIncorrectProducesAnnotation.
@Test(description = "Test incorrect Produces annotation with URL. /echo66/test2 ")
public void testIncorrectProducesAnnotation() {
String path = "/echo66/test2";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET");
cMsg.setHeader(HttpHeaderNames.ACCEPT.toString(), "multipart/*;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");
int trueResponse = (int) response.getProperty(HttpConstants.HTTP_STATUS_CODE);
Assert.assertEquals(trueResponse, 406, "Not acceptable");
}
use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.
the class ProducesConsumesAnnotationTest method testConsumesAnnotation.
@Test(description = "Test Consumes annotation with URL. /echo66/test1 ")
public void testConsumesAnnotation() {
String path = "/echo66/test1";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "POST", "Test");
cMsg.setHeader(HttpHeaderNames.CONTENT_TYPE.toString(), "application/xml; charset=ISO-8859-4");
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(), "wso2", "Content type matched");
}
use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.
the class UriTemplateDefaultDispatcherTest method testPureProxyService.
@Test(description = "Test dispatching with Service name when annotation is not available")
public void testPureProxyService() {
String path = "/";
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 proxy service", "Resource dispatched to wrong template");
}
use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.
the class UriTemplateDefaultDispatcherTest method testServiceNameDispatchingWithEmptyBasePath.
@Test(description = "Test dispatching when resource annotation unavailable")
public void testServiceNameDispatchingWithEmptyBasePath() {
String path = "/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 empty service name", "Resource dispatched to wrong template");
}
use of org.wso2.siddhi.query.api.annotation.Annotation in project ballerina by ballerina-lang.
the class CommandUtil method getResourceDocumentationByPosition.
/**
* Get the Documentation attachment for the resource.
* @param bLangPackage BLangPackage built
* @param line Start line of the resource in the source
* @return {@link String} Documentation attachment for the resource
*/
static DocAttachmentInfo getResourceDocumentationByPosition(BLangPackage bLangPackage, int line) {
// TODO: Currently resource position is invalid and we use the annotation attachment positions.
for (TopLevelNode topLevelNode : bLangPackage.topLevelNodes) {
if (topLevelNode instanceof BLangService) {
BLangService serviceNode = (BLangService) topLevelNode;
for (BLangResource bLangResource : serviceNode.getResources()) {
List<BLangAnnotationAttachment> annotationAttachments = bLangResource.getAnnotationAttachments();
DiagnosticPos resourcePos = CommonUtil.toZeroBasedPosition(bLangResource.getPosition());
if (!annotationAttachments.isEmpty()) {
DiagnosticPos lastAttachmentPos = CommonUtil.toZeroBasedPosition(annotationAttachments.get(annotationAttachments.size() - 1).getPosition());
if (lastAttachmentPos.getEndLine() < line && line < resourcePos.getEndLine()) {
return getResourceNodeDocumentation(bLangResource, lastAttachmentPos.getEndLine() + 1);
}
} else if (resourcePos.getStartLine() == line) {
return getResourceNodeDocumentation(bLangResource, line);
}
}
}
}
return null;
}
Aggregations