List of usage examples for org.apache.commons.lang.reflect FieldUtils readDeclaredField
public static Object readDeclaredField(Object target, String fieldName, boolean forceAccess) throws IllegalAccessException
Gets a Field value by name.
From source file:com.teradata.benchto.generator.HiveTypesGeneratorTest.java
private void extractMapperProperties(MapDriver mapDriver) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { HiveTypesGenerator.HiveTypesMapper mapper = (HiveTypesGenerator.HiveTypesMapper) mapDriver.getMapper(); serDe = (SerDe) FieldUtils.readDeclaredField(mapper, "serDe", true); objectInspector = (StructObjectInspector) FieldUtils.readDeclaredField(mapper, "objectInspector", true); hiveObjectsGenerator = (HiveObjectsGenerator) FieldUtils.readDeclaredField(mapper, "hiveObjectsGenerator", true);/*from ww w . j a v a 2 s . c o m*/ }
From source file:com.microfocus.application.automation.tools.octane.executor.UFTTestDetectionService.java
private static boolean isDir(ChangeLogSet.AffectedFile path) { //ONLY for SVN plugin : Check if path is directory if (path.getClass().getName().equals("hudson.scm.SubversionChangeLogSet$Path")) { try {//from ww w.java2s. c om String value = (String) FieldUtils.readDeclaredField(path, "kind", true); return "dir".equals(value); } catch (Exception e) { //treat it as false } } return false; }
From source file:com.hpe.application.automation.tools.octane.executor.UFTTestDetectionService.java
private static boolean isDir(ChangeLogSet.AffectedFile path) { if (path.getClass().getName().equals("hudson.scm.SubversionChangeLogSet$Path")) { try {/*from w ww . ja v a2s . c o m*/ String value = (String) FieldUtils.readDeclaredField(path, "kind", true); return "dir".equals(value); } catch (Exception e) { //treat it as false } } return false; }
From source file:org.alfresco.repo.content.caching.quota.StandardQuotaStrategyMockTest.java
@Test public void testCanSetMaxUsageInMB() throws IllegalAccessException { quota.setMaxUsageMB(0);/*from w w w . j ava 2 s . c om*/ assertEquals(0, ((Long) FieldUtils.readDeclaredField(quota, "maxUsageBytes", true)).longValue()); quota.setMaxUsageMB(500); assertEquals(524288000, ((Long) FieldUtils.readDeclaredField(quota, "maxUsageBytes", true)).longValue()); // 1 GB quota.setMaxUsageMB(1024); assertEquals(1073741824, ((Long) FieldUtils.readDeclaredField(quota, "maxUsageBytes", true)).longValue()); }
From source file:org.gradle.util.JavaReflectionUtil.java
public static Object getProperty(Object target, String property) { try {/*w w w .j av a 2 s .co m*/ return FieldUtils.readDeclaredField(target, property, true); } catch (IllegalAccessException e) { throw new UncheckedException(e); } }
From source file:org.openengsb.core.ekb.persistence.persist.edb.TestTransformationEngine.java
@Override public Object performTransformation(ModelDescription sourceClass, ModelDescription targetClass, Object source, Object target) {/*from w ww . j av a 2 s . com*/ TestModelRegistry registry = new TestModelRegistry(); try { Class<?> clazz = registry.loadModel(sourceClass); for (Field field : clazz.getDeclaredFields()) { String fieldName = field.getName(); if (fieldName.equals(ModelUtils.MODEL_TAIL_FIELD_NAME) || fieldName.contains("LOGGER")) { continue; } Object value = FieldUtils.readDeclaredField(source, fieldName, true); if (value != null) { if (FieldUtils.getDeclaredField(target.getClass(), fieldName, true) == null) { continue; } FieldUtils.writeDeclaredField(target, fieldName, value, true); } } return target; } catch (Exception e) { throw new EKBException("Unable to perform test transformation", e); } }
From source file:org.silverpeas.core.thread.task.RequestTaskManagerTest.java
@SuppressWarnings("unchecked") @Test//from w w w . j a v a 2 s . com public void newRequestPushWakeUpTheTaskBeforeAcquiringAccessToAddTheRequestIntoQueue() throws Exception { // Firstly initializing the monitor by pushing a request TestRequestTaskWithLimit.newEmptyRequest(); RequestTaskMonitor monitor = waitForTaskEndingAfterFirstInit(TestRequestTaskWithLimit.class); // Setting manually the queue monitor.requestList.add(new TestRequestTaskWithLimit.SleepTestRequest(0)); // Acquiring all access monitor.acquireAccess(); monitor.acquireAccess(); Thread.sleep(500); Semaphore semaphore = (Semaphore) FieldUtils.readDeclaredField(monitor, "queueSemaphore", true); assertThat(semaphore.availablePermits(), is(0)); assertThat(monitor.isTaskRunning(), is(false)); assertThat(monitor.task, nullValue()); assertThat(monitor.taskWatcher, nullValue()); assertThat(monitor.requestList.size(), is(1)); assertThat(getCounter(), is(0)); // Starting the thread by adding a new request whereas the semaphore has no more available // permits. TestRequestTaskWithLimit.newRandomSleepRequest(); waitForTaskEndingAtEndOfTest(TestRequestTaskWithLimit.class); assertThatThreadsAreStoppedAndMonitorsAreCleanedAndQueuesAreConsummed(monitor); assertThat(counter, is(2)); }