use of org.ballerinalang.util.codegen.attributes.AnnotationAttributeInfo in project ballerina by ballerina-lang.
the class AnnotationTest method testDefaultValues.
@Test(description = "Test default values for annotation", enabled = false)
public void testDefaultValues() {
CompileResult compileResult = BCompileUtil.compile("test-src/lang/annotations/default-values.bal");
AnnotationAttributeInfo annotationInfo = (AnnotationAttributeInfo) compileResult.getProgFile().getEntryPackage().getFunctionInfo("foo").getAttributeInfo(AttributeInfo.Kind.ANNOTATIONS_ATTRIBUTE);
AnnAttachmentInfo[] attachmentInfos = annotationInfo.getAttachmentInfoEntries();
// check for default values for basic literal attributes
Assert.assertEquals(attachmentInfos[0].getAttributeValue("value").getStringValue(), "Description of the service/function");
// check for default values for non-literal attributes
Assert.assertEquals(attachmentInfos[0].getAttributeValue("queryParamValue"), null);
// check for default values for nested annotations
AnnAttachmentInfo nestedArgAnnot = attachmentInfos[0].getAttributeValue("args").getAnnotationAttachmentValue();
Assert.assertEquals(nestedArgAnnot.getAttributeValue("value").getStringValue(), "default value for 'Args' annotation in doc package");
// check for default values for nested annotations arrays
AnnAttachmentInfo nestedAnnot = attachmentInfos[0].getAttributeValue("queryParamValue2").getAttributeValueArray()[0].getAnnotationAttachmentValue();
Assert.assertEquals(nestedAnnot.getAttributeValue("name").getStringValue(), "default name");
Assert.assertEquals(nestedAnnot.getAttributeValue("value").getStringValue(), "default value");
// check for default values for a local annotations
Assert.assertEquals(attachmentInfos[1].getAttributeValue("value").getStringValue(), "default value for local 'Args' annotation");
long status = attachmentInfos[3].getAttributeValue("status").getIntValue();
Assert.assertEquals(status, 200);
}
use of org.ballerinalang.util.codegen.attributes.AnnotationAttributeInfo in project ballerina by ballerina-lang.
the class AnnotationTest method testActionAnnotation.
@Test(description = "Test action annotation", enabled = false)
public void testActionAnnotation() {
AnnotationAttributeInfo annotationInfo = (AnnotationAttributeInfo) compileResult.getProgFile().getEntryPackage().getConnectorInfoEntries()[0].getActionInfoEntries()[1].getAttributeInfo(AttributeInfo.Kind.ANNOTATIONS_ATTRIBUTE);
AnnAttachmentInfo[] attachmentInfos = annotationInfo.getAttachmentInfoEntries();
String attributeValue = attachmentInfos[0].getAttributeValue("value").getStringValue();
Assert.assertEquals(attributeValue, "Test action of test connector");
}
use of org.ballerinalang.util.codegen.attributes.AnnotationAttributeInfo in project ballerina by ballerina-lang.
the class AnnotationTest method testAnnotationArray.
@Test(description = "Test annotation array", enabled = false)
public void testAnnotationArray() {
AnnotationAttributeInfo annotationInfo = (AnnotationAttributeInfo) compileResult.getProgFile().getEntryPackage().getFunctionInfo("foo").getAttributeInfo(AttributeInfo.Kind.ANNOTATIONS_ATTRIBUTE);
AnnAttachmentInfo[] attachmentInfos = annotationInfo.getAttachmentInfoEntries();
AnnAttributeValue[] annotationArray = attachmentInfos[0].getAttributeValue("queryParamValue").getAttributeValueArray();
Assert.assertEquals(annotationArray.length, 3, "Wrong annotation array length");
String attributeValue = annotationArray[2].getAnnotationAttachmentValue().getAttributeValue("name").getStringValue();
Assert.assertEquals(attributeValue, "paramName");
attributeValue = annotationArray[1].getAnnotationAttachmentValue().getAttributeValue("name").getStringValue();
Assert.assertEquals(attributeValue, "paramName2");
attributeValue = annotationArray[0].getAnnotationAttachmentValue().getAttributeValue("name").getStringValue();
Assert.assertEquals(attributeValue, "paramName3");
}
use of org.ballerinalang.util.codegen.attributes.AnnotationAttributeInfo in project ballerina by ballerina-lang.
the class AnnotationTest method testConnectorAnnotation.
@Test(description = "Test connector annotation", enabled = false)
public void testConnectorAnnotation() {
AnnotationAttributeInfo annotationInfo = (AnnotationAttributeInfo) compileResult.getProgFile().getEntryPackage().getConnectorInfoEntries()[0].getAttributeInfo(AttributeInfo.Kind.ANNOTATIONS_ATTRIBUTE);
AnnAttachmentInfo[] attachmentInfos = annotationInfo.getAttachmentInfoEntries();
String attributeValue = attachmentInfos[0].getAttributeValue("value").getStringValue();
Assert.assertEquals(attributeValue, "Test connector");
}
use of org.ballerinalang.util.codegen.attributes.AnnotationAttributeInfo in project ballerina by ballerina-lang.
the class AnnotationTest method testResourceAnnotation.
@Test(description = "Test resource annotation", enabled = false)
public void testResourceAnnotation() {
AnnotationAttributeInfo annotationInfo = (AnnotationAttributeInfo) compileResult.getProgFile().getEntryPackage().getServiceInfo("PizzaService").getResourceInfoEntries()[1].getAttributeInfo(AttributeInfo.Kind.ANNOTATIONS_ATTRIBUTE);
AnnAttachmentInfo[] attachmentInfos = annotationInfo.getAttachmentInfoEntries();
String attributeValue = attachmentInfos[0].getAttributeValue("value").getStringValue();
Assert.assertEquals(attributeValue, "Order pizza");
annotationInfo = (AnnotationAttributeInfo) compileResult.getProgFile().getEntryPackage().getServiceInfo("PizzaService").getResourceInfoEntries()[0].getAttributeInfo(AttributeInfo.Kind.ANNOTATIONS_ATTRIBUTE);
attachmentInfos = annotationInfo.getAttachmentInfoEntries();
attributeValue = attachmentInfos[0].getAttributeValue("value").getStringValue();
Assert.assertEquals(attributeValue, "Check order status");
// TODO ParamDef AnnAttachmentInfo are not available at AnnotationAttributeInfo
// String paramAnnotVal = orderPizzaResource.getParameterDefs()[0].getAnnotations()[0].getValue();
// Assert.assertEquals(paramAnnotVal, "input parameter for oderPizza resource");
}
Aggregations