[New] Added a ModelBuilder to conveniently create Resources and Orders
This commit is contained in:
parent
8efe85d6c8
commit
c57693d9c3
|
@ -1 +1,4 @@
|
||||||
target/
|
target/
|
||||||
|
/.project
|
||||||
|
/.classpath
|
||||||
|
/.settings
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>li.strolch</groupId>
|
||||||
|
<artifactId>li.strolch.parent</artifactId>
|
||||||
|
<version>0.1.0-SNAPSHOT</version>
|
||||||
|
<relativePath>../li.strolch.parent/pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>li.strolch.testbase</artifactId>
|
||||||
|
|
||||||
|
<name>runtime for Strolch</name>
|
||||||
|
<description>runtime for Strolch</description>
|
||||||
|
|
||||||
|
<url>https://github.com/eitch/li.strolch.testbase</url>
|
||||||
|
|
||||||
|
<inceptionYear>2011</inceptionYear>
|
||||||
|
|
||||||
|
<issueManagement>
|
||||||
|
<system>Github Issues</system>
|
||||||
|
<url>https://github.com/eitch/li.strolch.testbase/issues</url>
|
||||||
|
</issueManagement>
|
||||||
|
|
||||||
|
<scm>
|
||||||
|
<connection>scm:git:https://github.com/eitch/li.strolch.testbase.git</connection>
|
||||||
|
<developerConnection>scm:git:git@github.com:eitch/li.strolch.testbase.git</developerConnection>
|
||||||
|
<url>https://github.com/eitch/li.strolch.testbase</url>
|
||||||
|
</scm>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>li.strolch</groupId>
|
||||||
|
<artifactId>li.strolch.model</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-eclipse-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-site-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
|
@ -0,0 +1,179 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012, Robert von Burg
|
||||||
|
*
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This file is part of the li.strolch.model.
|
||||||
|
*
|
||||||
|
* li.strolch.model 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.
|
||||||
|
*
|
||||||
|
* li.strolch.model 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 li.strolch.model. If not, see
|
||||||
|
* <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package li.strolch.testbase.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>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("nls")
|
||||||
|
public class ModelBuilder {
|
||||||
|
|
||||||
|
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