From c57693d9c3e774e46b425e2d0588c89afd9aec09 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 24 Oct 2013 21:49:04 +0200 Subject: [PATCH] [New] Added a ModelBuilder to conveniently create Resources and Orders --- .gitignore | 3 + pom.xml | 63 ++++++ .../strolch/testbase/model/ModelBuilder.java | 179 ++++++++++++++++++ 3 files changed, 245 insertions(+) create mode 100644 pom.xml create mode 100644 src/main/java/li/strolch/testbase/model/ModelBuilder.java diff --git a/.gitignore b/.gitignore index 2f7896d1d..96dedc20e 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ target/ +/.project +/.classpath +/.settings diff --git a/pom.xml b/pom.xml new file mode 100644 index 000000000..3adeaabe1 --- /dev/null +++ b/pom.xml @@ -0,0 +1,63 @@ + + 4.0.0 + + + li.strolch + li.strolch.parent + 0.1.0-SNAPSHOT + ../li.strolch.parent/pom.xml + + + li.strolch.testbase + + runtime for Strolch + runtime for Strolch + + https://github.com/eitch/li.strolch.testbase + + 2011 + + + Github Issues + https://github.com/eitch/li.strolch.testbase/issues + + + + scm:git:https://github.com/eitch/li.strolch.testbase.git + scm:git:git@github.com:eitch/li.strolch.testbase.git + https://github.com/eitch/li.strolch.testbase + + + + + li.strolch + li.strolch.model + + + + + + + org.apache.maven.plugins + maven-eclipse-plugin + + + org.apache.maven.plugins + maven-compiler-plugin + + + org.apache.maven.plugins + maven-source-plugin + + + org.apache.maven.plugins + maven-jar-plugin + + + org.apache.maven.plugins + maven-site-plugin + + + + \ No newline at end of file diff --git a/src/main/java/li/strolch/testbase/model/ModelBuilder.java b/src/main/java/li/strolch/testbase/model/ModelBuilder.java new file mode 100644 index 000000000..77dda9446 --- /dev/null +++ b/src/main/java/li/strolch/testbase/model/ModelBuilder.java @@ -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 + * . + */ +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 + * + */ +@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}: + *
    + *
  • BooleanParameter - true
  • + *
  • FloatParameter - 44.3
  • + *
  • IntegerParameter - 77
  • + *
  • LongParameter - 4453234566L
  • + *
  • StringParameter - "Strolch"
  • + *
  • DateParameter - 1354295525628L
  • + *
  • StringListParameter - Hello, World
  • + *
+ * + * @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 stringList = new ArrayList(); + stringList.add("Hello"); + stringList.add("World"); + StringListParameter stringListP = new StringListParameter(PARAM_LIST_STRING_ID, PARAM_LIST_STRING_NAME, + stringList); + bag.addParameter(stringListP); + } +}