Search in sources :

Example 1 with AnnotationAttributeInfo

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);
}
Also used : AnnAttachmentInfo(org.ballerinalang.util.codegen.AnnAttachmentInfo) CompileResult(org.ballerinalang.launcher.util.CompileResult) AnnotationAttributeInfo(org.ballerinalang.util.codegen.attributes.AnnotationAttributeInfo) Test(org.testng.annotations.Test)

Example 2 with AnnotationAttributeInfo

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");
}
Also used : AnnAttachmentInfo(org.ballerinalang.util.codegen.AnnAttachmentInfo) AnnotationAttributeInfo(org.ballerinalang.util.codegen.attributes.AnnotationAttributeInfo) Test(org.testng.annotations.Test)

Example 3 with AnnotationAttributeInfo

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");
}
Also used : AnnAttachmentInfo(org.ballerinalang.util.codegen.AnnAttachmentInfo) AnnAttributeValue(org.ballerinalang.util.codegen.AnnAttributeValue) AnnotationAttributeInfo(org.ballerinalang.util.codegen.attributes.AnnotationAttributeInfo) Test(org.testng.annotations.Test)

Example 4 with AnnotationAttributeInfo

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");
}
Also used : AnnAttachmentInfo(org.ballerinalang.util.codegen.AnnAttachmentInfo) AnnotationAttributeInfo(org.ballerinalang.util.codegen.attributes.AnnotationAttributeInfo) Test(org.testng.annotations.Test)

Example 5 with AnnotationAttributeInfo

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");
}
Also used : AnnAttachmentInfo(org.ballerinalang.util.codegen.AnnAttachmentInfo) AnnotationAttributeInfo(org.ballerinalang.util.codegen.attributes.AnnotationAttributeInfo) Test(org.testng.annotations.Test)

Aggregations

AnnAttachmentInfo (org.ballerinalang.util.codegen.AnnAttachmentInfo)10 AnnotationAttributeInfo (org.ballerinalang.util.codegen.attributes.AnnotationAttributeInfo)10 Test (org.testng.annotations.Test)10 AnnAttributeValue (org.ballerinalang.util.codegen.AnnAttributeValue)2 CompileResult (org.ballerinalang.launcher.util.CompileResult)1