Samples JDK
Test.java
1 package com.freemindcafe.apache.commons.beanutils.sample1;
2 
3 import java.util.ArrayList;
4 import java.util.List;
5 
6 import junit.framework.Assert;
7 
8 import org.apache.commons.beanutils.PropertyUtils;
9 
10 public class Test {
11 
12  @org.junit.Test
13  public void it_is_easy_to_pull_the_indexed_properties() throws Exception{
15 
16  List<String> profiles = new ArrayList<String>(10);
17  profiles.add("profile 1");
18  profiles.add("profile 2");
19  //req.setProfiles(profiles);
20 
21  List<DeviceConfigurationProfile> deviceConfigurationProfiles = new ArrayList<>();
22  DeviceConfigurationProfile deviceConfigurationProfile = new DeviceConfigurationProfile();
23  deviceConfigurationProfile.setXmlMessage("first xml message");
24  deviceConfigurationProfiles.add(deviceConfigurationProfile);
25  //req.setDeviceConfigurations(deviceConfigurationProfiles);
26 
27  Assert.assertTrue(PropertyUtils.getProperty(req, "profiles[0]").equals("profile 1"));
28  Assert.assertTrue(PropertyUtils.getProperty(req, "profiles[1]").equals("profile 2"));
29  Assert.assertTrue(PropertyUtils.getProperty(req, "deviceConfigurations[0].xmlMessage").equals("first xml message"));
30 
31  }
32 
33  @org.junit.Test
34  public void can_we_set_the_indexed_property() throws Exception{
36  req.setDeviceConfigurations(0, null);
37  req.setDeviceConfigurations(1, null);
38 
39  PropertyUtils.setProperty(req, "profiles[0]", "profile 1");
40  PropertyUtils.setProperty(req, "profiles[1]", "profile 2");
41  PropertyUtils.setProperty(req, "deviceConfigurations[0].xmlMessage", "First xml message");
42 
43  Assert.assertTrue(req.getProfiles().get(0).equalsIgnoreCase("profile 1"));
44  Assert.assertTrue(req.getProfiles().get(1).equalsIgnoreCase("profile 2"));
45  Assert.assertTrue(req.getDeviceConfigurations().get(0).getXmlMessage().equalsIgnoreCase("First xml messag"));
46 
47  }
48 
49 }
void setDeviceConfigurations(int index, DeviceConfigurationProfile deviceConfiguration)