-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #168 from rinrinne/boot-on-startup
Add "No connection on bootup" option
- Loading branch information
Showing
10 changed files
with
148 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Check if this server should not connect to Gerrit on startup. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
.../com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritItemListenerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright 2014 rinrinne a.k.a. rin_ne All rights reserved. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger; | ||
|
||
import static org.powermock.api.mockito.PowerMockito.mock; | ||
import static org.powermock.api.mockito.PowerMockito.mockStatic; | ||
import static org.powermock.api.mockito.PowerMockito.when; | ||
import static org.powermock.api.mockito.PowerMockito.spy; | ||
import static org.powermock.api.mockito.PowerMockito.doNothing; | ||
|
||
import java.util.Arrays; | ||
|
||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
import org.mockito.Mockito; | ||
import org.powermock.core.classloader.annotations.PowerMockIgnore; | ||
import org.powermock.core.classloader.annotations.PrepareForTest; | ||
import org.powermock.modules.junit4.PowerMockRunner; | ||
|
||
import com.sonyericsson.hudson.plugins.gerrit.trigger.GerritServer; | ||
import com.sonyericsson.hudson.plugins.gerrit.trigger.PluginImpl; | ||
|
||
/** | ||
* Tests for {@link GerritItemListener}. | ||
*/ | ||
@RunWith(PowerMockRunner.class) | ||
@PrepareForTest(PluginImpl.class) | ||
@PowerMockIgnore({"javax.crypto.*" }) | ||
public class GerritItemListenerTest { | ||
|
||
/** | ||
* Jenkins rule instance. | ||
*/ | ||
// CS IGNORE VisibilityModifier FOR NEXT 3 LINES. REASON: Mocks tests. | ||
@Rule | ||
public JenkinsRule j = new JenkinsRule(); | ||
|
||
private final String gerritServerName = "testServer"; | ||
private GerritServer gerritServer; | ||
|
||
/** | ||
* Setup the mock'ed environment. | ||
*/ | ||
@Before | ||
public void setup() { | ||
PluginImpl plugin = mock(PluginImpl.class); | ||
mockStatic(PluginImpl.class); | ||
when(PluginImpl.getInstance()).thenReturn(plugin); | ||
gerritServer = spy(new GerritServer(gerritServerName)); | ||
doNothing().when(gerritServer).startConnection(); | ||
when(plugin.getServers()).thenReturn(Arrays.asList(gerritServer)); | ||
} | ||
|
||
/** | ||
* Tests {@link GerritItemListener#onLoad()} gets connection. | ||
* | ||
* @throws Exception if so. | ||
*/ | ||
@Test | ||
public void testOnLoadedWithConnection() throws Exception { | ||
gerritServer.setNoConnectionOnStartup(false); | ||
GerritItemListener listener = new GerritItemListener(); | ||
listener.onLoaded(); | ||
Mockito.verify(gerritServer, Mockito.times(1)).startConnection(); | ||
} | ||
|
||
/** | ||
* Tests {@link GerritItemListener#onLoad()} does not get connection. | ||
* | ||
* @throws Exception if so. | ||
*/ | ||
@Test | ||
public void testOnLoadedWithNoConnection() throws Exception { | ||
gerritServer.setNoConnectionOnStartup(true); | ||
GerritItemListener listener = new GerritItemListener(); | ||
listener.onLoaded(); | ||
Mockito.verify(gerritServer, Mockito.times(0)).startConnection(); | ||
} | ||
} |