diff --git a/src/opensesim/chart/SuperDlg.java b/src/opensesim/chart/SuperDlg.java index bf151b9..2c3388b 100644 --- a/src/opensesim/chart/SuperDlg.java +++ b/src/opensesim/chart/SuperDlg.java @@ -24,7 +24,6 @@ * POSSIBILITY OF SUCH DAMAGE. */ package opensesim.chart; -import opensesim.*; /** * diff --git a/src/opensesim/gui/AssetEditor/AssetEditorDialog.java b/src/opensesim/gui/AssetEditor/AssetEditorDialog.java index e610a6a..e652457 100644 --- a/src/opensesim/gui/AssetEditor/AssetEditorDialog.java +++ b/src/opensesim/gui/AssetEditor/AssetEditorDialog.java @@ -30,8 +30,8 @@ import java.awt.Window; import java.lang.annotation.Annotation; import java.lang.reflect.Field; -import opensesim.AbstractAsset; -import opensesim.World; +import opensesim.world.AbstractAsset; +import opensesim.world.World; import opensesim.gui.util.EscDialog; import opensesim.gui.Globals; diff --git a/src/opensesim/gui/AssetEditor/AssetEditorPanel.java b/src/opensesim/gui/AssetEditor/AssetEditorPanel.java index de9eace..7792457 100644 --- a/src/opensesim/gui/AssetEditor/AssetEditorPanel.java +++ b/src/opensesim/gui/AssetEditor/AssetEditorPanel.java @@ -33,7 +33,7 @@ import javax.swing.ComboBoxModel; import javax.swing.DefaultComboBoxModel; import javax.swing.JDialog; import javax.swing.JPanel; -import opensesim.AbstractAsset; +import opensesim.world.AbstractAsset; import opensesim.gui.Globals; import opensesim.gui.util.Json.Export; import opensesim.gui.util.Json.Import; diff --git a/src/opensesim/gui/AssetEditor/AssetListPanel.java b/src/opensesim/gui/AssetEditor/AssetListPanel.java index c1f4d25..b36526c 100644 --- a/src/opensesim/gui/AssetEditor/AssetListPanel.java +++ b/src/opensesim/gui/AssetEditor/AssetListPanel.java @@ -30,8 +30,8 @@ import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableModel; -import opensesim.AbstractAsset; -import opensesim.World; +import opensesim.world.AbstractAsset; +import opensesim.world.World; import opensesim.gui.Globals; import org.json.JSONObject; diff --git a/src/opensesim/gui/AssetEditor/SelectAssetTypeDialog.java b/src/opensesim/gui/AssetEditor/SelectAssetTypeDialog.java index 85a4a2e..2e3b805 100644 --- a/src/opensesim/gui/AssetEditor/SelectAssetTypeDialog.java +++ b/src/opensesim/gui/AssetEditor/SelectAssetTypeDialog.java @@ -31,7 +31,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.ComboBoxModel; import javax.swing.DefaultComboBoxModel; -import opensesim.AbstractAsset; +import opensesim.world.AbstractAsset; import opensesim.gui.Globals; import opensesim.gui.util.EscDialog; diff --git a/src/opensesim/gui/AssetPairEditor/EditAssetPairPanel.java b/src/opensesim/gui/AssetPairEditor/EditAssetPairPanel.java index fc8c4fb..d6fb6f6 100644 --- a/src/opensesim/gui/AssetPairEditor/EditAssetPairPanel.java +++ b/src/opensesim/gui/AssetPairEditor/EditAssetPairPanel.java @@ -1,8 +1,8 @@ package opensesim.gui.AssetPairEditor; import java.util.Collection; -import opensesim.AbstractAsset; -import opensesim.World; +import opensesim.world.AbstractAsset; +import opensesim.world.World; import opensesim.gui.Globals; /* diff --git a/src/opensesim/gui/AssetPairEditor/NewJDialog.java b/src/opensesim/gui/AssetPairEditor/NewJDialog.java index 8816991..dddbf4e 100644 --- a/src/opensesim/gui/AssetPairEditor/NewJDialog.java +++ b/src/opensesim/gui/AssetPairEditor/NewJDialog.java @@ -25,7 +25,7 @@ */ package opensesim.gui.AssetPairEditor; -import opensesim.World; +import opensesim.world.World; import opensesim.gui.util.EscDialog; import opensesim.gui.Globals; diff --git a/src/opensesim/gui/Globals.java b/src/opensesim/gui/Globals.java index 728e3f6..4a4782a 100644 --- a/src/opensesim/gui/Globals.java +++ b/src/opensesim/gui/Globals.java @@ -47,8 +47,8 @@ import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.LookAndFeel; import javax.swing.UIManager; -import opensesim.AbstractAsset; -import opensesim.World; +import opensesim.world.AbstractAsset; +import opensesim.world.World; import opensesim.gui.AssetEditor.AssetEditorPanel; import org.json.JSONArray; import org.json.JSONObject; @@ -299,7 +299,7 @@ public class Globals { prefs = Preferences.userNodeForPackage(c); - world = new World(); + // world = new World(); // initialize urllist used by class loader updateUrlList(); @@ -444,6 +444,13 @@ public class Globals { putTraders(traders); } + + public static JSONObject getWorld(){ + JSONObject world = new JSONObject(); + world.put(PrefKeys.ASSETS, getAssets()); + world.put(PrefKeys.EXCHANGES, getExchanges()); + return world; + } public static void clearAll() { putStrategies(new JSONObject()); diff --git a/src/opensesim/gui/SeSimApplication.java b/src/opensesim/gui/SeSimApplication.java index 16a4cae..6131e9b 100644 --- a/src/opensesim/gui/SeSimApplication.java +++ b/src/opensesim/gui/SeSimApplication.java @@ -597,6 +597,12 @@ public class SeSimApplication extends javax.swing.JFrame { } void startSim() { + + // World = new World(); + + + + resetSim(); JSONObject jo = new JSONObject(Globals.prefs.get("Exchange", "{}")); @@ -990,10 +996,11 @@ public class SeSimApplication extends javax.swing.JFrame { Class c = opensesim.gui.SeSimApplication.class; Globals.initGlobals(c); - String world_source = Globals.prefs.get("world", "{}"); + /* String world_source = Globals.prefs.get("world", "{}"); JSONObject world = new org.json.JSONObject(world_source); Globals.world.putConfig(world); - + */ + //Globals.installLookAndFeels(); diff --git a/src/opensesim/gui/exchangeeditor/ExchangeEditorPanel.java b/src/opensesim/gui/exchangeeditor/ExchangeEditorPanel.java index 99762af..52f5359 100644 --- a/src/opensesim/gui/exchangeeditor/ExchangeEditorPanel.java +++ b/src/opensesim/gui/exchangeeditor/ExchangeEditorPanel.java @@ -25,8 +25,8 @@ */ package opensesim.gui.exchangeeditor; -import opensesim.Exchange; -import opensesim.World; +import opensesim.world.Exchange; +import opensesim.world.World; import opensesim.gui.Globals; import opensesim.gui.util.Json.Export; import opensesim.gui.util.Json.Import; diff --git a/src/opensesim/gui/exchangeeditor/ExchangeListPanel.java b/src/opensesim/gui/exchangeeditor/ExchangeListPanel.java index 5bae2b4..866fc3a 100644 --- a/src/opensesim/gui/exchangeeditor/ExchangeListPanel.java +++ b/src/opensesim/gui/exchangeeditor/ExchangeListPanel.java @@ -27,9 +27,9 @@ package opensesim.gui.exchangeeditor; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableModel; -import opensesim.World; +import opensesim.world.World; import opensesim.gui.Globals; -import opensesim.Exchange; +import opensesim.world.Exchange; import org.json.JSONObject; /** diff --git a/src/opensesim/sesim/AssetPair.java b/src/opensesim/sesim/AssetPair.java index 4cfee73..b092a35 100644 --- a/src/opensesim/sesim/AssetPair.java +++ b/src/opensesim/sesim/AssetPair.java @@ -25,10 +25,11 @@ */ package opensesim.sesim; +import opensesim.world.Order; import java.util.HashMap; import java.util.SortedSet; import java.util.TreeSet; -import opensesim.AbstractAsset; +import opensesim.world.AbstractAsset; import opensesim.sesim.interfaces.Asset; diff --git a/src/opensesim/sesim/Assets/CryptoCurrency.java b/src/opensesim/sesim/Assets/CryptoCurrency.java index b652182..5f56baf 100644 --- a/src/opensesim/sesim/Assets/CryptoCurrency.java +++ b/src/opensesim/sesim/Assets/CryptoCurrency.java @@ -25,7 +25,7 @@ */ package opensesim.sesim.Assets; -import opensesim.AbstractAsset; +import opensesim.world.AbstractAsset; /** * diff --git a/src/opensesim/sesim/Assets/CurrencyAsset.java b/src/opensesim/sesim/Assets/CurrencyAsset.java index 22975e2..065ea10 100644 --- a/src/opensesim/sesim/Assets/CurrencyAsset.java +++ b/src/opensesim/sesim/Assets/CurrencyAsset.java @@ -25,7 +25,7 @@ */ package opensesim.sesim.Assets; -import opensesim.AbstractAsset; +import opensesim.world.AbstractAsset; /** * diff --git a/src/opensesim/sesim/Assets/FurtureAsset.java b/src/opensesim/sesim/Assets/FurtureAsset.java index d0e6675..3ce56a8 100644 --- a/src/opensesim/sesim/Assets/FurtureAsset.java +++ b/src/opensesim/sesim/Assets/FurtureAsset.java @@ -26,7 +26,7 @@ package opensesim.sesim.Assets; import javax.swing.JPanel; -import opensesim.AbstractAsset; +import opensesim.world.AbstractAsset; /** * diff --git a/src/opensesim/sesim/Assets/StockAssett.java b/src/opensesim/sesim/Assets/StockAssett.java index df34184..87bdff8 100644 --- a/src/opensesim/sesim/Assets/StockAssett.java +++ b/src/opensesim/sesim/Assets/StockAssett.java @@ -25,7 +25,7 @@ */ package opensesim.sesim.Assets; -import opensesim.AbstractAsset; +import opensesim.world.AbstractAsset; /** * diff --git a/src/opensesim/sesim/Assets/WarrentAsset.java b/src/opensesim/sesim/Assets/WarrentAsset.java index e74e8f5..0acea40 100644 --- a/src/opensesim/sesim/Assets/WarrentAsset.java +++ b/src/opensesim/sesim/Assets/WarrentAsset.java @@ -25,7 +25,7 @@ */ package opensesim.sesim.Assets; -import opensesim.AbstractAsset; +import opensesim.world.AbstractAsset; /** * diff --git a/src/opensesim/sesim/Order.java b/src/opensesim/sesim/Order.java deleted file mode 100644 index d0b2e49..0000000 --- a/src/opensesim/sesim/Order.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2018, 7u83 <7u83@mail.ru> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -package opensesim.sesim; - -/** - * - * @author 7u83 <7u83@mail.ru> - */ -public class Order implements Comparable{ - - @Override - public int compareTo(Object o) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - /** - * Order status - */ - public enum Status { - OPEN, PARTIALLY_EXECUTED, CLOSED, CANCELED - } - - /** - * Definition of order types - */ - public enum Type { - BUYLIMIT, SELLLIMIT, STOPLOSS, STOPBUY, BUY, SELL - } - - protected double limit; - protected double volume; - - public double getLimit() { - return limit; - } - - public double getVolume() { - return volume; - } - - AssetPair assetPair; - - -} diff --git a/src/opensesim/sesim/interfaces/Asset.java b/src/opensesim/sesim/interfaces/Asset.java index 2ddc700..b1eef09 100644 --- a/src/opensesim/sesim/interfaces/Asset.java +++ b/src/opensesim/sesim/interfaces/Asset.java @@ -27,7 +27,7 @@ package opensesim.sesim.interfaces; import java.util.HashMap; import javax.swing.JPanel; -import opensesim.World; +import opensesim.world.World; import opensesim.util.IDGenerator; import opensesim.util.IDGenerator.Id; diff --git a/src/opensesim/util/AssetVol.java b/src/opensesim/util/AssetVol.java index 00c92cd..25922ef 100644 --- a/src/opensesim/util/AssetVol.java +++ b/src/opensesim/util/AssetVol.java @@ -25,7 +25,7 @@ */ package opensesim.util; -import opensesim.AbstractAsset; +import opensesim.world.AbstractAsset; /** * diff --git a/src/opensesim/util/IDGenerator.java b/src/opensesim/util/IDGenerator.java index 8fc346a..d2e9ffe 100644 --- a/src/opensesim/util/IDGenerator.java +++ b/src/opensesim/util/IDGenerator.java @@ -37,7 +37,7 @@ import java.util.Objects; public class IDGenerator { - public static class Id { + public static class Id implements Comparable{ final Long value; public Id(String id) { @@ -62,6 +62,15 @@ public class IDGenerator { public String toString() { return value.toString(); } + + @Override + public int compareTo(Id o) { + if (this.value>o.value) + return 1; + if (this.value(); } - - - - + } diff --git a/src/opensesim/DefaultFeeModel.java b/src/opensesim/world/DefaultFeeModel.java similarity index 98% rename from src/opensesim/DefaultFeeModel.java rename to src/opensesim/world/DefaultFeeModel.java index 7fce4d5..3e03d3e 100644 --- a/src/opensesim/DefaultFeeModel.java +++ b/src/opensesim/world/DefaultFeeModel.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package opensesim; +package opensesim.world; import opensesim.sesim.AssetPair; import opensesim.sesim.interfaces.FeeModel; diff --git a/src/opensesim/Exchange.java b/src/opensesim/world/Exchange.java similarity index 96% rename from src/opensesim/Exchange.java rename to src/opensesim/world/Exchange.java index 7d2e97f..14ea13d 100644 --- a/src/opensesim/Exchange.java +++ b/src/opensesim/world/Exchange.java @@ -23,16 +23,15 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package opensesim; +package opensesim.world; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.SortedSet; import java.util.TreeSet; -import opensesim.World; +import opensesim.world.World; import opensesim.sesim.AssetPair; -import opensesim.sesim.Order; import opensesim.sesim.interfaces.Configurable; import org.json.JSONObject; @@ -78,7 +77,8 @@ public class Exchange implements Configurable{ } public Order createOrder(Account account, AssetPair pair, Order.Type type, double volume, double limit) { - + Order o = new Order(world,account,pair,type,volume,limit); + return null; } diff --git a/src/opensesim/world/Order.java b/src/opensesim/world/Order.java new file mode 100644 index 0000000..50a34eb --- /dev/null +++ b/src/opensesim/world/Order.java @@ -0,0 +1,174 @@ +/* + * Copyo (c) 2018, 7u83 <7u83@mail.ru> + * All os reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyo notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyo notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package opensesim.world; + +import opensesim.world.Account; +import opensesim.world.World; +import opensesim.sesim.AssetPair; +import opensesim.util.IDGenerator; +import opensesim.util.IDGenerator.Id; + +/** + * + * @author 7u83 <7u83@mail.ru> + */ +public class Order implements Comparable { + + + @Override + public int compareTo(Order o) { + { + double d; + switch (this.type) { + case BUYLIMIT: + case STOPBUY: + case BUY: + d = o.limit - this.limit; + break; + case SELLLIMIT: + case STOPLOSS: + case SELL: + d = this.limit - o.limit; + break; + default: + d = 0; + + } + if (d != 0) { + return d > 0 ? 1 : -1; + } + + d = o.initial_volume - this.initial_volume; + if (d != 0) { + return d > 0 ? 1 : -1; + } + + return this.id.compareTo(o.id); + } + + } + + public enum OrderStatus { + OPEN, PARTIALLY_EXECUTED, CLOSED, CANCELED + } + + /** + * Definition of order types + */ + public enum Type { + BUYLIMIT, SELLLIMIT, STOPLOSS, STOPBUY, BUY, SELL + } + + protected OrderStatus status; + protected Type type; + protected double limit; + protected double volume; + + protected final double initial_volume; + protected final Id id; + protected final long created; + + protected final Account account; + + double cost; + World world; + + Order(World world, Account account, AssetPair pair, Type type, + double volume, double limit) { + + this.account = account; + this.type = type; + this.limit = limit; + this.volume = volume; + this.initial_volume = this.volume; + this.created = 0; + this.status = OrderStatus.OPEN; + this.cost = 0; + // id = Order.idGenerator.getNext(); + this.world=world; + // id = world. + id = null; + } + + public Id getID() { + return id; + } + + public double getVolume() { + return volume; + } + + public double getLimit() { + return limit; + } + + public Type getType() { + return type; + } + + public double getExecuted() { + return initial_volume - volume; + } + + public double getInitialVolume() { + return initial_volume; + } + + public double getCost() { + return cost; + } + + public double getAvaragePrice() { + double e = getExecuted(); + if (e <= 0) { + return -1; + } + return cost / e; + } + + public Account getAccount() { + return account; + } + + public OrderStatus getOrderStatus() { + return status; + } + + public long getCreated() { + return created; + } + + /** + * Get the stock symbol that this order belongs to + * + * @return Stock symbol + */ + public String getStockSymbol() { + // return stock.getSymbol(); + return null; + } + +} diff --git a/src/opensesim/World.java b/src/opensesim/world/World.java similarity index 93% rename from src/opensesim/World.java rename to src/opensesim/world/World.java index 8ebc5e1..6147e31 100644 --- a/src/opensesim/World.java +++ b/src/opensesim/world/World.java @@ -23,7 +23,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -package opensesim; +package opensesim.world; import java.util.ArrayList; import java.util.Collection; @@ -44,9 +44,16 @@ import org.json.JSONObject; */ public class World implements Configurable { + public static final class JKEYS { + public static final String ASSETS = "assets"; + public static final String EXCHANGES = "exchanges"; + } + HashMap assetsById = new HashMap<>(); HashMap assetsBySymbol = new HashMap<>(); IDGenerator assetIdGenerator = new IDGenerator(); + IDGenerator orderIdGenerator = new IDGenerator(); + HashSet assetPairs = new HashSet<>(); @@ -54,8 +61,10 @@ public class World implements Configurable { /** * Create a World object. + * + * @param world */ - public World() { + public World(JSONObject world) { } diff --git a/test/opensesim/sesim/AssetPairTest.java b/test/opensesim/sesim/AssetPairTest.java deleted file mode 100644 index 0b99943..0000000 --- a/test/opensesim/sesim/AssetPairTest.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2018, 7u83 <7u83@mail.ru> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -package opensesim.sesim; - -import opensesim.sesim.Assets.BasicAsset; -import opensesim.sesim.AssetPair; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import static org.junit.Assert.*; - -/** - * - * @author 7u83 <7u83@mail.ru> - */ -public class AssetPairTest { - - public AssetPairTest() { - } - - @BeforeClass - public static void setUpClass() { - } - - @AfterClass - public static void tearDownClass() { - } - - @Before - public void setUp() { - } - - @After - public void tearDown() { - } - - /** - * Test of getAsset method, of class AssetPair. - */ - @Test - public void testGetAsset() { - System.out.println("getAsset"); - AssetPair instance = new AssetPair(null,null); - opensesim.sesim.interfaces.Asset expResult = null; - opensesim.sesim.interfaces.Asset result = instance.getAsset(); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - //fail("The test case is a prototype."); - } - - - /** - * Test of getCurrency method, of class AssetPair. - */ - @Test - public void testGetCurrency() { - System.out.println("getCurrency"); - AssetPair instance = new AssetPair(null,null); - opensesim.sesim.interfaces.Asset expResult = null; - opensesim.sesim.interfaces.Asset result = instance.getCurrency(); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - //fail("The test case is a prototype."); - } - - - /** - * Test of getSymbol method, of class AssetPair. - */ - @Test - public void testGetSymbol() { - System.out.println("getSymbol"); - - BasicAsset asset = new opensesim.sesim.Assets.BasicAsset("AAPL", "Apple", "Apple Inc."); - BasicAsset currency = new opensesim.sesim.Assets.BasicAsset("EUR", "Euro", "Euro desc"); - - AssetPair instance = new AssetPair(asset,currency); - - String expResult = "AAPL/EUR"; - String result = instance.getSymbol(); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - //fail("The test case is a prototype."); - } - -} diff --git a/test/opensesim/sesim/AssetTest.java b/test/opensesim/sesim/AssetTest.java deleted file mode 100644 index 4f36149..0000000 --- a/test/opensesim/sesim/AssetTest.java +++ /dev/null @@ -1,230 +0,0 @@ -/* - * Copyright (c) 2018, 7u83 <7u83@mail.ru> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -package opensesim.sesim; - -import opensesim.sesim.Assets.BasicAsset; -import org.json.JSONObject; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import static org.junit.Assert.*; - -/** - * - * @author 7u83 <7u83@mail.ru> - */ -public class AssetTest { - - public AssetTest() { - } - - @BeforeClass - public static void setUpClass() { - } - - @AfterClass - public static void tearDownClass() { - } - - @Before - public void setUp() { - } - - @After - public void tearDown() { - } - - /** - * Test of getSymbol method, of class Asset. - */ - @Test - public void testGetSymbol() { - System.out.println("getSymbol"); - BasicAsset instance = new BasicAsset(); - String expResult = "EUR"; - instance.setSymbol(expResult); - String result = instance.getSymbol(); - assertEquals(expResult, result); - - } - - /** - * Test of getConfig method, of class Asset. - */ - @Test - public void testGetConfig() { - System.out.println("getConfig"); - BasicAsset instance = new BasicAsset(); - - int decimals = 17; - String symbol = "EUR"; - String description = "Eruo - Europaen currency"; - String name = "Euro"; - - instance.setDecimals(decimals); - instance.setName(name); - instance.setDescription(description); - instance.setSymbol(symbol); - - JSONObject result = instance.getConfig(); - - assertEquals(symbol, result.getString(BasicAsset.JSON_SYMBOL)); - assertEquals(name, result.getString(BasicAsset.JSON_NAME)); - assertEquals(description, result.getString(BasicAsset.JSON_DESCRIPTION)); - assertEquals(decimals, result.getInt(BasicAsset.JSON_DECIMALS)); - - } - - /** - * Test of putConfig method, of class Asset. - */ - @Test - public void testPutConfig() { - System.out.println("putConfig"); - - int decimals = 17; - String symbol = "EUR"; - String name = "Euro"; - String description = "Eruo - Europaen currency"; - - JSONObject cfg = new JSONObject(); - cfg.put(BasicAsset.JSON_SYMBOL, symbol); - cfg.put(BasicAsset.JSON_NAME, name); - cfg.put(BasicAsset.JSON_DESCRIPTION, description); - cfg.put(BasicAsset.JSON_DECIMALS, decimals); - - BasicAsset instance = new BasicAsset(); - instance.putConfig(cfg); - - assertEquals(symbol,instance.getSymbol()); - assertEquals(name,instance.getName()); - assertEquals(description,instance.getDescription()); - assertEquals(decimals,instance.getDecimals()); - - } - - /** - * Test of setSymbol method, of class Asset. - */ - @Test - public void testSetSymbol() { - System.out.println("setSymbol"); - String symbol = "EUR"; - BasicAsset instance = new BasicAsset(); - instance.setSymbol(symbol); - String result = instance.getSymbol(); - assertEquals(symbol, result); - - } - - /** - * Test of getName method, of class Asset. - */ - @Test - public void testGetName() { - System.out.println("getName"); - BasicAsset instance = new BasicAsset(); - String expResult = "Euro"; - instance.setName(expResult); - String result = instance.getName(); - assertEquals(expResult, result); - - } - - /** - * Test of setName method, of class Asset. - */ - @Test - public void testSetName() { - System.out.println("setName"); - String name = "Euro"; - BasicAsset instance = new BasicAsset(); - instance.setName(name); - String result = instance.getName(); - assertEquals(name, result); - - } - - /** - * Test of getDescription method, of class Asset. - */ - @Test - public void testGetDescription() { - System.out.println("getDescription"); - BasicAsset instance = new BasicAsset(); - String expResult = "Euro - European currency"; - instance.setDescription(expResult); - String result = instance.getDescription(); - assertEquals(expResult, result); - - } - - /** - * Test of setDescription method, of class Asset. - */ - @Test - public void testSetDescription() { - System.out.println("setDescription"); - String description = "Eruo - Eruopean currency"; - BasicAsset instance = new BasicAsset(); - instance.setDescription(description); - String result = instance.getDescription(); - assertEquals(description, result); - - } - - /** - * Test of getDecimals method, of class Asset. - */ - @Test - public void testGetDecimals() { - System.out.println("getDecimals"); - BasicAsset instance = new BasicAsset(); - int expResult = 7; - instance.setDecimals(expResult); - int result = instance.getDecimals(); - assertEquals(expResult, result); - - } - - /** - * Test of setDecimals method, of class Asset. - */ - @Test - public void testSetDecimals() { - System.out.println("setDecimals"); - int decimals; - decimals = 350; - BasicAsset instance = new BasicAsset(); - instance.setDecimals(decimals); - int result = instance.getDecimals(); - assertEquals(decimals, result); - - } - -} diff --git a/test/opensesim/sesim/ExchangeTest.java b/test/opensesim/sesim/ExchangeTest.java deleted file mode 100644 index f16a39f..0000000 --- a/test/opensesim/sesim/ExchangeTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2018, 7u83 <7u83@mail.ru> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -package opensesim.sesim; - -import opensesim.Exchange; -import opensesim.sesim.Assets.BasicAsset; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import static org.junit.Assert.*; - -/** - * - * @author 7u83 <7u83@mail.ru> - */ -public class ExchangeTest { - - public ExchangeTest() { - } - - @BeforeClass - public static void setUpClass() { - } - - @AfterClass - public static void tearDownClass() { - } - - @Before - public void setUp() { - } - - @After - public void tearDown() { - } - - /** - * Test of add method, of class Exchange. - */ - @Test - public void testAdd() { - System.out.println("add"); - BasicAsset a = new BasicAsset(); - a.setSymbol("EUR"); - Exchange instance = new Exchange(); - instance.add(a); - // TODO review the generated test code and remove the default call to fail. - //fail("The test case is a prototype."); - } - -}