[New] Implemented Model tests
Added tests to test creating Resource and Order and each has a ParameterBag. The bag has all kinds of Parameters added and each is tested that it exists and that the right value is stored
This commit is contained in:
parent
6b5860c05f
commit
c324b22adf
|
@ -29,6 +29,7 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
|
import li.strolch.model.parameter.Parameter;
|
||||||
|
|
||||||
import org.dom4j.Element;
|
import org.dom4j.Element;
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ import li.strolch.model.parameter.DateParameter;
|
||||||
import li.strolch.model.parameter.FloatParameter;
|
import li.strolch.model.parameter.FloatParameter;
|
||||||
import li.strolch.model.parameter.IntegerParameter;
|
import li.strolch.model.parameter.IntegerParameter;
|
||||||
import li.strolch.model.parameter.LongParameter;
|
import li.strolch.model.parameter.LongParameter;
|
||||||
|
import li.strolch.model.parameter.Parameter;
|
||||||
import li.strolch.model.parameter.StringParameter;
|
import li.strolch.model.parameter.StringParameter;
|
||||||
|
|
||||||
import org.dom4j.Element;
|
import org.dom4j.Element;
|
||||||
|
|
|
@ -25,7 +25,6 @@ import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.AbstractStrolchElement;
|
import li.strolch.model.AbstractStrolchElement;
|
||||||
import li.strolch.model.Locator;
|
import li.strolch.model.Locator;
|
||||||
import li.strolch.model.Locator.LocatorBuilder;
|
import li.strolch.model.Locator.LocatorBuilder;
|
||||||
import li.strolch.model.Parameter;
|
|
||||||
import li.strolch.model.ParameterizedElement;
|
import li.strolch.model.ParameterizedElement;
|
||||||
|
|
||||||
import org.dom4j.Element;
|
import org.dom4j.Element;
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
package li.strolch.model.parameter;
|
package li.strolch.model.parameter;
|
||||||
|
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.Parameter;
|
|
||||||
|
|
||||||
import org.dom4j.Element;
|
import org.dom4j.Element;
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,6 @@ package li.strolch.model.parameter;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
|
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.Parameter;
|
|
||||||
|
|
||||||
import org.dom4j.Element;
|
import org.dom4j.Element;
|
||||||
|
|
||||||
|
@ -32,7 +31,6 @@ import ch.eitchnet.utils.helper.StringHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class DateParameter extends AbstractParameter<Long> {
|
public class DateParameter extends AbstractParameter<Long> {
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
package li.strolch.model.parameter;
|
package li.strolch.model.parameter;
|
||||||
|
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.Parameter;
|
|
||||||
|
|
||||||
import org.dom4j.Element;
|
import org.dom4j.Element;
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
package li.strolch.model.parameter;
|
package li.strolch.model.parameter;
|
||||||
|
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.Parameter;
|
|
||||||
|
|
||||||
import org.dom4j.Element;
|
import org.dom4j.Element;
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@ package li.strolch.model.parameter;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import li.strolch.model.Parameter;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
package li.strolch.model.parameter;
|
package li.strolch.model.parameter;
|
||||||
|
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.Parameter;
|
|
||||||
|
|
||||||
import org.dom4j.Element;
|
import org.dom4j.Element;
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,12 @@
|
||||||
* along with li.strolch.model. If not, see
|
* along with li.strolch.model. If not, see
|
||||||
* <http://www.gnu.org/licenses/>.
|
* <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package li.strolch.model;
|
package li.strolch.model.parameter;
|
||||||
|
|
||||||
|
import li.strolch.model.Order;
|
||||||
|
import li.strolch.model.ParameterizedElement;
|
||||||
|
import li.strolch.model.Resource;
|
||||||
|
import li.strolch.model.StrolchElement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert von Burg <eitch@eitchnet.ch>
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
|
@ -113,6 +113,9 @@ public class StringListParameter extends AbstractParameter<List<String>> impleme
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setValue(List<String> value) {
|
public void setValue(List<String> value) {
|
||||||
|
validateValue(value);
|
||||||
|
if (this.value == null)
|
||||||
|
this.value = new ArrayList<String>(value.size());
|
||||||
this.value.clear();
|
this.value.clear();
|
||||||
this.value.addAll(value);
|
this.value.addAll(value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
package li.strolch.model.parameter;
|
package li.strolch.model.parameter;
|
||||||
|
|
||||||
import li.strolch.exception.StrolchException;
|
import li.strolch.exception.StrolchException;
|
||||||
import li.strolch.model.Parameter;
|
|
||||||
|
|
||||||
import org.dom4j.Element;
|
import org.dom4j.Element;
|
||||||
|
|
||||||
|
|
|
@ -1,39 +0,0 @@
|
||||||
package li.strolch;
|
|
||||||
|
|
||||||
import li.strolch.model.Order;
|
|
||||||
import li.strolch.model.Parameter;
|
|
||||||
import li.strolch.model.ParameterBag;
|
|
||||||
import li.strolch.model.Resource;
|
|
||||||
import li.strolch.model.State;
|
|
||||||
import li.strolch.model.parameter.FloatParameter;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class ModelTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldCreateResource() {
|
|
||||||
|
|
||||||
Resource resource = new Resource("@res01", "Test resource", "MyType");
|
|
||||||
|
|
||||||
ParameterBag bag = new ParameterBag("@bag01", "Test Bag", "Test");
|
|
||||||
|
|
||||||
Parameter<Double> floatParam = new FloatParameter("@param1", "Float Param", 44.3);
|
|
||||||
bag.addParameter(floatParam);
|
|
||||||
|
|
||||||
resource.addParameterBag(bag);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldCreateOrder() {
|
|
||||||
|
|
||||||
Order order = new Order("@ord01", "Test Order", "MyType", System.currentTimeMillis(), State.OPEN);
|
|
||||||
|
|
||||||
ParameterBag bag = new ParameterBag("@bag01", "Test Bag", "Test");
|
|
||||||
|
|
||||||
Parameter<Double> floatParam = new FloatParameter("@param1", "Float Param", 44.3);
|
|
||||||
bag.addParameter(floatParam);
|
|
||||||
|
|
||||||
order.addParameterBag(bag);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,84 @@
|
||||||
|
package li.strolch.test.model;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import junit.framework.Assert;
|
||||||
|
import li.strolch.model.Order;
|
||||||
|
import li.strolch.model.ParameterBag;
|
||||||
|
import li.strolch.model.Resource;
|
||||||
|
import li.strolch.model.State;
|
||||||
|
import li.strolch.model.parameter.BooleanParameter;
|
||||||
|
import li.strolch.model.parameter.DateParameter;
|
||||||
|
import li.strolch.model.parameter.FloatParameter;
|
||||||
|
import li.strolch.model.parameter.IntegerParameter;
|
||||||
|
import li.strolch.model.parameter.LongParameter;
|
||||||
|
import li.strolch.model.parameter.StringListParameter;
|
||||||
|
import li.strolch.model.parameter.StringParameter;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class ModelTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldCreateResource() {
|
||||||
|
|
||||||
|
Resource resource = ModelTestHelper.createResource("@res01", "Test resource", "MyType");
|
||||||
|
ParameterBag bag = resource.getParameterBag(ModelTestHelper.BAG_ID);
|
||||||
|
validateBag(bag);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldCreateOrder() {
|
||||||
|
|
||||||
|
Order order = ModelTestHelper.createOrder("@ord01", "Test Order", "MyType", System.currentTimeMillis(),
|
||||||
|
State.OPEN);
|
||||||
|
ParameterBag bag = order.getParameterBag(ModelTestHelper.BAG_ID);
|
||||||
|
validateBag(bag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void validateBag(ParameterBag bag) {
|
||||||
|
|
||||||
|
Assert.assertNotNull(bag);
|
||||||
|
|
||||||
|
Assert.assertEquals(ModelTestHelper.BAG_ID, bag.getId());
|
||||||
|
Assert.assertEquals(ModelTestHelper.BAG_NAME, bag.getName());
|
||||||
|
Assert.assertEquals(ModelTestHelper.BAG_TYPE, bag.getType());
|
||||||
|
|
||||||
|
validateParams(bag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void validateParams(ParameterBag bag) {
|
||||||
|
|
||||||
|
BooleanParameter boolParam = bag.getParameter(ModelTestHelper.PARAM_BOOLEAN_ID);
|
||||||
|
Assert.assertNotNull("Boolean Param missing with id " + ModelTestHelper.PARAM_BOOLEAN_ID, boolParam);
|
||||||
|
Assert.assertEquals(true, boolParam.getValue().booleanValue());
|
||||||
|
|
||||||
|
FloatParameter floatParam = bag.getParameter(ModelTestHelper.PARAM_FLOAT_ID);
|
||||||
|
Assert.assertNotNull("Float Param missing with id " + ModelTestHelper.PARAM_FLOAT_ID, floatParam);
|
||||||
|
Assert.assertEquals(44.3, floatParam.getValue().doubleValue());
|
||||||
|
|
||||||
|
IntegerParameter integerParam = bag.getParameter(ModelTestHelper.PARAM_INTEGER_ID);
|
||||||
|
Assert.assertNotNull("Integer Param missing with id " + ModelTestHelper.PARAM_INTEGER_ID, integerParam);
|
||||||
|
Assert.assertEquals(77, integerParam.getValue().intValue());
|
||||||
|
|
||||||
|
LongParameter longParam = bag.getParameter(ModelTestHelper.PARAM_LONG_ID);
|
||||||
|
Assert.assertNotNull("Long Param missing with id " + ModelTestHelper.PARAM_LONG_ID, longParam);
|
||||||
|
Assert.assertEquals(4453234566L, longParam.getValue().longValue());
|
||||||
|
|
||||||
|
StringParameter stringParam = bag.getParameter(ModelTestHelper.PARAM_STRING_ID);
|
||||||
|
Assert.assertNotNull("String Param missing with id " + ModelTestHelper.PARAM_STRING_ID, stringParam);
|
||||||
|
Assert.assertEquals("Strolch", stringParam.getValue());
|
||||||
|
|
||||||
|
DateParameter dateParam = bag.getParameter(ModelTestHelper.PARAM_DATE_ID);
|
||||||
|
Assert.assertNotNull("Date Param missing with id " + ModelTestHelper.PARAM_DATE_ID, dateParam);
|
||||||
|
Assert.assertEquals(1354295525628L, dateParam.getValue().longValue());
|
||||||
|
|
||||||
|
StringListParameter stringListP = bag.getParameter(ModelTestHelper.PARAM_LIST_STRING_ID);
|
||||||
|
Assert.assertNotNull("StringList Param missing with id " + ModelTestHelper.PARAM_LIST_STRING_ID, stringListP);
|
||||||
|
|
||||||
|
ArrayList<String> stringList = new ArrayList<String>();
|
||||||
|
stringList.add("Hello");
|
||||||
|
stringList.add("World");
|
||||||
|
Assert.assertEquals(stringList, stringListP.getValue());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,178 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012, Robert von Burg
|
||||||
|
*
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This file is part of the XXX.
|
||||||
|
*
|
||||||
|
* XXX is free software: you can redistribute
|
||||||
|
* it and/or modify it under the terms of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the License,
|
||||||
|
* or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* XXX is distributed in the hope that it will
|
||||||
|
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with XXX. If not, see
|
||||||
|
* <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package li.strolch.test.model;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import li.strolch.model.Order;
|
||||||
|
import li.strolch.model.ParameterBag;
|
||||||
|
import li.strolch.model.Resource;
|
||||||
|
import li.strolch.model.State;
|
||||||
|
import li.strolch.model.parameter.BooleanParameter;
|
||||||
|
import li.strolch.model.parameter.DateParameter;
|
||||||
|
import li.strolch.model.parameter.FloatParameter;
|
||||||
|
import li.strolch.model.parameter.IntegerParameter;
|
||||||
|
import li.strolch.model.parameter.LongParameter;
|
||||||
|
import li.strolch.model.parameter.Parameter;
|
||||||
|
import li.strolch.model.parameter.StringListParameter;
|
||||||
|
import li.strolch.model.parameter.StringParameter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Robert von Burg <eitch@eitchnet.ch>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class ModelTestHelper {
|
||||||
|
|
||||||
|
public static final String PARAM_BOOLEAN_ID = "@param1";
|
||||||
|
public static final String PARAM_BOOLEAN_NAME = "Boolean Param";
|
||||||
|
|
||||||
|
public static final String PARAM_FLOAT_ID = "@param2";
|
||||||
|
public static final String PARAM_FLOAT_NAME = "Float Param";
|
||||||
|
|
||||||
|
public static final String PARAM_INTEGER_ID = "@param3";
|
||||||
|
public static final String PARAM_INTEGER_NAME = "Integer Param";
|
||||||
|
|
||||||
|
public static final String PARAM_LONG_ID = "@param4";
|
||||||
|
public static final String PARAM_LONG_NAME = "Long Param";
|
||||||
|
|
||||||
|
public static final String PARAM_STRING_ID = "@param5";
|
||||||
|
public static final String PARAM_STRING_NAME = "String Param";
|
||||||
|
|
||||||
|
public static final String PARAM_DATE_ID = "@param6";
|
||||||
|
public static final String PARAM_DATE_NAME = "Date Param";
|
||||||
|
|
||||||
|
public static final String PARAM_LIST_STRING_ID = "@param7";
|
||||||
|
public static final String PARAM_LIST_STRING_NAME = "StringList Param";
|
||||||
|
|
||||||
|
public static final String BAG_ID = "@bag01";
|
||||||
|
public static final String BAG_NAME = "Test Bag";
|
||||||
|
public static final String BAG_TYPE = "TestBag";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an {@link Resource} with the given values and adds a {@link ParameterBag} by calling
|
||||||
|
* {@link #createParameterBag(String, String, String)}
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* the id of the {@link Resource}
|
||||||
|
* @param name
|
||||||
|
* the name of the {@link Resource}
|
||||||
|
* @param type
|
||||||
|
* the type of the {@link Resource}
|
||||||
|
*
|
||||||
|
* @return the newly created {@link Resource}
|
||||||
|
*/
|
||||||
|
public static Resource createResource(String id, String name, String type) {
|
||||||
|
Resource resource = new Resource(id, name, type);
|
||||||
|
ParameterBag bag = createParameterBag(BAG_ID, BAG_NAME, BAG_TYPE);
|
||||||
|
resource.addParameterBag(bag);
|
||||||
|
|
||||||
|
return resource;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an {@link Order} with the given values and adds a {@link ParameterBag} by calling
|
||||||
|
* {@link #createParameterBag(String, String, String)}
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* the id of the {@link Order}
|
||||||
|
* @param name
|
||||||
|
* the name of the {@link Order}
|
||||||
|
* @param type
|
||||||
|
* the type of the {@link Order}
|
||||||
|
* @param date
|
||||||
|
* the date of the {@link Order}
|
||||||
|
* @param state
|
||||||
|
* the {@link State} of the {@link Order}
|
||||||
|
*
|
||||||
|
* @return the newly created {@link Order}
|
||||||
|
*/
|
||||||
|
public static Order createOrder(String id, String name, String type, long date, State state) {
|
||||||
|
|
||||||
|
Order order = new Order(id, name, type, date, state);
|
||||||
|
ParameterBag bag = createParameterBag(BAG_ID, BAG_NAME, BAG_TYPE);
|
||||||
|
order.addParameterBag(bag);
|
||||||
|
|
||||||
|
return order;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a {@link ParameterBag} with the given values and calls {@link #addAllParameters(ParameterBag)} to add
|
||||||
|
* {@link Parameter}s
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* the id of the {@link ParameterBag}
|
||||||
|
* @param name
|
||||||
|
* the name of the {@link ParameterBag}
|
||||||
|
* @param type
|
||||||
|
* the type of the {@link ParameterBag}
|
||||||
|
*
|
||||||
|
* @return the newly created {@link ParameterBag}
|
||||||
|
*/
|
||||||
|
public static ParameterBag createParameterBag(String id, String name, String type) {
|
||||||
|
|
||||||
|
ParameterBag bag = new ParameterBag(id, name, type);
|
||||||
|
addAllParameters(bag);
|
||||||
|
return bag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the following {@link Parameter}s to the given {@link ParameterBag}:
|
||||||
|
* <ul>
|
||||||
|
* <li>BooleanParameter - true</li>
|
||||||
|
* <li>FloatParameter - 44.3</li>
|
||||||
|
* <li>IntegerParameter - 77</li>
|
||||||
|
* <li>LongParameter - 4453234566L</li>
|
||||||
|
* <li>StringParameter - "Strolch"</li>
|
||||||
|
* <li>DateParameter - 1354295525628L</li>
|
||||||
|
* <li>StringListParameter - Hello, World</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* @param bag
|
||||||
|
*/
|
||||||
|
public static void addAllParameters(ParameterBag bag) {
|
||||||
|
|
||||||
|
BooleanParameter boolParam = new BooleanParameter(PARAM_BOOLEAN_ID, PARAM_BOOLEAN_NAME, true);
|
||||||
|
bag.addParameter(boolParam);
|
||||||
|
|
||||||
|
FloatParameter floatParam = new FloatParameter(PARAM_FLOAT_ID, PARAM_FLOAT_NAME, 44.3);
|
||||||
|
bag.addParameter(floatParam);
|
||||||
|
|
||||||
|
IntegerParameter integerParam = new IntegerParameter(PARAM_INTEGER_ID, PARAM_INTEGER_NAME, 77);
|
||||||
|
bag.addParameter(integerParam);
|
||||||
|
|
||||||
|
LongParameter longParam = new LongParameter(PARAM_LONG_ID, PARAM_LONG_NAME, 4453234566L);
|
||||||
|
bag.addParameter(longParam);
|
||||||
|
|
||||||
|
StringParameter stringParam = new StringParameter(PARAM_STRING_ID, PARAM_STRING_NAME, "Strolch");
|
||||||
|
bag.addParameter(stringParam);
|
||||||
|
|
||||||
|
DateParameter dateParam = new DateParameter(PARAM_DATE_ID, PARAM_DATE_NAME, 1354295525628L);
|
||||||
|
bag.addParameter(dateParam);
|
||||||
|
|
||||||
|
ArrayList<String> stringList = new ArrayList<String>();
|
||||||
|
stringList.add("Hello");
|
||||||
|
stringList.add("World");
|
||||||
|
StringListParameter stringListP = new StringListParameter(PARAM_LIST_STRING_ID, PARAM_LIST_STRING_NAME,
|
||||||
|
stringList);
|
||||||
|
bag.addParameter(stringListP);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue