diff --git a/pom.xml b/pom.xml index f2d41bf84..b188cfae4 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,5 @@ - 4.0.0 com.xceptance @@ -30,7 +31,7 @@ https://www.xceptance.com architect - developer + developer @@ -203,7 +204,6 @@ snakeyaml 1.24 - io.cucumber cucumber-junit @@ -219,12 +219,6 @@ jaxb-api 2.3.1 - - com.fasterxml.jackson.core - jackson-databind - 2.9.9 - - io.qameta.allure allure-junit4 @@ -240,18 +234,21 @@ allure-selenide ${allure.version} - - com.google.guava guava 27.1-jre - com.codeborne selenide 5.2.3 + + + net.lightbody.bmp + browsermob-core + + org.apache.commons diff --git a/src/main/java/com/xceptance/neodymium/module/statement/testdata/util/JsonFileReader.java b/src/main/java/com/xceptance/neodymium/module/statement/testdata/util/JsonFileReader.java index 550accbda..e77f6dd9d 100644 --- a/src/main/java/com/xceptance/neodymium/module/statement/testdata/util/JsonFileReader.java +++ b/src/main/java/com/xceptance/neodymium/module/statement/testdata/util/JsonFileReader.java @@ -38,7 +38,19 @@ public static List> readFile(InputStream inputStream) Map newDataSet = new HashMap<>(); for (Entry entry : dataSet.entrySet()) { - newDataSet.put(entry.getKey(), entry.getValue().getAsString()); + JsonElement element = entry.getValue(); + if (element.isJsonNull()) + { + newDataSet.put(entry.getKey(), null); + } + else if (element.isJsonArray() || element.isJsonObject()) + { + newDataSet.put(entry.getKey(), element.toString()); + } + else + { + newDataSet.put(entry.getKey(), element.getAsString()); + } } data.add(newDataSet); } diff --git a/src/main/java/com/xceptance/neodymium/util/DataUtils.java b/src/main/java/com/xceptance/neodymium/util/DataUtils.java index 721fbb86d..49df78425 100644 --- a/src/main/java/com/xceptance/neodymium/util/DataUtils.java +++ b/src/main/java/com/xceptance/neodymium/util/DataUtils.java @@ -1,12 +1,15 @@ package com.xceptance.neodymium.util; +import java.util.Iterator; +import java.util.Map; import java.util.UUID; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.text.RandomStringGenerator; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; public class DataUtils { @@ -60,15 +63,24 @@ public static String randomPassword() * @param * the inferred class * @param clazz - * A reference to an clazz that should be instaciated and filled from test data + * A reference to an clazz that should be instantiated and filled from test data * @return an instance of the class provided */ public static T get(final Class clazz) { - // just use what we have and ignore if we have more, so we can build up different objects - // with just the data that fits - final ObjectMapper m = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - return m.convertValue(Neodymium.getData(), clazz); + Map data = Neodymium.getData(); + + JsonObject jsonObject = new JsonObject(); + 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))); + } + + return new Gson().fromJson(jsonObject, clazz); } /** 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 6052dd132..e4a40cf4a 100644 --- a/src/test/java/com/xceptance/neodymium/testclasses/datautils/DataUtilsTests.java +++ b/src/test/java/com/xceptance/neodymium/testclasses/datautils/DataUtilsTests.java @@ -1,15 +1,14 @@ package com.xceptance.neodymium.testclasses.datautils; import java.text.MessageFormat; -import java.util.Map; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import com.xceptance.neodymium.NeodymiumRunner; +import com.xceptance.neodymium.module.statement.testdata.DataSet; import com.xceptance.neodymium.util.DataUtils; -import com.xceptance.neodymium.util.Neodymium; @RunWith(NeodymiumRunner.class) public class DataUtilsTests @@ -17,14 +16,9 @@ public class DataUtilsTests private static final String NIL = "not in list"; @Test + @DataSet(id = "asString") public void testAsString() throws Exception { - Map data = Neodymium.getData(); - data.clear(); - data.put("nullValue", null); - data.put("empty", ""); - data.put("value", "value"); - // expect IllegalArgumentException expectIAE(() -> { DataUtils.asString(null); @@ -46,20 +40,12 @@ public void testAsString() throws Exception Assert.assertEquals(null, DataUtils.asString("", null)); Assert.assertEquals(null, DataUtils.asString("nullValue", null)); Assert.assertEquals(null, DataUtils.asString(NIL, null)); - } @Test + @DataSet(id = "asInt") public void testAsInt() throws Exception { - Map data = Neodymium.getData(); - data.clear(); - data.put("nullValue", null); - data.put("empty", ""); - data.put("positiveValue", "3"); - data.put("negativeValue", "-3"); - data.put("zeroValue", "0"); - // expect IllegalArgumentException expectIAE(() -> { DataUtils.asInt(null); @@ -89,16 +75,9 @@ public void testAsInt() throws Exception } @Test + @DataSet(id = "asLong") public void testAsLong() throws Exception { - Map data = Neodymium.getData(); - data.clear(); - data.put("nullValue", null); - data.put("empty", ""); - data.put("positiveValue", "3"); - data.put("negativeValue", "-3"); - data.put("zeroValue", "0"); - // expect IllegalArgumentException expectIAE(() -> { DataUtils.asLong(null); @@ -128,16 +107,9 @@ public void testAsLong() throws Exception } @Test + @DataSet(id = "asFloat") public void testAsFloat() throws Exception { - Map data = Neodymium.getData(); - data.clear(); - data.put("nullValue", null); - data.put("empty", ""); - data.put("positiveValue", "3.3f"); - data.put("negativeValue", "-3.3"); - data.put("zeroValue", ".0"); - // expect IllegalArgumentException expectIAE(() -> { DataUtils.asFloat(null); @@ -167,16 +139,9 @@ public void testAsFloat() throws Exception } @Test + @DataSet(id = "asDouble") public void testAsDouble() throws Exception { - Map data = Neodymium.getData(); - data.clear(); - data.put("nullValue", null); - data.put("empty", ""); - data.put("positiveValue", "3.3d"); - data.put("negativeValue", "-3.3"); - data.put("zeroValue", ".0"); - // expect IllegalArgumentException expectIAE(() -> { DataUtils.asDouble(null); @@ -206,15 +171,9 @@ public void testAsDouble() throws Exception } @Test + @DataSet(id = "asBoolean") public void testAsBoolean() throws Exception { - Map data = Neodymium.getData(); - data.clear(); - data.put("nullValue", null); - data.put("empty", ""); - data.put("positiveValue", "true"); - data.put("negativeValue", "FaLsE"); - // expect IllegalArgumentException expectIAE(() -> { DataUtils.asBool(null); @@ -240,21 +199,28 @@ public void testAsBoolean() throws Exception } @Test + @DataSet(id = "asObject") public void testGetClass() throws Exception { - Map data = Neodymium.getData(); - data.clear(); - data.put("cardNumber", "4111111111111111"); - data.put("ccv", "123"); - data.put("month", "10"); - data.put("year", "2018"); - - TestCreditCard creditCard = DataUtils.get(TestCreditCard.class); - - Assert.assertEquals("4111111111111111", creditCard.getCardNumber()); - Assert.assertEquals("123", creditCard.getCcv()); - Assert.assertEquals(10, creditCard.getMonth()); - Assert.assertEquals(2018, creditCard.getYear()); + 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()); } 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 new file mode 100644 index 000000000..8d0517df8 --- /dev/null +++ b/src/test/java/com/xceptance/neodymium/testclasses/datautils/TestCompoundClass.java @@ -0,0 +1,98 @@ +package com.xceptance.neodymium.testclasses.datautils; + +import java.util.List; +import java.util.Map; + +public class TestCompoundClass +{ + enum Level + { + LOW, + MEDIUM, + HIGH + } + + String clubCardNumber; + + int age; + + TestCreditCard creditCard; + + List names; + + List persons; + + Map keyValueMap; + + Level level; + + public List getPersons() + { + return persons; + } + + public void setPersons(List persons) + { + this.persons = persons; + } + + public List getNames() + { + return names; + } + + public void setNames(List names) + { + this.names = names; + } + + public int getAge() + { + return age; + } + + public void setAge(int age) + { + this.age = age; + } + + public String getClubCardNumber() + { + return clubCardNumber; + } + + public void setClubCardNumber(String clubCardNumber) + { + this.clubCardNumber = clubCardNumber; + } + + public TestCreditCard getCreditCard() + { + return creditCard; + } + + public void setCreditCard(TestCreditCard creditCard) + { + this.creditCard = creditCard; + } + + public Map getKeyValueMap() + { + return keyValueMap; + } + + public void setKeyValueMap(Map keyValueMap) + { + this.keyValueMap = keyValueMap; + } + + public Level getLevel() + { + return level; + } + + public void setLevel(Level level) + { + this.level = level; + } +} diff --git a/src/test/java/com/xceptance/neodymium/testclasses/datautils/TestPerson.java b/src/test/java/com/xceptance/neodymium/testclasses/datautils/TestPerson.java new file mode 100644 index 000000000..05c24a86b --- /dev/null +++ b/src/test/java/com/xceptance/neodymium/testclasses/datautils/TestPerson.java @@ -0,0 +1,28 @@ +package com.xceptance.neodymium.testclasses.datautils; + +public class TestPerson +{ + String firstName; + + String lastName; + + public String getFirstName() + { + return firstName; + } + + public void setFirstName(String firstName) + { + this.firstName = firstName; + } + + public String getLastName() + { + return lastName; + } + + public void setLastName(String lastName) + { + this.lastName = lastName; + } +} diff --git a/src/test/resources/com/xceptance/neodymium/testclasses/datautils/DataUtilsTests.json b/src/test/resources/com/xceptance/neodymium/testclasses/datautils/DataUtilsTests.json new file mode 100644 index 000000000..e3bff8cb7 --- /dev/null +++ b/src/test/resources/com/xceptance/neodymium/testclasses/datautils/DataUtilsTests.json @@ -0,0 +1,77 @@ +[ + { + "testId": "asString", + "nullValue": null, + "empty": "", + "value": "value" + }, + { + "testId": "asInt", + "nullValue": null, + "empty": "", + "positiveValue": 3, + "negativeValue": -3, + "zeroValue": 0 + }, + { + "testId": "asLong", + "nullValue": null, + "empty": "", + "positiveValue": 3, + "negativeValue": -3, + "zeroValue": 0 + }, + { + "testId": "asFloat", + "nullValue": null, + "empty": "", + "positiveValue": "3.3f", + "negativeValue": -3.3, + "zeroValue": 0 + }, + { + "testId": "asDouble", + "nullValue": null, + "empty": "", + "positiveValue": "3.3d", + "negativeValue": -3.3, + "zeroValue": 0 + }, + { + "testId": "asBoolean", + "nullValue": null, + "empty": "", + "positiveValue": true, + "negativeValue": FaLsE + }, + { + "testId": "asObject", + "clubCardNumber": 1234567890, + "creditCard": { + "cardNumber": "4111111111111111", + "ccv": "123", + "month": "10", + "year": "2018" + }, + "age": 23, + "names": [ + "abc", + "def", + "ghi" + ], + "persons": [ + { + "firstName": "a", + "lastName": "b" + }, + { + "firstName": "c", + "lastName": "d" + } + ], + "keyValueMap": { + "key": "value" + }, + level: "HIGH" + } +]