From 404384eefe9e5abf65ae68b4b1bf0accf3dff8eb Mon Sep 17 00:00:00 2001 From: Alvaro Lobato Date: Wed, 27 Jul 2016 12:31:29 -0400 Subject: [PATCH] [JENKINS-36908] Make sure that the All view is created (#2472) * [JENKINS-36908] Make sure that the All view is created * Revert old All view behaviour * Fix changed comment * Tests * Delete unwanted file. --- core/src/main/java/jenkins/model/Jenkins.java | 5 +---- test/src/test/java/hudson/model/ViewTest.java | 16 ++++++++++++++++ .../ViewTest/testAllViewCreatedIfNoPrimary.zip | Bin 0 -> 364 bytes .../ViewTest/testAllViewNotCreatedIfPrimary.zip | Bin 0 -> 378 bytes 4 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 test/src/test/resources/hudson/model/ViewTest/testAllViewCreatedIfNoPrimary.zip create mode 100644 test/src/test/resources/hudson/model/ViewTest/testAllViewNotCreatedIfPrimary.zip diff --git a/core/src/main/java/jenkins/model/Jenkins.java b/core/src/main/java/jenkins/model/Jenkins.java index e01d3085f7..1852e7c110 100644 --- a/core/src/main/java/jenkins/model/Jenkins.java +++ b/core/src/main/java/jenkins/model/Jenkins.java @@ -2868,15 +2868,12 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve // initialize views by inserting the default view if necessary // this is both for clean Jenkins and for backward compatibility. - if(views.size()==0) { + if(views.size()==0 || primaryView==null) { View v = new AllView(Messages.Hudson_ViewName()); setViewOwner(v); views.add(0,v); primaryView = v.getViewName(); } - if (primaryView==null) { - primaryView = views.get(0).getViewName(); - } if (useSecurity!=null && !useSecurity) { // forced reset to the unsecure mode. diff --git a/test/src/test/java/hudson/model/ViewTest.java b/test/src/test/java/hudson/model/ViewTest.java index 36841da295..82314e9841 100644 --- a/test/src/test/java/hudson/model/ViewTest.java +++ b/test/src/test/java/hudson/model/ViewTest.java @@ -64,6 +64,7 @@ import org.jvnet.hudson.test.JenkinsRule.WebClient; import org.jvnet.hudson.test.MockAuthorizationStrategy; import org.jvnet.hudson.test.MockFolder; import org.jvnet.hudson.test.TestExtension; +import org.jvnet.hudson.test.recipes.LocalData; import org.kohsuke.stapler.DataBoundConstructor; /** @@ -505,5 +506,20 @@ public class ViewTest { private void assertCheckJobName(ViewGroup context, String name, FormValidation.Kind expected) { assertEquals(expected, context.getPrimaryView().doCheckJobName(name).kind); } + + + @Test + @Issue("JENKINS-36908") + @LocalData + public void testAllViewCreatedIfNoPrimary() throws Exception { + assertNotNull(j.getInstance().getView("All")); + } + + @Test + @Issue("JENKINS-36908") + @LocalData + public void testAllViewNotCreatedIfPrimary() throws Exception { + assertNull(j.getInstance().getView("All")); + } } diff --git a/test/src/test/resources/hudson/model/ViewTest/testAllViewCreatedIfNoPrimary.zip b/test/src/test/resources/hudson/model/ViewTest/testAllViewCreatedIfNoPrimary.zip new file mode 100644 index 0000000000000000000000000000000000000000..7e32a82640eaa9259f3a158b50a35a5c216737c0 GIT binary patch literal 364 zcmWIWW@Zs#U|`^2IN|-Qab1q9taNshJVKjWm1;*WL{e{8$4rDan_TltcT z`);c*ENi;I?Zm57l|imq96^6h1^)?Id`yJ*QituH>I30YCcM99W}GmzXIpkVd)2Wu zL4Rh(be*qqbK1)g;LXS+$BZi+B!D5pzyS0u!;(f23prF+A)$g6A_3m4Y#^14Ko|g| I*+7~Z0H8>MF#rGn literal 0 HcmV?d00001 diff --git a/test/src/test/resources/hudson/model/ViewTest/testAllViewNotCreatedIfPrimary.zip b/test/src/test/resources/hudson/model/ViewTest/testAllViewNotCreatedIfPrimary.zip new file mode 100644 index 0000000000000000000000000000000000000000..397d6d14a44666ed3e5f0f52abb61fe3e055f76d GIT binary patch literal 378 zcmWIWW@Zs#U|`^2PzwI-;S$Mw`~r~I&d9*P#UR6woS&DLnXXrnn-dzs$-w*|e@3`m z!Hn?I3T_5QmajlXV7<8k8?z1@h}`)rdPu}3G;2HGCL`5gF5NA6du#JpH;LTa{P@Xx zZTHX>&JKq!-+g&+?w4mK7KJPudH1cG_cU1b!R-r?|6{}F%kMruJu8{(uW_l&9?g~u z?%gw|Yo6nr=KSKplh;4BgE~87X4racS(mu(w2BVvLiVGqE4($YKArOF*Aa8(p5uFd zWR&hqU9~-rCD%V=xuL-9eT6)0^B!*fQ+udotBGS|*@6OwUa>uVzpiJT{PAg#~waJu@?4|z~Xl&}%tYZxDW@M6M#uX|O!0=&U0Q#L_Nh64b97e2= XFhUET0B=?{kV-}%3;@z1Ak7Q_)<=uH literal 0 HcmV?d00001 -- GitLab