Best EvoMaster code snippet using com.thrift.example.real.thrift.test.Numberz
Source:ThriftTestEndpointsBuilderTest.java
...34 assertEquals(expectedNumberOfEndpoints(), schema.getEndpoints().size());35 }36 @Test37 public void testDepth(){38 List<Class> clazz = Arrays.asList(Xtruct.class, Xtruct2.class, Insanity.class, Numberz.class, Xception.class, Xception2.class, TException.class);39 Map<String, NamedTypedValue> typedValueMap = schema.getObjParamCollections();40 assertEquals(clazz.size(), typedValueMap.size());41 assertEquals(0, typedValueMap.get(Xtruct.class.getName()).getType().depth);42 assertEquals(0, typedValueMap.get(Numberz.class.getName()).getType().depth);43 assertEquals(0, typedValueMap.get(Xception.class.getName()).getType().depth);44 assertEquals(0, typedValueMap.get(TException.class.getName()).getType().depth);45 assertEquals(1, typedValueMap.get(Xtruct2.class.getName()).getType().depth);46 assertEquals(1, typedValueMap.get(Xception2.class.getName()).getType().depth);47 assertEquals(2, typedValueMap.get(Insanity.class.getName()).getType().depth);48 }49 @Test50 public void testAllContainTException(){51 boolean all = schema.getEndpoints().stream().allMatch(e-> containType(e.getExceptions(),"org.apache.thrift.TException" ));52 assertTrue(all);53 }54 @Test55 public void testVoid(){56 EndpointSchema endpoint = getOneEndpoint("testVoid");57 NamedTypedValue response = endpoint.getResponse();58 assertNull(response);59 assertTrue(endpoint.getRequestParams().isEmpty());60 assertEquals(1, endpoint.getExceptions().size());61 }62 @Test63 public void testString() throws ClassNotFoundException {64 EndpointSchema endpoint = getOneEndpoint("testString");65 NamedTypedValue response = endpoint.getResponse();66 assertNotNull(response);67 assertTrue(response instanceof StringParam);68 assertEquals(1, endpoint.getRequestParams().size());69 NamedTypedValue p1 = endpoint.getRequestParams().get(0);70 assertTrue(p1 instanceof StringParam);71 assertEquals(1, endpoint.getExceptions().size());72 String input = "foo";73 p1.setValueBasedOnInstance(input);74 assertTrue(p1.newInstance().equals(input));75 assertTrue(p1.getDto().stringValue.equals(input));76 assertEquals(RPCSupportedDataType.STRING, p1.getDto().type.type);77 List<String> javaCode = p1.newInstanceWithJava(0);78 assertEquals(1, javaCode.size());79 assertTrue(javaCode.get(0).equals("java.lang.String arg0 = \"foo\";"));80 List<String> endpointJavaCode = endpoint.newInvocationWithJava("res1","controller",null);81 assertEquals(5, endpointJavaCode.size());82 assertEquals("java.lang.String res1 = null;", endpointJavaCode.get(0));83 assertEquals("{", endpointJavaCode.get(1));84 assertEquals(" java.lang.String arg0 = \"foo\";", endpointJavaCode.get(2));85 assertEquals(" res1 = ((com.thrift.example.artificial.RPCInterfaceExampleImpl)(controller.getRPCClient(\"com.thrift.example.real.thrift.test.ThriftTest$Iface\"))).testString(arg0);", endpointJavaCode.get(3));86 assertEquals("}", endpointJavaCode.get(4));87 List<String> assertionJavaCode = p1.newAssertionWithJava(0, "res1", -1);88 assertEquals(1, assertionJavaCode.size());89 assertEquals("assertEquals(\"foo\", res1);", assertionJavaCode.get(0));90 }91 @Test92 public void testBool() throws ClassNotFoundException {93 EndpointSchema endpoint = getOneEndpoint("testBool");94 NamedTypedValue response = endpoint.getResponse();95 assertNotNull(response);96 assertTrue(response instanceof BooleanParam);97 assertEquals(1, endpoint.getRequestParams().size());98 NamedTypedValue p1 = endpoint.getRequestParams().get(0);99 assertTrue(p1 instanceof BooleanParam);100 assertEquals(1, endpoint.getExceptions().size());101 boolean input = true;102 p1.setValueBasedOnInstance(input);103 assertTrue(p1.newInstance().equals(input));104 assertTrue(p1.getDto().stringValue.equals(""+input));105 assertEquals(RPCSupportedDataType.P_BOOLEAN, p1.getDto().type.type);106 List<String> javaCode = p1.newInstanceWithJava(0);107 assertEquals(1, javaCode.size());108 assertTrue(javaCode.get(0).equals("boolean arg0 = true;"));109 List<String> assertionJavaCode = p1.newAssertionWithJava(0, "res1", -1);110 assertEquals(1, assertionJavaCode.size());111 assertEquals("assertEquals(true, res1);", assertionJavaCode.get(0));112 }113 @Test114 public void testByte() throws ClassNotFoundException {115 EndpointSchema endpoint = getOneEndpoint("testByte");116 NamedTypedValue response = endpoint.getResponse();117 assertNotNull(response);118 assertTrue(response instanceof ByteParam);119 assertEquals(1, endpoint.getRequestParams().size());120 NamedTypedValue p1 = endpoint.getRequestParams().get(0);121 assertTrue(p1 instanceof ByteParam);122 assertEquals(1, endpoint.getExceptions().size());123 byte input = 42;124 p1.setValueBasedOnInstance(input);125 assertTrue(p1.newInstance().equals(input));126 assertTrue(p1.getDto().stringValue.equals(""+input));127 assertEquals(RPCSupportedDataType.P_BYTE, p1.getDto().type.type);128 List<String> javaCode = p1.newInstanceWithJava(0);129 assertEquals(1, javaCode.size());130 assertTrue(javaCode.get(0).equals("byte arg0 = 42;"));131 List<String> assertionJavaCode = p1.newAssertionWithJava(0, "res1", -1);132 assertEquals(1, assertionJavaCode.size());133 assertEquals("assertEquals(42, res1);", assertionJavaCode.get(0));134 }135 @Test136 public void testInt() throws ClassNotFoundException {137 EndpointSchema endpoint = getOneEndpoint("testI32");138 NamedTypedValue response = endpoint.getResponse();139 assertNotNull(response);140 assertTrue(response instanceof IntParam);141 assertEquals(1, endpoint.getRequestParams().size());142 NamedTypedValue p1 = endpoint.getRequestParams().get(0);143 assertTrue(p1 instanceof IntParam);144 assertEquals(1, endpoint.getExceptions().size());145 int input = 42;146 p1.setValueBasedOnInstance(input);147 assertTrue(p1.newInstance().equals(input));148 assertTrue(p1.getDto().stringValue.equals(""+input));149 assertEquals(RPCSupportedDataType.P_INT, p1.getDto().type.type);150 List<String> javaCode = p1.newInstanceWithJava(0);151 assertEquals(1, javaCode.size());152 assertTrue(javaCode.get(0).equals("int arg0 = 42;"));153 List<String> assertionJavaCode = p1.newAssertionWithJava(0, "res1", -1);154 assertEquals(1, assertionJavaCode.size());155 assertEquals("assertEquals(42, res1);", assertionJavaCode.get(0));156 }157 @Test158 public void testLong() throws ClassNotFoundException {159 EndpointSchema endpoint = getOneEndpoint("testI64");160 NamedTypedValue response = endpoint.getResponse();161 assertNotNull(response);162 assertTrue(response instanceof LongParam);163 assertEquals(1, endpoint.getRequestParams().size());164 NamedTypedValue p1 = endpoint.getRequestParams().get(0);165 assertTrue(p1 instanceof LongParam);166 assertEquals(1, endpoint.getExceptions().size());167 long input = 42L;168 p1.setValueBasedOnInstance(input);169 assertTrue(p1.newInstance().equals(input));170 assertTrue(p1.getDto().stringValue.equals(""+input));171 assertEquals(RPCSupportedDataType.P_LONG, p1.getDto().type.type);172 List<String> javaCode = p1.newInstanceWithJava(0);173 assertEquals(1, javaCode.size());174 assertTrue(javaCode.get(0).equals("long arg0 = 42L;"));175 List<String> assertionJavaCode = p1.newAssertionWithJava(0, "res1", -1);176 assertEquals(1, assertionJavaCode.size());177 assertEquals("assertEquals(42L, res1);", assertionJavaCode.get(0));178 }179 @Test180 public void testDouble() throws ClassNotFoundException {181 EndpointSchema endpoint = getOneEndpoint("testDouble");182 NamedTypedValue response = endpoint.getResponse();183 assertNotNull(response);184 assertTrue(response instanceof DoubleParam);185 assertEquals(1, endpoint.getRequestParams().size());186 NamedTypedValue p1 = endpoint.getRequestParams().get(0);187 assertTrue(p1 instanceof DoubleParam);188 assertEquals(1, endpoint.getExceptions().size());189 double input = 42.42;190 p1.setValueBasedOnInstance(input);191 assertTrue(p1.newInstance().equals(input));192 assertTrue(p1.getDto().stringValue.equals(""+input));193 assertEquals(RPCSupportedDataType.P_DOUBLE, p1.getDto().type.type);194 List<String> javaCode = p1.newInstanceWithJava(0);195 assertEquals(1, javaCode.size());196 assertTrue(javaCode.get(0).equals("double arg0 = 42.42;"));197 List<String> assertionJavaCode = p1.newAssertionWithJava(0, "res1", -1);198 assertEquals(1, assertionJavaCode.size());199 assertEquals("assertTrue(numbersMatch(42.42, res1));", assertionJavaCode.get(0));200 }201 @Test202 public void testBinary() throws ClassNotFoundException {203 EndpointSchema endpoint = getOneEndpoint("testBinary");204 NamedTypedValue response = endpoint.getResponse();205 assertNotNull(response);206 assertTrue(response instanceof ByteBufferParam);207 assertEquals(1, endpoint.getRequestParams().size());208 NamedTypedValue p1 = endpoint.getRequestParams().get(0);209 assertTrue(p1 instanceof ByteBufferParam);210 assertEquals(1, endpoint.getExceptions().size());211 byte[] input = "foo".getBytes(StandardCharsets.UTF_8);212 ByteBuffer buffer = ByteBuffer.allocate(input.length);213 buffer.put(input);214 p1.setValueBasedOnInstance(buffer);215 assertTrue(p1.newInstance() instanceof ByteBuffer);216 String extracted = new String(((ByteBuffer) p1.newInstance()).array(), StandardCharsets.UTF_8);217 assertTrue(extracted.equals("foo"));218 assertTrue(p1.getDto().stringValue.equals("foo"));219 assertEquals(RPCSupportedDataType.BYTEBUFFER, p1.getDto().type.type);220 List<String> javaCode = p1.newInstanceWithJava(0);221 assertEquals(6, javaCode.size());222 assertEquals("java.nio.ByteBuffer arg0 = null;", javaCode.get(0));223 assertEquals("{", javaCode.get(1));224 assertEquals(" byte[] arg0_byteArray = \"foo\".getBytes(java.nio.charset.StandardCharsets.UTF_8);", javaCode.get(2));225 assertEquals(" arg0 = java.nio.ByteBuffer.allocate(arg0_byteArray.length);", javaCode.get(3));226 assertEquals(" arg0.put(arg0_byteArray);", javaCode.get(4));227 assertEquals("}", javaCode.get(5));228 List<String> assertionJavaCode = p1.newAssertionWithJava(0, "res1", -1);229 assertEquals(1, assertionJavaCode.size());230 assertEquals("// not handle ByteBuffer assertion", assertionJavaCode.get(0));231 }232 @Test233 public void testStruct() throws ClassNotFoundException {234 EndpointSchema endpoint = getOneEndpoint("testStruct");235 NamedTypedValue response = endpoint.getResponse();236 assertNotNull(response);237 assertTrue(response instanceof ObjectParam);238 assertEquals("com.thrift.example.real.thrift.test.Xtruct", response.getType().getFullTypeName());239 List<NamedTypedValue> fields = ((ObjectType)response.getType()).getFields();240 assertEquals(4, fields.size());241 assertTrue(fields.get(0) instanceof StringParam);242 assertTrue(fields.get(1) instanceof ByteParam);243 assertTrue(fields.get(2) instanceof IntParam);244 assertTrue(fields.get(3) instanceof LongParam);245 assertEquals(1, endpoint.getRequestParams().size());246 NamedTypedValue request = endpoint.getRequestParams().get(0);247 assertTrue(request instanceof ObjectParam);248 assertEquals("com.thrift.example.real.thrift.test.Xtruct", request.getType().getFullTypeName());249 Xtruct input = new Xtruct();250 input.string_thing = "foo";251 input.byte_thing = 42;252 input.i32_thing = 42;253 input.i64_thing = 42L;254 request.setValueBasedOnInstance(input);255 Object instance = request.newInstance();256 assertTrue(instance instanceof Xtruct);257 assertEquals(input.byte_thing, ((Xtruct)instance).byte_thing);258 assertEquals(input.i32_thing, ((Xtruct)instance).i32_thing);259 assertEquals(input.i64_thing, ((Xtruct)instance).i64_thing);260 assertEquals(input.string_thing, ((Xtruct)instance).string_thing);261 ParamDto dto = request.getDto();262 assertEquals(dto.type.type, RPCSupportedDataType.CUSTOM_OBJECT);263 assertEquals(4, dto.innerContent.size());264 for (ParamDto fdto : dto.innerContent){265 if (fdto.name.equals("string_thing")){266 assertEquals(input.string_thing, fdto.stringValue);267 } else if (fdto.name.equals("byte_thing")){268 assertEquals(fdto.stringValue, "" + input.byte_thing);269 } else if (fdto.name.equals("i32_thing")){270 assertEquals(fdto.stringValue, "" + input.i32_thing);271 } else if (fdto.name.equals("i64_thing")){272 assertEquals(fdto.stringValue, "" + input.i64_thing);273 } else {274 fail("error field name "+fdto.name);275 }276 }277 List<String> javaCode = request.newInstanceWithJava(0);278 assertEquals(8, javaCode.size());279 assertEquals("com.thrift.example.real.thrift.test.Xtruct arg0 = null;", javaCode.get(0));280 assertEquals("{", javaCode.get(1));281 assertEquals(" arg0 = new com.thrift.example.real.thrift.test.Xtruct();", javaCode.get(2));282 assertEquals(" arg0.string_thing = \"foo\";", javaCode.get(3));283 assertEquals(" arg0.byte_thing = 42;", javaCode.get(4));284 assertEquals(" arg0.i32_thing = 42;", javaCode.get(5));285 assertEquals(" arg0.i64_thing = 42L;", javaCode.get(6));286 assertEquals("}", javaCode.get(7));287 List<String> assertionJavaCode = request.newAssertionWithJava(0, "res1", -1);288 assertEquals(4, assertionJavaCode.size());289 assertEquals("assertEquals(\"foo\", res1.string_thing);", assertionJavaCode.get(0));290 assertEquals("assertEquals(42, res1.byte_thing);", assertionJavaCode.get(1));291 assertEquals("assertEquals(42, res1.i32_thing);", assertionJavaCode.get(2));292 assertEquals("assertEquals(42L, res1.i64_thing);", assertionJavaCode.get(3));293 // thrift inits the default value for primitive types294 Xtruct empty = new Xtruct();295 request.setValueBasedOnInstance(empty);296 javaCode = request.newInstanceWithJava(0);297 assertEquals(8, javaCode.size());298 assertEquals("com.thrift.example.real.thrift.test.Xtruct arg0 = null;", javaCode.get(0));299 assertEquals("{", javaCode.get(1));300 assertEquals(" arg0 = new com.thrift.example.real.thrift.test.Xtruct();", javaCode.get(2));301 assertEquals(" arg0.byte_thing = 0;", javaCode.get(4));302 assertEquals(" arg0.i32_thing = 0;", javaCode.get(5));303 assertEquals(" arg0.i64_thing = 0L;", javaCode.get(6));304 assertEquals("}", javaCode.get(7));305 assertionJavaCode = request.newAssertionWithJava(0, "res1", -1);306 assertEquals(4, assertionJavaCode.size());307 assertEquals("assertNull(res1.string_thing);", assertionJavaCode.get(0));308 assertEquals("assertEquals(0, res1.byte_thing);", assertionJavaCode.get(1));309 assertEquals("assertEquals(0, res1.i32_thing);", assertionJavaCode.get(2));310 assertEquals("assertEquals(0L, res1.i64_thing);", assertionJavaCode.get(3));311 }312 @Test313 public void testNest() throws ClassNotFoundException {314 EndpointSchema endpoint = getOneEndpoint("testNest");315 NamedTypedValue response = endpoint.getResponse();316 assertNotNull(response);317 assertTrue(response instanceof ObjectParam);318 assertEquals(Xtruct2.class.getName(), response.getType().getFullTypeName());319 List<NamedTypedValue> fields = ((ObjectType)response.getType()).getFields();320 assertEquals(3, fields.size());321 assertTrue(fields.get(0) instanceof ByteParam);322 assertTrue(fields.get(1) instanceof ObjectParam);323 assertTrue(fields.get(2) instanceof IntParam);324 List<NamedTypedValue> ifields = ((ObjectType)(fields.get(1)).getType()).getFields();325 assertEquals(4, ifields.size());326 assertEquals(1, endpoint.getRequestParams().size());327 NamedTypedValue request = endpoint.getRequestParams().get(0);328 assertTrue(request instanceof ObjectParam);329 assertEquals(Xtruct2.class.getName(), request.getType().getFullTypeName());330 List<NamedTypedValue> rfields = ((ObjectType)request.getType()).getFields();331 assertEquals(3, rfields.size());332 assertTrue(rfields.get(0) instanceof ByteParam);333 assertTrue(rfields.get(1) instanceof ObjectParam);334 assertTrue(rfields.get(2) instanceof IntParam);335 List<NamedTypedValue> rifields = ((ObjectType)(rfields.get(1)).getType()).getFields();336 assertEquals(4, rifields.size());337 Xtruct2 input = new Xtruct2();338 input.byte_thing = 42;339 input.i32_thing = 42;340 Xtruct objField = new Xtruct();341 input.struct_thing = objField;342 objField.i64_thing = 100L;343 objField.i32_thing = 100;344 objField.byte_thing = 100;345 objField.string_thing = "bar";346 request.setValueBasedOnInstance(input);347 Object requestInstance = request.newInstance();348 assertTrue(requestInstance instanceof Xtruct2);349 Xtruct2 xinstance2 = (Xtruct2) requestInstance;350 assertEquals(input.byte_thing, xinstance2.byte_thing);351 assertEquals(input.i32_thing, xinstance2.i32_thing);352 assertEquals(objField.byte_thing, input.struct_thing.byte_thing);353 assertEquals(objField.i32_thing, input.struct_thing.i32_thing);354 assertEquals(objField.i64_thing, input.struct_thing.i64_thing);355 ParamDto requestDto = request.getDto();356 assertEquals(RPCSupportedDataType.CUSTOM_OBJECT, requestDto.type.type);357 assertEquals(3, requestDto.innerContent.size());358 for (ParamDto fdto : requestDto.innerContent){359 if (fdto.name.equals("byte_thing")){360 assertEquals(fdto.stringValue, "" + input.byte_thing);361 } else if (fdto.name.equals("i32_thing")){362 assertEquals(fdto.stringValue, "" + input.i32_thing);363 } else if (fdto.name.equals("struct_thing")){364 assertEquals(4, fdto.innerContent.size());365 for (ParamDto fidto : fdto.innerContent){366 if (fidto.name.equals("string_thing")){367 assertEquals(objField.string_thing, fidto.stringValue);368 } else if (fidto.name.equals("byte_thing")){369 assertEquals("" + objField.byte_thing, fidto.stringValue);370 } else if (fidto.name.equals("i32_thing")){371 assertEquals("" + objField.i32_thing, fidto.stringValue);372 } else if (fidto.name.equals("i64_thing")){373 assertEquals("" + objField.i64_thing, fidto.stringValue);374 } else {375 fail("error field name of Xtruct "+fidto.name);376 }377 }378 } else {379 fail("error field name of Xtruct "+fdto.name);380 }381 }382 List<String> javaCode = request.newInstanceWithJava(0);383 assertEquals(14, javaCode.size());384 assertEquals("com.thrift.example.real.thrift.test.Xtruct2 arg0 = null;", javaCode.get(0));385 assertEquals("{", javaCode.get(1));386 assertEquals(" arg0 = new com.thrift.example.real.thrift.test.Xtruct2();", javaCode.get(2));387 assertEquals(" arg0.byte_thing = 42;", javaCode.get(3));388 assertEquals(" arg0.struct_thing = null;", javaCode.get(4));389 assertEquals(" {", javaCode.get(5));390 assertEquals(" arg0.struct_thing = new com.thrift.example.real.thrift.test.Xtruct();", javaCode.get(6));391 assertEquals(" arg0.struct_thing.string_thing = \"bar\";", javaCode.get(7));392 assertEquals(" arg0.struct_thing.byte_thing = 100;", javaCode.get(8));393 assertEquals(" arg0.struct_thing.i32_thing = 100;", javaCode.get(9));394 assertEquals(" arg0.struct_thing.i64_thing = 100L;", javaCode.get(10));395 assertEquals(" }", javaCode.get(11));396 assertEquals(" arg0.i32_thing = 42;", javaCode.get(12));397 assertEquals("}", javaCode.get(13));398 List<String> assertionJavaCode = request.newAssertionWithJava(0, "res1", -1);399 assertEquals(6, assertionJavaCode.size());400 assertEquals("assertEquals(42, res1.byte_thing);", assertionJavaCode.get(0));401 assertEquals("assertEquals(\"bar\", res1.struct_thing.string_thing);", assertionJavaCode.get(1));402 assertEquals("assertEquals(100, res1.struct_thing.byte_thing);", assertionJavaCode.get(2));403 assertEquals("assertEquals(100, res1.struct_thing.i32_thing);", assertionJavaCode.get(3));404 assertEquals("assertEquals(100L, res1.struct_thing.i64_thing);", assertionJavaCode.get(4));405 assertEquals("assertEquals(42, res1.i32_thing);", assertionJavaCode.get(5));406 }407 @Test408 public void testMap() throws ClassNotFoundException {409 EndpointSchema endpoint = getOneEndpoint("testMap");410 NamedTypedValue response = endpoint.getResponse();411 assertNotNull(response);412 assertTrue(response instanceof MapParam);413 PairParam template = ((MapParam)response).getType().getTemplate();414 assertTrue(template.getType().getFirstTemplate() instanceof IntParam);415 assertTrue(template.getType().getSecondTemplate() instanceof IntParam);416 assertEquals(1, endpoint.getRequestParams().size());417 NamedTypedValue p1 = endpoint.getRequestParams().get(0);418 assertTrue(p1 instanceof MapParam);419 assertEquals(1, endpoint.getExceptions().size());420 Map<Integer, Integer> input = new HashMap<Integer, Integer>(){{421 put(1, 2);422 put(2, 3);423 put(42, 43);424 put(100, 101);425 }};426 p1.setValueBasedOnInstance(input);427 Object instance = p1.newInstance();428 assertTrue(instance instanceof Map);429 assertEquals(4, input.size());430 assertEquals(2, input.get(1));431 assertEquals(3, input.get(2));432 assertEquals(43, input.get(42));433 assertEquals(101, input.get(100));434 ParamDto dto = p1.getDto();435 assertEquals(RPCSupportedDataType.MAP, dto.type.type);436 assertEquals(4, dto.innerContent.size());437 Map<Integer, Integer> results = new HashMap<>();438 for (ParamDto e: dto.innerContent){439 assertEquals(2, e.innerContent.size());440 results.put(Integer.parseInt(e.innerContent.get(0).stringValue), Integer.parseInt(e.innerContent.get(1).stringValue));441 }442 assertEquals(4, results.size());443 assertEquals(2, results.get(1));444 assertEquals(3, results.get(2));445 assertEquals(43, results.get(42));446 assertEquals(101, results.get(100));447 List<String> javaCode = p1.newInstanceWithJava(0);448 assertEquals(16, javaCode.size());449 assertEquals("java.util.Map<java.lang.Integer,java.lang.Integer> arg0 = null;", javaCode.get(0));450 assertEquals("{", javaCode.get(1));451 assertEquals(" arg0 = new java.util.HashMap<>();", javaCode.get(2));452 assertEquals(" java.lang.Integer arg0_key_0 = 1;", javaCode.get(3));453 assertEquals(" java.lang.Integer arg0_value_0 = 2;", javaCode.get(4));454 assertEquals(" arg0.put(arg0_key_0,arg0_value_0);", javaCode.get(5));455 assertEquals(" java.lang.Integer arg0_key_1 = 2;", javaCode.get(6));456 assertEquals(" java.lang.Integer arg0_value_1 = 3;", javaCode.get(7));457 assertEquals(" arg0.put(arg0_key_1,arg0_value_1);", javaCode.get(8));458 assertEquals(" java.lang.Integer arg0_key_2 = 100;", javaCode.get(9));459 assertEquals(" java.lang.Integer arg0_value_2 = 101;", javaCode.get(10));460 assertEquals(" arg0.put(arg0_key_2,arg0_value_2);", javaCode.get(11));461 assertEquals(" java.lang.Integer arg0_key_3 = 42;", javaCode.get(12));462 assertEquals(" java.lang.Integer arg0_value_3 = 43;", javaCode.get(13));463 assertEquals(" arg0.put(arg0_key_3,arg0_value_3);", javaCode.get(14));464 assertEquals("}", javaCode.get(15));465 List<String> assertionJavaCode = p1.newAssertionWithJava(0, "res1", -1);466 assertEquals(5, assertionJavaCode.size());467 assertEquals("assertEquals(4, res1.size());", assertionJavaCode.get(0));468 assertEquals("assertEquals(2, res1.get(1).intValue());", assertionJavaCode.get(1));469 assertEquals("assertEquals(3, res1.get(2).intValue());", assertionJavaCode.get(2));470 assertEquals("assertEquals(101, res1.get(100).intValue());", assertionJavaCode.get(3));471 assertEquals("assertEquals(43, res1.get(42).intValue());", assertionJavaCode.get(4));472 assertionJavaCode = p1.newAssertionWithJava(0, "res1", 2);473 assertEquals(1+2, assertionJavaCode.size());474 assertionJavaCode = p1.newAssertionWithJava(0, "res1", 0);475 assertEquals(1, assertionJavaCode.size());476 }477 @Test478 public void testStringMap() throws ClassNotFoundException {479 EndpointSchema endpoint = getOneEndpoint("testStringMap");480 NamedTypedValue response = endpoint.getResponse();481 assertNotNull(response);482 assertTrue(response instanceof MapParam);483 PairParam template = ((MapParam)response).getType().getTemplate();484 assertTrue(template.getType().getFirstTemplate() instanceof StringParam);485 assertTrue(template.getType().getSecondTemplate() instanceof StringParam);486 assertEquals(1, endpoint.getRequestParams().size());487 NamedTypedValue p1 = endpoint.getRequestParams().get(0);488 assertTrue(p1 instanceof MapParam);489 assertEquals(1, endpoint.getExceptions().size());490 Map<String, String> input = new HashMap<String, String>(){{491 put("foo", ""+2);492 put("bar", ""+3);493 put("abc", ""+43);494 put("def", ""+101);495 }};496 p1.setValueBasedOnInstance(input);497 Object instance = p1.newInstance();498 assertTrue(instance instanceof Map);499 assertEquals(4, input.size());500 assertEquals(""+2, input.get("foo"));501 assertEquals(""+3, input.get("bar"));502 assertEquals(""+43, input.get("abc"));503 assertEquals(""+101, input.get("def"));504 ParamDto dto = p1.getDto();505 assertEquals(RPCSupportedDataType.MAP, dto.type.type);506 assertEquals(4, dto.innerContent.size());507 Map<String, String> results = new HashMap<>();508 for (ParamDto e: dto.innerContent){509 assertEquals(2, e.innerContent.size());510 results.put(e.innerContent.get(0).stringValue, e.innerContent.get(1).stringValue);511 }512 assertEquals(4, results.size());513 assertEquals(""+2, results.get("foo"));514 assertEquals(""+3, results.get("bar"));515 assertEquals(""+43, results.get("abc"));516 assertEquals(""+101, results.get("def"));517 List<String> javaCode = p1.newInstanceWithJava(0);518 assertEquals(16, javaCode.size());519 assertEquals("java.util.Map<java.lang.String,java.lang.String> arg0 = null;", javaCode.get(0));520 assertEquals("{", javaCode.get(1));521 assertEquals(" arg0 = new java.util.HashMap<>();", javaCode.get(2));522 assertEquals(" java.lang.String arg0_key_0 = \"bar\";", javaCode.get(3));523 assertEquals(" java.lang.String arg0_value_0 = \"3\";", javaCode.get(4));524 assertEquals(" arg0.put(arg0_key_0,arg0_value_0);", javaCode.get(5));525 assertEquals(" java.lang.String arg0_key_1 = \"abc\";", javaCode.get(6));526 assertEquals(" java.lang.String arg0_value_1 = \"43\";", javaCode.get(7));527 assertEquals(" arg0.put(arg0_key_1,arg0_value_1);", javaCode.get(8));528 assertEquals(" java.lang.String arg0_key_2 = \"def\";", javaCode.get(9));529 assertEquals(" java.lang.String arg0_value_2 = \"101\";", javaCode.get(10));530 assertEquals(" arg0.put(arg0_key_2,arg0_value_2);", javaCode.get(11));531 assertEquals(" java.lang.String arg0_key_3 = \"foo\";", javaCode.get(12));532 assertEquals(" java.lang.String arg0_value_3 = \"2\";", javaCode.get(13));533 assertEquals(" arg0.put(arg0_key_3,arg0_value_3);", javaCode.get(14));534 assertEquals("}", javaCode.get(15));535 List<String> assertionJavaCode = p1.newAssertionWithJava(0, "res1", -1);536 assertEquals(5, assertionJavaCode.size());537 assertEquals("assertEquals(4, res1.size());", assertionJavaCode.get(0));538 assertEquals("assertEquals(\"3\", res1.get(\"bar\"));", assertionJavaCode.get(1));539 assertEquals("assertEquals(\"43\", res1.get(\"abc\"));", assertionJavaCode.get(2));540 assertEquals("assertEquals(\"101\", res1.get(\"def\"));", assertionJavaCode.get(3));541 assertEquals("assertEquals(\"2\", res1.get(\"foo\"));", assertionJavaCode.get(4));542 }543 @Test544 public void testSet() throws ClassNotFoundException {545 EndpointSchema endpoint = getOneEndpoint("testSet");546 NamedTypedValue response = endpoint.getResponse();547 assertNotNull(response);548 assertTrue(response instanceof SetParam);549 NamedTypedValue template = ((SetParam)response).getType().getTemplate();550 assertTrue(template instanceof IntParam);551 assertEquals(1, endpoint.getRequestParams().size());552 NamedTypedValue p1 = endpoint.getRequestParams().get(0);553 assertTrue(p1 instanceof SetParam);554 assertEquals(1, endpoint.getExceptions().size());555 Set<Integer> input = new LinkedHashSet<Integer>(){{556 add(1);557 add(2);558 add(3);559 }};560 p1.setValueBasedOnInstance(input);561 Object instance = p1.newInstance();562 assertTrue(instance instanceof Set);563 assertEquals(3, ((Set)instance).size());564 assertTrue(((Set)instance).containsAll(input));565 ParamDto dto = p1.getDto();566 assertEquals(RPCSupportedDataType.SET, dto.type.type);567 assertEquals(RPCSupportedDataType.INT, dto.type.example.type.type);568 assertEquals(3, dto.innerContent.size());569 assertTrue(dto.innerContent.stream().allMatch(s-> input.contains(Integer.parseInt(s.stringValue))));570 List<String> javaCodes = p1.newInstanceWithJava(0);571 assertEquals(10, javaCodes.size());572 assertEquals("java.util.Set<java.lang.Integer> arg0 = null;", javaCodes.get(0));573 assertEquals("{", javaCodes.get(1));574 assertEquals(" arg0 = new java.util.HashSet<>();", javaCodes.get(2));575 assertEquals(" java.lang.Integer arg0_e_0 = 1;", javaCodes.get(3));576 assertEquals(" arg0.add(arg0_e_0);", javaCodes.get(4));577 assertEquals(" java.lang.Integer arg0_e_1 = 2;", javaCodes.get(5));578 assertEquals(" arg0.add(arg0_e_1);", javaCodes.get(6));579 assertEquals(" java.lang.Integer arg0_e_2 = 3;", javaCodes.get(7));580 assertEquals(" arg0.add(arg0_e_2);", javaCodes.get(8));581 assertEquals("}", javaCodes.get(9));582 List<String> assertionJavaCode = p1.newAssertionWithJava(0, "res1", -1);583 assertEquals(1, assertionJavaCode.size());584 assertEquals("assertEquals(3, res1.size());", assertionJavaCode.get(0));585 assertionJavaCode = p1.newAssertionWithJava(0, "res1", 2);586 assertEquals(1, assertionJavaCode.size());587 }588 @Test589 public void testList() throws ClassNotFoundException {590 EndpointSchema endpoint = getOneEndpoint("testList");591 NamedTypedValue response = endpoint.getResponse();592 assertNotNull(response);593 assertTrue(response instanceof ListParam);594 NamedTypedValue template = ((ListParam)response).getType().getTemplate();595 assertTrue(template instanceof IntParam);596 assertEquals(1, endpoint.getRequestParams().size());597 NamedTypedValue p1 = endpoint.getRequestParams().get(0);598 assertTrue(p1 instanceof ListParam);599 assertEquals(1, endpoint.getExceptions().size());600 List<Integer> input = new ArrayList<Integer>(){{601 add(1);602 add(2);603 add(3);604 }};605 p1.setValueBasedOnInstance(input);606 Object instance = p1.newInstance();607 assertTrue(instance instanceof List);608 assertEquals(3, ((List)instance).size());609 assertTrue(((List)instance).containsAll(input));610 ParamDto dto = p1.getDto();611 assertEquals(RPCSupportedDataType.LIST, dto.type.type);612 assertEquals(RPCSupportedDataType.INT, dto.type.example.type.type);613 assertEquals(3, dto.innerContent.size());614 assertTrue(dto.innerContent.stream().allMatch(s-> input.contains(Integer.parseInt(s.stringValue))));615 List<String> javaCodes = p1.newInstanceWithJava(0);616 assertEquals(10, javaCodes.size());617 assertEquals("java.util.List<java.lang.Integer> arg0 = null;", javaCodes.get(0));618 assertEquals("{", javaCodes.get(1));619 assertEquals(" arg0 = new java.util.ArrayList<>();", javaCodes.get(2));620 assertEquals(" java.lang.Integer arg0_e_0 = 1;", javaCodes.get(3));621 assertEquals(" arg0.add(arg0_e_0);", javaCodes.get(4));622 assertEquals(" java.lang.Integer arg0_e_1 = 2;", javaCodes.get(5));623 assertEquals(" arg0.add(arg0_e_1);", javaCodes.get(6));624 assertEquals(" java.lang.Integer arg0_e_2 = 3;", javaCodes.get(7));625 assertEquals(" arg0.add(arg0_e_2);", javaCodes.get(8));626 assertEquals("}", javaCodes.get(9));627 List<String> assertionJavaCode = p1.newAssertionWithJava(0, "res1", -1);628 assertEquals(4, assertionJavaCode.size());629 assertEquals("assertEquals(3, res1.size());", assertionJavaCode.get(0));630 assertEquals("assertEquals(1, res1.get(0).intValue());", assertionJavaCode.get(1));631 assertEquals("assertEquals(2, res1.get(1).intValue());", assertionJavaCode.get(2));632 assertEquals("assertEquals(3, res1.get(2).intValue());", assertionJavaCode.get(3));633 assertionJavaCode = p1.newAssertionWithJava(0, "res1", 2);634 assertEquals(1+2, assertionJavaCode.size());635 assertionJavaCode = p1.newAssertionWithJava(0, "res1", 0);636 assertEquals(1, assertionJavaCode.size());637 }638 @Test639 public void testEnum() throws ClassNotFoundException {640 EndpointSchema endpoint = getOneEndpoint("testEnum");641 NamedTypedValue response = endpoint.getResponse();642 assertNotNull(response);643 assertTrue(response instanceof EnumParam);644 String[] items = ((EnumParam)response).getType().getItems();645 assertEquals(6, items.length);646 assertTrue(Arrays.asList(items).containsAll(Arrays.asList("ONE", "TWO", "THREE", "FIVE", "SIX", "EIGHT")));647 assertEquals(1, endpoint.getRequestParams().size());648 NamedTypedValue p1 = endpoint.getRequestParams().get(0);649 assertTrue(p1 instanceof EnumParam);650 assertEquals(1, endpoint.getExceptions().size());651 Numberz two = Numberz.TWO;652 int index = two.ordinal();653 p1.setValueBasedOnInstance(two);654 assertEquals(index, ((EnumParam) p1).getValue());655 assertEquals(Numberz.TWO, p1.newInstance());656 ParamDto dto = p1.getDto();657 assertEquals(RPCSupportedDataType.ENUM, dto.type.type);658 assertEquals(""+index, dto.stringValue);659 List<String> javaCode = p1.newInstanceWithJava(0);660 assertEquals(1, javaCode.size());661 assertEquals("com.thrift.example.real.thrift.test.Numberz arg0 = com.thrift.example.real.thrift.test.Numberz.TWO;", javaCode.get(0));662 List<String> assertionJavaCode = p1.newAssertionWithJava(0, "res1", -1);663 assertEquals(1, assertionJavaCode.size());664 assertEquals("assertEquals(com.thrift.example.real.thrift.test.Numberz.TWO, res1);", assertionJavaCode.get(0));665 }666 @Test667 public void testTypedef(){668 EndpointSchema endpoint = getOneEndpoint("testTypedef");669 NamedTypedValue response = endpoint.getResponse();670 assertNotNull(response);671 assertTrue(response instanceof LongParam);672 assertEquals(1, endpoint.getRequestParams().size());673 assertTrue(endpoint.getRequestParams().get(0) instanceof LongParam);674 assertEquals(1, endpoint.getExceptions().size());675 }676 @Test677 public void testMapMap() throws ClassNotFoundException {678 EndpointSchema endpoint = getOneEndpoint("testMapMap");679 NamedTypedValue response = endpoint.getResponse();680 assertNotNull(response);681 assertTrue(response instanceof MapParam);682 PairParam template = ((MapParam)response).getType().getTemplate();683 assertTrue(template.getType().getFirstTemplate() instanceof IntParam);684 NamedTypedValue mapValue = template.getType().getSecondTemplate();685 assertTrue(mapValue instanceof MapParam);686 PairParam templateMapValue=((MapParam)mapValue).getType().getTemplate();687 assertTrue(templateMapValue.getType().getFirstTemplate() instanceof IntParam);688 assertTrue(templateMapValue.getType().getSecondTemplate() instanceof IntParam);689 assertEquals(1, endpoint.getRequestParams().size());690 NamedTypedValue p1 = endpoint.getRequestParams().get(0);691 assertTrue(p1 instanceof IntParam);692 assertEquals(1, endpoint.getExceptions().size());693 // check response for this method694 Map<Integer, Map<Integer, Integer>> responseObj = new HashMap<Integer, Map<Integer, Integer>>(){{695 put(1, new HashMap<Integer, Integer>(){{696 put(1,1);697 put(2,2);698 }});699 put(2, new HashMap<Integer, Integer>(){{700 put(1,2);701 put(2,4);702 put(3,6);703 }});704 }};705 response.setValueBasedOnInstance(responseObj);706 Object instance = response.newInstance();707 assertTrue(instance instanceof Map);708 assertEquals(2, ((Map<?, ?>) instance).size());709 Object key1 = ((Map<?, ?>) instance).get(1);710 assertTrue(key1 instanceof Map);711 assertEquals(2, ((Map<?, ?>) key1).size());712 assertTrue(((Map<?, ?>) key1).keySet().containsAll(responseObj.get(1).keySet()));713 assertTrue(((Map<?, ?>) key1).values().containsAll(responseObj.get(1).values()));714 Object key2 = ((Map<?, ?>) instance).get(2);715 assertTrue(key2 instanceof Map);716 assertEquals(3, ((Map<?, ?>) key2).size());717 assertTrue(((Map<?, ?>) key2).keySet().containsAll(responseObj.get(2).keySet()));718 assertTrue(((Map<?, ?>) key2).values().containsAll(responseObj.get(2).values()));719 ParamDto dto = response.getDto();720 assertEquals(RPCSupportedDataType.MAP, dto.type.type);721 // two pair elements722 assertEquals(2, dto.innerContent.size());723 // 1st pair element724 assertEquals(2, dto.innerContent.get(0).innerContent.size());725 assertEquals(""+1, dto.innerContent.get(0).innerContent.get(0).stringValue);726 assertEquals(RPCSupportedDataType.MAP, dto.innerContent.get(0).innerContent.get(1).type.type);727 assertEquals(2, dto.innerContent.get(0).innerContent.get(1).innerContent.size());728 for (ParamDto p : dto.innerContent.get(0).innerContent.get(1).innerContent){729 assertEquals(2, p.innerContent.size());730 if (p.innerContent.get(0).stringValue.equals("1")){731 assertEquals("1", p.innerContent.get(1).stringValue);732 } else if (p.innerContent.get(0).stringValue.equals("2")){733 assertEquals("2", p.innerContent.get(1).stringValue);734 } else {735 fail("invalid key:value, ie,"+ p.innerContent.get(0).stringValue +":"+p.innerContent.get(1).stringValue);736 }737 }738 // 2nd pair element739 assertEquals(2, dto.innerContent.get(1).innerContent.size());740 assertEquals(""+2, dto.innerContent.get(1).innerContent.get(0).stringValue);741 assertEquals(RPCSupportedDataType.MAP,dto.innerContent.get(1).innerContent.get(1).type.type);742 assertEquals(3, dto.innerContent.get(1).innerContent.get(1).innerContent.size());743 for (ParamDto p : dto.innerContent.get(1).innerContent.get(1).innerContent){744 assertEquals(2, p.innerContent.size());745 if (p.innerContent.get(0).stringValue.equals("1")){746 assertEquals("2", p.innerContent.get(1).stringValue);747 } else if (p.innerContent.get(0).stringValue.equals("2")){748 assertEquals("4", p.innerContent.get(1).stringValue);749 } else if (p.innerContent.get(0).stringValue.equals("3")){750 assertEquals("6", p.innerContent.get(1).stringValue);751 } else {752 fail("invalid key:value, ie,"+ p.innerContent.get(0).stringValue +":"+p.innerContent.get(1).stringValue);753 }754 }755 List<String> assertionNullJavaCode = p1.newAssertionWithJava(0, "res1", -1);756 assertEquals(1, assertionNullJavaCode.size());757 assertEquals("assertNull(res1);", assertionNullJavaCode.get(0));758 List<String> assertionJavaCode = response.newAssertionWithJava(0, "res1", -1);759 assertEquals(8, assertionJavaCode.size());760 assertEquals("assertEquals(2, res1.size());", assertionJavaCode.get(0));761 assertEquals("assertEquals(2, res1.get(1).size());", assertionJavaCode.get(1));762 assertEquals("assertEquals(1, res1.get(1).get(1).intValue());", assertionJavaCode.get(2));763 assertEquals("assertEquals(2, res1.get(1).get(2).intValue());", assertionJavaCode.get(3));764 assertEquals("assertEquals(3, res1.get(2).size());", assertionJavaCode.get(4));765 assertEquals("assertEquals(2, res1.get(2).get(1).intValue());", assertionJavaCode.get(5));766 assertEquals("assertEquals(4, res1.get(2).get(2).intValue());", assertionJavaCode.get(6));767 assertEquals("assertEquals(6, res1.get(2).get(3).intValue());", assertionJavaCode.get(7));768 assertionJavaCode = response.newAssertionWithJava(0, "res1", 1);769 // 2 set size + at most 1 check for value (there is no value at index 0)770 assertTrue(2+1 >= assertionJavaCode.size());771 assertionJavaCode = response.newAssertionWithJava(0, "res1", 0);772 // 2 set size + at most 1 check for value (there is no value at index 0)773 assertEquals(1, assertionJavaCode.size());774 }775 @Test776 public void testInsanity() throws ClassNotFoundException {777 EndpointSchema endpoint = getOneEndpoint("testInsanity");778 NamedTypedValue response = endpoint.getResponse();779 assertNotNull(response);780 assertTrue(response instanceof MapParam);781 PairParam template = ((MapParam)response).getType().getTemplate();782 assertTrue(template.getType().getFirstTemplate() instanceof LongParam);783 NamedTypedValue mapValue = template.getType().getSecondTemplate();784 assertTrue(mapValue instanceof MapParam);785 PairParam templateMapValue=((MapParam)mapValue).getType().getTemplate();786 assertTrue(templateMapValue.getType().getFirstTemplate() instanceof EnumParam);787 assertTrue(templateMapValue.getType().getSecondTemplate() instanceof ObjectParam);788 assertEquals(1, endpoint.getRequestParams().size());789 NamedTypedValue p1 = endpoint.getRequestParams().get(0);790 assertTrue(p1 instanceof ObjectParam);791 assertEquals(1, endpoint.getExceptions().size());792 Map<Numberz, Long> userMap = new HashMap<Numberz, Long>(){{793 put(Numberz.TWO, 2L);794 put(Numberz.EIGHT, 8L);795 put(Numberz.SIX, 6L);796 }};797 List<Xtruct> xtructs = new ArrayList<Xtruct>(){{798 add(new Xtruct("foo",((byte)100), 100, 100L));799 }};800 Insanity input = new Insanity(userMap, xtructs);801 p1.setValueBasedOnInstance(input);802 Object instance = p1.newInstance();803 assertTrue(instance instanceof Insanity);804 assertEquals(3, ((Insanity) instance).userMap.size());805 assertTrue(((Insanity) instance).userMap.keySet().containsAll(userMap.keySet()));806 assertTrue(((Insanity) instance).userMap.values().containsAll(userMap.values()));807 ParamDto dto = p1.getDto();808 assertEquals(RPCSupportedDataType.CUSTOM_OBJECT, dto.type.type);809 assertEquals(2, dto.innerContent.size());810 ParamDto userMapDto = dto.innerContent.get(0);811 assertEquals(RPCSupportedDataType.MAP, userMapDto.type.type);812 // check example813 assertEquals(2, userMapDto.type.example.innerContent.size());814 assertEquals(RPCSupportedDataType.ENUM, userMapDto.type.example.innerContent.get(0).type.type);815 assertEquals(RPCSupportedDataType.LONG, userMapDto.type.example.innerContent.get(1).type.type);816 assertEquals(3, userMapDto.innerContent.size());817 for (ParamDto p: userMapDto.innerContent){818 assertEquals(2, p.innerContent.size());819 ParamDto key = p.innerContent.get(0);820 ParamDto value = p.innerContent.get(1);821 assertEquals(RPCSupportedDataType.ENUM, key.type.type);822 assertEquals(RPCSupportedDataType.LONG, value.type.type);823 if (key.stringValue.equals(""+Numberz.TWO.ordinal())){824 assertEquals(""+2L, value.stringValue);825 } else if (key.stringValue.equals(""+Numberz.EIGHT.ordinal())){826 assertEquals(""+8L, value.stringValue);827 } else if (key.stringValue.equals(""+Numberz.SIX.ordinal())){828 assertEquals(""+6L, value.stringValue);829 } else {830 fail("invalid key:value, ie,"+ key.stringValue +":"+value.stringValue);831 }832 }833 ParamDto xtructsDto = dto.innerContent.get(1);834 assertEquals(1, xtructsDto.innerContent.size());835 assertEquals(RPCSupportedDataType.LIST, xtructsDto.type.type);836 ParamDto xtructDto = xtructsDto.innerContent.get(0);837 assertEquals(RPCSupportedDataType.CUSTOM_OBJECT, xtructDto.type.type);838 for (ParamDto fdto : xtructDto.innerContent){839 if (fdto.name.equals("string_thing")){840 assertEquals("foo", fdto.stringValue);841 } else if (fdto.name.equals("byte_thing")){842 assertEquals(""+((byte)100), fdto.stringValue);843 } else if (fdto.name.equals("i32_thing")){844 assertEquals(""+100, fdto.stringValue);845 } else if (fdto.name.equals("i64_thing")){846 assertEquals(""+100L, fdto.stringValue);847 } else {848 fail("error field name "+fdto.name);849 }850 }851 List<String> assertionJavaCode = p1.newAssertionWithJava(0, "res1", -1);852 assertEquals(9, assertionJavaCode.size());853 // disable due to flaky854// assertEquals("assertEquals(3, res1.userMap.size());", assertionJavaCode.get(0));855// assertEquals("assertEquals(8L, res1.userMap.get(com.thrift.example.real.thrift.test.Numberz.EIGHT));", assertionJavaCode.get(1));856// assertEquals("assertEquals(6L, res1.userMap.get(com.thrift.example.real.thrift.test.Numberz.SIX));", assertionJavaCode.get(2));857// assertEquals("assertEquals(2L, res1.userMap.get(com.thrift.example.real.thrift.test.Numberz.TWO));", assertionJavaCode.get(3));858// assertEquals("assertEquals(1, res1.xtructs.size());", assertionJavaCode.get(4));859// assertEquals("assertEquals(\"foo\", res1.xtructs.get(0).string_thing);", assertionJavaCode.get(5));860// assertEquals("assertEquals(100, res1.xtructs.get(0).byte_thing);", assertionJavaCode.get(6));861// assertEquals("assertEquals(100, res1.xtructs.get(0).i32_thing);", assertionJavaCode.get(7));862// assertEquals("assertEquals(100L, res1.xtructs.get(0).i64_thing);", assertionJavaCode.get(8));863 }864 @Test865 public void testMulti(){866 EndpointSchema endpoint = getOneEndpoint("testMulti");867 NamedTypedValue response = endpoint.getResponse();868 assertNotNull(response);869 assertTrue(response instanceof ObjectParam);870 assertEquals(6, endpoint.getRequestParams().size());871 assertTrue(endpoint.getRequestParams().get(0) instanceof ByteParam);...
Numberz
Using AI Code Generation
1TTransport transport = new TSocket("localhost", 9090);2transport.open();3TProtocol protocol = new TBinaryProtocol(transport);4Numberz.Client client = new Numberz.Client(protocol);5System.out.println(client.ONE);6transport.close();7transport = new TSocket("localhost", 9090);8transport.open();9protocol = new TBinaryProtocol(transport);10Work.Client client = new Work.Client(protocol);11Work work = new Work();12work.setNum1(1);13work.setNum2(1);14work.setOp(Operation.DIVIDE);15System.out.println(client.calculate(1, work));16transport.close();17transport = new TSocket("localhost", 9090);18transport.open();19protocol = new TBinaryProtocol(transport);20Xtruct.Client client = new Xtruct.Client(protocol);21Xtruct out = client.testStruct(new Xtruct("Zero"));22System.out.println(out);23transport.close();24transport = new TSocket("localhost", 9090);25transport.open();26protocol = new TBinaryProtocol(transport);27Insanity.Client client = new Insanity.Client(protocol);28Insanity out = client.testInsanity();29System.out.println(out);30transport.close();31transport = new TSocket("localhost", 9090);32transport.open();33protocol = new TBinaryProtocol(transport);34XceptionTest.Client client = new XceptionTest.Client(protocol);35try {36 client.testException("Xception");37} catch (Xception e) {38 System.out.println(e);39}40transport.close();41transport = new TSocket("localhost", 9090);42transport.open();43protocol = new TBinaryProtocol(transport);44XceptionTest.Client client = new XceptionTest.Client(protocol);45try {46 client.testException("TException");47} catch (Xception e) {48 System.out.println(e);49}50transport.close();51transport = new TSocket("localhost", 9090);52transport.open();53protocol = new TBinaryProtocol(transport);
Numberz
Using AI Code Generation
1TTransport transport = new TSocket("localhost", 9090);2TProtocol protocol = new TBinaryProtocol(transport);3Numberz.Client client = new Numberz.Client(protocol);4transport.open();5Numberz num = client.testEnum(1);6System.out.println("The enum value is " + num.getValue());7transport.close();8transport = new TSocket("localhost", 9090);9protocol = new TBinaryProtocol(transport);10Work.Client client1 = new Work.Client(protocol);11transport.open();12Work work = new Work();13work.op = Operation.DIVIDE;14work.num1 = 1;15work.num2 = 0;16try {17 int i = client1.testException("test1", work);18 System.out.println(i);19} catch (InvalidOperation io) {20 System.out.println(io.whatOp);21 System.out.println(io.why);22} catch (Exception e) {23 System.out.println(e);24}25transport.close();26transport = new TSocket("localhost", 9090);27protocol = new TBinaryProtocol(transport);28Work.Client client2 = new Work.Client(protocol);29transport.open();30Work work1 = new Work();31work1.op = Operation.SUBTRACT;32work1.num1 = 1;33work1.num2 = 0;34try {35 int i = client2.testException("test2", work1);36 System.out.println(i);37} catch (InvalidOperation io) {38 System.out.println(io.whatOp);39 System.out.println(io.why);40} catch (Exception e) {41 System.out.println(e);42}43transport.close();44transport = new TSocket("localhost", 9090);45protocol = new TBinaryProtocol(transport);46Work.Client client3 = new Work.Client(protocol);47transport.open();48Work work2 = new Work();49work2.op = Operation.MULTIPLY;50work2.num1 = 1;51work2.num2 = 0;52try {53 int i = client3.testException("test3", work2);54 System.out.println(i);55} catch (InvalidOperation io) {56 System.out.println(io.whatOp);57 System.out.println(io.why);58} catch (Exception e) {59 System.out.println(e);60}
Numberz
Using AI Code Generation
1import "com.thrift.example.real.thrift.test.Numberz"2service Calculator {3 i32 add(1:i32 num1, 2:i32 num2),4 i32 calculate(1:i32 logid, 2:Work work),5 void zip(),6 void ping(),7}8struct Work {9}10enum Operation { ADD, SUBTRACT, MULTIPLY, DIVIDE }11exception InvalidOperation {12}13enum Numberz { ONE, TWO, THREE, FIVE, EIGHT, THIRTEEN, TWENTY_ONE, FORTY_TWO }
Numberz
Using AI Code Generation
1import com.thrift.example.real.thrift.test.Numberz;2public class Client {3 public static void main(String[] args) throws Exception {4 TTransport transport = new TSocket("localhost", 9090);5 transport.open();6 TProtocol protocol = new TBinaryProtocol(transport);7 Calculator.Client client = new Calculator.Client(protocol);8 client.ping();9 System.out.println("ping()");10 int sum = client.add(1, 1);11 System.out.println("1+1=" + sum);12 Work work = new Work();13 work.op = Operation.DIVIDE;14 work.num1 = 1;15 work.num2 = 0;16 try {17 int quotient = client.calculate(1, work);18 System.out.println("Whoa we can divide by 0");19 } catch (InvalidOperation io) {20 System.out.println("Invalid operation: " + io.why);21 }22 work.op = Operation.SUBTRACT;23 work.num1 = 15;24 work.num2 = 10;25 try {26 int diff = client.calculate(1, work);27 System.out.println("15-10=" + diff);28 } catch (InvalidOperation io) {29 System.out.println("Invalid operation: " + io.why);30 }31 SharedStruct log = client.getStruct(1);32 System.out.println("Check log: " + log.value);33 transport.close();34 }35}36ping()37package com.thrift.example.real.thrift.test;38import java.util.HashMap;39import java.util.Map;40import org.apache.thrift.TException;41import org.apache.thrift.protocol.TBinaryProtocol;42import org.apache.thrift.protocol.TProtocol;43import org.apache.thrift.server.TServer;44import org.apache.thrift.server.TSimpleServer;45import org.apache.thrift.server.TServer.Args;46import org.apache.thrift.transport.TServerSocket;47import org.apache.thrift.transport.TServerTransport;48import org.apache.thrift.transport.TTransportException;49public class Server {50 public static CalculatorHandler handler;51 public static Calculator.Processor processor;52 public static void main(String [] args) {53 try {
Numberz
Using AI Code Generation
1Numberz x = Numberz.TWO;2Numberz y = Numberz.THREE;3Numberz z = Numberz.FIVE;4Numberz w = Numberz.EIGHT;5Work work = new Work();6work.num1 = 1;7work.num2 = 2;8work.op = Operation.ADD;9work.comment = "1+2";10SharedStruct log = new SharedStruct();11log.key = "1";12log.value = "1";13Insanity crazy = new Insanity();14crazy.userMap = new HashMap<Numberz, Long>();15crazy.userMap.put(Numberz.FIVE, 5000L);16crazy.xtrct = new HashMap<Numberz, Insanity>();17Insanity crazy2 = new Insanity();18crazy2.userMap = new HashMap<Numberz, Long>();19crazy2.userMap.put(Numberz.SIX, 6000L);20crazy2.xtrct = new HashMap<Numberz, Insanity>();21Insanity crazy3 = new Insanity();22crazy3.userMap = new HashMap<Numberz, Long>();23crazy3.userMap.put(Numberz.SIX, 6000L);24crazy3.userMap.put(Numberz.EIGHT, 8000L);25crazy3.xtrct = new HashMap<Numberz, Insanity>();26crazy.xtrct.put(Numberz.SIX, crazy2);27crazy.xtrct.put(Numberz.EIGHT, crazy3);28Xtruct hello = new Xtruct();
Numberz
Using AI Code Generation
1TTransport transport = new TSocket("localhost", 9090);2TProtocol protocol = new TBinaryProtocol(transport);3TestService.Client client = new TestService.Client(protocol);4transport.open();5String resp = client.testString("Hello World");6transport.close();7System.out.println(resp);8import com.thrift.example.real.thrift.test.Numberz;9import com.thrift.example.real.thrift.test.Numberz;10import com.thrift.example.real.thrift.test.Numberz;11TTransport transport = new TSocket("localhost", 9090);12TProtocol protocol = new TBinaryProtocol(transport);13TestService.Client client = new TestService.Client(protocol);14transport.open();15String resp = client.testString("Hello World");16transport.close();17System.out.println(resp);18import com.thrift.example.real.thrift.test.Numberz;19import com.thrift.example.real.thrift.test.Numberz;20import
Numberz
Using AI Code Generation
1import "com.thrift.example.real.thrift.test.Numberz"2import "com.thrift.example.real.thrift.test.Numberz"3service ThriftTest {4 void testVoid(),5 i32 testInt32(1:i32 thing),6 i64 testInt64(1:i64 thing),7 string testString(1:string thing),8 double testDouble(1:double thing),9 Numberz testEnum(1:Numberz thing),10 struct testStruct(1:Struct thing),11 i32 testException(1:string arg),12 map<i32, i32> testMap(1:map<i32, i32> thing),13 set<i32> testSet(1:set<i32> thing),14 list<i32> testList(1:list<i32> thing),15 void testMulti(1:i32 arg0, 2:i64 arg1, 3:string arg2, 4:double arg3, 5:Struct arg4, 6:map<i32, i32> arg5, 7:set<i32> arg6, 8:list<i32> arg7, 9:Numberz arg8),16 void testNest(1:Struct2 thing),17 void testMapMap(1:i32 arg0),18 void testInsanity(1:Insanity arg),19 string testMultiException(1:string arg0, 2:string arg1),20 void testOneway(1:i32 secondsToSleep),21}
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!