DynamicCatalogAccessorProvider extends AbstractAnnotationCatalogAccessorProvider { @Override public CatalogAccessor getCatalogAccessor() { final List<BrokerServiceAccessor> serviceAccessors = new ArrayList<>(); final String[] serviceBrokers = context.getBeanNamesForAnnotation(ServiceBroker.class); for (String serviceBrokerName : serviceBrokers) { final Object serviceBroker = context.getBean(serviceBrokerName); final Class<?> clazz = getBeanClass(serviceBrokerName); final Method method = findMethodWithAnnotation(clazz, DynamicCatalog.class); if (method != null) { validateReturnType(method, DynamicCatalog.class, Catalog.class); try { final Catalog catalog = (Catalog) invokeMethod(serviceBroker, method); for (CatalogService catalogService : catalog.getServices()) { serviceAccessors.add(getMethodAccessor(serviceBrokerName, catalogService)); } } catch (Throwable e) { LOGGER.warn("The broker (" + serviceBrokerName + ") fails to return its catalog", e); } } } return new CatalogAccessor(serviceAccessors); }  @Override CatalogAccessor getCatalogAccessor();  }
@Test public void catalog() { final BrokerServiceAccessor serviceAccessor = getProvider().getCatalogAccessor().getServiceAccessor(BROKER_ID); final CatalogService serviceDescription = serviceAccessor.getServiceDescription(); assertEquals(BROKER_ID, serviceDescription.getId()); assertEquals(SERVICE_NAME, serviceDescription.getName()); assertEquals(SERVICE_DESCRIPTION, serviceDescription.getDescription()); assertEquals(1, serviceDescription.getPlans().size()); final Plan plan = serviceDescription.getPlans().get(0); assertEquals(PLAN_ID, plan.getId()); assertEquals(PLAN_NAME, plan.getName()); assertEquals(PLAN_DESCRIPTION, plan.getDescription()); final ServiceDashboardClient dashboardClient = serviceDescription.getDashboardClient(); assertNotNull(dashboardClient); assertEquals(DASHBOARD_CLIENT_ID, dashboardClient.getId()); assertEquals(DASHBOARD_SECRET, dashboardClient.getSecret()); assertEquals(DASHBOARD_URI, dashboardClient.getRedirectUri()); }
@Test(expectedExceptions = NotFoundException.class) public void serviceNotExist() { getProvider().getCatalogAccessor().getServiceAccessor("1234"); }