Java Code Examples for org.apache.servicecomb.foundation.common.utils.BeanUtils#getContext()

The following examples show how to use org.apache.servicecomb.foundation.common.utils.BeanUtils#getContext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PojoProducerProvider.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Override
  public List<ProducerMeta> init() {
    // for some test cases, there is no spring context
    if (BeanUtils.getContext() == null) {
      return Collections.emptyList();
    }

    PojoProducers pojoProducers = BeanUtils.getContext().getBean(PojoProducers.class);
    for (ProducerMeta producerMeta : pojoProducers.getProducerMetas()) {
      PojoProducerMeta pojoProducerMeta = (PojoProducerMeta) producerMeta;
      initPojoProducerMeta(pojoProducerMeta);

//      try {
//        producerSchemaFactory.getOrCreateProducerSchema(
//            pojoProducerMeta.getSchemaId(),
//            pojoProducerMeta.getInstanceClass(),
//            pojoProducerMeta.getInstance());
//      } catch (Throwable e) {
//        throw new IllegalArgumentException(
//            "create producer schema failed, class=" + pojoProducerMeta.getInstanceClass().getName(), e);
//      }
    }

    return pojoProducers.getProducerMetas();
  }
 
Example 2
Source File: RestProducerProvider.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Override
public List<ProducerMeta> init() {
  // for some UT case, there is no spring context
  if (BeanUtils.getContext() == null) {
    return null;
  }

  RestProducers restProducers = BeanUtils.getContext().getBean(RestProducers.class);
  return restProducers.getProducerMetaList();
}
 
Example 3
Source File: TestRestServiceProvider.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Test
public void testInit(@Mocked ApplicationContext context) {
  new Expectations(BeanUtils.class) {
    {
      BeanUtils.getContext();
      result = context;
      context.getBean(RestProducers.class);
      result = new RestProducers();
    }
  };

  RestProducerProvider restProducerProvider = new RestProducerProvider();
  restProducerProvider.init();
  Assert.assertEquals(RestConst.REST, restProducerProvider.getName());
}