How to use newInstance method of org.evomaster.client.java.controller.problem.rpc.schema.params.ListParam class

Best EvoMaster code snippet using org.evomaster.client.java.controller.problem.rpc.schema.params.ListParam.newInstance

Source:ExampleBuilderTest.java Github

copy

Full Screen

...267 assertEquals("10", dto.innerContent.get(4).stringValue);268 assertEquals("0", dto.innerContent.get(5).stringValue);269 assertEquals("-10", dto.innerContent.get(6).stringValue);270 assertEquals("-2", dto.innerContent.get(7).stringValue);271 List<String> testScript = p1.newInstanceWithJava(0);272 assertEquals("com.thrift.example.artificial.BigNumberObj arg0 = null;",testScript.get(0));273 assertEquals("{",testScript.get(1));274 assertEquals(" arg0 = new com.thrift.example.artificial.BigNumberObj();",testScript.get(2));275 assertEquals(" java.math.BigDecimal arg0_bdPositiveFloat = null;",testScript.get(3));276 assertEquals(" {",testScript.get(4));277 assertEquals(" java.math.MathContext arg0_bdPositiveFloat_mc = new java.math.MathContext(4);",testScript.get(5));278 assertEquals(" arg0_bdPositiveFloat = new java.math.BigDecimal(\"10.12\", arg0_bdPositiveFloat_mc);",testScript.get(6));279 assertEquals(" arg0_bdPositiveFloat.setScale(2, java.math.RoundingMode.HALF_UP);",testScript.get(7));280 assertEquals(" }",testScript.get(8));281 assertEquals(" arg0.setBdPositiveFloat(arg0_bdPositiveFloat);",testScript.get(9));282 assertEquals(" java.math.BigDecimal arg0_bdNegativeFloat = null;",testScript.get(10));283 assertEquals(" {",testScript.get(11));284 assertEquals(" java.math.MathContext arg0_bdNegativeFloat_mc = new java.math.MathContext(4);",testScript.get(12));285 assertEquals(" arg0_bdNegativeFloat = new java.math.BigDecimal(\"-10.12\", arg0_bdNegativeFloat_mc);",testScript.get(13));286 assertEquals(" arg0_bdNegativeFloat.setScale(2, java.math.RoundingMode.HALF_UP);",testScript.get(14));287 assertEquals(" }",testScript.get(15));288 assertEquals(" arg0.setBdNegativeFloat(arg0_bdNegativeFloat);",testScript.get(16));289 assertEquals(" java.math.BigDecimal arg0_bdPositiveOrZeroFloat = null;",testScript.get(17));290 assertEquals(" {",testScript.get(18));291 assertEquals(" java.math.MathContext arg0_bdPositiveOrZeroFloat_mc = new java.math.MathContext(4);",testScript.get(19));292 assertEquals(" arg0_bdPositiveOrZeroFloat = new java.math.BigDecimal(\"0.00\", arg0_bdPositiveOrZeroFloat_mc);",testScript.get(20));293 assertEquals(" arg0_bdPositiveOrZeroFloat.setScale(2, java.math.RoundingMode.HALF_UP);",testScript.get(21));294 assertEquals(" }",testScript.get(22));295 assertEquals(" arg0.setBdPositiveOrZeroFloat(arg0_bdPositiveOrZeroFloat);",testScript.get(23));296 assertEquals(" java.math.BigDecimal arg0_bdNegativeOrZeroFloat = null;",testScript.get(24));297 assertEquals(" {",testScript.get(25));298 assertEquals(" java.math.MathContext arg0_bdNegativeOrZeroFloat_mc = new java.math.MathContext(4);",testScript.get(26));299 assertEquals(" arg0_bdNegativeOrZeroFloat = new java.math.BigDecimal(\"-2.16\", arg0_bdNegativeOrZeroFloat_mc);",testScript.get(27));300 assertEquals(" arg0_bdNegativeOrZeroFloat.setScale(2, java.math.RoundingMode.HALF_UP);",testScript.get(28));301 assertEquals(" }",testScript.get(29));302 assertEquals(" arg0.setBdNegativeOrZeroFloat(arg0_bdNegativeOrZeroFloat);",testScript.get(30));303 assertEquals(" java.math.BigInteger arg0_biPositive = null;",testScript.get(31));304 assertEquals(" {",testScript.get(32));305 assertEquals(" arg0_biPositive = new java.math.BigInteger(\"10\");",testScript.get(33));306 assertEquals(" }",testScript.get(34));307 assertEquals(" arg0.setBiPositive(arg0_biPositive);",testScript.get(35));308 assertEquals(" java.math.BigInteger arg0_biPositiveOrZero = null;",testScript.get(36));309 assertEquals(" {",testScript.get(37));310 assertEquals(" arg0_biPositiveOrZero = new java.math.BigInteger(\"0\");",testScript.get(38));311 assertEquals(" }",testScript.get(39));312 assertEquals(" arg0.setBiPositiveOrZero(arg0_biPositiveOrZero);",testScript.get(40));313 assertEquals(" java.math.BigInteger arg0_biNegative = null;",testScript.get(41));314 assertEquals(" {",testScript.get(42));315 assertEquals(" arg0_biNegative = new java.math.BigInteger(\"-10\");",testScript.get(43));316 assertEquals(" }",testScript.get(44));317 assertEquals(" arg0.setBiNegative(arg0_biNegative);",testScript.get(45));318 assertEquals(" java.math.BigInteger arg0_biNegativeOrZero = null;",testScript.get(46));319 assertEquals(" {",testScript.get(47));320 assertEquals(" arg0_biNegativeOrZero = new java.math.BigInteger(\"-2\");",testScript.get(48));321 assertEquals(" }",testScript.get(49));322 assertEquals(" arg0.setBiNegativeOrZero(arg0_biNegativeOrZero);",testScript.get(50));323 assertEquals("}",testScript.get(51));324 List<String> assertionScript = p1.newAssertionWithJava("arg0", 0);325 assertEquals("assertEquals(\"10.12\", arg0.getBdPositiveFloat().toString());", assertionScript.get(0));326 assertEquals("assertEquals(\"-10.12\", arg0.getBdNegativeFloat().toString());", assertionScript.get(1));327 assertEquals("assertEquals(\"0.00\", arg0.getBdPositiveOrZeroFloat().toString());", assertionScript.get(2));328 assertEquals("assertEquals(\"-2.16\", arg0.getBdNegativeOrZeroFloat().toString());", assertionScript.get(3));329 assertEquals("assertEquals(\"10\", arg0.getBiPositive().toString());", assertionScript.get(4));330 assertEquals("assertEquals(\"0\", arg0.getBiPositiveOrZero().toString());", assertionScript.get(5));331 assertEquals("assertEquals(\"-10\", arg0.getBiNegative().toString());", assertionScript.get(6));332 assertEquals("assertEquals(\"-2\", arg0.getBiNegativeOrZero().toString());", assertionScript.get(7));333 }334 @Test335 public void testEnumWithConstructor(){336 EndpointSchema endpoint = getOneEndpoint("handleEnumWithConstructor");337 assertNotNull(endpoint.getResponse());338 assertNotNull(endpoint.getRequestParams());339 assertEquals(1, endpoint.getRequestParams().size());340 NamedTypedValue p1 = endpoint.getRequestParams().get(0);341 assertTrue(p1 instanceof ObjectParam);342 ObjectEnum objectEnum = new ObjectEnum(){{343 enumWithConstructor = EnumWithConstructor.FIRST;344 }};345 p1.setValueBasedOnInstance(objectEnum);346 List<String> testScript = p1.newInstanceWithJava(0);347 assertEquals(5, testScript.size());348 assertEquals("com.thrift.example.artificial.ObjectEnum arg0 = null;", testScript.get(0));349 assertEquals("{", testScript.get(1));350 assertEquals(" arg0 = new com.thrift.example.artificial.ObjectEnum();", testScript.get(2));351 assertEquals(" arg0.enumWithConstructor = com.thrift.example.artificial.EnumWithConstructor.FIRST;", testScript.get(3));352 assertEquals("}", testScript.get(4));353 }354 @Test355 public void testNestedGeneric() throws ClassNotFoundException {356 EndpointSchema endpoint = getOneEndpoint("handleNestedGenericString");357 assertNotNull(endpoint.getResponse());358 assertNotNull(endpoint.getRequestParams());359 assertEquals(1, endpoint.getRequestParams().size());360 NamedTypedValue p1 = endpoint.getRequestParams().get(0);361 assertTrue(p1 instanceof ObjectParam);362 assertEquals(3, ((ObjectParam)p1).getType().getFields().size());363 assertNull(((ObjectParam)p1).getValue());364 Object p1Instance = p1.newInstance();365 assertNull(p1Instance);366 List<String> testScript = p1.newInstanceWithJava(0);367 ParamDto dto = p1.getDto();368 dto.innerContent = null;369 p1.setValueBasedOnDto(dto);370 List<String> testScriptWithDto = p1.newInstanceWithJava(0);371 assertEquals(testScript, testScriptWithDto);372 }373 @Test374 public void testLocalAuthSetup(){375 EndpointSchema endpoint = getOneEndpoint("authorizedEndpoint");376 assertTrue(endpoint.getRequestParams() == null || endpoint.getRequestParams().isEmpty());377 assertNotNull(endpoint.getResponse());378 RPCActionDto dto = endpoint.getDto();379 }380 @Test381 public void testEndpointsLoad() {382 assertEquals(expectedNumberOfEndpoints(), schema.getEndpoints().size());383 }384 @Test385 public void testAuthValueSetup() throws ClassNotFoundException {386 assertNotNull(schema.getAuthEndpoints());387 assertEquals(2, schema.getAuthEndpoints().size());388 for (Map.Entry<Integer, EndpointSchema> entry : schema.getAuthEndpoints().entrySet()){389 EndpointSchema endpointSchema = entry.getValue();390 assertEquals(1, endpointSchema.getRequestParams().size());391 NamedTypedValue p1 = endpointSchema.getRequestParams().get(0);392 assertTrue(p1 instanceof ObjectParam);393 Object p1Instance = p1.newInstance();394 assertTrue(p1Instance instanceof AuthLoginDto);395 if (entry.getKey().equals(0)){396 assertEquals("foo", ((AuthLoginDto) p1Instance).id);397 assertEquals("zXQV47zsrjfJRnTD", ((AuthLoginDto) p1Instance).passcode);398 }else if (entry.getKey().equals(1)){399 assertEquals("bar", ((AuthLoginDto) p1Instance).id);400 assertEquals("5jbNvXvaejDG5MhS", ((AuthLoginDto) p1Instance).passcode);401 }402 }403 }404 @Test405 public void testHandleCustomizedRequestA() {406 EndpointSchema endpoint = getOneEndpoint("handleCustomizedRequestA");407 assertNotNull(endpoint.getRelatedCustomizedCandidates());408 assertEquals(2, endpoint.getRelatedCustomizedCandidates().size());409 assertTrue(endpoint.getRelatedCustomizedCandidates().containsAll(Arrays.asList("0", "1")));410 NamedTypedValue p1 = endpoint.getRequestParams().get(0);411 assertTrue(p1 instanceof ObjectParam);412 assertTrue(p1.isNullable());413 assertEquals(3, ((ObjectParam) p1).getType().getFields().size());414 for (NamedTypedValue f : ((ObjectParam) p1).getType().getFields()) {415 if (f.getName().equals("value")) {416 assertTrue(f instanceof IntParam);417 assertNull(((IntParam) f).getMin());418 assertNull(((IntParam) f).getMax());419 } else if (f.getName().equals("id")) {420 assertTrue(f instanceof StringParam);421 assertNotNull(f.getCandidateReferences());422 assertNotNull(f.getCandidates());423 assertEquals(2, f.getCandidates().size());424 assertEquals(2, f.getCandidateReferences().size());425 IntStream.range(0, 1).forEach(i -> {426 assertTrue(f.getCandidates().get(i) instanceof StringParam);427 String value = ((StringParam) f.getCandidates().get(i)).getValue();428 if (f.getCandidateReferences().get(i).equals("0")) {429 assertEquals("foo", value);430 } else if (f.getCandidateReferences().get(i).equals("1")) {431 assertEquals("bar", value);432 }433 });434 } else if (f.getName().equals("passcode")) {435 assertTrue(f instanceof StringParam);436 assertNotNull(f.getCandidateReferences());437 assertNotNull(f.getCandidates());438 assertEquals(2, f.getCandidates().size());439 assertEquals(2, f.getCandidateReferences().size());440 IntStream.range(0, 1).forEach(i -> {441 assertTrue(f.getCandidates().get(i) instanceof StringParam);442 String value = ((StringParam) f.getCandidates().get(i)).getValue();443 if (f.getCandidateReferences().get(i).equals("0")) {444 assertEquals("foo_passcode", value);445 } else if (f.getCandidateReferences().get(i).equals("1")) {446 assertEquals("bar_passcode", value);447 }448 });449 } else450 fail("do not handle param " + f.getName());451 }452 }453 @Test454 public void testHandleCustomizedRequestB() {455 EndpointSchema endpoint = getOneEndpoint("handleCustomizedRequestB");456 assertNotNull(endpoint.getRelatedCustomizedCandidates());457 assertEquals(0, endpoint.getRelatedCustomizedCandidates().size());458 NamedTypedValue p1 = endpoint.getRequestParams().get(0);459 assertTrue(p1 instanceof ObjectParam);460 assertTrue(p1.isNullable());461 assertEquals(1, ((ObjectParam) p1).getType().getFields().size());462 NamedTypedValue f = ((ObjectParam) p1).getType().getFields().get(0);463 assertNull(f.getCandidateReferences());464 assertNotNull(f.getCandidates());465 assertEquals(3, f.getCandidates().size());466 List<Double> candidates = Arrays.asList(0.42, 42.42, 100.42);467 IntStream.range(0, 2).forEach(i -> {468 assertTrue(f.getCandidates().get(i) instanceof DoubleParam);469 Double value = ((DoubleParam) f.getCandidates().get(i)).getValue();470 assertTrue(candidates.contains(value));471 });472 }473 @Test474 public void testConstraintInputs() {475 EndpointSchema endpoint = getOneEndpoint("constraintInputs");476 assertNotNull(endpoint.getResponse());477 assertEquals(2, endpoint.getRequestParams().size());478 NamedTypedValue p1 = endpoint.getRequestParams().get(0);479 checkConstrainedRequest(p1);480 checkConstrainedRequest(p1.copyStructureWithProperties());481 NamedTypedValue p2 = endpoint.getRequestParams().get(1);482 assertTrue(p2 instanceof StringParam);483 assertFalse(p2.isNullable());484 ConstrainedRequest input = new ConstrainedRequest();485 p1.setValueBasedOnInstance(input);486 ParamDto dto = p1.getDto();487 dto.innerContent.get(1).stringValue = null;488 dto.innerContent.get(2).stringValue = null;489 p1.setValueBasedOnDto(dto);490 List<String> javaCode = p1.newInstanceWithJava(0);491 assertEquals(13, javaCode.size());492 assertEquals("com.thrift.example.artificial.ConstrainedRequest arg0 = null;", javaCode.get(0));493 assertEquals("{", javaCode.get(1));494 assertEquals(" arg0 = new com.thrift.example.artificial.ConstrainedRequest();", javaCode.get(2));495 assertEquals(" arg0.list = null;", javaCode.get(3));496 assertEquals(" arg0.notBlankString = null;", javaCode.get(4));497 assertEquals(" arg0.nullableString = null;", javaCode.get(5));498 assertEquals(" arg0.stringSize = null;", javaCode.get(6));499 assertEquals(" arg0.listSize = null;", javaCode.get(7));500 assertEquals(" arg0.kind = null;", javaCode.get(8));501 assertEquals(" arg0.date = null;", javaCode.get(9));502 assertEquals(" arg0.longWithDecimalMinMax = 0L;", javaCode.get(10));503 assertEquals(" arg0.longWithInclusiveFDecimalMainMax = null;", javaCode.get(11));504 assertEquals("}", javaCode.get(12));505 }506 private void checkConstrainedRequest(NamedTypedValue p){507 assertTrue(p instanceof ObjectParam);508 assertTrue(p.isNullable());509 assertEquals(11, ((ObjectParam) p).getType().getFields().size());510 for (NamedTypedValue f : ((ObjectParam) p).getType().getFields()) {511 if (f.getName().equals("list")) {512 assertTrue(f instanceof ListParam);513 assertFalse(f.isNullable());514 assertEquals(1, ((ListParam) f).getMinSize());515 } else if (f.getName().equals("listSize")) {516 assertTrue(f instanceof ListParam);517 assertEquals(1, ((ListParam) f).getMinSize());518 assertEquals(10, ((ListParam) f).getMaxSize());519 assertFalse(f.isNullable());520 } else if (f.getName().equals("intWithMinMax")) {521 assertTrue(f instanceof IntParam);522 assertEquals(0, ((IntParam) f).getMin().intValue());523 assertEquals(100, ((IntParam) f).getMax().intValue());524 assertFalse(f.isNullable());525 } else if (f.getName().equals("longWithMinMax")) {526 assertTrue(f instanceof LongParam);527 assertEquals(-100L, ((LongParam) f).getMin());528 assertEquals(1000L, ((LongParam) f).getMax());529 assertFalse(f.isNullable());530 } else if (f.getName().equals("notBlankString")) {531 assertTrue(f instanceof StringParam);532 assertFalse(f.isNullable());533 assertEquals(1, ((StringParam) f).getMinSize());534 } else if (f.getName().equals("nullableString")) {535 assertTrue(f instanceof StringParam);536 assertTrue(f.isNullable());537 } else if (f.getName().equals("stringSize")) {538 assertTrue(f instanceof StringParam);539 assertEquals(2, ((StringParam) f).getMinSize());540 assertEquals(10, ((StringParam) f).getMaxSize());541 assertTrue(f.isNullable());542 } else if(f.getName().equals("kind")){543 assertTrue(f instanceof EnumParam);544 assertFalse(f.isNullable());545 } else if(f.getName().equals("date")){546 assertTrue(f instanceof StringParam);547 assertTrue(f.isNullable());548 assertNotNull(((StringParam) f).getPattern());549 }else if(f.getName().equals("longWithDecimalMinMax")){550 assertTrue(f instanceof LongParam);551 assertEquals(1L, ((LongParam) f).getMin());552 assertEquals(10L, ((LongParam) f).getMax());553 assertFalse(f.isNullable());554 }else if(f.getName().equals("longWithInclusiveFDecimalMainMax")){555 assertTrue(f instanceof LongParam);556 assertEquals(1L, ((LongParam) f).getMin());557 assertFalse(((LongParam) f).getMinInclusive());558 assertEquals(10L, ((LongParam) f).getMax());559 assertFalse(((LongParam) f).getMaxInclusive());560 assertTrue(f.isNullable());561 }else562 fail("do not handle param " + f.getName());563 }564 }565 @Test566 public void testAccessFieldDtoCheck(){567 EndpointSchema endpoint = getOneEndpoint("accessFieldDtoCheck");568 assertNotNull(endpoint.getResponse());569 assertEquals(1, endpoint.getRequestParams().size());570 NamedTypedValue p1 = endpoint.getRequestParams().get(0);571 assertTrue(p1 instanceof ObjectParam);572 assertTrue(p1.getType() instanceof ObjectType);573 List<NamedTypedValue> fs = ((ObjectType) p1.getType()).getFields();574 assertEquals(13, fs.size());575 for (NamedTypedValue f: fs){576 if (f.getName().equals("pubField")){577 assertTrue(f.accessibleSchema.isAccessible);578 }else if (f.getName().equals("priField")){579 assertFalse(f.accessibleSchema.isAccessible);580 assertEquals("setPriField", f.accessibleSchema.setterMethodName);581 assertEquals("getPriField", f.accessibleSchema.getterMethodName);582 } else if (f.getName().equals("stringList")){583 assertFalse(f.accessibleSchema.isAccessible);584 assertEquals("setStringList", f.accessibleSchema.setterMethodName);585 assertEquals("getStringList", f.accessibleSchema.getterMethodName);586 } else if (f.getName().equals("priEnum")){587 assertFalse(f.accessibleSchema.isAccessible);588 assertEquals("setPriEnum", f.accessibleSchema.setterMethodName);589 assertEquals("getPriEnum", f.accessibleSchema.getterMethodName);590 } else if (f.getName().equals("priBoolean")){591 assertFalse(f.accessibleSchema.isAccessible);592 assertEquals("setPriBoolean", f.accessibleSchema.setterMethodName);593 assertEquals("getPriBoolean", f.accessibleSchema.getterMethodName);594 } else if (f.getName().equals("pribool")){595 assertFalse(f.accessibleSchema.isAccessible);596 assertEquals("setPribool", f.accessibleSchema.setterMethodName);597 assertEquals("isPribool", f.accessibleSchema.getterMethodName);598 } else if (f.getName().equals("pribyte")){599 assertFalse(f.accessibleSchema.isAccessible);600 assertEquals("setPribyte", f.accessibleSchema.setterMethodName);601 assertEquals("getPribyte", f.accessibleSchema.getterMethodName);602 } else if (f.getName().equals("priBByte")){603 assertFalse(f.accessibleSchema.isAccessible);604 assertEquals("setPriBByte", f.accessibleSchema.setterMethodName);605 assertEquals("getPriBByte", f.accessibleSchema.getterMethodName);606 } else if (f.getName().equals("priCharacter")){607 assertFalse(f.accessibleSchema.isAccessible);608 assertEquals("setPriCharacter", f.accessibleSchema.setterMethodName);609 assertEquals("getPriCharacter", f.accessibleSchema.getterMethodName);610 } else if (f.getName().equals("priChar")){611 assertFalse(f.accessibleSchema.isAccessible);612 assertEquals("setPriChar", f.accessibleSchema.setterMethodName);613 assertEquals("getPriChar", f.accessibleSchema.getterMethodName);614 } else if (f.getName().equals("priSShort")){615 assertFalse(f.accessibleSchema.isAccessible);616 assertEquals("setPriSShort", f.accessibleSchema.setterMethodName);617 assertEquals("getPriSShort", f.accessibleSchema.getterMethodName);618 } else if (f.getName().equals("priShot")){619 assertFalse(f.accessibleSchema.isAccessible);620 assertEquals("setPriShot", f.accessibleSchema.setterMethodName);621 assertEquals("getPriShot", f.accessibleSchema.getterMethodName);622 } else if (f.getName().equals("priMap")){623 assertFalse(f.accessibleSchema.isAccessible);624 assertEquals("setPriMap", f.accessibleSchema.setterMethodName);625 assertEquals("getPriMap", f.accessibleSchema.getterMethodName);626 }627 }628 PrivateFieldInRequestDto p1Instance = new PrivateFieldInRequestDto(){{629 pubField = "foo";630 setPriField("bar");631 setStringList(Arrays.asList("1","2","3"));632 setPriEnum(EnumKind.ONE);633 setPriBoolean(true);634 setPriBByte((byte) 15);635 setPribyte((byte) 5);636 setPriChar('0');637 setPriCharacter('a');638 setPriShort((short) 2);639 setPriSShort((short) 42);640 setPriMap(new HashMap<String, String>(){{641 put("foo","foo");642 put("bar", "bar");643 }});644 }};645 p1.setValueBasedOnInstance(p1Instance);646 List<String> javaCodes = p1.newInstanceWithJava(0);647 assertEquals(37, javaCodes.size());648 assertEquals("com.thrift.example.artificial.PrivateFieldInRequestDto arg0 = null;", javaCodes.get(0));649 assertEquals("{", javaCodes.get(1));650 assertEquals(" arg0 = new com.thrift.example.artificial.PrivateFieldInRequestDto();", javaCodes.get(2));651 assertEquals(" arg0.pubField = \"foo\";", javaCodes.get(3));652 assertEquals(" arg0.setPriField(\"bar\");", javaCodes.get(4));653 assertEquals(" java.util.List<java.lang.String> arg0_stringList = null;", javaCodes.get(5));654 assertEquals(" {", javaCodes.get(6));655 assertEquals(" arg0_stringList = new java.util.ArrayList<>();", javaCodes.get(7));656 assertEquals(" java.lang.String arg0_stringList_e_0 = \"1\";", javaCodes.get(8));657 assertEquals(" arg0_stringList.add(arg0_stringList_e_0);", javaCodes.get(9));658 assertEquals(" java.lang.String arg0_stringList_e_1 = \"2\";", javaCodes.get(10));659 assertEquals(" arg0_stringList.add(arg0_stringList_e_1);", javaCodes.get(11));660 assertEquals(" java.lang.String arg0_stringList_e_2 = \"3\";", javaCodes.get(12));661 assertEquals(" arg0_stringList.add(arg0_stringList_e_2);", javaCodes.get(13));662 assertEquals(" }", javaCodes.get(14));663 assertEquals(" arg0.setStringList(arg0_stringList);", javaCodes.get(15));664 assertEquals(" arg0.setPriEnum(((com.thrift.example.artificial.EnumKind)(com.thrift.example.artificial.EnumKind.ONE)));", javaCodes.get(16));665 assertEquals(" arg0.setPriBoolean(true);", javaCodes.get(17));666 assertEquals(" arg0.setPribool(false);", javaCodes.get(18));667 assertEquals(" arg0.setPriBByte(((byte)(15)));", javaCodes.get(19));668 assertEquals(" arg0.setPribyte(((byte)(5)));", javaCodes.get(20));669 assertEquals(" arg0.setPriCharacter('\\u0061');", javaCodes.get(21));670 assertEquals(" arg0.setPriChar('\\u0030');", javaCodes.get(22));671 assertEquals(" arg0.setPriShort(((short)(2)));", javaCodes.get(23));672 assertEquals(" arg0.setPriSShort(((short)(42)));", javaCodes.get(24));673 assertEquals(" java.util.Map<java.lang.String,java.lang.String> arg0_priMap = null;", javaCodes.get(25));674 assertEquals(" {", javaCodes.get(26));675 assertEquals(" arg0_priMap = new java.util.HashMap<>();", javaCodes.get(27));676 assertEquals(" java.lang.String arg0_priMap_key_0 = \"bar\";", javaCodes.get(28));677 assertEquals(" java.lang.String arg0_priMap_value_0 = \"bar\";", javaCodes.get(29));678 assertEquals(" arg0_priMap.put(arg0_priMap_key_0,arg0_priMap_value_0);", javaCodes.get(30));679 assertEquals(" java.lang.String arg0_priMap_key_1 = \"foo\";", javaCodes.get(31));680 assertEquals(" java.lang.String arg0_priMap_value_1 = \"foo\";", javaCodes.get(32));681 assertEquals(" arg0_priMap.put(arg0_priMap_key_1,arg0_priMap_value_1);", javaCodes.get(33));682 assertEquals(" }", javaCodes.get(34));683 assertEquals(" arg0.setPriMap(arg0_priMap);", javaCodes.get(35));684 assertEquals("}", javaCodes.get(36));685 List<String> assertionJavaCode = p1.newAssertionWithJava(0, "res1", -1);686 assertEquals(18, assertionJavaCode.size());687 assertEquals("assertEquals(\"foo\", res1.pubField);", assertionJavaCode.get(0));688 assertEquals("assertEquals(\"bar\", res1.getPriField());", assertionJavaCode.get(1));689 assertEquals("assertEquals(3, res1.getStringList().size());", assertionJavaCode.get(2));690 assertEquals("assertEquals(\"1\", res1.getStringList().get(0));", assertionJavaCode.get(3));691 assertEquals("assertEquals(\"2\", res1.getStringList().get(1));", assertionJavaCode.get(4));692 assertEquals("assertEquals(\"3\", res1.getStringList().get(2));", assertionJavaCode.get(5));693 assertEquals("assertEquals(com.thrift.example.artificial.EnumKind.ONE, res1.getPriEnum());", assertionJavaCode.get(6));694 assertEquals("assertEquals(true, res1.getPriBoolean().booleanValue());", assertionJavaCode.get(7));695 assertEquals("assertEquals(false, res1.isPribool());", assertionJavaCode.get(8));696 assertEquals("assertEquals(15, res1.getPriBByte().byteValue());", assertionJavaCode.get(9));697 assertEquals("assertEquals(5, res1.getPribyte());", assertionJavaCode.get(10));698 assertEquals("assertEquals('\\u0061', res1.getPriCharacter().charValue());", assertionJavaCode.get(11));699 assertEquals("assertEquals('\\u0030', res1.getPriChar());", assertionJavaCode.get(12));700 assertEquals("assertEquals(2, res1.getPriShort());", assertionJavaCode.get(13));701 assertEquals("assertEquals(42, res1.getPriSShort().shortValue());", assertionJavaCode.get(14));702 assertEquals("assertEquals(2, res1.getPriMap().size());", assertionJavaCode.get(15));703 assertEquals("assertEquals(\"bar\", res1.getPriMap().get(\"bar\"));", assertionJavaCode.get(16));704 assertEquals("assertEquals(\"foo\", res1.getPriMap().get(\"foo\"));", assertionJavaCode.get(17));705 NamedTypedValue res = endpoint.getResponse();706 PrivateFieldInResponseDto resInstance = new PrivateFieldInResponseDto(){{707 pubField = 42;708 setPriRequest(p1Instance);709 }};710 res.setValueBasedOnInstance(resInstance);711 List<String> javaCodesForResponse = res.newInstanceWithJava(true, true, "tmp", 0);712 assertEquals(43, javaCodesForResponse.size());713 assertEquals("com.thrift.example.artificial.PrivateFieldInResponseDto tmp = null;", javaCodesForResponse.get(0));714 assertEquals("{", javaCodesForResponse.get(1));715 assertEquals(" tmp = new com.thrift.example.artificial.PrivateFieldInResponseDto();", javaCodesForResponse.get(2));716 assertEquals(" tmp.pubField = 42;", javaCodesForResponse.get(3));717 assertEquals(" com.thrift.example.artificial.PrivateFieldInRequestDto tmp_priRequest = null;", javaCodesForResponse.get(4));718 assertEquals(" {", javaCodesForResponse.get(5));719 assertEquals(" tmp_priRequest = new com.thrift.example.artificial.PrivateFieldInRequestDto();", javaCodesForResponse.get(6));720 assertEquals(" tmp_priRequest.pubField = \"foo\";", javaCodesForResponse.get(7));721 assertEquals(" tmp_priRequest.setPriField(\"bar\");", javaCodesForResponse.get(8));722 assertEquals(" java.util.List<java.lang.String> tmp_priRequest_stringList = null;", javaCodesForResponse.get(9));723 assertEquals(" {", javaCodesForResponse.get(10));724 assertEquals(" tmp_priRequest_stringList = new java.util.ArrayList<>();", javaCodesForResponse.get(11));725 assertEquals(" java.lang.String tmp_priRequest_stringList_e_0 = \"1\";", javaCodesForResponse.get(12));726 assertEquals(" tmp_priRequest_stringList.add(tmp_priRequest_stringList_e_0);", javaCodesForResponse.get(13));727 assertEquals(" java.lang.String tmp_priRequest_stringList_e_1 = \"2\";", javaCodesForResponse.get(14));728 assertEquals(" tmp_priRequest_stringList.add(tmp_priRequest_stringList_e_1);", javaCodesForResponse.get(15));729 assertEquals(" java.lang.String tmp_priRequest_stringList_e_2 = \"3\";", javaCodesForResponse.get(16));730 assertEquals(" tmp_priRequest_stringList.add(tmp_priRequest_stringList_e_2);", javaCodesForResponse.get(17));731 assertEquals(" }", javaCodesForResponse.get(18));732 assertEquals(" tmp_priRequest.setStringList(tmp_priRequest_stringList);", javaCodesForResponse.get(19));733 assertEquals(" tmp_priRequest.setPriEnum(((com.thrift.example.artificial.EnumKind)(com.thrift.example.artificial.EnumKind.ONE)));", javaCodesForResponse.get(20));734 assertEquals(" tmp_priRequest.setPriBoolean(true);", javaCodesForResponse.get(21));735 assertEquals(" tmp_priRequest.setPribool(false);", javaCodesForResponse.get(22));736 assertEquals(" tmp_priRequest.setPriBByte(((byte)(15)));", javaCodesForResponse.get(23));737 assertEquals(" tmp_priRequest.setPribyte(((byte)(5)));", javaCodesForResponse.get(24));738 assertEquals(" tmp_priRequest.setPriCharacter('\\u0061');", javaCodesForResponse.get(25));739 assertEquals(" tmp_priRequest.setPriChar('\\u0030');", javaCodesForResponse.get(26));740 assertEquals(" tmp_priRequest.setPriShort(((short)(2)));", javaCodesForResponse.get(27));741 assertEquals(" tmp_priRequest.setPriSShort(((short)(42)));", javaCodesForResponse.get(28));742 assertEquals(" java.util.Map<java.lang.String,java.lang.String> tmp_priRequest_priMap = null;", javaCodesForResponse.get(29));743 assertEquals(" {", javaCodesForResponse.get(30));744 assertEquals(" tmp_priRequest_priMap = new java.util.HashMap<>();", javaCodesForResponse.get(31));745 assertEquals(" java.lang.String tmp_priRequest_priMap_key_0 = \"bar\";", javaCodesForResponse.get(32));746 assertEquals(" java.lang.String tmp_priRequest_priMap_value_0 = \"bar\";", javaCodesForResponse.get(33));747 assertEquals(" tmp_priRequest_priMap.put(tmp_priRequest_priMap_key_0,tmp_priRequest_priMap_value_0);", javaCodesForResponse.get(34));748 assertEquals(" java.lang.String tmp_priRequest_priMap_key_1 = \"foo\";", javaCodesForResponse.get(35));749 assertEquals(" java.lang.String tmp_priRequest_priMap_value_1 = \"foo\";", javaCodesForResponse.get(36));750 assertEquals(" tmp_priRequest_priMap.put(tmp_priRequest_priMap_key_1,tmp_priRequest_priMap_value_1);", javaCodesForResponse.get(37));751 assertEquals(" }", javaCodesForResponse.get(38));752 assertEquals(" tmp_priRequest.setPriMap(tmp_priRequest_priMap);", javaCodesForResponse.get(39));753 assertEquals(" }", javaCodesForResponse.get(40));754 assertEquals(" tmp.setPriRequest(tmp_priRequest);", javaCodesForResponse.get(41));755 assertEquals("}", javaCodesForResponse.get(42));756 List<String> assertionJavaCodeForResponse = res.newAssertionWithJava(0, "res1", -1);757 assertEquals(19, assertionJavaCodeForResponse.size());758 assertEquals("assertEquals(42, res1.pubField);", assertionJavaCodeForResponse.get(0));759 assertEquals("assertEquals(\"foo\", res1.getPriRequest().pubField);", assertionJavaCodeForResponse.get(1));760 assertEquals("assertEquals(\"bar\", res1.getPriRequest().getPriField());", assertionJavaCodeForResponse.get(2));761 assertEquals("assertEquals(3, res1.getPriRequest().getStringList().size());", assertionJavaCodeForResponse.get(3));762 assertEquals("assertEquals(\"1\", res1.getPriRequest().getStringList().get(0));", assertionJavaCodeForResponse.get(4));763 assertEquals("assertEquals(\"2\", res1.getPriRequest().getStringList().get(1));", assertionJavaCodeForResponse.get(5));764 assertEquals("assertEquals(\"3\", res1.getPriRequest().getStringList().get(2));", assertionJavaCodeForResponse.get(6));765 assertEquals("assertEquals(com.thrift.example.artificial.EnumKind.ONE, res1.getPriRequest().getPriEnum());", assertionJavaCodeForResponse.get(7));766 assertEquals("assertEquals(true, res1.getPriRequest().getPriBoolean().booleanValue());", assertionJavaCodeForResponse.get(8));767 assertEquals("assertEquals(false, res1.getPriRequest().isPribool());", assertionJavaCodeForResponse.get(9));768 assertEquals("assertEquals(15, res1.getPriRequest().getPriBByte().byteValue());", assertionJavaCodeForResponse.get(10));769 assertEquals("assertEquals(5, res1.getPriRequest().getPribyte());", assertionJavaCodeForResponse.get(11));770 assertEquals("assertEquals('\\u0061', res1.getPriRequest().getPriCharacter().charValue());", assertionJavaCodeForResponse.get(12));771 assertEquals("assertEquals('\\u0030', res1.getPriRequest().getPriChar());", assertionJavaCodeForResponse.get(13));772 assertEquals("assertEquals(2, res1.getPriRequest().getPriShort());", assertionJavaCodeForResponse.get(14));773 assertEquals("assertEquals(42, res1.getPriRequest().getPriSShort().shortValue());", assertionJavaCodeForResponse.get(15));774 assertEquals("assertEquals(2, res1.getPriRequest().getPriMap().size());", assertionJavaCodeForResponse.get(16));775 assertEquals("assertEquals(\"bar\", res1.getPriRequest().getPriMap().get(\"bar\"));", assertionJavaCodeForResponse.get(17));776 assertEquals("assertEquals(\"foo\", res1.getPriRequest().getPriMap().get(\"foo\"));", assertionJavaCodeForResponse.get(18));777 }778 @Test779 public void testAccessFieldDtoWithNullCheck(){780 EndpointSchema endpoint = getOneEndpoint("accessFieldDtoCheck");781 assertNotNull(endpoint.getResponse());782 assertEquals(1, endpoint.getRequestParams().size());783 NamedTypedValue p1 = endpoint.getRequestParams().get(0);784 assertTrue(p1 instanceof ObjectParam);785 PrivateFieldInRequestDto p1Instance = new PrivateFieldInRequestDto();786 p1.setValueBasedOnInstance(p1Instance);787 List<String> javaCodes = p1.newInstanceWithJava(0);788 assertEquals(19, javaCodes.size());789 assertEquals("com.thrift.example.artificial.PrivateFieldInRequestDto arg0 = null;", javaCodes.get(0));790 assertEquals("{", javaCodes.get(1));791 assertEquals(" arg0 = new com.thrift.example.artificial.PrivateFieldInRequestDto();", javaCodes.get(2));792 assertEquals(" arg0.pubField = null;", javaCodes.get(3));793 assertEquals(" arg0.setPriField(null);", javaCodes.get(4));794 assertEquals(" java.util.List<java.lang.String> arg0_stringList = null;", javaCodes.get(5));795 assertEquals(" arg0.setStringList(arg0_stringList);", javaCodes.get(6));796 assertEquals(" arg0.setPriEnum(null);", javaCodes.get(7));797 assertEquals(" arg0.setPriBoolean(null);", javaCodes.get(8));798 assertEquals(" arg0.setPribool(false);", javaCodes.get(9));799 assertEquals(" arg0.setPriBByte(null);", javaCodes.get(10));800 assertEquals(" arg0.setPribyte(((byte)(0)));", javaCodes.get(11));801 assertEquals(" arg0.setPriCharacter(null);", javaCodes.get(12));802 assertEquals(" arg0.setPriChar('\\u0000');", javaCodes.get(13));803 assertEquals(" arg0.setPriShort(((short)(0)));", javaCodes.get(14));804 assertEquals(" arg0.setPriSShort(null);", javaCodes.get(15));805 assertEquals(" java.util.Map<java.lang.String,java.lang.String> arg0_priMap = null;", javaCodes.get(16));806 assertEquals(" arg0.setPriMap(arg0_priMap);", javaCodes.get(17));807 assertEquals("}", javaCodes.get(18));808 List<String> assertionJavaCode = p1.newAssertionWithJava(0, "res1", -1);809 assertEquals(13, assertionJavaCode.size());810 assertEquals("assertNull(res1.pubField);", assertionJavaCode.get(0));811 assertEquals("assertNull(res1.getPriField());", assertionJavaCode.get(1));812 assertEquals("assertNull(res1.getStringList());", assertionJavaCode.get(2));813 assertEquals("assertNull(res1.getPriEnum());", assertionJavaCode.get(3));814 assertEquals("assertNull(res1.getPriBoolean());", assertionJavaCode.get(4));815 assertEquals("assertEquals(false, res1.isPribool());", assertionJavaCode.get(5));816 assertEquals("assertNull(res1.getPriBByte());", assertionJavaCode.get(6));817 assertEquals("assertEquals(0, res1.getPribyte());", assertionJavaCode.get(7));818 assertEquals("assertNull(res1.getPriCharacter());", assertionJavaCode.get(8));819 assertEquals("assertEquals('\\u0000', res1.getPriChar());", assertionJavaCode.get(9));820 assertEquals("assertEquals(0, res1.getPriShort());", assertionJavaCode.get(10));821 assertEquals("assertNull(res1.getPriSShort());", assertionJavaCode.get(11));822 assertEquals("assertNull(res1.getPriMap());", assertionJavaCode.get(12));823 NamedTypedValue res = endpoint.getResponse();824 PrivateFieldInResponseDto resInstance = new PrivateFieldInResponseDto(){{825 pubField = 42;826 }};827 res.setValueBasedOnInstance(resInstance);828 List<String> javaCodesForResponse = res.newInstanceWithJava(true, true, "tmp", 0);829 assertEquals(7, javaCodesForResponse.size());830 assertEquals("com.thrift.example.artificial.PrivateFieldInResponseDto tmp = null;", javaCodesForResponse.get(0));831 assertEquals("{", javaCodesForResponse.get(1));832 assertEquals(" tmp = new com.thrift.example.artificial.PrivateFieldInResponseDto();", javaCodesForResponse.get(2));833 assertEquals(" tmp.pubField = 42;", javaCodesForResponse.get(3));834 assertEquals(" com.thrift.example.artificial.PrivateFieldInRequestDto tmp_priRequest = null;", javaCodesForResponse.get(4));835 assertEquals(" tmp.setPriRequest(tmp_priRequest);", javaCodesForResponse.get(5));836 assertEquals("}", javaCodesForResponse.get(6));837 List<String> assertionJavaCodeForResponse = res.newAssertionWithJava(0, "res1", -1);838 assertEquals(2, assertionJavaCodeForResponse.size());839 assertEquals("assertEquals(42, res1.pubField);", assertionJavaCodeForResponse.get(0));840 assertEquals("assertNull(res1.getPriRequest());", assertionJavaCodeForResponse.get(1));841 PrivateFieldInResponseDto resInstance2 = new PrivateFieldInResponseDto(){{842 pubField = 42;843 setPriRequest(new PrivateFieldInRequestDto());844 }};845 res.setValueBasedOnInstance(resInstance2);846 javaCodesForResponse = res.newInstanceWithJava(true, true, "tmp", 0);847 assertEquals(25, javaCodesForResponse.size());848 assertEquals("com.thrift.example.artificial.PrivateFieldInResponseDto tmp = null;", javaCodesForResponse.get(0));849 assertEquals("{", javaCodesForResponse.get(1));850 assertEquals(" tmp = new com.thrift.example.artificial.PrivateFieldInResponseDto();", javaCodesForResponse.get(2));851 assertEquals(" tmp.pubField = 42;", javaCodesForResponse.get(3));852 assertEquals(" com.thrift.example.artificial.PrivateFieldInRequestDto tmp_priRequest = null;", javaCodesForResponse.get(4));853 assertEquals(" {", javaCodesForResponse.get(5));854 assertEquals(" tmp_priRequest = new com.thrift.example.artificial.PrivateFieldInRequestDto();", javaCodesForResponse.get(6));855 assertEquals(" tmp_priRequest.pubField = null;", javaCodesForResponse.get(7));856 assertEquals(" tmp_priRequest.setPriField(null);", javaCodesForResponse.get(8));857 assertEquals(" java.util.List<java.lang.String> tmp_priRequest_stringList = null;", javaCodesForResponse.get(9));858 assertEquals(" tmp_priRequest.setStringList(tmp_priRequest_stringList);", javaCodesForResponse.get(10));859 assertEquals(" tmp_priRequest.setPriEnum(null);", javaCodesForResponse.get(11));860 assertEquals(" tmp_priRequest.setPriBoolean(null);", javaCodesForResponse.get(12));861 assertEquals(" tmp_priRequest.setPribool(false);", javaCodesForResponse.get(13));862 assertEquals(" tmp_priRequest.setPriBByte(null);", javaCodesForResponse.get(14));863 assertEquals(" tmp_priRequest.setPribyte(((byte)(0)));", javaCodesForResponse.get(15));864 assertEquals(" tmp_priRequest.setPriCharacter(null);", javaCodesForResponse.get(16));865 assertEquals(" tmp_priRequest.setPriChar('\\u0000');", javaCodesForResponse.get(17));866 assertEquals(" tmp_priRequest.setPriShort(((short)(0)));", javaCodesForResponse.get(18));867 assertEquals(" tmp_priRequest.setPriSShort(null);", javaCodesForResponse.get(19));868 assertEquals(" java.util.Map<java.lang.String,java.lang.String> tmp_priRequest_priMap = null;", javaCodesForResponse.get(20));869 assertEquals(" tmp_priRequest.setPriMap(tmp_priRequest_priMap);", javaCodesForResponse.get(21));870 assertEquals(" }", javaCodesForResponse.get(22));871 assertEquals(" tmp.setPriRequest(tmp_priRequest);", javaCodesForResponse.get(23));872 assertEquals("}", javaCodesForResponse.get(24));873 assertionJavaCodeForResponse = res.newAssertionWithJava(0, "res1", -1);874 assertEquals(14, assertionJavaCodeForResponse.size());875 assertEquals("assertEquals(42, res1.pubField);", assertionJavaCodeForResponse.get(0));876 assertEquals("assertNull(res1.getPriRequest().pubField);", assertionJavaCodeForResponse.get(1));877 assertEquals("assertNull(res1.getPriRequest().getPriField());", assertionJavaCodeForResponse.get(2));878 assertEquals("assertNull(res1.getPriRequest().getStringList());", assertionJavaCodeForResponse.get(3));879 assertEquals("assertNull(res1.getPriRequest().getPriEnum());", assertionJavaCodeForResponse.get(4));880 assertEquals("assertNull(res1.getPriRequest().getPriBoolean());", assertionJavaCodeForResponse.get(5));881 assertEquals("assertEquals(false, res1.getPriRequest().isPribool());", assertionJavaCodeForResponse.get(6));882 assertEquals("assertNull(res1.getPriRequest().getPriBByte());", assertionJavaCodeForResponse.get(7));883 assertEquals("assertEquals(0, res1.getPriRequest().getPribyte());", assertionJavaCodeForResponse.get(8));884 assertEquals("assertNull(res1.getPriRequest().getPriCharacter());", assertionJavaCodeForResponse.get(9));885 assertEquals("assertEquals('\\u0000', res1.getPriRequest().getPriChar());", assertionJavaCodeForResponse.get(10));886 assertEquals("assertEquals(0, res1.getPriRequest().getPriShort());", assertionJavaCodeForResponse.get(11));887 assertEquals("assertNull(res1.getPriRequest().getPriSShort());", assertionJavaCodeForResponse.get(12));888 assertEquals("assertNull(res1.getPriRequest().getPriMap());", assertionJavaCodeForResponse.get(13));889 }890 @Test891 public void testDateToString() throws ClassNotFoundException, ParseException {892 EndpointSchema endpoint = getOneEndpoint("dateToString");893 assertNotNull(endpoint.getResponse());894 assertEquals(1, endpoint.getRequestParams().size());895 NamedTypedValue p1 = endpoint.getRequestParams().get(0);896 assertTrue(p1 instanceof DateParam);897 //String stringDate = "2021-12-14 19:45:23.722 +0100";898 String stringDate = "2021-12-14 19:45:23";899 Date date = DateType.SIMPLE_DATE_FORMATTER.parse(stringDate);900 long time = date.getTime();901 p1.setValueBasedOnInstance(date);902 Object instance = p1.newInstance();903 assertTrue(instance instanceof Date);904 assertEquals(time, ((Date) instance).getTime());905 ParamDto dto = p1.getDto();906 assertEquals(6, dto.innerContent.size());907 assertEquals("2021", dto.innerContent.get(0).stringValue);908 assertEquals("12", dto.innerContent.get(1).stringValue);909 assertEquals("14", dto.innerContent.get(2).stringValue);910 assertEquals("19", dto.innerContent.get(3).stringValue);911 assertEquals("45", dto.innerContent.get(4).stringValue);912 assertEquals("23", dto.innerContent.get(5).stringValue);913// assertEquals("722", dto.innerContent.get(6).jsonValue);914// assertEquals("100", dto.innerContent.get(7).jsonValue);915 List<String> javacode = p1.newInstanceWithJava(0);916 assertEquals(5, javacode.size());917 assertEquals("java.util.Date arg0 = null;", javacode.get(0));918 assertEquals("{", javacode.get(1));919 assertEquals(" // Date is " + stringDate, javacode.get(2));920 assertEquals(" arg0 = new java.util.Date(" + time + "L);", javacode.get(3));921 assertEquals("}", javacode.get(4));922 List<String> assertions = p1.newAssertionWithJava(0, "res1", -1);923 assertEquals(1, assertions.size());924 assertTrue(assertions.get(0).contains("// runtime value is "));925 }926 @Test927 public void testSimplePrimitive() {928 EndpointSchema endpoint = getOneEndpoint("simplePrimitive");929 assertNotNull(endpoint.getResponse());930 assertEquals(8, endpoint.getRequestParams().size());931 assertTrue(endpoint.getRequestParams().get(0) instanceof IntParam);932 assertTrue(endpoint.getRequestParams().get(1) instanceof FloatParam);933 assertTrue(endpoint.getRequestParams().get(2) instanceof LongParam);934 assertTrue(endpoint.getRequestParams().get(3) instanceof DoubleParam);935 assertTrue(endpoint.getRequestParams().get(4) instanceof CharParam);936 assertTrue(endpoint.getRequestParams().get(5) instanceof ByteParam);937 assertTrue(endpoint.getRequestParams().get(6) instanceof BooleanParam);938 assertTrue(endpoint.getRequestParams().get(7) instanceof ShortParam);939 }940 @Test941 public void testSimplePrimitiveToFromDTO() throws ClassNotFoundException {942 EndpointSchema endpoint = getOneEndpoint("simplePrimitive");943 RPCActionDto dto = endpoint.getDto().copy();944 assertEquals(8, dto.requestParams.size());945 dto.requestParams.get(0).stringValue = "" + 42;946 dto.requestParams.get(1).stringValue = "" + 4.2f;947 dto.requestParams.get(2).stringValue = "" + 42L;948 dto.requestParams.get(3).stringValue = "" + 4.2;949 dto.requestParams.get(4).stringValue = "" + 'x';950 dto.requestParams.get(5).stringValue = "" + Byte.parseByte("42");951 dto.requestParams.get(6).stringValue = "" + false;952 dto.requestParams.get(7).stringValue = "" + Short.parseShort("42");953 endpoint.setValue(dto);954 assertEquals(42, endpoint.getRequestParams().get(0).newInstance());955 assertEquals(4.2f, endpoint.getRequestParams().get(1).newInstance());956 assertEquals(42L, endpoint.getRequestParams().get(2).newInstance());957 assertEquals(4.2, endpoint.getRequestParams().get(3).newInstance());958 assertEquals('x', endpoint.getRequestParams().get(4).newInstance());959 assertEquals(Byte.parseByte("42"), endpoint.getRequestParams().get(5).newInstance());960 assertEquals(false, endpoint.getRequestParams().get(6).newInstance());961 assertEquals(Short.parseShort("42"), endpoint.getRequestParams().get(7).newInstance());962 }963 @Test964 public void testSimpleWrapPrimitive() {965 EndpointSchema endpoint = getOneEndpoint("simpleWrapPrimitive");966 assertNotNull(endpoint.getResponse());967 assertEquals(8, endpoint.getRequestParams().size());968 assertTrue(endpoint.getRequestParams().get(0) instanceof IntParam);969 assertTrue(endpoint.getRequestParams().get(1) instanceof FloatParam);970 assertTrue(endpoint.getRequestParams().get(2) instanceof LongParam);971 assertTrue(endpoint.getRequestParams().get(3) instanceof DoubleParam);972 assertTrue(endpoint.getRequestParams().get(4) instanceof CharParam);973 assertTrue(endpoint.getRequestParams().get(5) instanceof ByteParam);974 assertTrue(endpoint.getRequestParams().get(6) instanceof BooleanParam);975 assertTrue(endpoint.getRequestParams().get(7) instanceof ShortParam);976 }977 @Test978 public void testSimpleWrapPrimitiveToFromDTO() throws ClassNotFoundException {979 EndpointSchema endpoint = getOneEndpoint("simpleWrapPrimitive");980 RPCActionDto dto = endpoint.getDto().copy();981 assertEquals(8, dto.requestParams.size());982 dto.requestParams.get(0).stringValue = "" + 42;983 dto.requestParams.get(1).stringValue = "" + 4.2f;984 dto.requestParams.get(2).stringValue = "" + 42L;985 dto.requestParams.get(3).stringValue = "" + 4.2;986 dto.requestParams.get(4).stringValue = "" + 'x';987 dto.requestParams.get(5).stringValue = "" + Byte.parseByte("42");988 dto.requestParams.get(6).stringValue = "" + false;989 dto.requestParams.get(7).stringValue = "" + Short.parseShort("42");990 endpoint.setValue(dto);991 assertEquals(42, endpoint.getRequestParams().get(0).newInstance());992 assertEquals(4.2f, endpoint.getRequestParams().get(1).newInstance());993 assertEquals(42L, endpoint.getRequestParams().get(2).newInstance());994 assertEquals(4.2, endpoint.getRequestParams().get(3).newInstance());995 assertEquals('x', endpoint.getRequestParams().get(4).newInstance());996 assertEquals(Byte.parseByte("42"), endpoint.getRequestParams().get(5).newInstance());997 assertEquals(false, endpoint.getRequestParams().get(6).newInstance());998 assertEquals(Short.parseShort("42"), endpoint.getRequestParams().get(7).newInstance());999 }1000 @Test1001 public void testArray() {1002 EndpointSchema endpoint = getOneEndpoint("array");1003 assertNotNull(endpoint.getResponse());1004 assertEquals(1, endpoint.getRequestParams().size());1005 NamedTypedValue param = endpoint.getRequestParams().get(0);1006 assertTrue(param instanceof ArrayParam);1007 assertTrue(param.getType() instanceof CollectionType);1008 NamedTypedValue template = ((CollectionType) param.getType()).getTemplate();1009 assertTrue(template instanceof ListParam);1010 assertTrue(template.getType() instanceof CollectionType);1011 assertTrue(((CollectionType) template.getType()).getTemplate() instanceof StringParam);1012 }...

Full Screen

Full Screen

Source:ListParam.java Github

copy

Full Screen

...17 public ListParam(String name, CollectionType type, AccessibleSchema accessibleSchema) {18 super(name, type, accessibleSchema);19 }20 @Override21 public Object newInstance() throws ClassNotFoundException {22 if (getValue() == null) return null;23 return getValue().stream().map(v-> {24 try {25 return v.newInstance();26 } catch (ClassNotFoundException e) {27 throw new RuntimeException("ArrayParam: could not create new instance for value:"+v.getType());28 }29 }).collect(Collectors.toList());30 }31 @Override32 public ParamDto getDto() {33 ParamDto dto = super.getDto();34 dto.type.type = RPCSupportedDataType.LIST;35 if (getValue() != null){36 dto.innerContent = getValue().stream().map(s-> s.getDto()).collect(Collectors.toList());37 }38 return dto;39 }40 @Override41 public ListParam copyStructure() {42 return new ListParam(getName(), getType(), accessibleSchema);43 }44 @Override45 public void setValueBasedOnDto(ParamDto dto) {46 if (dto.innerContent!= null && !dto.innerContent.isEmpty()){47 NamedTypedValue t = getType().getTemplate();48 List<NamedTypedValue> values = dto.innerContent.stream().map(s-> {49 NamedTypedValue v = t.copyStructureWithProperties();50 v.setValueBasedOnDto(s);51 return v;52 }).collect(Collectors.toList());53 setValue(values);54 }55 }56 @Override57 protected void setValueBasedOnValidInstance(Object instance) {58 NamedTypedValue t = getType().getTemplate();59 List<NamedTypedValue> values = new ArrayList<>();60 for (Object e : (List) instance){61 NamedTypedValue copy = t.copyStructureWithProperties();62 copy.setValueBasedOnInstance(e);63 values.add(copy);64 }65 setValue(values);66 }67 @Override68 public void setValueBasedOnInstanceOrJson(Object json) throws JsonProcessingException {69 NamedTypedValue t = getType().getTemplate();70 List<NamedTypedValue> values = new ArrayList<>();71 assert json instanceof String;72 Object instance = parseValueWithJson((String) json);73 for (Object e : (List) instance){74 NamedTypedValue copy = t.copyStructureWithProperties();75 copy.setValueBasedOnInstanceOrJson(e);76 values.add(copy);77 }78 setValue(values);79 }80 @Override81 public List<String> newInstanceWithJava(boolean isDeclaration, boolean doesIncludeName, String variableName, int indent) {82 String fullName = getType().getTypeNameForInstance();83 List<String> codes = new ArrayList<>();84 String var = CodeJavaGenerator.oneLineInstance(isDeclaration, doesIncludeName, fullName, variableName, null);85 CodeJavaGenerator.addCode(codes, var, indent);86 if (getValue() == null) return codes;87 CodeJavaGenerator.addCode(codes, "{", indent);88 // new array89 CodeJavaGenerator.addCode(codes,90 CodeJavaGenerator.setInstance(91 variableName,92 CodeJavaGenerator.newList()), indent+1);93 int index = 0;94 for (NamedTypedValue e: getValue()){95 String eVarName = CodeJavaGenerator.handleVariableName(variableName+"_e_"+index);96 codes.addAll(e.newInstanceWithJava(true, true, eVarName, indent+1));97 CodeJavaGenerator.addCode(codes, variableName+".add("+eVarName+");", indent+1);98 index++;99 }100 CodeJavaGenerator.addCode(codes, "}", indent);101 return codes;102 }103 @Override104 public List<String> newAssertionWithJava(int indent, String responseVarName, int maxAssertionForDataInCollection) {105 List<String> codes = new ArrayList<>();106 if (getValue() == null){107 CodeJavaGenerator.addCode(codes, CodeJavaGenerator.junitAssertNull(responseVarName), indent);108 return codes;109 }110 CodeJavaGenerator.addCode(codes, CodeJavaGenerator.junitAssertEquals(""+getValue().size(), CodeJavaGenerator.withSize(responseVarName)), indent);...

Full Screen

Full Screen

newInstance

Using AI Code Generation

copy

Full Screen

1import org.evomaster.client.java.controller.problem.rpc.schema.params.ListParam;2import java.util.ArrayList;3import java.util.List;4public class 2 {5 public static void main(String[] args) {6 ListParam listParam0 = new ListParam();7 List<Object> list1 = new ArrayList<Object>();8 listParam0.setList(list1);9 ListParam listParam2 = new ListParam();10 listParam2.setList(list1);11 listParam0.setList(list1);12 ListParam listParam4 = new ListParam();13 listParam4.setList(list1);14 listParam0.setList(list1);15 ListParam listParam6 = new ListParam();16 listParam6.setList(list1);17 listParam0.setList(list1);18 ListParam listParam8 = new ListParam();19 listParam8.setList(list1);20 listParam0.setList(list1);21 ListParam listParam10 = new ListParam();22 listParam10.setList(list1);23 listParam0.setList(list1);24 ListParam listParam12 = new ListParam();25 listParam12.setList(list1);26 listParam0.setList(list1);27 ListParam listParam14 = new ListParam();28 listParam14.setList(list1);29 listParam0.setList(list1);30 ListParam listParam16 = new ListParam();31 listParam16.setList(list1);32 listParam0.setList(list1);33 ListParam listParam18 = new ListParam();34 listParam18.setList(list1);35 listParam0.setList(list1);36 ListParam listParam20 = new ListParam();37 listParam20.setList(list1);38 listParam0.setList(list1);39 ListParam listParam22 = new ListParam();40 listParam22.setList(list1);41 listParam0.setList(list1);42 ListParam listParam24 = new ListParam();43 listParam24.setList(list1);44 listParam0.setList(list1);45 ListParam listParam26 = new ListParam();46 listParam26.setList(list1);47 listParam0.setList(list1);48 ListParam listParam28 = new ListParam();49 listParam28.setList(list1);50 listParam0.setList(list1);51 ListParam listParam30 = new ListParam();52 listParam30.setList(list1);

Full Screen

Full Screen

newInstance

Using AI Code Generation

copy

Full Screen

1import org.evomaster.client.java.controller.problem.rpc.schema.params.ListParam;2import java.util.ArrayList;3import java.util.List;4import java.util.stream.Collectors;5public class ListParamTest {6 public static void main(String[] args) {7 ListParam listParam = new ListParam();8 List<String> list = new ArrayList<>();9 list.add("foo");10 list.add("bar");11 listParam.setList(list);12 System.out.println(listParam.getList());13 ListParam listParam2 = listParam.newInstance();14 System.out.println(listParam2.getList());15 }16}

Full Screen

Full Screen

newInstance

Using AI Code Generation

copy

Full Screen

1ListParam listParam = new ListParam();2listParam.setValues(new ArrayList<>());3listParam.getValues().add("value1");4listParam.getValues().add("value2");5listParam.getValues().add("value3");6listParam.getValues().add("value4");7listParam.getValues().add("value5");8listParam.getValues().add("value6");9listParam.getValues().add("value7");10listParam.getValues().add("value8");11listParam.getValues().add("value9");12listParam.getValues().add("value10");13listParam.getValues().add("value11");14listParam.getValues().add("value12");15listParam.getValues().add("value13");16listParam.getValues().add("value14");17listParam.getValues().add("value15");18listParam.getValues().add("value16");19listParam.getValues().add("value17");20listParam.getValues().add("value18");21listParam.getValues().add("value19");22listParam.getValues().add("value20");23listParam.getValues().add("value21");24listParam.getValues().add("value22");25listParam.getValues().add("value23");26listParam.getValues().add("value24");27listParam.getValues().add("value25");28listParam.getValues().add("value26");29listParam.getValues().add("value27");30listParam.getValues().add("value28");31listParam.getValues().add("value29");32listParam.getValues().add("value30");33listParam.getValues().add("value31");34listParam.getValues().add("value32");35listParam.getValues().add("value33");36listParam.getValues().add("value34");37listParam.getValues().add("value35");38listParam.getValues().add("value36");39listParam.getValues().add("value37");40listParam.getValues().add("value38");41listParam.getValues().add("value39");42listParam.getValues().add("value40");43listParam.getValues().add("value41");44listParam.getValues().add("value42");45listParam.getValues().add("value43");46listParam.getValues().add("value44");47listParam.getValues().add("value45");48listParam.getValues().add("value46");49listParam.getValues().add("value47");50listParam.getValues().add("value48");

Full Screen

Full Screen

newInstance

Using AI Code Generation

copy

Full Screen

1public class ListParam {2 public static ListParam newInstance() {3 ListParam listParam = new ListParam();4 return listParam;5 }6 public static ListParam newInstance(List<Param> value) {7 ListParam listParam = new ListParam();8 listParam.value = value;9 return listParam;10 }11 private List<Param> value;12 public List<Param> getValue() {13 return value;14 }15 public void setValue(List<Param> value) {16 this.value = value;17 }18 public ListParam() {19 }20}21public class Param {22 public static Param newInstance() {23 Param param = new Param();24 return param;25 }26 public static Param newInstance(String name, String value) {27 Param param = new Param();28 param.name = name;29 param.value = value;30 return param;31 }32 private String name;33 public String getName() {34 return name;35 }36 public void setName(String name) {37 this.name = name;38 }39 private String value;40 public String getValue() {41 return value;42 }43 public void setValue(String value) {44 this.value = value;45 }46 public Param() {47 }48}49public class StringParam {50 public static StringParam newInstance() {51 StringParam stringParam = new StringParam();52 return stringParam;53 }54 public static StringParam newInstance(String value) {55 StringParam stringParam = new StringParam();56 stringParam.value = value;57 return stringParam;58 }59 private String value;60 public String getValue() {61 return value;62 }63 public void setValue(String value) {64 this.value = value;65 }66 public StringParam() {67 }68}69public class VoidParam {70 public static VoidParam newInstance() {71 VoidParam voidParam = new VoidParam();72 return voidParam;73 }74 public VoidParam() {75 }76}

Full Screen

Full Screen

newInstance

Using AI Code Generation

copy

Full Screen

1public class 2 {2 public static void main(String[] args) throws Exception {3 ListParam listParam = new ListParam();4 listParam.setValues(new ArrayList<>());5 listParam.setClassName("java.util.ArrayList");6 listParam.setGenericClass("java.lang.String");7 ListParam listParam2 = listParam.newInstance();8 listParam2.setValues(new ArrayList<>());9 listParam2.setClassName("java.util.ArrayList");10 listParam2.setGenericClass("java.lang.String");11 System.out.println(listParam2);12 }13}14ListParam{values=[], className='java.util.ArrayList', genericClass='java.lang.String'}15public class 3 {16 public static void main(String[] args) throws Exception {17 ListParam listParam = new ListParam();18 listParam.setValues(new ArrayList<>());19 listParam.setClassName("java.util.ArrayList");20 listParam.setGenericClass("java.lang.String");21 ListParam listParam2 = listParam.newInstance();22 listParam2.setValues(new ArrayList<>());23 listParam2.setClassName("java.util.ArrayList");24 listParam2.setGenericClass("java.lang.String");25 System.out.println(listParam2);26 }27}28ListParam{values=[], className='java.util.ArrayList', genericClass='java.lang.String'}29public class 4 {30 public static void main(String[] args) throws Exception {31 ListParam listParam = new ListParam();32 listParam.setValues(new ArrayList<>());33 listParam.setClassName("java.util.ArrayList");34 listParam.setGenericClass("java.lang.String");35 ListParam listParam2 = listParam.newInstance();36 listParam2.setValues(new ArrayList<>());37 listParam2.setClassName("java.util.ArrayList");38 listParam2.setGenericClass("java.lang.String");39 System.out.println(listParam2);40 }41}42ListParam{values=[], className='java.util.ArrayList', genericClass='java.lang.String'}43public class 5 {44 public static void main(String[] args) throws Exception {

Full Screen

Full Screen

newInstance

Using AI Code Generation

copy

Full Screen

1package org.evomaster.client.java.controller.problem.rpc;2import java.util.List;3import java.util.ArrayList;4public class ListParam{5 private List<String> list;6 private String string;7 public ListParam(List<String> list, String string){8 this.list = list;9 this.string = string;10 }11 public ListParam(){12 this.list = new ArrayList<>();13 this.string = new String();14 }15 public List<String> getList(){16 return this.list;17 }18 public void setList(List<String> list){19 this.list = list;20 }21 public String getString(){22 return this.string;23 }24 public void setString(String string){25 this.string = string;26 }27 public ListParam clone(){28 ListParam clone = new ListParam();29 clone.setList(this.list);30 clone.setString(this.string);31 return clone;32 }33 public static ListParam newInstance(){34 return new ListParam();35 }36 public String toString(){37 return "ListParam{" +38 '}';39 }40}41package org.evomaster.client.java.controller.problem.rpc;42import java.util.List;43import java.util.ArrayList;44public class ListParam{45 private List<String> list;46 private String string;47 public ListParam(List<String> list, String string){48 this.list = list;49 this.string = string;50 }51 public ListParam(){52 this.list = new ArrayList<>();53 this.string = new String();54 }55 public List<String> getList(){56 return this.list;57 }58 public void setList(List<String> list){59 this.list = list;60 }61 public String getString(){62 return this.string;63 }64 public void setString(String string){65 this.string = string;66 }67 public ListParam clone(){68 ListParam clone = new ListParam();69 clone.setList(this.list);70 clone.setString(this.string);71 return clone;72 }73 public static ListParam newInstance(){74 return new ListParam();75 }76 public String toString(){77 return "ListParam{" +78 '}';79 }80}

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