Coverage Report - org.homeunix.thecave.buddi.plugin.builtin.imports.ImportTestData
 
Classes in this File Line Coverage Branch Coverage Complexity
ImportTestData
0%
0/24
0%
0/10
2.5
 
 1  
 /*
 2  
  * Created on Dec 6, 2007 by wyatt
 3  
  */
 4  
 package org.homeunix.thecave.buddi.plugin.builtin.imports;
 5  
 
 6  
 import java.io.File;
 7  
 import java.util.List;
 8  
 import java.util.logging.Logger;
 9  
 
 10  
 import org.homeunix.thecave.buddi.i18n.keys.BudgetCategoryTypes;
 11  
 import org.homeunix.thecave.buddi.plugin.api.BuddiImportPlugin;
 12  
 import org.homeunix.thecave.buddi.plugin.api.exception.ModelException;
 13  
 import org.homeunix.thecave.buddi.plugin.api.exception.PluginException;
 14  
 import org.homeunix.thecave.buddi.plugin.api.exception.PluginMessage;
 15  
 import org.homeunix.thecave.buddi.plugin.api.model.MutableAccount;
 16  
 import org.homeunix.thecave.buddi.plugin.api.model.MutableBudgetCategory;
 17  
 import org.homeunix.thecave.buddi.plugin.api.model.MutableDocument;
 18  
 import org.homeunix.thecave.buddi.plugin.api.model.MutableModelFactory;
 19  
 import org.homeunix.thecave.buddi.plugin.api.model.MutableTransaction;
 20  
 
 21  
 import ca.digitalcave.moss.common.DateUtil;
 22  
 import ca.digitalcave.moss.swing.MossDocumentFrame;
 23  
 
 24  0
 public class ImportTestData extends BuddiImportPlugin {
 25  
 
 26  
         @Override
 27  
         public void importData(MutableDocument model, MossDocumentFrame callingFrame, File file) throws PluginException, PluginMessage {
 28  
                 try {
 29  0
                         for (int i = 0; i < 5; i++){
 30  0
                                 MutableAccount a = MutableModelFactory.createMutableAccount("ACME " + i, 10000, model.getMutableAccountTypes().get((int) (Math.random() * model.getMutableAccountTypes().size())));
 31  0
                                 model.addAccount(a);                                
 32  
                         }
 33  
                         
 34  0
                         for (int i = 0; i < 15; i++){
 35  0
                                 MutableBudgetCategory bc = MutableModelFactory.createMutableBudgetCategory("ACME" + i, model.getBudgetCategoryType(BudgetCategoryTypes.BUDGET_CATEGORY_TYPE_MONTH), (Math.random() > 0.5));
 36  0
                                 model.addBudgetCategory(bc);
 37  
                         }
 38  
                         
 39  0
                         List<MutableBudgetCategory> budgetCategories = model.getMutableBudgetCategories();
 40  0
                         List<MutableAccount> accounts = model.getMutableAccounts();
 41  
                         
 42  0
                         int MAX = 100000;
 43  0
                         for (int i = 0; i < MAX; i++){
 44  0
                                 if (i % 100 == 0)
 45  0
                                         Logger.getLogger(this.getClass().getName()).info("Creating transaction " + i + " of " + MAX);
 46  0
                                 MutableAccount a = accounts.get((int) (Math.random() * accounts.size()));
 47  0
                                 MutableBudgetCategory bc = budgetCategories.get((int) (Math.random() * budgetCategories.size()));
 48  0
                                 MutableTransaction t = MutableModelFactory.createMutableTransaction(DateUtil.getDate(2006, (int) (Math.random() * 12), (int) (Math.random() * 28)), "Test Transaction " + i, (long) (Math.random() * 1000000), a, bc);
 49  0
                                 model.addTransaction(t);
 50  
                         }
 51  
                 }
 52  0
                 catch (ModelException me){
 53  0
                         throw new PluginException(me);
 54  0
                 }
 55  0
         }
 56  
         
 57  
         @Override
 58  
         public boolean isPromptForFile() {
 59  0
                 return false;
 60  
         }
 61  
         
 62  
         @Override
 63  
         public boolean isCreateNewFile() {
 64  0
                 return true;
 65  
         }
 66  
         
 67  
         public String getName() {
 68  0
                 return "Create Test Data";
 69  
         }
 70  
 }