org.apache.commons.lang.reflect.FieldUtils#readStaticField ( )源码实例Demo

下面列出了org.apache.commons.lang.reflect.FieldUtils#readStaticField ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: das   文件: RefreshableDataSourceTest.java
@Test
public void test() throws SQLException, IllegalAccessException {
    DasClient client = DasClientFactory.getClient("MySqlSimple");
    SqlBuilder sqlBuilder = SqlBuilder.selectCount().from(Person.PERSON).intoObject();
    Number before = client.queryObject(sqlBuilder);

    DataSourceConfigure oldConfig = DataSourceConfigureLocatorManager.getInstance().getDataSourceConfigure("dal_shard_0");
    DataSourceConfigure newConfig = new DataSourceConfigure(oldConfig.getName(), oldConfig.getProperties());
    DataSourceConfigureChangeEvent event = new DataSourceConfigureChangeEvent("testEvent", newConfig, oldConfig);

    ConcurrentHashMap<String, DataSource> dss = (ConcurrentHashMap<String, DataSource>) FieldUtils.readStaticField(DataSourceLocator.class, "cache", true);
    RefreshableDataSource dataSource = (RefreshableDataSource) dss.get("dal_shard_0");
    SingleDataSource oldSingleDataSource = ((AtomicReference<SingleDataSource>)FieldUtils.readField(dataSource, "dataSourceReference", true)).get();
    dataSource.configChanged(event);
    Number after = client.queryObject(sqlBuilder);

    //verify datasource changed
    assertNotSame(oldSingleDataSource, ((AtomicReference<SingleDataSource>)FieldUtils.readField(dataSource, "dataSourceReference", true)).get());
    //verify new datasource work fine
    assertEquals(before, after);
}
 
源代码2 项目: hop   文件: SFTPPutDialogTest.java
@BeforeClass
public static void hackPropsUi() throws Exception {
  Field props = getPropsField();
  if ( props == null ) {
    throw new IllegalStateException( "Cannot find 'props' field in " + Props.class.getName() );
  }

  Object value = FieldUtils.readStaticField( props, true );
  if ( value == null ) {
    PropsUI mock = mock( PropsUI.class );
    FieldUtils.writeStaticField( props, mock, true );
    changedPropsUi = true;
  } else {
    changedPropsUi = false;
  }
}
 
源代码3 项目: hop   文件: TextFileInputDialogTest.java
@BeforeClass
public static void hackPropsUi() throws Exception {
  Field props = getPropsField();
  if ( props == null ) {
    throw new IllegalStateException( "Cannot find 'props' field in " + Props.class.getName() );
  }

  Object value = FieldUtils.readStaticField( props, true );
  if ( value == null ) {
    PropsUI mock = mock( PropsUI.class );
    FieldUtils.writeStaticField( props, mock, true );
    changedPropsUi = true;
  } else {
    changedPropsUi = false;
  }
}
 
源代码4 项目: pentaho-kettle   文件: SFTPPutDialogTest.java
@BeforeClass
public static void hackPropsUi() throws Exception {
  Field props = getPropsField();
  if ( props == null ) {
    throw new IllegalStateException( "Cannot find 'props' field in " + Props.class.getName() );
  }

  Object value = FieldUtils.readStaticField( props, true );
  if ( value == null ) {
    PropsUI mock = mock( PropsUI.class );
    FieldUtils.writeStaticField( props, mock, true );
    changedPropsUi = true;
  } else {
    changedPropsUi = false;
  }
}
 
源代码5 项目: pentaho-kettle   文件: TextFileInputDialogTest.java
@BeforeClass
public static void hackPropsUi() throws Exception {
  Field props = getPropsField();
  if ( props == null ) {
    throw new IllegalStateException( "Cannot find 'props' field in " + Props.class.getName() );
  }

  Object value = FieldUtils.readStaticField( props, true );
  if ( value == null ) {
    PropsUI mock = mock( PropsUI.class );
    FieldUtils.writeStaticField( props, mock, true );
    changedPropsUi = true;
  } else {
    changedPropsUi = false;
  }
}
 
@BeforeClass
public static void hackPropsUi() throws Exception {
  Field props = getPropsField();
  if ( props == null ) {
    throw new IllegalStateException( "Cannot find 'props' field in " + Props.class.getName() );
  }
  Object value = FieldUtils.readStaticField( props, true );
  if ( value == null ) {
    PropsUI mock = mock( PropsUI.class );
    FieldUtils.writeStaticField( props, mock, true );
    changedPropsUi = true;
  } else {
    changedPropsUi = false;
  }
}