001 /******************************************************************************
002 * Copyright (C) MActor Developers. All rights reserved. *
003 * ---------------------------------------------------------------------------*
004 * This file is part of MActor. *
005 * *
006 * MActor is free software; you can redistribute it and/or modify *
007 * it under the terms of the GNU General Public License as published by *
008 * the Free Software Foundation; either version 2 of the License, or *
009 * (at your option) any later version. *
010 * *
011 * MActor is distributed in the hope that it will be useful, *
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
014 * GNU General Public License for more details. *
015 * *
016 * You should have received a copy of the GNU General Public License *
017 * along with MActor; if not, write to the Free Software *
018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
019 ******************************************************************************/
020 package org.mactor.framework.spec;
021
022 import java.util.Iterator;
023 import java.util.LinkedList;
024 import java.util.List;
025
026 import org.dom4j.Document;
027 import org.dom4j.Element;
028 import org.mactor.framework.MactorException;
029
030 public class MockBatterySpec {
031 private String name;
032 private int threadCount = 1;
033 public List<String> getTests() {
034 return tests;
035 }
036 public List<TestSpec> getTestSpecs() throws MactorException {
037 List<TestSpec> ts = new LinkedList<TestSpec>();
038 for (String t : tests)
039 ts.add(TestSpec.loadFromFile(t));
040 return ts;
041 }
042 public int getThreadCount() {
043 return threadCount;
044 }
045 public String getType() {
046 return "mock_battery";
047 }
048 public static MockBatterySpec loadFromFile(String name) throws MactorException {
049 return MockBatterySpec.loadFromDocument(ProjectContext.getGlobalInstance().readFromFile(name, false), name);
050 }
051 private List<String> tests = new LinkedList<String>();
052 public static MockBatterySpec loadFromDocument(Document doc, String name) throws MactorException {
053 if (doc == null)
054 throw new MactorException("Invalid document: null");
055 Element element = doc.getRootElement();
056 if (element == null)
057 throw new MactorException("Invalid MockBattery: null");
058 MockBatterySpec b = new MockBatterySpec();
059 b.name = name;
060 if (element.attributeValue("test_threads") != null)
061 b.threadCount = Integer.parseInt(element.attributeValue("test_threads"));
062 Iterator it = element.elementIterator("test");
063 while (it.hasNext()) {
064 Element e = (Element) it.next();
065 b.tests.add(e.attributeValue("name"));
066 }
067 return b;
068 }
069 public String getName() {
070 return name;
071 }
072 }