|
20 | 20 | * #L% |
21 | 21 | */ |
22 | 22 |
|
23 | | -import static org.easymock.EasyMock.*; |
| 23 | +import static org.easymock.EasyMock.anyString; |
| 24 | +import static org.easymock.EasyMock.capture; |
| 25 | +import static org.easymock.EasyMock.eq; |
| 26 | +import static org.easymock.EasyMock.expect; |
| 27 | +import static org.easymock.EasyMock.expectLastCall; |
24 | 28 | import static org.junit.Assert.assertEquals; |
25 | 29 | import static org.junit.Assert.assertTrue; |
26 | 30 |
|
|
35 | 39 | import com.github.kklisura.cdt.protocol.definition.types.Command; |
36 | 40 | import com.github.kklisura.cdt.protocol.definition.types.Domain; |
37 | 41 | import com.github.kklisura.cdt.protocol.definition.types.Event; |
| 42 | +import com.github.kklisura.cdt.protocol.definition.types.type.ArrayType; |
| 43 | +import com.github.kklisura.cdt.protocol.definition.types.type.StringType; |
| 44 | +import com.github.kklisura.cdt.protocol.definition.types.type.array.items.StringArrayItem; |
38 | 45 | import com.github.kklisura.cdt.protocol.definition.types.type.object.ObjectType; |
39 | 46 | import com.github.kklisura.cdt.protocol.definition.types.type.object.Property; |
40 | 47 | import com.github.kklisura.cdt.protocol.definition.types.type.object.properties.ArrayProperty; |
|
43 | 50 | import com.github.kklisura.cdt.protocol.definition.types.type.object.properties.RefProperty; |
44 | 51 | import com.github.kklisura.cdt.protocol.definition.types.type.object.properties.StringProperty; |
45 | 52 | import com.github.kklisura.cdt.protocol.definition.types.type.object.properties.array.items.EnumArrayItem; |
| 53 | +import com.github.kklisura.cdt.protocol.definition.types.type.object.properties.array.items.RefArrayItem; |
46 | 54 | import java.util.Arrays; |
47 | 55 | import java.util.Collections; |
48 | 56 | import java.util.List; |
@@ -367,6 +375,215 @@ public void testBuildCommandWithMethodWithComplexParams() |
367 | 375 | assertEquals(arrayProperty.getName(), allParams.get(1).getAnnotations().get(2).getValue()); |
368 | 376 | } |
369 | 377 |
|
| 378 | + @Test |
| 379 | + public void testBuildCommandWithMethodWithArrayStringParam() { |
| 380 | + final Domain domain = new Domain(); |
| 381 | + domain.setDomain("domainName"); |
| 382 | + domain.setDescription("Description"); |
| 383 | + |
| 384 | + final Command command = new Command(); |
| 385 | + command.setName("command"); |
| 386 | + command.setDescription("command description"); |
| 387 | + |
| 388 | + final ArrayProperty arrayProperty = new ArrayProperty(); |
| 389 | + arrayProperty.setName("enumParam1"); |
| 390 | + arrayProperty.setOptional(Boolean.FALSE); |
| 391 | + arrayProperty.setDescription("enum param 1 description"); |
| 392 | + |
| 393 | + RefArrayItem enumArrayItem = new RefArrayItem(); |
| 394 | + enumArrayItem.setRef("SomeRefType"); |
| 395 | + arrayProperty.setItems(enumArrayItem); |
| 396 | + command.setParameters(Collections.singletonList(arrayProperty)); |
| 397 | + |
| 398 | + domain.setCommands(Collections.singletonList(command)); |
| 399 | + |
| 400 | + expect(javaBuilderFactory.createInterfaceBuilder(BASE_PACKAGE_NAME, "DomainName")) |
| 401 | + .andReturn(interfaceBuilder); |
| 402 | + interfaceBuilder.setJavaDoc("Description"); |
| 403 | + |
| 404 | + Capture<List<MethodParam>> methodParamCapture = Capture.newInstance(); |
| 405 | + interfaceBuilder.addMethod( |
| 406 | + eq("command"), |
| 407 | + anyString(), |
| 408 | + capture(methodParamCapture), |
| 409 | + eq(null)); |
| 410 | + |
| 411 | + final ArrayType resolvedRefType = new ArrayType(); |
| 412 | + resolvedRefType.setId("arrayRefType"); |
| 413 | + |
| 414 | + final StringArrayItem stringArrayItem = new StringArrayItem(); |
| 415 | + resolvedRefType.setItems(stringArrayItem); |
| 416 | + |
| 417 | + expect(resolver.resolve("domainName", "SomeRefType")).andReturn(resolvedRefType); |
| 418 | + |
| 419 | + interfaceBuilder.addImport("java.util", "List"); |
| 420 | + expectLastCall().times(2); |
| 421 | + |
| 422 | + replayAll(); |
| 423 | + |
| 424 | + Builder build = commandBuilder.build(domain, resolver); |
| 425 | + |
| 426 | + verifyAll(); |
| 427 | + |
| 428 | + assertTrue(build instanceof JavaInterfaceBuilder); |
| 429 | + assertEquals(interfaceBuilder, build); |
| 430 | + |
| 431 | + List<MethodParam> params = methodParamCapture.getValue(); |
| 432 | + assertEquals(1, params.size()); |
| 433 | + |
| 434 | + Assert.assertEquals(arrayProperty.getName(), params.get(0).getName()); |
| 435 | + assertEquals("List<List<String>>", params.get(0).getType()); |
| 436 | + assertEquals("ParamName", params.get(0).getAnnotations().get(0).getName()); |
| 437 | + assertEquals(arrayProperty.getName(), params.get(0).getAnnotations().get(0).getValue()); |
| 438 | + } |
| 439 | + |
| 440 | + @Test |
| 441 | + public void testBuildCommandWithMethodWithArrayRefParam() { |
| 442 | + final Domain domain = new Domain(); |
| 443 | + domain.setDomain("domainName"); |
| 444 | + domain.setDescription("Description"); |
| 445 | + |
| 446 | + final Command command = new Command(); |
| 447 | + command.setName("command"); |
| 448 | + command.setDescription("command description"); |
| 449 | + |
| 450 | + final ArrayProperty arrayProperty = new ArrayProperty(); |
| 451 | + arrayProperty.setName("enumParam1"); |
| 452 | + arrayProperty.setOptional(Boolean.FALSE); |
| 453 | + arrayProperty.setDescription("enum param 1 description"); |
| 454 | + |
| 455 | + RefArrayItem enumArrayItem = new RefArrayItem(); |
| 456 | + enumArrayItem.setRef("SomeRefType"); |
| 457 | + arrayProperty.setItems(enumArrayItem); |
| 458 | + command.setParameters(Collections.singletonList(arrayProperty)); |
| 459 | + |
| 460 | + domain.setCommands(Collections.singletonList(command)); |
| 461 | + |
| 462 | + expect(javaBuilderFactory.createInterfaceBuilder(BASE_PACKAGE_NAME, "DomainName")) |
| 463 | + .andReturn(interfaceBuilder); |
| 464 | + interfaceBuilder.setJavaDoc("Description"); |
| 465 | + |
| 466 | + Capture<List<MethodParam>> methodParamCapture = Capture.newInstance(); |
| 467 | + interfaceBuilder.addMethod( |
| 468 | + eq("command"), |
| 469 | + anyString(), |
| 470 | + capture(methodParamCapture), |
| 471 | + eq(null)); |
| 472 | + |
| 473 | + final ArrayType resolvedRefType = new ArrayType(); |
| 474 | + resolvedRefType.setId("arrayRefType"); |
| 475 | + |
| 476 | + final com.github.kklisura.cdt.protocol.definition.types.type.array.items.RefArrayItem refArrayItem = new com.github.kklisura.cdt.protocol.definition.types.type.array.items.RefArrayItem(); |
| 477 | + refArrayItem.setRef("TestRefArrayItem"); |
| 478 | + resolvedRefType.setItems(refArrayItem); |
| 479 | + |
| 480 | + final StringType stringType = new StringType(); |
| 481 | + stringType.setId("stringType"); |
| 482 | + |
| 483 | + expect(resolver.resolve("domainName", "SomeRefType")).andReturn(resolvedRefType); |
| 484 | + expect(resolver.resolve("domainName", "TestRefArrayItem")).andReturn(stringType); |
| 485 | + |
| 486 | + interfaceBuilder.addImport("java.util", "List"); |
| 487 | + expectLastCall().times(2); |
| 488 | + |
| 489 | + replayAll(); |
| 490 | + |
| 491 | + Builder build = commandBuilder.build(domain, resolver); |
| 492 | + |
| 493 | + verifyAll(); |
| 494 | + |
| 495 | + assertTrue(build instanceof JavaInterfaceBuilder); |
| 496 | + assertEquals(interfaceBuilder, build); |
| 497 | + |
| 498 | + List<MethodParam> params = methodParamCapture.getValue(); |
| 499 | + assertEquals(1, params.size()); |
| 500 | + |
| 501 | + Assert.assertEquals(arrayProperty.getName(), params.get(0).getName()); |
| 502 | + assertEquals("List<List<String>>", params.get(0).getType()); |
| 503 | + assertEquals("ParamName", params.get(0).getAnnotations().get(0).getName()); |
| 504 | + assertEquals(arrayProperty.getName(), params.get(0).getAnnotations().get(0).getValue()); |
| 505 | + } |
| 506 | + |
| 507 | + @Test |
| 508 | + public void testBuildCommandWithMethodWithDeepArrayRefParam() { |
| 509 | + final Domain domain = new Domain(); |
| 510 | + domain.setDomain("domainName"); |
| 511 | + domain.setDescription("Description"); |
| 512 | + |
| 513 | + final Command command = new Command(); |
| 514 | + command.setName("command"); |
| 515 | + command.setDescription("command description"); |
| 516 | + |
| 517 | + final ArrayProperty arrayProperty = new ArrayProperty(); |
| 518 | + arrayProperty.setName("enumParam1"); |
| 519 | + arrayProperty.setOptional(Boolean.FALSE); |
| 520 | + arrayProperty.setDescription("enum param 1 description"); |
| 521 | + |
| 522 | + RefArrayItem enumArrayItem = new RefArrayItem(); |
| 523 | + enumArrayItem.setRef("SomeRefType"); |
| 524 | + arrayProperty.setItems(enumArrayItem); |
| 525 | + command.setParameters(Collections.singletonList(arrayProperty)); |
| 526 | + |
| 527 | + domain.setCommands(Collections.singletonList(command)); |
| 528 | + |
| 529 | + expect(javaBuilderFactory.createInterfaceBuilder(BASE_PACKAGE_NAME, "DomainName")) |
| 530 | + .andReturn(interfaceBuilder); |
| 531 | + interfaceBuilder.setJavaDoc("Description"); |
| 532 | + |
| 533 | + Capture<List<MethodParam>> methodParamCapture = Capture.newInstance(); |
| 534 | + interfaceBuilder.addMethod( |
| 535 | + eq("command"), |
| 536 | + anyString(), |
| 537 | + capture(methodParamCapture), |
| 538 | + eq(null)); |
| 539 | + |
| 540 | + final ArrayType resolvedRefType = new ArrayType(); |
| 541 | + resolvedRefType.setId("arrayRefType"); |
| 542 | + |
| 543 | + final com.github.kklisura.cdt.protocol.definition.types.type.array.items.RefArrayItem refArrayItem = new com.github.kklisura.cdt.protocol.definition.types.type.array.items.RefArrayItem(); |
| 544 | + refArrayItem.setRef("TestRefArrayItem"); |
| 545 | + resolvedRefType.setItems(refArrayItem); |
| 546 | + |
| 547 | + final ArrayType resolvedRefType2 = new ArrayType(); |
| 548 | + resolvedRefType2.setId("arrayRefType2"); |
| 549 | + |
| 550 | + final com.github.kklisura.cdt.protocol.definition.types.type.array.items.RefArrayItem refArrayItem2 = new com.github.kklisura.cdt.protocol.definition.types.type.array.items.RefArrayItem(); |
| 551 | + refArrayItem2.setRef("SomeOtherDomain.TestRefArrayItem2"); |
| 552 | + resolvedRefType2.setItems(refArrayItem2); |
| 553 | + |
| 554 | + final ObjectType objectType = new ObjectType(); |
| 555 | + objectType.setId("objectType"); |
| 556 | + final StringProperty stringProperty = new StringProperty(); |
| 557 | + stringProperty.setName("stringProperty"); |
| 558 | + objectType.setProperties(Collections.singletonList(stringProperty)); |
| 559 | + |
| 560 | + expect(resolver.resolve("domainName", "SomeRefType")).andReturn(resolvedRefType); |
| 561 | + expect(resolver.resolve("domainName", "TestRefArrayItem")).andReturn(resolvedRefType2); |
| 562 | + expect(resolver.resolve("SomeOtherDomain", "TestRefArrayItem2")).andReturn(objectType); |
| 563 | + |
| 564 | + interfaceBuilder.addImport("com.github.kklisura.types.someotherdomain", "TestRefArrayItem2"); |
| 565 | + |
| 566 | + interfaceBuilder.addImport("java.util", "List"); |
| 567 | + expectLastCall().times(3); |
| 568 | + |
| 569 | + replayAll(); |
| 570 | + |
| 571 | + Builder build = commandBuilder.build(domain, resolver); |
| 572 | + |
| 573 | + verifyAll(); |
| 574 | + |
| 575 | + assertTrue(build instanceof JavaInterfaceBuilder); |
| 576 | + assertEquals(interfaceBuilder, build); |
| 577 | + |
| 578 | + List<MethodParam> params = methodParamCapture.getValue(); |
| 579 | + assertEquals(1, params.size()); |
| 580 | + |
| 581 | + Assert.assertEquals(arrayProperty.getName(), params.get(0).getName()); |
| 582 | + assertEquals("List<List<List<TestRefArrayItem2>>>", params.get(0).getType()); |
| 583 | + assertEquals("ParamName", params.get(0).getAnnotations().get(0).getName()); |
| 584 | + assertEquals(arrayProperty.getName(), params.get(0).getAnnotations().get(0).getValue()); |
| 585 | + } |
| 586 | + |
370 | 587 | @Test |
371 | 588 | public void testBuildCommandWithMethodWithComplexReturnParams() { |
372 | 589 | final Domain domain = new Domain(); |
|
0 commit comments