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

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

Introduction

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

Prototype

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

Source Link

Document

Write a field.

Usage

From source file:com.adobe.acs.commons.reports.models.StringReportCellCSVExporterTest.java

@Test
public void testMultiple() throws IllegalAccessException {
    log.info("testMultiple");
    StringReportCellCSVExporter exporter = new StringReportCellCSVExporter();
    FieldUtils.writeField(exporter, "property", "multiple", true);
    assertEquals(StringUtils.join(ARRAY_VALUE, ";"), exporter.getValue(mockResource));
    log.info("Test successful!");
}

From source file:com.adobe.acs.commons.reports.models.DateReportCellCSVExporterTest.java

@Test
public void testExporter() throws IllegalAccessException {
    log.info("testExporter");

    DateReportCellCSVExporter exporter = new DateReportCellCSVExporter();
    FieldUtils.writeField(exporter, "property", "now", true);
    FieldUtils.writeField(exporter, "format", FORMAT, true);

    String formattedDate = new SimpleDateFormat(FORMAT).format(start.getTime());
    assertEquals(formattedDate, exporter.getValue(mockResource));

    log.info("Test successful!");
}

From source file:ch.algotrader.util.FieldUtil.java

/**
 * copies all field values by direct field access.
 *///from w  w  w  .j a va  2s. c om
public static void copyAllFields(Object source, Object target) {

    for (Field field : FieldUtil.getAllFields(target.getClass())) {

        try {
            Object targetValue = FieldUtils.readField(field, source, true);
            FieldUtils.writeField(field, target, targetValue, true);
        } catch (IllegalAccessException e) {
            LOGGER.error("problem copying field", e);
        }
    }
}

From source file:com.adobe.acs.commons.reports.models.StringReportCellCSVExporterTest.java

@Test
public void testNotFound() throws IllegalAccessException {
    log.info("testNotFound");
    StringReportCellCSVExporter exporter = new StringReportCellCSVExporter();
    FieldUtils.writeField(exporter, "property", "somethingelse", true);
    assertEquals("", exporter.getValue(mockResource));
    log.info("Test successful!");
}

From source file:com.adobe.acs.commons.reports.models.DateReportCellCSVExporterTest.java

@Test
public void testNullProperty() throws IllegalAccessException {
    log.info("testNullProperty");

    DateReportCellCSVExporter exporter = new DateReportCellCSVExporter();
    FieldUtils.writeField(exporter, "property", "someothertime", true);
    FieldUtils.writeField(exporter, "format", FORMAT, true);

    assertNull(exporter.getValue(mockResource));

    log.info("Test successful!");
}

From source file:com.adobe.acs.commons.reports.models.TagReportCellCSVExporterTest.java

@Test
public void testEmpty() throws IllegalAccessException {
    log.info("testEmpty");
    TagReportCellCSVExporter exporter = new TagReportCellCSVExporter();
    FieldUtils.writeField(exporter, "property", "tags2", true);
    assertEquals("", exporter.getValue(mockResource));
    log.info("Test successful!");
}

From source file:com.adobe.acs.commons.reports.models.StringReportCellCSVExporterTest.java

@Test
public void testSingle() throws IllegalAccessException {
    log.info("testSingle");
    StringReportCellCSVExporter exporter = new StringReportCellCSVExporter();
    FieldUtils.writeField(exporter, "property", "single", true);
    assertEquals(ARRAY_VALUE[0], exporter.getValue(mockResource));
    log.info("Test successful!");
}

From source file:com.adobe.acs.commons.reports.models.TagsCellValueTest.java

@Test
public void testEmpty() throws IllegalAccessException {
    log.info("testEmpty");
    TagsCellValue val = new TagsCellValue();
    FieldUtils.writeField(val, "property", "tags2", true);
    FieldUtils.writeField(val, "request", request, true);
    List<Tag> tags = val.getTags();
    assertEquals(0, tags.size());//from  ww  w.java  2 s .  c  om
    log.info("Test successful!");
}

From source file:com.adobe.acs.commons.reports.models.TagReportCellCSVExporterTest.java

@Test
public void testExporter() throws IllegalAccessException {
    log.info("testExporter");
    TagReportCellCSVExporter exporter = new TagReportCellCSVExporter();
    FieldUtils.writeField(exporter, "property", "tags", true);
    assertEquals(StringUtils.join(TAGS_VALUE, ";"), exporter.getValue(mockResource));
    log.info("Test successful!");
}

From source file:com.adobe.acs.commons.reports.models.DateReportCellCSVExporterTest.java

@Test
public void testDefaultFormatting() throws IllegalAccessException {
    log.info("testDefaultFormatting");

    DateReportCellCSVExporter exporter = new DateReportCellCSVExporter();
    FieldUtils.writeField(exporter, "property", "now", true);

    String formattedDate = start.getTime().toString();
    assertEquals(formattedDate, exporter.getValue(mockResource));

    log.info("Test successful!");
}