1
2
3
4
5
6
7
8
9
10
11
12
13 package org.gscg.serialize;
14
15 import java.awt.Dimension;
16 import java.io.Serializable;
17 import java.rmi.MarshalledObject;
18 import java.rmi.RemoteException;
19 import java.util.logging.Level;
20
21 import javax.media.j3d.Bounds;
22 import javax.vecmath.Point3d;
23
24 import junit.framework.Assert;
25 import junit.framework.TestCase;
26 import nl.tudelft.simulation.dsol.animation.LocatableInterface;
27 import nl.tudelft.simulation.dsol.experiment.Experiment;
28 import nl.tudelft.simulation.dsol.simulators.DEVSSimulator;
29 import nl.tudelft.simulation.dsol.simulators.DEVSSimulatorInterface;
30 import nl.tudelft.simulation.language.d3.BoundingBox;
31 import nl.tudelft.simulation.language.d3.DirectedPoint;
32 import nl.tudelft.simulation.language.io.URLResource;
33 import nl.tudelft.simulation.logger.Logger;
34 import nl.tudelft.simulation.supplychain.animation.ContentAnimation;
35 import nl.tudelft.simulation.supplychain.content.InternalDemand;
36 import nl.tudelft.simulation.supplychain.content.RequestForQuote;
37
38 import org.gscg.ActorImplementation;
39 import org.gscg.TestExperiment;
40 import org.gscg.TestModel;
41 import org.gscg.common.interactionlayer.location.YellowPage;
42 import org.gscg.common.interactionlayer.messaging.ScenarioText;
43 import org.gscg.common.interactionlayer.timecontrol.GlobalProgressDateAndTime;
44 import org.gscg.common.interactionlayer.timecontrol.GlobalRowOrColumnNumber;
45 import org.gscg.experiment.DistributorParser;
46 import org.gscg.experiment.Distributors;
47 import org.gscg.experiment.ManufacturerParser;
48 import org.gscg.experiment.Manufacturers;
49 import org.gscg.experiment.MarketParser;
50 import org.gscg.experiment.Markets;
51 import org.gscg.experiment.ProductParser;
52 import org.gscg.experiment.Products;
53 import org.gscg.game.GameGlobalData;
54 import org.gscg.gameleader.animation2D.DistributedGisLegendRenderable;
55 import org.gscg.gameleader.animation2D.DistributedGisRenderable2D;
56 import org.gscg.gameleader.animation2D.DistributedSingleImageRenderable;
57 import org.gscg.gameleader.animation2D.GisActorAnimation;
58 import org.gscg.gameleader.animation2D.GisLegendRenderable;
59 import org.gscg.singleuser.interactionlayer.DistributorSingleUserInteractionLayer;
60
61 /***
62 * This class defines the JUnit test for the SerializeTest
63 * <p>
64 * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628 BX
65 * Delft, the Netherlands. All rights reserved.
66 *
67 * See for project information <a href="http://www.simulation.tudelft.nl/">
68 * www.simulation.tudelft.nl </a>.
69 *
70 * The source code and binary code of this software is proprietary information
71 * of Delft University of Technology.
72 *
73 * @author <a
74 * href="http://www.tbm.tudelft.nl/webstaf/stijnh/index.htm">Stijn-Pieter
75 * van Houten </a>
76 * @version $Revision: 1.3 $ $Date: 2005/08/09 15:43:42 $
77 * @since 1.0.11
78 */
79 public class SerializeTest extends TestCase implements Serializable
80 {
81 /*** the serial version uid */
82 private static final long serialVersionUID = 11L;
83
84 /*** TEST_METHOD_NAME refers to the name of the test method */
85 public static final String TEST_METHOD_NAME = "test";
86
87 /***
88 * constructs a new SerializeTest
89 */
90 public SerializeTest()
91 {
92 super(SerializeTest.TEST_METHOD_NAME);
93 }
94
95 /*** test the serializability of the game objects */
96 public void test()
97 {
98 try
99 {
100 Logger.setLogLevel(Level.SEVERE);
101
102 Experiment experiment = TestExperiment.createExperiment();
103 DEVSSimulatorInterface simulator = new DEVSSimulator();
104 experiment.setSimulator(simulator);
105 experiment.setModel(new TestModel(experiment));
106
107 try
108 {
109 simulator.initialize(experiment.getTreatments()[0]
110 .getRunControl().getReplications()[0]);
111 experiment.start();
112
113
114
115
116 String xsd = URLResource.getResource("/product.xsd")
117 .toExternalForm();
118 ProductParser.parseProducts(xsd, URLResource
119 .getResource("/products.xml"));
120
121
122
123
124 xsd = URLResource.getResource("/manufacturer.xsd")
125 .toExternalForm();
126 ManufacturerParser.parseManufacturers(xsd, URLResource
127 .getResource("/manufacturers.xml"), null, simulator);
128
129
130
131
132 xsd = URLResource.getResource("/distributor.xsd")
133 .toExternalForm();
134 DistributorParser.parseDistributors(xsd, URLResource
135 .getResource("/distributors.xml"), null, simulator);
136
137
138
139
140 xsd = URLResource.getResource("/market.xsd").toExternalForm();
141 MarketParser.parseMarkets(xsd, URLResource
142 .getResource("/markets.xml"), simulator);
143
144
145
146
147
148
149 new MarshalledObject(Products.getProductsArray()[0]);
150
151
152 new MarshalledObject(new ActorImplementation("name", simulator,
153 new Point3d(0.0, 0.0, 0.0)));
154 new MarshalledObject(Manufacturers.getManufacturersArray()[0]);
155 new MarshalledObject(Distributors.getDistributorsArray()[0]);
156 new MarshalledObject(Markets.getMarketsArray()[0]);
157 new MarshalledObject(new YellowPage());
158
159
160 new MarshalledObject(new Dimension(0, 0));
161 new MarshalledObject(
162 new GisActorAnimation(
163 new Locatable(new DirectedPoint(0.0, 0.0, 0.0),
164 null),
165 simulator,
166 URLResource
167 .getResource("/nl/tudelft/simulation/supplychain/images/Market.gif")));
168 new MarshalledObject(new GisLegendRenderable(
169 new DirectedPoint(), simulator, null));
170
171
172 new MarshalledObject(
173 new DistributedSingleImageRenderable(
174 new Locatable(new DirectedPoint(0.0, 0.0, 0.0),
175 null),
176 simulator,
177 URLResource
178 .getResource("/nl/tudelft/simulation/supplychain/images/Market.gif")));
179 new MarshalledObject(new DistributedGisLegendRenderable(
180 new DirectedPoint(0.0, 0.0, 0.0), simulator));
181 new MarshalledObject(new DistributedGisRenderable2D(URLResource
182 .getResource("/world.map.xml")));
183
184
185 InternalDemand id = new InternalDemand(Manufacturers
186 .getManufacturersArray()[0], Products
187 .getProductsArray()[0], 10, 0.0, 0.0);
188 RequestForQuote rfq = new RequestForQuote(Manufacturers
189 .getManufacturersArray()[0], Distributors
190 .getDistributorsArray()[0], id, Products
191 .getProductsArray()[0], 10.0);
192 new MarshalledObject(new ContentAnimation(rfq, 10.0));
193
194
195
196 new GlobalProgressDateAndTime(simulator);
197 new GlobalRowOrColumnNumber(simulator);
198
199 GameGlobalData globalSupplyChainData = new GameGlobalData(
200 simulator);
201 new MarshalledObject(globalSupplyChainData);
202 new MarshalledObject(new DistributorSingleUserInteractionLayer(
203 simulator, "id",
204 Distributors.getDistributorsArray()[0],
205 globalSupplyChainData));
206 new MarshalledObject(new ScenarioText(simulator));
207 } catch (NullPointerException exception)
208 {
209
210 exception = null;
211 }
212
213 } catch (Exception exception)
214 {
215 exception.printStackTrace();
216 Assert.fail(exception.getMessage());
217 }
218 }
219 /***
220 * A private implementation of a locatable class.
221 * <p>
222 * (c) copyright 2005 <a href="http://www.simulation.tudelft.nl">Delft
223 * University of Technology </a>, the Netherlands. <br>
224 * See for project information <a
225 * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a>
226 * <br>
227 *
228 * Copyright (c) 2003-2005 Delft University of Technology, Jaffalaan 5, 2628
229 * BX Delft, the Netherlands. All rights reserved.
230 *
231 * See for project information <a href="http://www.simulation.tudelft.nl/">
232 * www.simulation.tudelft.nl </a>.
233 *
234 * The source code and binary code of this software are proprietary
235 * information of Delft University of Technology.
236 *
237 * @author <a
238 * href="http://www.tbm.tudelft.nl/webstaf/stijnh/index.htm">Stijn-Pieter
239 * van Houten </a>
240 * @version $Revision: 1.3 $ $Date: 2005/08/09 15:43:42 $
241 * @since 1.1.3
242 */
243 private class Locatable implements LocatableInterface, Serializable
244 {
245 /*** the serial version uid */
246 private static final long serialVersionUID = 10L;
247
248 /*** the location */
249 private DirectedPoint location = null;
250
251 /*** the bounds */
252 private BoundingBox bounds = null;
253
254 /***
255 * constructs a new Locatable
256 *
257 * @param location the location
258 * @param bounds the bounds
259 */
260 public Locatable(final DirectedPoint location, final BoundingBox bounds)
261 {
262 super();
263 this.location = location;
264 this.bounds = bounds;
265 }
266
267 /***
268 * @see nl.tudelft.simulation.dsol.animation.LocatableInterface#getLocation()
269 */
270 public DirectedPoint getLocation() throws RemoteException
271 {
272 return this.location;
273 }
274
275 /***
276 * @see nl.tudelft.simulation.dsol.animation.LocatableInterface#getBounds()
277 */
278 public Bounds getBounds() throws RemoteException
279 {
280 return this.bounds;
281 }
282 }
283 }