1 /*******************************************************************************
2 * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * VTT Technical Research Centre of Finland - initial API and implementation
10 *******************************************************************************/
11 package org.simantics.trend;
14 import java.util.UUID;
16 import org.simantics.databoard.util.Bean;
17 import org.simantics.history.Collector;
18 import org.simantics.history.History;
19 import org.simantics.history.HistoryException;
20 import org.simantics.history.util.subscription.SubscriptionItem;
21 import org.simantics.history.HistoryManager;
22 import org.simantics.history.impl.CollectorImpl;
23 import org.simantics.simulation.data.DatasourceAdapter;
24 import org.simantics.simulation.data.PseudoSolver;
25 import org.simantics.trend.configuration.TrendSamplingFormats;
26 import org.simantics.utils.FileUtils;
29 * Test Data initializes PseudoSolver, HistoryCollector and DatasourceRepository
31 * @author Toni Kalajainen <toni.kalajainen@vtt.fi>
33 public class TestData {
35 public PseudoSolver solver;
37 public HistoryManager historyManager;
38 public Collector collector;
39 public DatasourceAdapter adapter;
40 public String subscriptionId = UUID.randomUUID().toString();
42 public TestData() throws HistoryException {
43 historyManager = History.createMemoryHistory();
44 collector = new CollectorImpl( historyManager );
48 public TestData(File workarea) throws HistoryException {
49 this.workarea = workarea;
50 historyManager = History.openFileHistory(workarea);
51 collector = new CollectorImpl( historyManager );
55 void init() throws HistoryException {
56 solver = new PseudoSolver();
57 SubscriptionItem[] hi = null;
58 hi = SubscriptionItem.createItems( PseudoSolver.SINE, subscriptionId, TrendSamplingFormats.createAnalogSamplingFormats(0, 0, "m") );
59 historyManager.create(hi);
60 collector.addItems(hi);
61 hi = SubscriptionItem.createItems( PseudoSolver.RAMP, subscriptionId, TrendSamplingFormats.createBinarySamplingFormats(0) );
62 historyManager.create(hi);
63 collector.addItems(hi);
64 hi = SubscriptionItem.createItems( PseudoSolver.RANDOM, subscriptionId, TrendSamplingFormats.createAnalogSamplingFormats(0, 0, "j") );
65 historyManager.create(hi);
66 collector.addItems(hi);
68 adapter = new DatasourceAdapter( collector );
69 solver.addListener(adapter);
72 public void dispose() {
73 solver.removeListener(adapter);
78 for (Bean bean : collector.getItems()) {
79 String id = (String) bean.getFieldUnchecked("id");
80 historyManager.delete(id);
82 } catch (HistoryException e) {
85 historyManager.close();
86 if (workarea != null) {
87 FileUtils.deleteDir(workarea);