Search in sources :

Example 6 with PlaceHolderBinder

use of com.alipay.sofa.boot.annotation.PlaceHolderBinder in project sofa-boot by sofastack.

the class PlaceHolderAnnotationTest method testAnnotationPlaceHolder.

@Test
public void testAnnotationPlaceHolder() {
    PlaceHolderBinder placeHolderBinder = new PlaceHolderBinder() {

        @Override
        public String bind(String key) {
            if ("${key}".equals(key)) {
                return "value";
            } else if ("${subKey}".equals(key)) {
                return "subValue";
            } else {
                return "invalid";
            }
        }
    };
    SampleAnnotation origin = SampleClass.class.getAnnotation(SampleAnnotation.class);
    SampleAnnotation delegate = (SampleAnnotation) PlaceHolderAnnotationInvocationHandler.AnnotationWrapperBuilder.wrap(origin).withBinder(placeHolderBinder).build();
    Assert.assertEquals("value", delegate.id());
    Assert.assertEquals("subValue", delegate.bindings()[0].id());
    Assert.assertEquals("invalid", delegate.bindings()[1].id());
}
Also used : PlaceHolderBinder(com.alipay.sofa.boot.annotation.PlaceHolderBinder) Test(org.junit.Test)

Aggregations

PlaceHolderBinder (com.alipay.sofa.boot.annotation.PlaceHolderBinder)6 Test (org.junit.Test)6 PlaceHolderAnnotationInvocationHandler (com.alipay.sofa.boot.annotation.PlaceHolderAnnotationInvocationHandler)4 WrapperAnnotation (com.alipay.sofa.boot.annotation.WrapperAnnotation)4 SofaReference (com.alipay.sofa.runtime.api.annotation.SofaReference)2 SofaReferenceBinding (com.alipay.sofa.runtime.api.annotation.SofaReferenceBinding)2 SofaService (com.alipay.sofa.runtime.api.annotation.SofaService)2 SofaServiceBinding (com.alipay.sofa.runtime.api.annotation.SofaServiceBinding)2 AnnotationSampleService (com.alipay.sofa.runtime.test.beans.service.AnnotationSampleService)2