Prohibit creating two views with the same name.

http://d.hatena.ne.jp/ssogabe/20090101/1230744150

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@14067 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
kohsuke committed 2008-12-31 23:58:43 +00:00
1 parent 17cecbc66b
commit c5a4e8c463
3 files changed
+38 -2

No files matched your search

+4 -1
View File
@@ -531,7 +531,10 @@ public abstract class View extends AbstractModelObject implements AccessControll
public static View create(StaplerRequest req, StaplerResponse rsp, ViewGroup owner) throws ParseException, FormException, IOException, ServletException {
req.setCharacterEncoding("UTF-8");
checkGoodName(req.getParameter("name"));
String name = req.getParameter("name");
checkGoodName(name);
if(owner.getView(name)!=null)
throw new FormException(Messages.Hudson_ViewAlreadyExists(name),"name");
// create a view
View v = LIST.findByName(req.getParameter("mode")).newInstance(req,req.getSubmittedForm());
+1 -1
View File
@@ -72,7 +72,7 @@
<dependency>
<groupId>org.jvnet.hudson</groupId>
<artifactId>htmlunit</artifactId>
<version>2.2-hudson-8</version>
<version>2.2-hudson-9</version>
</dependency>
<dependency>
<!-- for testing JNLP launch. -->
@@ -0,0 +1,33 @@
package hudson.model;
import org.jvnet.hudson.test.Email;
import org.jvnet.hudson.test.HudsonTestCase;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
/**
* @author Kohsuke Kawaguchi
*/
public class ViewTest extends HudsonTestCase {
/**
* Creating two views with the same name.
*/
@Email("http://d.hatena.ne.jp/ssogabe/20090101/1230744150")
public void testConflictingName() throws Exception {
assertNull(hudson.getView("foo"));
HtmlForm form = new WebClient().goTo("newView").getFormByName("createView");
form.getInputByName("name").setValueAttribute("foo");
form.getRadioButtonsByName("mode").get(0).setChecked(true);
submit(form);
assertNotNull(hudson.getView("foo"));
// do it again and verify an error
try {
submit(form);
fail("shouldn't be allowed to create two views of the same name.");
} catch (FailingHttpStatusCodeException e) {
assertEquals(400,e.getStatusCode());
}
}
}