1 15 package org.apache.tapestry.junit.parse; 16 17 import java.util.List ; 18 19 import org.apache.hivemind.Locatable; 20 import org.apache.tapestry.bean.BindingBeanInitializer; 21 import org.apache.tapestry.bean.LightweightBeanInitializer; 22 import org.apache.tapestry.junit.TapestryTestCase; 23 import org.apache.tapestry.spec.BindingType; 24 import org.apache.tapestry.spec.IApplicationSpecification; 25 import org.apache.tapestry.spec.IAssetSpecification; 26 import org.apache.tapestry.spec.IBeanSpecification; 27 import org.apache.tapestry.spec.IBindingSpecification; 28 import org.apache.tapestry.spec.IComponentSpecification; 29 import org.apache.tapestry.spec.IContainedComponent; 30 import org.apache.tapestry.spec.IExtensionSpecification; 31 import org.apache.tapestry.spec.ILibrarySpecification; 32 import org.apache.tapestry.spec.IListenerBindingSpecification; 33 import org.apache.tapestry.spec.IParameterSpecification; 34 import org.apache.tapestry.spec.IPropertySpecification; 35 import org.apache.tapestry.spec.InjectSpecification; 36 import org.apache.tapestry.spec.ListenerBindingSpecification; 37 import org.apache.tapestry.util.xml.DocumentParseException; 38 39 46 47 public class TestSpecificationParser extends TapestryTestCase 48 { 49 50 private void checkLine(Locatable locatable, int line) 51 { 52 assertEquals("Line", line, locatable.getLocation().getLineNumber()); 53 } 54 55 58 59 public void tesMessageBinding() throws Exception 60 { 61 IComponentSpecification spec = parseComponent("TestMessageBinding.jwc"); 62 63 IBindingSpecification bs = spec.getComponent("hello").getBinding("value"); 64 65 assertEquals("type", BindingType.PREFIXED, bs.getType()); 66 assertEquals("key", "message:label.hello", bs.getValue()); 67 68 checkLine(bs, 25); 69 } 70 71 74 75 public void testBinding40() throws Exception 76 { 77 IComponentSpecification spec = parseComponent("Binding40.jwc"); 78 IContainedComponent cc = spec.getComponent("component"); 79 80 IBindingSpecification bs = cc.getBinding("simple"); 81 82 assertEquals(BindingType.PREFIXED, bs.getType()); 83 assertEquals("message:some-key", bs.getValue()); 84 85 bs = cc.getBinding("enclosed"); 86 87 assertEquals(BindingType.PREFIXED, bs.getType()); 88 assertEquals("ognl:zip.zap.zoop", bs.getValue()); 89 } 90 91 96 97 public void testValidParameterName() throws Exception 98 { 99 IComponentSpecification spec = parseComponent("ValidParameterName.jwc"); 100 101 IParameterSpecification ps = spec.getParameter("valid"); 102 103 assertNotNull("Parameter specification.", ps); 104 checkLine(ps, 24); 105 } 106 107 112 113 public void testInvalidParameterName() throws Exception 114 { 115 try 116 { 117 parseComponent("InvalidParameterName.jwc"); 118 119 unreachable(); 120 } 121 catch (DocumentParseException ex) 122 { 123 checkException(ex, "in-valid"); 124 checkException(ex, "Parameter"); 125 } 126 } 127 128 133 134 public void testInvalidComponentId() throws Exception 135 { 136 try 137 { 138 parseComponent("InvalidComponentId.jwc"); 139 140 unreachable(); 141 } 142 catch (DocumentParseException ex) 143 { 144 checkException(ex, "in.valid"); 145 checkException(ex, "component id"); 146 } 147 } 148 149 154 155 public void testInvalidLibraryId() throws Exception 156 { 157 try 158 { 159 parseLib("InvalidLibraryId.library"); 160 161 unreachable(); 162 } 163 catch (DocumentParseException ex) 164 { 165 checkException(ex, "in.valid"); 166 checkException(ex, "library id"); 167 } 168 } 169 170 175 176 public void testValidLibrary() throws Exception 177 { 178 ILibrarySpecification spec = parseLib("ValidLibrary.library"); 179 180 checkLine(spec, 24); 181 182 checkList("pageNames", new String [] 183 { "FirstPage", "SecondPage" }, spec.getPageNames()); 184 185 checkList("componentAliases", new String [] 186 { "FirstComponent", "SecondComponent" }, spec.getComponentTypes()); 187 188 checkList("libraryIds", new String [] 189 { "lib1", "lib2" }, spec.getLibraryIds()); 190 191 assertNotNull(spec.getSpecificationLocation()); 192 } 193 194 199 200 public void testInvalidAssetName() throws Exception 201 { 202 try 203 { 204 parseComponent("InvalidAssetName.jwc"); 205 206 unreachable(); 207 } 208 catch (DocumentParseException ex) 209 { 210 checkException(ex, "in.valid"); 211 checkException(ex, "asset name"); 212 } 213 } 214 215 220 221 public void testInvalidPageName() throws Exception 222 { 223 try 224 { 225 parseApp("InvalidPageName.application"); 226 227 unreachable(); 228 } 229 catch (DocumentParseException ex) 230 { 231 checkException(ex, "in$valid"); 232 checkException(ex, "page name"); 233 } 234 } 235 236 241 242 public void testInvalidComponentAlias() throws Exception 243 { 244 try 245 { 246 parseApp("InvalidComponentAlias.application"); 247 248 unreachable(); 249 } 250 catch (DocumentParseException ex) 251 { 252 checkException(ex, "Invalid$Component"); 253 checkException(ex, "type"); 254 } 255 } 256 257 262 263 public void testInvalidExtensionName() throws Exception 264 { 265 try 266 { 267 parseApp("InvalidExtensionName.application"); 268 269 unreachable(); 270 } 271 catch (DocumentParseException ex) 272 { 273 checkException(ex, "Invalid$Extension"); 274 checkException(ex, "extension name"); 275 } 276 } 277 278 283 284 public void testMissingDoctype() throws Exception 285 { 286 try 287 { 288 parseApp("MissingDoctype.application"); 289 290 unreachable(); 291 } 292 catch (DocumentParseException ex) 293 { 294 checkException(ex, "DOCTYPE"); 297 } 298 } 299 300 303 304 public void testInvalidPublicId() throws Exception 305 { 306 try 307 { 308 parseApp("InvalidPublicId.application"); 309 310 unreachable(); 311 } 312 catch (DocumentParseException ex) 313 { 314 checkException(ex, "has an unexpected public id"); 315 } 316 } 317 318 323 324 public void testNulledApplication() throws Exception 325 { 326 IApplicationSpecification spec = parseApp("NulledApplication.application"); 327 328 assertNull(spec.getEngineClassName()); 329 assertNull(spec.getName()); 330 checkLine(spec, 25); 331 332 assertNotNull(spec.getSpecificationLocation()); 333 } 334 335 340 341 public void testComponentType() throws Exception 342 { 343 IApplicationSpecification spec = parseApp("ComponentType.application"); 344 345 assertEquals("/path/Fred.jwc", spec.getComponentSpecificationPath("Fred")); 346 } 347 348 351 352 public void testNulledComponent() throws Exception 353 { 354 IComponentSpecification spec = parseComponent("NulledComponent.jwc"); 355 356 assertNull(spec.getComponentClassName()); 357 checkLine(spec, 22); 358 359 assertEquals(false, spec.isPageSpecification()); 360 assertNotNull(spec.getSpecificationLocation()); 361 362 assertEquals(false, spec.isDeprecated()); 363 } 364 365 368 369 public void testNulledPage() throws Exception 370 { 371 IComponentSpecification spec = parsePage("NulledPage.page"); 372 373 assertNull(spec.getComponentClassName()); 374 checkLine(spec, 22); 375 376 assertEquals(true, spec.isPageSpecification()); 377 assertNotNull(spec.getSpecificationLocation()); 378 } 379 380 385 386 public void testPropertyValue() throws Exception 387 { 388 IComponentSpecification spec = parsePage("PropertyValue.page"); 389 390 checkLine(spec, 22); 391 392 assertEquals("rubble", spec.getProperty("barney")); 393 assertEquals("flintstone", spec.getProperty("wilma")); 394 } 395 396 401 402 public void testStaticBindingValue() throws Exception 403 { 404 IComponentSpecification spec = parsePage("StaticBindingValue.page"); 405 406 checkLine(spec, 22); 407 408 IContainedComponent c = spec.getComponent("c"); 409 410 checkLine(c, 24); 411 412 IBindingSpecification b = c.getBinding("fred"); 413 checkLine(b, 25); 414 415 assertEquals("literal:flintstone", b.getValue()); 416 417 b = c.getBinding("barney"); 418 checkLine(b, 26); 419 420 assertEquals("literal:rubble", b.getValue()); 421 422 b = c.getBinding("rock"); 423 checkLine(b, 27); 424 assertEquals("literal:hudson", b.getValue()); 425 } 426 427 public void testAttributeAndBody() throws Exception 428 { 429 try 430 { 431 parsePage("AttributeAndBody.page"); 432 433 unreachable(); 434 } 435 catch (DocumentParseException ex) 436 { 437 checkException( 438 ex, 439 "It is not valid to specify a value for attribute 'value' of <static-binding> and provide a value in the body of the element."); 440 } 441 } 442 443 448 449 public void testConfigureValue() throws Exception 450 { 451 ILibrarySpecification spec = parseLib("ConfigureValue.library"); 452 453 checkLine(spec, 22); 454 checkLine(spec.getExtensionSpecification("bedrock"), 24); 455 456 Bedrock bedrock = (Bedrock) spec.getExtension("bedrock", Bedrock.class); 457 458 assertEquals("flintstone", bedrock.getFred()); 459 } 460 461 466 467 public void testListenerBinding() throws Exception 468 { 469 IComponentSpecification spec = parsePage("ListenerBinding.page"); 470 471 checkLine(spec, 22); 472 IContainedComponent c = spec.getComponent("c"); 473 474 checkLine(c, 24); 475 476 IListenerBindingSpecification lbs = (ListenerBindingSpecification) c.getBinding("listener"); 477 478 checkLine(lbs, 25); 479 480 String expectedScript = buildExpectedScript(new String [] 481 { "if page.isFormInputValid():", " cycle.page = \"Results\"", "else:", 482 " page.message = \"Please fix errors before continuing.\";" }); 483 484 assertEquals("jython", lbs.getLanguage()); 485 assertEquals(expectedScript, lbs.getScript()); 486 } 487 488 private String buildExpectedScript(String [] lines) 489 { 490 StringBuffer buffer = new StringBuffer (); 491 492 for (int i = 0; i < lines.length; i++) 493 { 494 if (i > 0) 495 buffer.append("\n"); 496 497 buffer.append(lines[i]); 498 } 499 500 return buffer.toString(); 501 } 502 503 504 505 public void testPropertySpecifications() throws Exception 506 { 507 IComponentSpecification spec = parsePage("PropertySpecifications.page"); 508 509 checkList("propertySpecificationNames", new String [] 510 { "bool", "init", "longInitialValue", "persist" }, spec.getPropertySpecificationNames()); 511 512 IPropertySpecification ps = spec.getPropertySpecification("bool"); 513 assertEquals("name", "bool", ps.getName()); 514 assertEquals("persistent", false, ps.isPersistent()); 515 assertEquals("type", "boolean", ps.getType()); 516 assertNull("initialValue", ps.getInitialValue()); 517 checkLine(ps, 24); 518 519 ps = spec.getPropertySpecification("init"); 520 assertEquals("name", "init", ps.getName()); 521 assertEquals("persistent", false, ps.isPersistent()); 522 assertNull("type", ps.getType()); 523 524 527 assertEquals("initialValue", "ognl:pageName", ps.getInitialValue()); 528 checkLine(ps, 26); 529 530 ps = spec.getPropertySpecification("persist"); 531 assertEquals("name", "persist", ps.getName()); 532 assertEquals("persistent", true, ps.isPersistent()); 533 assertNull("type", ps.getType()); 534 assertNull("initialValue", ps.getInitialValue()); 535 checkLine(ps, 25); 536 537 ps = spec.getPropertySpecification("longInitialValue"); 538 assertEquals("ognl:long.initial.value", ps.getInitialValue()); 539 540 ps = spec.getPropertySpecification("unknown"); 541 542 assertNull("Unknown PropertySpecification", ps); 543 } 544 545 546 547 public void testMissingRequiredExtendedAttribute() throws Exception 548 { 549 try 550 { 551 parsePage("MissingRequiredExtendedAttribute.page"); 552 553 unreachable(); 554 } 555 catch (DocumentParseException ex) 556 { 557 checkException( 558 ex, 559 "Element <binding> does not specify a value for attribute 'expression', or contain a body value."); 560 } 561 } 562 563 564 565 public void testMessageBeanInitializer() throws Exception 566 { 567 IComponentSpecification spec = parsePage("MessageBeanInitializer.page"); 568 569 IBeanSpecification bs = spec.getBeanSpecification("fred"); 570 checkLine(bs, 24); 571 BindingBeanInitializer i = (BindingBeanInitializer) bs.getInitializers().get(0); 572 573 assertEquals("barney", i.getPropertyName()); 574 assertEquals("message:rubble", i.getBindingReference()); 575 checkLine(i, 25); 576 } 577 578 583 584 public void testExpressionBeanInitializer() throws Exception 585 { 586 IComponentSpecification spec = parsePage("ExpressionBeanInitializer_3_0.page"); 587 588 IBeanSpecification bs = spec.getBeanSpecification("zebean"); 589 590 BindingBeanInitializer i = (BindingBeanInitializer) bs.getInitializers().get(0); 591 592 assertEquals("barney", i.getPropertyName()); 593 assertEquals("ognl:rubble", i.getBindingReference()); 594 595 i = (BindingBeanInitializer) bs.getInitializers().get(1); 596 597 assertEquals("fred", i.getPropertyName()); 598 assertEquals("ognl:flintstone", i.getBindingReference()); 599 } 600 601 602 603 public void testBeanSet() throws Exception 604 { 605 IComponentSpecification spec = parsePage("BeanSet.page"); 606 IBeanSpecification bs = spec.getBeanSpecification("target"); 607 608 BindingBeanInitializer i = (BindingBeanInitializer) bs.getInitializers().get(0); 609 610 assertEquals("literal", i.getPropertyName()); 611 assertEquals("literal-string", i.getBindingReference()); 612 613 } 614 615 public void testInheritInformalParameters() throws Exception 616 { 617 IComponentSpecification spec = parseComponent("TestInheritInformal.jwc"); 618 619 IContainedComponent border = spec.getComponent("border"); 620 assertEquals(border.getInheritInformalParameters(), false); 621 622 IContainedComponent textField = spec.getComponent("textField"); 623 assertEquals(textField.getInheritInformalParameters(), true); 624 } 625 626 627 628 public void testConfigureExtension() throws Exception 629 { 630 IApplicationSpecification spec = parseApp("ConfigureExtension.application"); 631 IExtensionSpecification es = spec.getExtensionSpecification("my-extension"); 632 633 637 assertEquals("-227", es.getConfiguration().get("long")); 638 assertEquals("22.7", es.getConfiguration().get("double")); 639 assertEquals("true", es.getConfiguration().get("boolean")); 640 assertEquals("An extended string.", es.getConfiguration().get("string")); 641 } 642 643 public void testConfigureExtensionProperty() throws Exception 644 { 645 IApplicationSpecification spec = parseApp("ConfigureExtension.application"); 646 IExtensionSpecification es = spec.getExtensionSpecification("my-extension"); 647 648 assertEquals("my-value", es.getProperty("my-property")); 649 } 650 651 652 653 public void testComponentProperty() throws Exception 654 { 655 IComponentSpecification cs = parseComponent("ComponentProperty.jwc"); 656 657 IContainedComponent cc = cs.getComponent("body"); 658 659 assertEquals("my-value", cc.getProperty("my-property")); 660 } 661 662 663 664 public void testComponentInjectProperty() throws Exception 665 { 666 IComponentSpecification cs = parseComponent("ComponentInjectProperty.jwc"); 667 668 IContainedComponent cc = cs.getComponent("body"); 669 670 assertEquals("myProperty", cc.getPropertyName()); 671 672 cc = cs.getComponent("fred"); 673 674 assertNull(cc.getPropertyName()); 675 } 676 677 678 679 public void testBeanDescription() throws Exception 680 { 681 IComponentSpecification cs = parseComponent("BeanDescription.jwc"); 682 IBeanSpecification bs = cs.getBeanSpecification("mybean"); 683 684 assertEquals("Description of mybean.", bs.getDescription()); 685 assertNotNull(bs.getLocation()); 686 } 687 688 689 690 public void testBeanProperty() throws Exception 691 { 692 IComponentSpecification cs = parseComponent("BeanDescription.jwc"); 693 IBeanSpecification bs = cs.getBeanSpecification("mybean"); 694 695 assertEquals("myvalue", bs.getProperty("myproperty")); 696 } 697 698 701 702 public void testBeanInject() throws Exception 703 { 704 IComponentSpecification cs = parseComponent("BeanInject.jwc"); 705 IBeanSpecification bs = cs.getBeanSpecification("bean"); 706 assertEquals("myProperty", bs.getPropertyName()); 707 } 708 709 712 713 public void testBeanInitializer() throws Exception 714 { 715 IComponentSpecification cs = parseComponent("BeanInitializer.jwc"); 716 IBeanSpecification bs = cs.getBeanSpecification("bean"); 717 718 List l = bs.getInitializers(); 719 LightweightBeanInitializer lbi = (LightweightBeanInitializer) l.get(0); 720 721 assertEquals("foo=bar", lbi.getPropertyName()); 722 } 723 724 725 726 public void testLibraryDescription() throws Exception 727 { 728 ILibrarySpecification ls = parseLib("LibraryDescription.library"); 729 730 assertEquals("Often, these are just placeholders.", ls.getDescription()); 731 } 732 733 734 735 public void testPageDescription() throws Exception 736 { 737 IComponentSpecification spec = parsePage("PageDescription.page"); 738 739 assertEquals("Description of this page.", spec.getDescription()); 740 } 741 742 747 748 public void testRootElementMismatch() throws Exception 749 { 750 try 751 { 752 parseComponent("NulledPage.page"); 753 unreachable(); 754 } 755 catch (Exception ex) 756 { 757 checkException( 758 ex, 759 "Incorrect document type; expected page-specification but received component-specification."); 760 } 761 } 762 763 769 770 public void testLibraryFrameworkNamespace() throws Exception 771 { 772 try 773 { 774 parseLib("LibraryFrameworkNamespace.library"); 775 unreachable(); 776 } 777 catch (Exception ex) 778 { 779 checkException(ex, "The library id 'framework' is reserved and may not be used."); 780 } 781 } 782 783 788 789 public void testComponentWithTypeAndCopyOf() throws Exception 790 { 791 try 792 { 793 parseComponent("ComponentWithTypeAndCopyOf.jwc"); 794 unreachable(); 795 } 796 catch (Exception ex) 797 { 798 checkException(ex, "Contained component bad contains both type and copy-of attributes."); 799 } 800 } 801 802 807 808 public void testComponentWithoutType() throws Exception 809 { 810 try 811 { 812 parseComponent("ComponentWithoutType.jwc"); 813 unreachable(); 814 } 815 catch (Exception ex) 816 { 817 checkException( 818 ex, 819 "Contained component bad does not specify attribute type or copy-of."); 820 } 821 } 822 823 828 829 public void testComponentCopyOf() throws Exception 830 { 831 IComponentSpecification cs = parseComponent("ComponentCopyOf.jwc"); 832 833 IContainedComponent source = cs.getComponent("source"); 834 IContainedComponent copy = cs.getComponent("copy"); 835 IContainedComponent override = cs.getComponent("override"); 836 837 assertEquals("Insert", source.getType()); 838 assertEquals("Insert", copy.getType()); 839 assertEquals("Insert", override.getType()); 840 841 IBindingSpecification b = source.getBinding("value"); 842 843 assertEquals(BindingType.PREFIXED, b.getType()); 844 assertEquals("ognl:date", b.getValue()); 845 846 assertSame(b, copy.getBinding("value")); 847 848 IBindingSpecification b2 = override.getBinding("value"); 849 assertEquals("ognl:tomorrow", b2.getValue()); 850 851 b = copy.getBinding("foo"); 852 853 assertSame(b, override.getBinding("foo")); 854 855 b = copy.getBinding("formatter"); 856 857 assertSame(b, override.getBinding("formatter")); 858 } 859 860 865 public void testComponentBadCopy() 866 { 867 try 868 { 869 parseComponent("ComponentBadCopy.jwc"); 870 unreachable(); 871 } 872 catch (Exception ex) 873 { 874 checkException(ex, "Unable to copy component missing, which does not exist."); 875 } 876 } 877 878 883 884 public void testServiceElement() throws Exception 885 { 886 interceptLogging("org.apache.tapestry"); 887 888 parseLib("ServiceElement.library"); 889 890 assertLoggedMessagePattern("The <service> element is no longer supported"); 891 } 892 893 894 public void testMeta() throws Exception 895 { 896 ILibrarySpecification spec = parseLib("Meta.library"); 897 898 assertEquals("bar", spec.getProperty("foo")); 899 assertEquals("long value", spec.getProperty("long")); 900 } 901 902 903 public void testInject() throws Exception 904 { 905 IComponentSpecification spec = parseComponent("Inject.jwc"); 906 907 List l = spec.getInjectSpecifications(); 908 909 assertEquals(2, l.size()); 910 911 InjectSpecification i1 = (InjectSpecification) l.get(0); 912 913 assertEquals("fred", i1.getProperty()); 914 assertEquals("object", i1.getType()); 915 assertEquals("flintstone", i1.getObject()); 916 assertNotNull(i1.getLocation()); 917 918 InjectSpecification i2 = (InjectSpecification) l.get(1); 919 assertEquals("barney", i2.getProperty()); 920 assertEquals("state", i2.getType()); 921 assertEquals("rubble", i2.getObject()); 922 assertNotNull(i2.getLocation()); 923 } 924 925 931 932 public void testProperty() throws Exception 933 { 934 IComponentSpecification spec = parsePage("Property.page"); 935 936 checkList("propertySpecificationNames", new String [] 937 { "bool", "init", "longInit", "persist" }, spec.getPropertySpecificationNames()); 938 939 IPropertySpecification ps = spec.getPropertySpecification("bool"); 940 assertEquals("name", "bool", ps.getName()); 941 assertEquals("persistent", false, ps.isPersistent()); 942 943 assertNull("type", ps.getType()); 945 946 949 assertNull("initialValue", ps.getInitialValue()); 950 checkLine(ps, 24); 951 952 ps = spec.getPropertySpecification("init"); 953 assertEquals("name", "init", ps.getName()); 954 assertEquals("persistent", false, ps.isPersistent()); 955 956 assertEquals("initialValue", "ognl:pageName", ps.getInitialValue()); 957 checkLine(ps, 26); 958 959 ps = spec.getPropertySpecification("persist"); 960 assertEquals("name", "persist", ps.getName()); 961 assertEquals("persistent", true, ps.isPersistent()); 962 assertNull("initialValue", ps.getInitialValue()); 963 checkLine(ps, 25); 964 965 ps = spec.getPropertySpecification("longInit"); 966 assertEquals("message:long-init-key", ps.getInitialValue()); 967 968 ps = spec.getPropertySpecification("unknown"); 969 970 assertNull("Unknown PropertySpecification", ps); 971 } 972 973 978 979 public void testParameter_3_0() throws Exception 980 { 981 IComponentSpecification spec = parseComponent("Parameter_3_0.jwc"); 982 983 IParameterSpecification ps = spec.getParameter("noDefault"); 984 985 assertEquals("noDefault", ps.getPropertyName()); 986 assertEquals("noDefault", ps.getParameterName()); 987 assertEquals(true, ps.isRequired()); 988 assertEquals("bar", ps.getType()); 989 assertNull(ps.getDefaultValue()); 990 assertNull(ps.getDefaultBindingType()); 991 assertEquals(false, ps.isDeprecated()); 992 993 ps = spec.getParameter("withDefault"); 994 assertEquals("withDefault", ps.getParameterName()); 995 assertNull(ps.getType()); 996 assertEquals(false, ps.isRequired()); 997 998 1001 assertEquals("ognl:an.expression", ps.getDefaultValue()); 1002 1003 ps = spec.getParameter("withDescription"); 1004 assertEquals("A parameter with a description.", ps.getDescription()); 1005 1006 ps = spec.getParameter("altName"); 1007 assertEquals("altNameParameter", ps.getPropertyName()); 1008 1009 ps = spec.getParameter("directionIn"); 1010 assertEquals(true, ps.getCache()); 1011 1012 ps = spec.getParameter("directionAuto"); 1013 assertEquals(false, ps.getCache()); 1014 } 1015 1016 1022 1023 public void testParameter() throws Exception 1024 { 1025 IComponentSpecification spec = parseComponent("Parameter.jwc"); 1026 1027 IParameterSpecification ps = spec.getParameter("noDefault"); 1028 1029 assertNull(ps.getDefaultValue()); 1030 assertNull(ps.getDefaultBindingType()); 1031 assertEquals(true, ps.getCache()); 1032 assertTrue(ps.getAliasNames().isEmpty()); 1033 assertEquals(false, ps.isDeprecated()); 1034 1035 ps = spec.getParameter("literalDefault"); 1036 1037 assertEquals("literal-value", ps.getDefaultValue()); 1038 1039 ps = spec.getParameter("expressionDefault"); 1040 1041 assertEquals("ognl:an.expression", ps.getDefaultValue()); 1042 1043 ps = spec.getParameter("defaultBindingType"); 1044 1045 assertEquals("ognl", ps.getDefaultBindingType()); 1046 1047 ps = spec.getParameter("noCache"); 1048 assertEquals(false, ps.getCache()); 1049 1050 ps = spec.getParameter("withAliases"); 1051 assertListsEqual(new String [] 1052 { "fred", "barney" }, ps.getAliasNames().toArray()); 1053 1054 assertSame(ps, spec.getParameter("fred")); 1055 assertSame(ps, spec.getParameter("barney")); 1056 1057 ps = spec.getParameter("deprecated"); 1058 assertEquals(true, ps.isDeprecated()); 1059 } 1060 1061 1067 public void testAssets_3_0() throws Exception 1068 { 1069 IComponentSpecification cs = parsePage("Assets_3_0.page"); 1070 1071 IAssetSpecification as = cs.getAsset("mycontext"); 1072 1073 assertEquals("context:path/to/context", as.getPath()); 1074 1075 as = cs.getAsset("myprivate"); 1076 1077 assertEquals("classpath:path/to/private", as.getPath()); 1078 1079 as = cs.getAsset("myexternal"); 1080 1081 assertEquals("http://myexternal/asset", as.getPath()); 1082 1083 assertListsEqual(new String [] 1084 { "mycontext", "myexternal", "myprivate" }, cs.getAssetNames()); 1085 } 1086 1087 1088 1089 public void testAssets() throws Exception 1090 { 1091 IComponentSpecification cs = parsePage("Assets.page"); 1092 1093 IAssetSpecification as = cs.getAsset("myasset"); 1094 1095 assertEquals("path/to/asset", as.getPath()); 1096 assertEquals("myProperty", as.getPropertyName()); 1097 } 1098 1099 1100 1101 public void testDeprecatedComponent() throws Exception 1102 { 1103 IComponentSpecification cs = parseComponent("DeprecatedComponent.jwc"); 1104 1105 assertEquals(true, cs.isDeprecated()); 1106 } 1107} | Popular Tags |