ControllerConstructorInterceptor implements InstanceConstructorInterceptor { @Override public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { String basePath = ""; RequestMapping basePathRequestMapping = objInst.getClass().getAnnotation(RequestMapping.class); if (basePathRequestMapping != null) { if (basePathRequestMapping.value().length > 0) { basePath = basePathRequestMapping.value()[0]; } else if (basePathRequestMapping.path().length > 0) { basePath = basePathRequestMapping.path()[0]; } } EnhanceRequireObjectCache enhanceRequireObjectCache = new EnhanceRequireObjectCache(); enhanceRequireObjectCache.setPathMappingCache(new PathMappingCache(basePath)); objInst.setSkyWalkingDynamicField(enhanceRequireObjectCache); }  @Override void onConstruct(EnhancedInstance objInst, Object[] allArguments);  }
@Test public void testOnConstruct_Accuracy1() throws Throwable { controllerConstructorInterceptor.onConstruct(inst1, null); EnhanceRequireObjectCache cache = (EnhanceRequireObjectCache) inst1.getSkyWalkingDynamicField(); Assert.assertNotNull(cache); Object obj = new Object(); Method m = obj.getClass().getMethods()[0]; cache.addPathMapping(m, "#toString"); Assert.assertEquals("the two value should be equal", cache.findPathMapping(m), "/test1/#toString"); }
@Test public void testOnConstruct_Accuracy2() throws Throwable { controllerConstructorInterceptor.onConstruct(inst2, null); EnhanceRequireObjectCache cache = (EnhanceRequireObjectCache) inst2.getSkyWalkingDynamicField(); Assert.assertNotNull(cache); Object obj = new Object(); Method m = obj.getClass().getMethods()[0]; cache.addPathMapping(m, "#toString"); Assert.assertEquals("the two value should be equal", cache.findPathMapping(m), "/#toString"); }
@Test public void testOnConstruct_Accuracy3() throws Throwable { controllerConstructorInterceptor.onConstruct(inst3, null); EnhanceRequireObjectCache cache = (EnhanceRequireObjectCache) inst3.getSkyWalkingDynamicField(); Assert.assertNotNull(cache); Object obj = new Object(); Method m = obj.getClass().getMethods()[0]; cache.addPathMapping(m, "#toString"); Assert.assertEquals("the two value should be equal", cache.findPathMapping(m), "/test3/#toString"); }