From 55d1f1fec3d7d7502dfde376b19a292925ba7448 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Thu, 31 Mar 2011 18:19:13 -0700 Subject: [PATCH] added test cases --- .../java/hudson/model/JobPropertyTest.java | 75 ++++++++++++++++--- .../JobPropertyWithConfigImpl/config.jelly | 5 ++ 2 files changed, 71 insertions(+), 9 deletions(-) create mode 100644 test/src/test/resources/hudson/model/JobPropertyTest/JobPropertyWithConfigImpl/config.jelly diff --git a/test/src/test/java/hudson/model/JobPropertyTest.java b/test/src/test/java/hudson/model/JobPropertyTest.java index 3d76df4502..9e8db1df75 100644 --- a/test/src/test/java/hudson/model/JobPropertyTest.java +++ b/test/src/test/java/hudson/model/JobPropertyTest.java @@ -1,7 +1,7 @@ /* * The MIT License * - * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Erik Ramfelt + * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Erik Ramfelt, CloudBees, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -27,13 +27,20 @@ import com.gargoylesoftware.htmlunit.WebAssert; import com.gargoylesoftware.htmlunit.html.HtmlPage; import hudson.matrix.MatrixProject; import hudson.maven.MavenModuleSet; +import hudson.model.Descriptor.FormException; +import net.sf.json.JSONObject; +import org.jvnet.hudson.test.Bug; import org.jvnet.hudson.test.HudsonTestCase; +import org.jvnet.hudson.test.TestExtension; +import org.kohsuke.stapler.DataBoundConstructor; +import org.kohsuke.stapler.StaplerRequest; public class JobPropertyTest extends HudsonTestCase { /** * Asserts that rfe#2398 is fixed. */ + @Bug(2398) public void testJobPropertySummaryIsShownInMavenModuleSetIndexPage() throws Exception { assertJobPropertySummaryIsShownInIndexPage(MavenModuleSet.DESCRIPTOR); } @@ -54,7 +61,6 @@ public class JobPropertyTest extends HudsonTestCase { } public static class JobPropertyImpl extends JobProperty> { - public static DescriptorImpl DESCRIPTOR = new DescriptorImpl(); private final String propertyString; public JobPropertyImpl(String propertyString) { this.propertyString = propertyString; @@ -64,13 +70,8 @@ public class JobPropertyTest extends HudsonTestCase { return propertyString; } - @Override - public JobPropertyDescriptor getDescriptor() { - return DESCRIPTOR; - } - - @SuppressWarnings("unchecked") - private static class DescriptorImpl extends JobPropertyDescriptor { + @TestExtension + public static class DescriptorImpl extends JobPropertyDescriptor { @Override public boolean isApplicable(Class jobType) { return false; @@ -82,4 +83,60 @@ public class JobPropertyTest extends HudsonTestCase { } } } + + /** + * Make sure that the UI rendering works as designed. + */ + public void testConfigRoundtrip() throws Exception { + FreeStyleProject p = createFreeStyleProject(); + JobPropertyWithConfigImpl before = new JobPropertyWithConfigImpl("Duke"); + p.addProperty(before); + configRoundtrip(p); + JobPropertyWithConfigImpl after = p.getProperty(JobPropertyWithConfigImpl.class); + assertNotSame(after,before); + assertEqualDataBoundBeans(before, after); + } + + public static class JobPropertyWithConfigImpl extends JobProperty> { + public String name; + + @DataBoundConstructor + public JobPropertyWithConfigImpl(String name) { + this.name = name; + } + + @TestExtension("testConfigRoundtrip") + public static class DescriptorImpl extends JobPropertyDescriptor { + @Override + public String getDisplayName() { return null; } + } + } + + + + public void testInvisibleProperty() throws Exception { + FreeStyleProject p = createFreeStyleProject(); + InvisibleImpl before = new InvisibleImpl(); + p.addProperty(before); + configRoundtrip(p); + InvisibleImpl after = p.getProperty(InvisibleImpl.class); + assertSame(after,before); + } + + public static class InvisibleImpl extends JobProperty> { + public String name; + + InvisibleImpl() {} + + @Override + public JobProperty reconfigure(StaplerRequest req, JSONObject form) throws FormException { + return this; + } + + @TestExtension("testInvisibleProperty") + public static class DescriptorImpl extends JobPropertyDescriptor { + @Override + public String getDisplayName() { return null; } + } + } } diff --git a/test/src/test/resources/hudson/model/JobPropertyTest/JobPropertyWithConfigImpl/config.jelly b/test/src/test/resources/hudson/model/JobPropertyTest/JobPropertyWithConfigImpl/config.jelly new file mode 100644 index 0000000000..8dc663c544 --- /dev/null +++ b/test/src/test/resources/hudson/model/JobPropertyTest/JobPropertyWithConfigImpl/config.jelly @@ -0,0 +1,5 @@ + + + + + -- GitLab