Example usage for org.apache.commons.lang3.reflect FieldUtils writeField

List of usage examples for org.apache.commons.lang3.reflect FieldUtils writeField

Introduction

In this page you can find the example usage for org.apache.commons.lang3.reflect FieldUtils writeField.

Prototype

public static void writeField(final Object target, final String fieldName, final Object value,
        final boolean forceAccess) throws IllegalAccessException 

Source Link

Document

Writes a Field .

Usage

From source file:org.apache.usergrid.persistence.model.util.EntityUtils.java

/**
 * Set the id into the entity//from w  w  w.  jav  a  2s .c om
 */
public static void setId(Entity entity, Id id) {
    try {
        FieldUtils.writeField(ID, entity, id, true);
    } catch (IllegalAccessException e) {
        throw new RuntimeException("Unable to set the field " + ID + " into the entity", e);
    }
}

From source file:org.eclipse.hawkbit.repository.jpa.model.CacheFieldEntityListener.java

/**
 * enriches the JPA entities after loading the entity from the SQL database.
 * /*from ww w .  j  a  v a 2  s  .c om*/
 * @param target
 *            the target which has been loaded from the database
 */
@PostLoad
public void postLoad(final Object target) {
    if (target instanceof Identifiable) {
        final CacheManager cacheManager = CacheManagerHolder.getInstance().getCacheManager();
        @SuppressWarnings("rawtypes")
        final String id = ((Identifiable) target).getId().toString();
        final Class<? extends Object> type = target.getClass();
        findCacheFields(type, id, (field, cacheKey, id1) -> {
            final Cache cache = cacheManager.getCache(type.getName());
            final ValueWrapper valueWrapper = cache
                    .get(CacheKeys.entitySpecificCacheKey(id1.toString(), cacheKey));
            if (valueWrapper != null && valueWrapper.get() != null) {
                FieldUtils.writeField(field, target, valueWrapper.get(), true);
            }
        });
    }
}

From source file:org.edgexfoundry.BaseServiceTest.java

@Before
public void setup() throws IllegalAccessException {
    MockitoAnnotations.initMocks(this);
    FieldUtils.writeField(baseService, "serviceName", TEST_SERVICE_NAME, true);
    FieldUtils.writeField(baseService, "host", TEST_HOST, true);
    FieldUtils.writeField(baseService, "port", TEST_PORT, true);
    FieldUtils.writeField(baseService, "labels", TEST_LABELS, true);
    FieldUtils.writeField(baseService, "callbackUrl", TEST_CALLBACK_URL, true);
    FieldUtils.writeField(baseService, "initRetries", TEST_RETRIES, true);
    FieldUtils.writeField(baseService, "initInterval", TEST_INTERVAL, true);
}

From source file:org.edgexfoundry.BaseServiceTest.java

@Test
public void testAddDefaultSchedules() throws IllegalAccessException {
    SimpleSchedule schedule = SimpleScheduleData.newTestInstance();
    FieldUtils.writeField(baseService, "defaultSchedules", schedule, true);
    baseService.addDefaultSchedules();/* ww  w . j  a  va 2 s . co m*/
}

From source file:org.edgexfoundry.BaseServiceTest.java

@Test
public void testAddDefaultScheduleEvents() throws IllegalAccessException {
    SimpleScheduleEvent event = SimpleScheduleEventData.newTestInstance();
    FieldUtils.writeField(baseService, "defaultScheduleEvents", event, true);
    baseService.addDefaultScheduleEvents();
}

From source file:org.edgexfoundry.BaseServiceTest.java

@Test
public void testAddDefaultScheduleEventsWithExistingAddressable() throws IllegalAccessException {
    Addressable addressable = AddressableData.newTestInstance();
    DeviceService service = ServiceData.newTestInstance();
    service.setAddressable(addressable);
    SimpleScheduleEvent event = SimpleScheduleEventData.newTestInstance();
    FieldUtils.writeField(baseService, "defaultScheduleEvents", event, true);
    Mockito.when(serviceClient.deviceServiceForName(event.getService()[0])).thenReturn(service);
    baseService.addDefaultScheduleEvents();
}

From source file:org.edgexfoundry.engine.CommandExecutorTest.java

@Test
public void testFireCommandNoClient() throws IllegalAccessException {
    FieldUtils.writeField(executor, "client", null, true);
    executor.fireCommand(TEST_DEVICE, TEST_CMD, TEST_BODY);
}

From source file:org.edgexfoundry.engine.RuleCreatorTest.java

@Before
public void setup() throws IllegalAccessException, IOException {
    MockitoAnnotations.initMocks(this);
    FieldUtils.writeField(creator, FIELD_LOC, TEMP_LOC, true);
    FieldUtils.writeField(creator, FIELD_NAME, TEMP_NAME, true);
    FieldUtils.writeField(creator, FIELD_ENC, TEMP_ENC, true);
    creator.init();/*www. j a v a 2 s  .co  m*/
    rule = RuleData.newTestInstance();
}

From source file:org.edgexfoundry.engine.RuleCreatorTest.java

@Test(expected = IOException.class)
public void testInitException() throws NoSuchFieldException, SecurityException, IllegalArgumentException,
        IllegalAccessException, IOException {
    FieldUtils.writeField(creator, FIELD_LOC, "foobar", true);
    creator.init();/*from   w w w.  j  a va  2  s. c om*/
}

From source file:org.edgexfoundry.engine.RuleCreatorTest.java

@Test(expected = IOException.class)
public void testCreateDroolRuleIOException() throws IllegalAccessException, TemplateException, IOException {
    FieldUtils.writeField(creator, FIELD_NAME, "foobar", true);
    creator.createDroolRule(rule);/*from www .j a  v a  2  s .c  o  m*/
}