How to use verifyTypeOfFieldInProperties method of org.evomaster.client.java.instrumentation.object.ClassToSchemaTest class

Best EvoMaster code snippet using org.evomaster.client.java.instrumentation.object.ClassToSchemaTest.verifyTypeOfFieldInProperties

Source:ClassToSchemaTest.java Github

copy

Full Screen

...23 assertEquals(1, obj.get("properties").getAsJsonObject().entrySet().size());24 assertEquals("string", obj.get("properties").getAsJsonObject()25 .get("foo").getAsJsonObject().get("type").getAsString());26 }27 private void verifyTypeOfFieldInProperties(JsonObject obj, String expected, String fieldName){28 assertEquals(expected, obj.get("properties").getAsJsonObject()29 .get(fieldName).getAsJsonObject().get("type").getAsString());30 }31 private void verifyTypeAndFormatOfFieldInProperties(JsonObject obj, String type, String format, String fieldName){32 JsonObject field = obj.get("properties").getAsJsonObject().get(fieldName).getAsJsonObject();33 assertEquals(type, field.get("type").getAsString());34 assertEquals(format, field.get("format").getAsString());35 }36 @Test37 public void testNumeric(){38 String schema = ClassToSchema.getOrDeriveSchema(DtoNumeric.class);39 JsonObject json = parse(schema);40 JsonObject obj = json.get(DtoNumeric.class.getName()).getAsJsonObject();41 assertNotNull(obj);42 assertNotNull(obj.get("type"));43 assertNotNull(obj.get("properties"));44 assertEquals(2, obj.entrySet().size());45 assertEquals("object", obj.get("type").getAsString());46 assertEquals(12, obj.get("properties").getAsJsonObject().entrySet().size());47 verifyTypeAndFormatOfFieldInProperties(obj, "integer", "int8", "byte_p");48 verifyTypeAndFormatOfFieldInProperties(obj, "integer", "int8", "byte_w");49 verifyTypeAndFormatOfFieldInProperties(obj, "integer", "int16", "short_p");50 verifyTypeAndFormatOfFieldInProperties(obj, "integer", "int16", "short_w");51 verifyTypeAndFormatOfFieldInProperties(obj, "integer", "int32", "integer_p");52 verifyTypeAndFormatOfFieldInProperties(obj, "integer", "int32", "integer_w");53 verifyTypeAndFormatOfFieldInProperties(obj, "integer", "int64", "long_p");54 verifyTypeAndFormatOfFieldInProperties(obj, "integer", "int64", "long_w");55 verifyTypeAndFormatOfFieldInProperties(obj, "number", "float", "float_p");56 verifyTypeAndFormatOfFieldInProperties(obj, "number", "float", "float_w");57 verifyTypeAndFormatOfFieldInProperties(obj, "number", "double", "double_p");58 verifyTypeAndFormatOfFieldInProperties(obj, "number", "double", "double_w");59 }60 private void verifyTypeInArray(JsonObject obj, String expected, String fieldName){61 JsonObject array = obj.get("properties").getAsJsonObject()62 .get(fieldName).getAsJsonObject();63 assertEquals("array", array.get("type").getAsString());64 assertEquals(expected, array.get("items").getAsJsonObject().get("type").getAsString());65 }66 @Test67 public void testExtending(){68 String schema = ClassToSchema.getOrDeriveSchema(DtoExtending.class);69 JsonObject json = parse(schema);70 JsonObject obj = json.get(DtoExtending.class.getName()).getAsJsonObject();71 // WARN: this is limitation in GSON, as it does not have entryList(), so we72 // cannot verify that entries are unique, and not repeated by mistake :(73 assertEquals(3, obj.get("properties").getAsJsonObject().entrySet().size());74 verifyTypeOfFieldInProperties(obj, "string", "foo");75 verifyTypeOfFieldInProperties(obj, "boolean", "boolean_p");76 verifyTypeOfFieldInProperties(obj, "boolean", "boolean_w");77 }78 @Test79 public void testArray(){80 String schema = ClassToSchema.getOrDeriveSchema(DtoArray.class);81 JsonObject json = parse(schema);82 JsonObject obj = json.get(DtoArray.class.getName()).getAsJsonObject();83 assertEquals(5, obj.get("properties").getAsJsonObject().entrySet().size());84 verifyTypeInArray(obj, "string", "array");85 verifyTypeInArray(obj, "integer", "set");86 verifyTypeInArray(obj, "string", "set_raw");87 verifyTypeInArray(obj, "boolean", "list");88 verifyTypeInArray(obj, "string", "list_raw");89 }90 @Test91 public void testIgnore(){92 String schema = ClassToSchema.getOrDeriveSchema(DtoIgnore.class);93 JsonObject json = parse(schema);94 JsonObject obj = json.get(DtoIgnore.class.getName()).getAsJsonObject();95 assertEquals(1, obj.get("properties").getAsJsonObject().entrySet().size());96 verifyTypeOfFieldInProperties(obj, "string", "a");97 }98 @Test99 public void testNaming(){100 String schema = ClassToSchema.getOrDeriveSchema(DtoNaming.class);101 JsonObject json = parse(schema);102 JsonObject obj = json.get(DtoNaming.class.getName()).getAsJsonObject();103 assertEquals(3, obj.get("properties").getAsJsonObject().entrySet().size());104 verifyTypeOfFieldInProperties(obj, "string", "foo_bar");105 verifyTypeOfFieldInProperties(obj, "string", "hello_world");106 verifyTypeOfFieldInProperties(obj, "string", "foo");107 }108}...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run EvoMaster automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful