List of usage examples for org.apache.commons.lang.reflect FieldUtils writeField
public static void writeField(Object target, String fieldName, Object value, boolean forceAccess) throws IllegalAccessException
From source file:com.adobe.acs.commons.reports.models.TagsCellValueTest.java
@Test public void testExporter() throws IllegalAccessException { log.info("testExporter"); TagsCellValue val = new TagsCellValue(); FieldUtils.writeField(val, "property", "tags", true); FieldUtils.writeField(val, "request", request, true); assertTrue(ArrayUtils.isEquals(new Tag[] { tag1, tag2 }, val.getTags().toArray(new Tag[val.getTags().size()]))); log.info("Test successful!"); }
From source file:com.cognifide.slice.mapper.GenericSlingMapper.java
private <T> void mapResourceToField(final Resource resource, final T object, ValueMap valueMap, Field field) throws IllegalAccessException { MapperStrategy mapperStrategy = mapperStrategyFactory.getMapperStrategy(field.getDeclaringClass()); if (shouldFieldBeMapped(field, mapperStrategy)) { Object value = getValueForField(resource, valueMap, field); if (value == null && field.getType().isPrimitive()) { // don't write null values to primitive return; }/*from w ww . ja v a 2 s .c o m*/ FieldUtils.writeField(field, object, value, ReflectionHelper.FORCE_ACCESS); } }
From source file:com.adobe.acs.commons.hc.impl.HealthCheckStatusEmailerTest.java
@Test public void throttledExecution() throws IllegalAccessException { results.add(failureExecutionResult); config.put(HealthCheckStatusEmailer.PROP_SEND_EMAIL_ONLY_ON_FAILURE, true); // Set a long delay to ensure we hit it on the 2nd .run() call.. config.put(HealthCheckStatusEmailer.PROP_HEALTH_CHECK_TIMEOUT_OVERRIDE, 100000); healthCheckStatusEmailer.activate(config); Calendar minuteAgo = Calendar.getInstance(); // Make sure enough time has "ellapsed" so that the call to send email does something minuteAgo.add(Calendar.MINUTE, -1); minuteAgo.add(Calendar.SECOND, -1); FieldUtils.writeField(healthCheckStatusEmailer, "nextEmailTime", minuteAgo, true); // Send the first time healthCheckStatusEmailer.run();/*from ww w .j a v a 2s . c o m*/ // Get throttled the 2nd time healthCheckStatusEmailer.run(); verify(emailService, times(1)).sendEmail(any(String.class), any(Map.class), any(String[].class)); }
From source file:gov.va.vinci.leo.ae.LeoBaseAnnotator.java
/** * Initialize this annotator./*from w w w .java 2 s. c o m*/ * * @param aContext the UimaContext to initialize with. * @param params the annotator params to load from the descriptor. * * @see org.apache.uima.analysis_component.JCasAnnotator_ImplBase#initialize(org.apache.uima.UimaContext) * @param aContext * @param params * @throws ResourceInitializationException if any exception occurs during initialization. */ public void initialize(UimaContext aContext, ConfigurationParameter[] params) throws ResourceInitializationException { super.initialize(aContext); if (params != null) { for (ConfigurationParameter param : params) { if (param.isMandatory()) { /** Check for null value **/ if (aContext.getConfigParameterValue(param.getName()) == null) { throw new ResourceInitializationException(new IllegalArgumentException( "Required parameter: " + param.getName() + " not set.")); } /** Check for empty as well if it is a plain string. */ if (ConfigurationParameter.TYPE_STRING.equals(param.getType()) && !param.isMultiValued() && GenericValidator .isBlankOrNull((String) aContext.getConfigParameterValue(param.getName()))) { throw new ResourceInitializationException(new IllegalArgumentException( "Required parameter: " + param.getName() + " cannot be blank.")); } } parameters.put(param, aContext.getConfigParameterValue(param.getName())); /** Set the parameter value in the class field variable **/ try { Field field = FieldUtils.getField(this.getClass(), param.getName(), true); if (field != null) { FieldUtils.writeField(field, this, aContext.getConfigParameterValue(param.getName()), true); } } catch (IllegalAccessException e) { logger.warn("Could not set field (" + param.getName() + "). Field not found on annotator class to reflectively set."); } } } }
From source file:org.alfresco.solr.SolrCoreTestBase.java
@Before public void setUpBase() throws Exception { coreContainer = new CoreContainer(); coreDescriptor = new CoreDescriptor(coreContainer, "name", "instanceDir"); when(resourceLoader.getCoreProperties()).thenReturn(new Properties()); // SolrCore is final, we can't mock with mockito core = new SolrCore("name", coreDescriptor); FieldUtils.writeField(core, "updateHandler", updateHandler, true); FieldUtils.writeField(core, "resourceLoader", resourceLoader, true); infoRegistry = new HashMap<String, SolrInfoMBean>(); FieldUtils.writeField(core, "infoRegistry", infoRegistry, true); reqHandlers = new RequestHandlers(core); reqHandlers.register("/select", selectRequestHandler); reqHandlers.register("/afts", aftsRequestHandler); FieldUtils.writeField(core, "reqHandlers", reqHandlers, true); Map<String, UpdateRequestProcessorChain> map = new HashMap<>(); UpdateRequestProcessorFactory[] factories = new UpdateRequestProcessorFactory[] { runUpdateProcessorFactory }; when(runUpdateProcessorFactory.getInstance(any(SolrQueryRequest.class), any(SolrQueryResponse.class), any(UpdateRequestProcessor.class))).thenReturn(processor); UpdateRequestProcessorChain def = new UpdateRequestProcessorChain(factories, core); map.put(null, def);//from w w w .j a va 2 s. co m map.put("", def); FieldUtils.writeField(core, "updateProcessorChains", map, true); }
From source file:org.alfresco.solr.tracker.AclTrackerTest.java
@Test public void trackingAbortsWhenAlreadyRunning() throws Throwable { trackerState.setRunning(true);//from w w w . j av a 2s . c om // Prove running state, before attempt to track() assertTrue(trackerState.isRunning()); FieldUtils.writeField(tracker, "state", trackerState, true); tracker.track(); // Still running - these values are unaffected. assertTrue(trackerState.isRunning()); assertFalse(trackerState.isCheck()); // Prove doTrack() was not called verify(tracker, never()).doTrack(); }
From source file:org.alfresco.solr.tracker.AclTrackerTest.java
@Test public void canClose() throws IllegalAccessException { ThreadHandler threadHandler = (ThreadHandler) FieldUtils.readField(tracker, "threadHandler", true); threadHandler = spy(threadHandler);//from ww w .j av a2s. c o m FieldUtils.writeField(tracker, "threadHandler", threadHandler, true); tracker.close(); // AclTracker specific verify(threadHandler).shutDownThreadPool(); // Applicable to all AbstractAclTracker verify(client).close(); }
From source file:org.carewebframework.ui.zk.ZKUtil.java
/** * Wires variables from a map into a controller. Useful to inject parameters passed in an * argument map./* www . j av a 2 s.c o m*/ * * @param map The argument map. * @param controller The controller to be wired. */ public static void wireController(Map<?, ?> map, Object controller) { if (map == null || map.isEmpty() || controller == null) { return; } for (Entry<?, ?> entry : map.entrySet()) { String key = entry.getKey().toString(); Object value = entry.getValue(); try { PropertyUtils.setProperty(controller, key, value); } catch (Exception e) { try { FieldUtils.writeField(controller, key, value, true); } catch (Exception e1) { } } } }
From source file:org.commonjava.maven.ext.core.impl.JSONManipulatorTest.java
@Before public void setup() throws IOException, IllegalAccessException { FieldUtils.writeField(jsonManipulator, "jsonIO", new JSONIO(), true); URL resource = JSONIOTest.class.getResource("npm-shrinkwrap.json"); npmFile = tf.newFile();/*from w w w. j a v a 2 s . co m*/ pluginFile = tf.newFile(); FileUtils.copyURLToFile(resource, npmFile); URL resource2 = JSONIOTest.class.getResource("amg-plugin-registry.json"); FileUtils.copyURLToFile(resource2, pluginFile); }
From source file:org.commonjava.maven.ext.manip.impl.DistributionEnforcingManipulatorTest.java
@Before public void before() throws Exception { userCliProperties = new Properties(); session = new ManipulationSession(); final GalleyInfrastructure galleyInfra = new GalleyInfrastructure(session.getTargetDir(), session.getRemoteRepositories(), session.getLocalRepository(), session.getSettings(), session.getActiveProfiles(), null, null, null, temp.newFolder("cache-dir")); final GalleyAPIWrapper wrapper = new GalleyAPIWrapper(galleyInfra); manipulator = new DistributionEnforcingManipulator(); FieldUtils.writeField(manipulator, "galleyWrapper", wrapper, true); }