1 /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
16 * The Original Code is Rhino code, released
19 * The Initial Developer of the Original Code is
20 * Netscape Communications Corporation.
21 * Portions created by the Initial Developer are Copyright (C) 1997-2000
22 * the Initial Developer. All Rights Reserved.
29 * Alternatively, the contents of this file may be used under the terms of
30 * either the GNU General Public License Version 2 or later (the "GPL"), or
31 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
32 * in which case the provisions of the GPL or the LGPL are applicable instead
33 * of those above. If you wish to allow use of your version of this file only
34 * under the terms of either the GPL or the LGPL, and not to allow others to
35 * use your version of this file under the terms of the MPL, indicate your
36 * decision by deleting the provisions above and replace them with the notice
37 * and other provisions required by the GPL or the LGPL. If you do not delete
38 * the provisions above, a recipient may use your version of this file under
39 * the terms of any one of the MPL, the GPL or the LGPL.
41 * ***** END LICENSE BLOCK ***** */
44 START("11.6.2 - XMLList Assignment");
46 // Set the name of the only customer in the order to Fred Jones
50 <name>John Smith</name>
53 <description>Big Screen Television</description>
54 <price>1299.99</price>
57 <description>DVD Player</description>
65 <name>Fred Jones</name>
68 <description>Big Screen Television</description>
69 <price>1299.99</price>
72 <description>DVD Player</description>
77 order.customer.name = "Fred Jones";
78 TEST(1, correct, order);
80 // Replace all the hobbies for the only customer in the order
84 <name>John Smith</name>
88 <description>Big Screen Television</description>
89 <price>1299.99</price>
92 <description>DVD Player</description>
100 <name>John Smith</name>
101 <hobby>shopping</hobby>
104 <description>Big Screen Television</description>
105 <price>1299.99</price>
108 <description>DVD Player</description>
109 <price>399.99</price>
113 order.customer.hobby = "shopping"
114 TEST(2, correct, order);
116 // Attempt to set the sale date of the item. Throw an exception if more than 1 item exists.
120 <name>John Smith</name>
123 <description>Big Screen Television</description>
124 <price>1299.99</price>
125 <saledate>01-05-2002</saledate>
132 <name>John Smith</name>
135 <description>Big Screen Television</description>
136 <price>1299.99</price>
137 <saledate>05-07-2002</saledate>
141 order.item.saledate = "05-07-2002"
142 TEST(3, correct, order);
147 <name>John Smith</name>
148 <hobby>Biking</hobby>
151 <description>Big Screen Television</description>
152 <price>1299.99</price>
155 <description>DVD Player</description>
156 <price>399.99</price>
161 order.item.saledate = "05-07-2002";
164 TEST(4, "TypeError", ex.name);
167 // Replace all the employee's hobbies with their new favorite pastime
173 <hobby>skiing</hobby>
178 <hobby>running</hobby>
183 <hobby>Biking</hobby>
192 <hobby>skiing</hobby>
197 <hobby>running</hobby>
202 <hobby>working</hobby>
206 emps.employee.(@id == 3).hobby = "working";
207 TEST(5, correct, emps);
209 // Replace the first employee with George
242 emps.employee[0] = <employee id="4"><name>George</name><age>27</age></employee>;
243 TEST(6, emps, correct);
245 // Add a new employee to the end of the employee list
282 emps.employee += <employee id="4"><name>Frank</name><age>39</age></employee>;
283 TEST(7, correct, emps);
285 // Add a new employee to the end of the employee list
322 emps.employee[emps.employee.length()] = <employee id="4"><name>Frank</name><age>39</age></employee>;
323 TEST(7, correct, emps);