diff --git a/README.md b/README.md index f93fede5b..cf9aa1f74 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/pom.xml b/pom.xml index e4f171e3c..5d9fa9809 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.xceptance neodymium-library - 3.3.0 + 3.3.1 neodymium-library https://github.com/Xceptance/neodymium-library diff --git a/src/main/java/com/xceptance/neodymium/util/DataUtils.java b/src/main/java/com/xceptance/neodymium/util/DataUtils.java index bed566db3..ebf459cea 100644 --- a/src/main/java/com/xceptance/neodymium/util/DataUtils.java +++ b/src/main/java/com/xceptance/neodymium/util/DataUtils.java @@ -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 { @@ -68,16 +70,30 @@ public static String randomPassword() */ public static T get(final Class clazz) { - Map data = Neodymium.getData(); + final Map 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 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); @@ -94,7 +110,7 @@ public static T get(final Class 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); diff --git a/src/test/java/com/xceptance/neodymium/testclasses/datautils/DataUtilsTests.java b/src/test/java/com/xceptance/neodymium/testclasses/datautils/DataUtilsTests.java index e4a40cf4a..0f3b2cb98 100644 --- a/src/test/java/com/xceptance/neodymium/testclasses/datautils/DataUtilsTests.java +++ b/src/test/java/com/xceptance/neodymium/testclasses/datautils/DataUtilsTests.java @@ -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 @@ -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) diff --git a/src/test/java/com/xceptance/neodymium/testclasses/datautils/DataUtilsTestsXml.java b/src/test/java/com/xceptance/neodymium/testclasses/datautils/DataUtilsTestsXml.java index f92dda2f7..fa2ddc17f 100644 --- a/src/test/java/com/xceptance/neodymium/testclasses/datautils/DataUtilsTestsXml.java +++ b/src/test/java/com/xceptance/neodymium/testclasses/datautils/DataUtilsTestsXml.java @@ -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)); @@ -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) diff --git a/src/test/java/com/xceptance/neodymium/testclasses/datautils/TestCompoundClass.java b/src/test/java/com/xceptance/neodymium/testclasses/datautils/TestCompoundClass.java index 8d0517df8..a8ed95996 100644 --- a/src/test/java/com/xceptance/neodymium/testclasses/datautils/TestCompoundClass.java +++ b/src/test/java/com/xceptance/neodymium/testclasses/datautils/TestCompoundClass.java @@ -14,6 +14,14 @@ enum Level String clubCardNumber; + String description; + + Object notSet; + + Double numberValue; + + Object nullValue = new Object(); + int age; TestCreditCard creditCard; @@ -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; + } } diff --git a/src/test/resources/com/xceptance/neodymium/testclasses/datautils/DataUtilsTests.json b/src/test/resources/com/xceptance/neodymium/testclasses/datautils/DataUtilsTests.json index d20fc3e5c..2b3edb09f 100644 --- a/src/test/resources/com/xceptance/neodymium/testclasses/datautils/DataUtilsTests.json +++ b/src/test/resources/com/xceptance/neodymium/testclasses/datautils/DataUtilsTests.json @@ -3,7 +3,8 @@ "testId": "asString", "nullValue": null, "empty": "", - "value": "value" + "value": "value", + "sentence": "containing strange things like spaces and äüø" }, { "testId": "asInt", @@ -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", diff --git a/src/test/resources/com/xceptance/neodymium/testclasses/datautils/DataUtilsTestsXml.xml b/src/test/resources/com/xceptance/neodymium/testclasses/datautils/DataUtilsTestsXml.xml index 41a9d3977..481d29074 100644 --- a/src/test/resources/com/xceptance/neodymium/testclasses/datautils/DataUtilsTestsXml.xml +++ b/src/test/resources/com/xceptance/neodymium/testclasses/datautils/DataUtilsTestsXml.xml @@ -4,6 +4,7 @@ asString value + containing strange things like spaces and äüø asInt @@ -42,10 +43,14 @@ asObject 1234567890 - {"cardNumber": "4111111111111111","ccv": "123","month":"10","year": "2018"} + containing strange things like spaces and äüø + 12.34 + {"cardNumber": "4111111111111111","ccv": + "123","month":"10","year": "2018"} 23 ["abc","def","ghi"] - [{"firstName": "a","lastName": "b"},{"firstName":"c","lastName": "d"}] + [{"firstName": "a","lastName": + "b"},{"firstName":"c","lastName": "d"}] {"key": "value"} HIGH