Java Code Examples for org.apache.commons.lang.reflect.FieldUtils#writeField()
The following examples show how to use
org.apache.commons.lang.reflect.FieldUtils#writeField() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HomegearClient.java From openhab1-addons with Eclipse Public License 2.0 | 6 votes |
/** * Parses the device informations into the binding model. */ @SuppressWarnings("unchecked") private HmDevice parseDevice(Map<String, ?> deviceData) throws IllegalAccessException { HmDevice device = new HmDevice(); FieldUtils.writeField(device, "address", deviceData.get("ADDRESS"), true); FieldUtils.writeField(device, "type", deviceData.get("TYPE"), true); FieldUtils.writeField(device, "hmInterface", HmInterface.HOMEGEAR, true); Object[] channelList = (Object[]) deviceData.get("CHANNELS"); for (int i = 0; i < channelList.length; i++) { Map<String, ?> channelData = (Map<String, ?>) channelList[i]; device.addChannel(parseChannel(device, channelData)); } return device; }
Example 2
Source File: PurRepository_GetObjectInformation_IT.java From pentaho-kettle with Apache License 2.0 | 6 votes |
private void testDeletedFlagForObject( Callable<RepositoryElementInterface> elementProvider ) throws Exception { TransDelegate transDelegate = new TransDelegate( purRepository, unifiedRepository ); JobDelegate jobDelegate = new JobDelegate( purRepository, unifiedRepository ); FieldUtils.writeField( purRepository, "transDelegate", transDelegate, true ); FieldUtils.writeField( purRepository, "jobDelegate", jobDelegate, true ); RepositoryElementInterface element = elementProvider.call(); RepositoryDirectoryInterface directory = purRepository.findDirectory( element.getRepositoryDirectory().getPath() ); element.setRepositoryDirectory( directory ); purRepository.save( element, null, null ); assertNotNull( "Element was saved", element.getObjectId() ); RepositoryObject information; information = purRepository.getObjectInformation( element.getObjectId(), element.getRepositoryElementType() ); assertNotNull( information ); assertFalse( information.isDeleted() ); purRepository.deleteTransformation( element.getObjectId() ); assertNotNull( "Element was moved to Trash", unifiedRepository.getFileById( element.getObjectId().getId() ) ); information = purRepository.getObjectInformation( element.getObjectId(), element.getRepositoryElementType() ); assertNotNull( information ); assertTrue( information.isDeleted() ); }
Example 3
Source File: BaseHomematicClient.java From openhab1-addons with Eclipse Public License 2.0 | 6 votes |
/** * Adds the battery info datapoint to the specified device if the device has * batteries. */ protected void addBatteryInfo(HmDevice device) throws HomematicClientException { HmBattery battery = HmBatteryTypeProvider.getBatteryType(device.getType()); if (battery != null) { for (HmChannel channel : device.getChannels()) { if ("0".equals(channel.getNumber())) { try { logger.debug("Adding battery type to device {}: {}", device.getType(), battery.getInfo()); HmDatapoint dp = new HmDatapoint(); FieldUtils.writeField(dp, "name", "BATTERY_TYPE", true); FieldUtils.writeField(dp, "writeable", Boolean.FALSE, true); FieldUtils.writeField(dp, "valueType", 20, true); dp.setValue(battery.getInfo()); channel.addDatapoint(dp); } catch (IllegalAccessException ex) { throw new HomematicClientException(ex.getMessage(), ex); } } } } }
Example 4
Source File: ExtensibleTrustManagerImplTest.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Test public void shouldBeResilientAgainstMissingCommonNames() throws CertificateException, IllegalAccessException { FieldUtils.writeField(subject, "defaultTrustManager", defaultTrustManager, true); when(topOfChain.getSubjectX500Principal()).thenReturn(new X500Principal("OU=Smarthome, O=Eclipse, C=DE")); subject.checkClientTrusted(chain, "just"); verify(defaultTrustManager).checkClientTrusted(chain, "just", (Socket) null); verifyNoMoreInteractions(trustmanager); }
Example 5
Source File: ExtensibleTrustManagerImplTest.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Test public void shouldBeResilientAgainstInvalidCertificates() throws CertificateException, IllegalAccessException { FieldUtils.writeField(subject, "defaultTrustManager", defaultTrustManager, true); when(topOfChain.getSubjectX500Principal()) .thenReturn(new X500Principal("CN=example.com, OU=Smarthome, O=Eclipse, C=DE")); when(topOfChain.getSubjectAlternativeNames()) .thenThrow(new CertificateParsingException("Invalid certificate!!!")); subject.checkClientTrusted(chain, "just"); verify(defaultTrustManager).checkClientTrusted(chain, "just", (Socket) null); verifyNoMoreInteractions(trustmanager); }
Example 6
Source File: ExtensibleTrustManagerImplTest.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Test public void shouldNotForwardCallsToMockForDifferentCN() throws CertificateException, IllegalAccessException { FieldUtils.writeField(subject, "defaultTrustManager", defaultTrustManager, true); mockSubjectForCertificate(topOfChain, "CN=example.com, OU=Smarthome, O=Eclipse, C=DE"); mockIssuerForCertificate(topOfChain, "CN=Eclipse, OU=Smarthome, O=Eclipse, C=DE"); mockSubjectForCertificate(bottomOfChain, "CN=Eclipse, OU=Smarthome, O=Eclipse, C=DE"); mockIssuerForCertificate(bottomOfChain, ""); when(topOfChain.getEncoded()).thenReturn(new byte[0]); subject.checkServerTrusted(chain, "just"); verify(defaultTrustManager).checkServerTrusted(chain, "just", (Socket) null); verifyZeroInteractions(trustmanager); }
Example 7
Source File: JSONManipulatorTest.java From pom-manipulation-ext with Apache License 2.0 | 5 votes |
@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(); pluginFile = tf.newFile(); FileUtils.copyURLToFile( resource, npmFile ); URL resource2 = JSONIOTest.class.getResource( "amg-plugin-registry.json"); FileUtils.copyURLToFile( resource2, pluginFile ); }
Example 8
Source File: Serializer.java From das with Apache License 2.0 | 5 votes |
default void writeField(Object target, String fieldName, Object value) { try { FieldUtils.writeField(target, fieldName, value, true); } catch (IllegalAccessException e) { throw new RuntimeException(e); } }
Example 9
Source File: HomegearClient.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
/** * Parses the channel informations into the binding model. */ @SuppressWarnings("unchecked") private HmChannel parseChannel(HmDevice device, Map<String, ?> channelData) throws IllegalAccessException { HmChannel channel = new HmChannel(); FieldUtils.writeField(channel, "device", device, true); FieldUtils.writeField(channel, "number", String.valueOf(channelData.get("INDEX")), true); Map<String, ?> paramsList = (Map<String, ?>) channelData.get("PARAMSET"); for (String name : paramsList.keySet()) { channel.addDatapoint(parseDatapoint(channel, name, (Map<String, ?>) paramsList.get(name))); } return channel; }
Example 10
Source File: HomegearClient.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
/** * Parses the datapoint informations into the binding model. */ private HmDatapoint parseDatapoint(HmChannel channel, String name, Map<String, ?> dpData) throws IllegalAccessException { HmDatapoint dp = new HmDatapoint(); dp.setName(name); FieldUtils.writeField(dp, "channel", channel, true); FieldUtils.writeField(dp, "writeable", dpData.get("WRITEABLE"), true); Object valueList = dpData.get("VALUE_LIST"); if (valueList != null && valueList instanceof Object[]) { Object[] vl = (Object[]) valueList; String[] stringArray = new String[vl.length]; for (int i = 0; i < vl.length; i++) { stringArray[i] = vl[i].toString(); } FieldUtils.writeField(dp, "valueList", stringArray, true); } Object value = dpData.get("VALUE"); String type = (String) dpData.get("TYPE"); boolean isString = StringUtils.equals("STRING", type); if (isString && value != null && !(value instanceof String)) { value = ObjectUtils.toString(value); } setValueType(dp, type, value); if (dp.isNumberValueType()) { FieldUtils.writeField(dp, "minValue", dpData.get("MIN"), true); FieldUtils.writeField(dp, "maxValue", dpData.get("MAX"), true); } dp.setValue(value); return dp; }
Example 11
Source File: ExtensibleTrustManagerImplTest.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Test public void shouldBeResilientAgainstNullSubjectAlternativeNames() throws CertificateException, IllegalAccessException { FieldUtils.writeField(subject, "defaultTrustManager", defaultTrustManager, true); when(topOfChain.getSubjectX500Principal()) .thenReturn(new X500Principal("CN=example.com, OU=Smarthome, O=Eclipse, C=DE")); when(topOfChain.getSubjectAlternativeNames()).thenReturn(null); subject.checkClientTrusted(chain, "just"); verify(defaultTrustManager).checkClientTrusted(chain, "just", (Socket) null); verifyNoMoreInteractions(trustmanager); }
Example 12
Source File: ConverterTest.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
private HmDatapoint getDatapoint(String name, Object value, Number min, Number max, String channelNumber, String deviceType) throws Exception { HmDatapoint dp = new HmDatapoint(); FieldUtils.writeField(dp, "name", name, true); FieldUtils.writeField(dp, "minValue", min, true); FieldUtils.writeField(dp, "maxValue", max, true); Object convertedValue = new TypeGuessAdapter().unmarshal(value == null ? null : value.toString()); if (convertedValue instanceof Boolean) { FieldUtils.writeField(dp, "valueType", 2, true); } else if (convertedValue instanceof Integer) { FieldUtils.writeField(dp, "valueType", 8, true); } else if (convertedValue instanceof Double) { FieldUtils.writeField(dp, "valueType", 4, true); } else { FieldUtils.writeField(dp, "valueType", -1, true); } dp.setValue(convertedValue); HmChannel channel = new HmChannel(); FieldUtils.writeField(dp, "channel", channel, true); FieldUtils.writeField(channel, "number", channelNumber, true); HmDevice device = new HmDevice(); FieldUtils.writeField(device, "type", StringUtils.defaultString(deviceType, ""), true); FieldUtils.writeField(channel, "device", device, true); return dp; }
Example 13
Source File: AbstractWeatherParser.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void setValue(Weather weather, String propertyName, String value) { ProviderMappingInfo providerMappingInfo = metadataHandler.getProviderMappingInfo(weather.getProvider(), propertyName); if (providerMappingInfo != null) { logger.trace("Setting property '{} ({})' with value '{}'", providerMappingInfo.getTarget(), propertyName, value); try { String targetProperty = providerMappingInfo.getTarget(); Object target = PropertyUtils.getNestedObject(weather, targetProperty); String objectProperty = PropertyResolver.last(targetProperty); String preparedValue = stripEmptyValues(value); Converter<?> converter = providerMappingInfo.getConverter(); Object valueToSet = preparedValue == null ? null : converter.convert(preparedValue); if (valueToSet != null) { FieldUtils.writeField(target, objectProperty, valueToSet, true); } } catch (Exception ex) { logger.warn("{}: Error setting property '{}' with value '{}' and converter {}", weather.getProvider(), propertyName, value, providerMappingInfo.getConverter().getType()); } } else { logger.trace("Property not mapped: '{}' with value '{}'", propertyName, value); } }
Example 14
Source File: GaInputStepTest.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Test public void getNextDataEntry_WithPaging() throws Exception { final int recordsCount = 30; final String stepName = "GaInputStepTest"; StepMeta stepMeta = new StepMeta( stepName, stepName, new GaInputStepMeta() ); Trans trans = mock( Trans.class ); TransMeta transMeta = mock( TransMeta.class ); when( transMeta.findStep( stepName ) ).thenReturn( stepMeta ); GaInputStepData data = new GaInputStepData(); GaInputStep step = new GaInputStep( stepMeta, data, 0, transMeta, trans ); FieldUtils.writeField( FieldUtils.getField( GaInputStep.class, "data", true ), step, data, true ); Analytics.Data.Ga.Get mockQuery = prepareMockQuery( recordsCount ); step = spy( step ); doReturn( mockQuery ).when( step ).getQuery( any( Analytics.class ) ); for ( int i = 0; i < recordsCount; i++ ) { List<String> next = step.getNextDataEntry(); assertEquals( Integer.toString( i + 1 ), next.get( 0 ) ); } assertNull( step.getNextDataEntry() ); }
Example 15
Source File: ProcessDefinitionUtils.java From openwebflow with BSD 2-Clause "Simplified" License | 5 votes |
public static void grantPermission(ActivityImpl activity, String assigneeExpression, String candidateGroupIdExpressions, String candidateUserIdExpressions) throws Exception { TaskDefinition taskDefinition = ((UserTaskActivityBehavior) activity.getActivityBehavior()).getTaskDefinition(); taskDefinition.setAssigneeExpression(assigneeExpression == null ? null : new FixedValue(assigneeExpression)); FieldUtils.writeField(taskDefinition, "candidateUserIdExpressions", ExpressionUtils.stringToExpressionSet(candidateUserIdExpressions), true); FieldUtils.writeField(taskDefinition, "candidateGroupIdExpressions", ExpressionUtils.stringToExpressionSet(candidateGroupIdExpressions), true); Logger.getLogger(ProcessDefinitionUtils.class).info( String.format("granting previledges for [%s, %s, %s] on [%s, %s]", assigneeExpression, candidateGroupIdExpressions, candidateUserIdExpressions, activity.getProcessDefinition().getKey(), activity.getProperty("name"))); }
Example 16
Source File: HandleServiceUnavailableTest.java From pom-manipulation-ext with Apache License 2.0 | 4 votes |
/** * Ensures that the version translation does not fail upon receiving 503 * and follow the same behavior as that of a 504. */ @Test public void testTranslateVersionsCorrectSplit() throws IllegalAccessException { List<ProjectVersionRef> data = aLotOfGavs.subList( 0, 37 ); handler.getRequestData().clear(); try { // Decrease the wait time so that the test does not take too long FieldUtils.writeField( versionTranslator, "retryDuration", 5, true); versionTranslator.translateVersions( data ); fail(); } catch ( RestException ex ) { // ok } List<List<Map<String, Object>>> requestData = handler.getRequestData(); // split 37 -> 9, 9, 9, 10 // split 9 -> 2, 2, 2, 3 (x3) // split 10 -> 2, 2, 2, 4 // split 4 -> 1, 1, 1, 1 // 37, 9, 9, 9, 10, 2, 2, 2, 3, ..., 2, 2, 2, 4, 1, 1, 1, 1 -> total 21 chunks // However, split fails after the 6th attempt LOG.debug( requestData.toString() ); assertEquals( 6, requestData.size() ); assertEquals( 37, requestData.get( 0 ).size() ); for ( int i = 1; i < 4; i++ ) assertEquals( 9, requestData.get( i ).size() ); assertEquals( 10, requestData.get( 4 ).size() ); assertEquals( 2, requestData.get( 5 ).size() ); Set<Map<String, Object>> original = new HashSet<>( requestData.get( 0 ) ); Set<Map<String, Object>> chunks = new HashSet<>(); for ( List<Map<String, Object>> e : requestData.subList( 1, 5 ) ) { chunks.addAll( e ); } assertEquals( original, chunks ); }
Example 17
Source File: ConverterTest.java From openhab1-addons with Eclipse Public License 2.0 | 3 votes |
private HmVariable getValueListVariable(Object value, String valueList) throws Exception { HmVariable var = new HmVariable(); FieldUtils.writeField(var, "name", "Var", true); FieldUtils.writeField(var, "valueType", 16, true); FieldUtils.writeField(var, "subType", 29, true); Object convertedValueList = new ValueListAdapter().unmarshal(valueList == null ? null : valueList.toString()); FieldUtils.writeField(var, "valueList", convertedValueList, true); var.setValue(value); return var; }