Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
# Conflicts:
#	pom.xml

bumped version to 3.3.1
  • Loading branch information
Marcel Pfotenhauer committed Jun 12, 2019
2 parents bd27733 + f3c8a29 commit 38c4ff9
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 49 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![Maven Central](https://img.shields.io/maven-central/v/com.xceptance/neodymium-library.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.xceptance%22%20AND%20a:%22neodymium-library%22) [![Join the chat at https://gitter.im/neodymium-library/community](https://badges.gitter.im/neodymium-library/community.svg)](https://gitter.im/neodymium-library/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

# Neodymium 3.3.0
# Neodymium v3.3.1
Neodymium tries to solve your typical and most pressing UI test automation problems by combining JUnit, WebDriver, BDD/Cucumber, and proper reporting. It gives you ready to use templates, assembles well-known open source projects, and enhances this all with additional functionality that is often missing.

Neodymium is basically the combination of state of the art open source test libraries with additionally glue to make it stick reliably together.
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.xceptance</groupId>
<artifactId>neodymium-library</artifactId>
<version>3.3.0</version>
<version>3.3.1</version>

<name>neodymium-library</name>
<url>https://github.com/Xceptance/neodymium-library</url>
Expand Down
28 changes: 22 additions & 6 deletions src/main/java/com/xceptance/neodymium/util/DataUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import java.util.UUID;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.RandomStringGenerator;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;

public class DataUtils
{
Expand Down Expand Up @@ -68,16 +70,30 @@ public static String randomPassword()
*/
public static <T> T get(final Class<T> clazz)
{
Map<String, String> data = Neodymium.getData();
final Map<String, String> data = Neodymium.getData();

JsonObject jsonObject = new JsonObject();
JsonParser parser = new JsonParser();
final JsonObject jsonObject = new JsonObject();
final JsonParser parser = new JsonParser();

// iterate over every data entry and parse the entries to prepare complex structures for object mapping
for (Iterator<String> iterator = data.keySet().iterator(); iterator.hasNext();)
{
String key = (String) iterator.next();
jsonObject.add(key, parser.parse(data.get(key)));
final String key = (String) iterator.next();
final String value = data.get(key);
final String trimmedValue = StringUtils.defaultString(value).trim();

if (value == null)
{
jsonObject.add(key, null);
}
else if (trimmedValue.startsWith("{") || trimmedValue.startsWith("["))
{
jsonObject.add(key, parser.parse(value));
}
else
{
jsonObject.add(key, new JsonPrimitive(value));
}
}

return new Gson().fromJson(jsonObject, clazz);
Expand All @@ -94,7 +110,7 @@ public static <T> T get(final Class<T> clazz)
*/
public static String asString(String key)
{
String value = Neodymium.dataValue(key);
final String value = Neodymium.dataValue(key);
if (value == null)
{
throw new IllegalArgumentException("Test data could not be found for key: " + key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ public void testAsString() throws Exception

Assert.assertEquals("", DataUtils.asString("empty"));
Assert.assertEquals("value", DataUtils.asString("value"));
Assert.assertEquals("containing strange things like spaces and äüø", DataUtils.asString("sentence"));

Assert.assertEquals(null, DataUtils.asString(null, null));
Assert.assertEquals(null, DataUtils.asString("", null));
Assert.assertEquals(null, DataUtils.asString("nullValue", null));
Assert.assertEquals(null, DataUtils.asString(NIL, null));

}

@Test
Expand Down Expand Up @@ -202,25 +204,29 @@ public void testAsBoolean() throws Exception
@DataSet(id = "asObject")
public void testGetClass() throws Exception
{
TestCompoundClass testClass = DataUtils.get(TestCompoundClass.class);

Assert.assertEquals("1234567890", testClass.getClubCardNumber());
Assert.assertEquals("4111111111111111", testClass.getCreditCard().getCardNumber());
Assert.assertEquals("123", testClass.getCreditCard().getCcv());
Assert.assertEquals(10, testClass.getCreditCard().getMonth());
Assert.assertEquals(2018, testClass.getCreditCard().getYear());
Assert.assertEquals(23, testClass.getAge());
Assert.assertEquals(3, testClass.getNames().size());
Assert.assertEquals("abc", testClass.getNames().get(0));
Assert.assertEquals("def", testClass.getNames().get(1));
Assert.assertEquals("ghi", testClass.getNames().get(2));
Assert.assertEquals(2, testClass.getPersons().size());
Assert.assertEquals("a", testClass.getPersons().get(0).getFirstName());
Assert.assertEquals("b", testClass.getPersons().get(0).getLastName());
Assert.assertEquals("c", testClass.getPersons().get(1).getFirstName());
Assert.assertEquals("d", testClass.getPersons().get(1).getLastName());
Assert.assertEquals("value", testClass.getKeyValueMap().get("key"));
Assert.assertEquals(TestCompoundClass.Level.HIGH, testClass.getLevel());
TestCompoundClass testCompound = DataUtils.get(TestCompoundClass.class);

Assert.assertEquals("1234567890", testCompound.getClubCardNumber());
Assert.assertEquals(null, testCompound.getNotSet());
Assert.assertEquals(null, testCompound.getNullValue());
Assert.assertEquals(new Double(12.34), testCompound.getNumberValue());
Assert.assertEquals("containing strange things like spaces and äüø", testCompound.getDescription());
Assert.assertEquals("4111111111111111", testCompound.getCreditCard().getCardNumber());
Assert.assertEquals("123", testCompound.getCreditCard().getCcv());
Assert.assertEquals(10, testCompound.getCreditCard().getMonth());
Assert.assertEquals(2018, testCompound.getCreditCard().getYear());
Assert.assertEquals(23, testCompound.getAge());
Assert.assertEquals(3, testCompound.getNames().size());
Assert.assertEquals("abc", testCompound.getNames().get(0));
Assert.assertEquals("def", testCompound.getNames().get(1));
Assert.assertEquals("ghi", testCompound.getNames().get(2));
Assert.assertEquals(2, testCompound.getPersons().size());
Assert.assertEquals("a", testCompound.getPersons().get(0).getFirstName());
Assert.assertEquals("b", testCompound.getPersons().get(0).getLastName());
Assert.assertEquals("c", testCompound.getPersons().get(1).getFirstName());
Assert.assertEquals("d", testCompound.getPersons().get(1).getLastName());
Assert.assertEquals("value", testCompound.getKeyValueMap().get("key"));
Assert.assertEquals(TestCompoundClass.Level.HIGH, testCompound.getLevel());
}

private void expectIAE(Runnable function)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void testAsString() throws Exception

Assert.assertEquals("", DataUtils.asString("empty"));
Assert.assertEquals("value", DataUtils.asString("value"));
Assert.assertEquals("containing strange things like spaces and äüø", DataUtils.asString("sentence"));

Assert.assertEquals(null, DataUtils.asString(null, null));
Assert.assertEquals(null, DataUtils.asString("", null));
Expand Down Expand Up @@ -202,25 +203,30 @@ public void testAsBoolean() throws Exception
@DataSet(id = "asObject")
public void testGetClass() throws Exception
{
TestCompoundClass testClass = DataUtils.get(TestCompoundClass.class);

Assert.assertEquals("1234567890", testClass.getClubCardNumber());
Assert.assertEquals("4111111111111111", testClass.getCreditCard().getCardNumber());
Assert.assertEquals("123", testClass.getCreditCard().getCcv());
Assert.assertEquals(10, testClass.getCreditCard().getMonth());
Assert.assertEquals(2018, testClass.getCreditCard().getYear());
Assert.assertEquals(23, testClass.getAge());
Assert.assertEquals(3, testClass.getNames().size());
Assert.assertEquals("abc", testClass.getNames().get(0));
Assert.assertEquals("def", testClass.getNames().get(1));
Assert.assertEquals("ghi", testClass.getNames().get(2));
Assert.assertEquals(2, testClass.getPersons().size());
Assert.assertEquals("a", testClass.getPersons().get(0).getFirstName());
Assert.assertEquals("b", testClass.getPersons().get(0).getLastName());
Assert.assertEquals("c", testClass.getPersons().get(1).getFirstName());
Assert.assertEquals("d", testClass.getPersons().get(1).getLastName());
Assert.assertEquals("value", testClass.getKeyValueMap().get("key"));
Assert.assertEquals(TestCompoundClass.Level.HIGH, testClass.getLevel());
TestCompoundClass testCompound = DataUtils.get(TestCompoundClass.class);

Assert.assertEquals("1234567890", testCompound.getClubCardNumber());
Assert.assertEquals(null, testCompound.getNotSet());
// our XML parer does not support explicit null value
// Assert.assertEquals(null, testCompound.getNullValue());
Assert.assertEquals(new Double(12.34), testCompound.getNumberValue());
Assert.assertEquals("containing strange things like spaces and äüø", testCompound.getDescription());
Assert.assertEquals("4111111111111111", testCompound.getCreditCard().getCardNumber());
Assert.assertEquals("123", testCompound.getCreditCard().getCcv());
Assert.assertEquals(10, testCompound.getCreditCard().getMonth());
Assert.assertEquals(2018, testCompound.getCreditCard().getYear());
Assert.assertEquals(23, testCompound.getAge());
Assert.assertEquals(3, testCompound.getNames().size());
Assert.assertEquals("abc", testCompound.getNames().get(0));
Assert.assertEquals("def", testCompound.getNames().get(1));
Assert.assertEquals("ghi", testCompound.getNames().get(2));
Assert.assertEquals(2, testCompound.getPersons().size());
Assert.assertEquals("a", testCompound.getPersons().get(0).getFirstName());
Assert.assertEquals("b", testCompound.getPersons().get(0).getLastName());
Assert.assertEquals("c", testCompound.getPersons().get(1).getFirstName());
Assert.assertEquals("d", testCompound.getPersons().get(1).getLastName());
Assert.assertEquals("value", testCompound.getKeyValueMap().get("key"));
Assert.assertEquals(TestCompoundClass.Level.HIGH, testCompound.getLevel());
}

private void expectIAE(Runnable function)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ enum Level

String clubCardNumber;

String description;

Object notSet;

Double numberValue;

Object nullValue = new Object();

int age;

TestCreditCard creditCard;
Expand Down Expand Up @@ -95,4 +103,44 @@ public void setLevel(Level level)
{
this.level = level;
}

public String getDescription()
{
return description;
}

public void setDescription(String description)
{
this.description = description;
}

public Double getNumberValue()
{
return numberValue;
}

public void setNumberValue(Double numberValue)
{
this.numberValue = numberValue;
}

public Object getNullValue()
{
return nullValue;
}

public void setNullValue(Object nullValue)
{
this.nullValue = nullValue;
}

public void setNotSet(Object notSet)
{
this.notSet = notSet;
}

public Object getNotSet()
{
return notSet;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"testId": "asString",
"nullValue": null,
"empty": "",
"value": "value"
"value": "value",
"sentence": "containing strange things like spaces and äüø"
},
{
"testId": "asInt",
Expand Down Expand Up @@ -47,6 +48,9 @@
{
"testId": "asObject",
"clubCardNumber": 1234567890,
"description": "containing strange things like spaces and äüø",
"numberValue":12.34,
"nullValue":null,
"creditCard": {
"cardNumber": "4111111111111111",
"ccv": "123",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<data key="testId">asString</data>
<data key="empty"></data>
<data key="value">value</data>
<data key="sentence">containing strange things like spaces and äüø</data>
</dataset>
<dataset>
<data key="testId">asInt</data>
Expand Down Expand Up @@ -42,10 +43,14 @@
<dataset>
<data key="testId">asObject</data>
<data key="clubCardNumber">1234567890</data>
<data key="creditCard">{"cardNumber": "4111111111111111","ccv": "123","month":"10","year": "2018"}</data>
<data key="description">containing strange things like spaces and äüø</data>
<data key="numberValue"> 12.34</data>
<data key="creditCard">{"cardNumber": "4111111111111111","ccv":
"123","month":"10","year": "2018"}</data>
<data key="age">23</data>
<data key="names">["abc","def","ghi"]</data>
<data key="persons">[{"firstName": "a","lastName": "b"},{"firstName":"c","lastName": "d"}]</data>
<data key="persons">[{"firstName": "a","lastName":
"b"},{"firstName":"c","lastName": "d"}]</data>
<data key="keyValueMap">{"key": "value"}</data>
<data key="level">HIGH</data>
</dataset>
Expand Down

0 comments on commit 38c4ff9

Please sign in to comment.