Skip to content

Commit

Permalink
Fixes the merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
katelovescode committed Nov 27, 2017
2 parents dc6fb95 + b223600 commit 5b8134d
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/jenkins_api_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
require 'jenkins_api_client/build_queue'
require 'jenkins_api_client/plugin_manager'
require 'jenkins_api_client/user'
require 'jenkins_api_client/root'

require 'jenkins_api_client/cli/helper'
require 'jenkins_api_client/cli/base'
Expand Down
8 changes: 8 additions & 0 deletions lib/jenkins_api_client/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,14 @@ def user
JenkinsApi::Client::User.new(self)
end

# Creates an instance of the Root class by passing a reference to self
#
# @return [JenkinsApi::Client::Root] An object of Root subclass
#
def root
JenkinsApi::Client::Root.new(self)
end

# Returns a string representing the class name
#
# @return [String] string representation of class name
Expand Down
67 changes: 67 additions & 0 deletions lib/jenkins_api_client/root.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#
# 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.
#

require 'jenkins_api_client/urihelper'

module JenkinsApi
class Client
# This class communicates with Jenkins API at the root address to obtain details
# on the page displayed to users on the Jenkins' 'homepage,' and other
# data items such as quietingDown
class Root
include JenkinsApi::UriHelper

# Initializes a new root object
#
# @param client [Client] the client object
#
# @return [Root] the root object
#
def initialize(client)
@client = client
@logger = @client.logger
end

# Return a string representation of the object
#
def to_s
"#<JenkinsApi::Client::Root>"
end

# Check if Jenkins is in shutdown mode
#
# @return [Boolean] true if server in shutdown mode
#
def quieting_down?
response_json = @client.api_get_request('', 'tree=quietingDown')
response_json['quietingDown']
end

# Get message displayed to users on the homepage
#
# @return [String] description - message displayed to users
#
def description
response_json = @client.api_get_request('', 'tree=description')
response_json['description']
end
end
end
end
9 changes: 8 additions & 1 deletion lib/jenkins_api_client/system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,20 @@ def quiet_down
@client.api_post_request("/quietDown")
end

# Cancels the quiet doen request sent to the server.
# Cancels the quiet down request sent to the server.
#
def cancel_quiet_down
@logger.info "Cancelling jenkins form quiet down..."
@client.api_post_request("/cancelQuietDown")
end

# Checks if server is in quiet down mode.
#
def check_quiet_down?
@logger.info "Checking if jenkins is in quiet down mode..."
@client.root.quieting_down?
end

# Restarts the Jenkins server
#
# @param [Boolean] force whether to force restart or wait till all
Expand Down
12 changes: 12 additions & 0 deletions spec/unit_tests/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,18 @@
end
end

describe "#root" do
it "Should return a Client::Root object" do
client = JenkinsApi::Client.new(
:server_ip => '127.0.0.1',
:server_port => 8080,
:username => 'username',
:password => 'password'
)
client.root.class.should == JenkinsApi::Client::Root
end
end

describe "InstanceMethods" do
describe "#get_root" do
it "is defined with no parameters" do
Expand Down
56 changes: 56 additions & 0 deletions spec/unit_tests/root_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
require File.expand_path('../spec_helper', __FILE__)

describe JenkinsApi::Client::Root do
context "With properly initialized Client" do
before do
mock_logger = Logger.new "/dev/null"
@client = double
@client.should_receive(:logger).and_return(mock_logger)
@root = JenkinsApi::Client::Root.new(@client)
@sample_root_json1 = {
"description" => "Hello Users",
"primaryView" => [
"name" => "default_view",
"url" => "http://buildsystem:9999/jenkins"
],
"quietingDown" => false,
"useCrumbs" => "true",
"useSecurity" => "true"
}
@sample_root_json2 = {
"quietingDown" => true
}
end

describe "InstanceMethods" do
describe "#initialize" do
it "initializes by receiving an instance of client object" do
mock_logger = Logger.new "/dev/null"
@client.should_receive(:logger).and_return(mock_logger)
expect(
lambda { JenkinsApi::Client::Root.new(@client) }
).not_to raise_error
end
end

describe "#quieting_down?" do
it "returns false if jenkins is jenkins is not quieting down" do
allow(@client).to receive(:api_get_request).with('', 'tree=quietingDown').and_return(@sample_root_json1)
expect @root.quieting_down?.should be false
end

it "returns true if jenkins quieting down" do
allow(@client).to receive(:api_get_request).with('', 'tree=quietingDown').and_return(@sample_root_json2)
expect @root.quieting_down?.should be true
end
end

describe "#description" do
it "gets the message displayed to users on the home page" do
allow(@client).to receive(:api_get_request).with('', 'tree=description').and_return(@sample_root_json1)
expect @root.description.should == "Hello Users"
end
end
end
end
end
10 changes: 10 additions & 0 deletions spec/unit_tests/system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@
end
end

describe "#check_quiet_down" do
it "checks if the server is presently in quiet down mode" do
@client.should_receive(:logger).and_return(Logger.new "/dev/null")
@root = JenkinsApi::Client::Root.new(@client)
@root.should_receive(:quieting_down?)
@client.should_receive(:root).and_return(@root)
@system.check_quiet_down?
end
end

describe "#restart" do
it "sends a safe restart request to the server" do
@client.should_receive(:api_post_request).with("/safeRestart")
Expand Down

0 comments on commit 5b8134d

Please sign in to comment.