crv_api_client 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +26 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/Guardfile +10 -0
- data/LICENSE.txt +22 -0
- data/README.md +47 -0
- data/Rakefile +7 -0
- data/crv_api_client.gemspec +30 -0
- data/lib/crv_api_client/animals.rb +84 -0
- data/lib/crv_api_client/api/animals/animals.rb +1734 -0
- data/lib/crv_api_client/api/animals/animals_driver.rb +113 -0
- data/lib/crv_api_client/api/animals/animals_mapping_registry.rb +2082 -0
- data/lib/crv_api_client/api/animals/rs_animal_service_client.rb +122 -0
- data/lib/crv_api_client/api/animals.rb +9 -0
- data/lib/crv_api_client/api/reproduction/esb_rs_reproduction_service_client.rb +158 -0
- data/lib/crv_api_client/api/reproduction/reproduction.rb +8810 -0
- data/lib/crv_api_client/api/reproduction/reproduction_driver.rb +136 -0
- data/lib/crv_api_client/api/reproduction/reproduction_mapping_registry.rb +5244 -0
- data/lib/crv_api_client/api/reproduction.rb +9 -0
- data/lib/crv_api_client/api.rb +6 -0
- data/lib/crv_api_client/errors.rb +57 -0
- data/lib/crv_api_client/helpers/attributes.rb +34 -0
- data/lib/crv_api_client/helpers/crv.rb +89 -0
- data/lib/crv_api_client/helpers/endpoint.rb +46 -0
- data/lib/crv_api_client/helpers.rb +7 -0
- data/lib/crv_api_client/reproduction.rb +87 -0
- data/lib/crv_api_client/utils/configuration.rb +40 -0
- data/lib/crv_api_client/utils.rb +5 -0
- data/lib/crv_api_client/version.rb +3 -0
- data/lib/crv_api_client.rb +26 -0
- data/spec/lib/crv/animals_spec.rb +95 -0
- data/spec/lib/crv/api/animals/animals_driver_spec.rb +39 -0
- data/spec/lib/crv/api/reproduction/reproduction_driver_spec.rb +39 -0
- data/spec/lib/crv/helpers/attributes_spec.rb +52 -0
- data/spec/lib/crv/helpers/crv_spec.rb +146 -0
- data/spec/lib/crv/helpers/endpoint_spec.rb +54 -0
- data/spec/lib/crv/reproduction_spec.rb +137 -0
- data/spec/lib/crv_spec.rb +22 -0
- data/spec/spec_helper.rb +91 -0
- metadata +204 -0
@@ -0,0 +1,9 @@
|
|
1
|
+
module CrvApiClient
|
2
|
+
module Api
|
3
|
+
module Reproduction
|
4
|
+
require 'crv_api_client/api/reproduction/reproduction'
|
5
|
+
require 'crv_api_client/api/reproduction/reproduction_driver'
|
6
|
+
require 'crv_api_client/api/reproduction/reproduction_mapping_registry'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module CrvApiClient
|
2
|
+
module Errors
|
3
|
+
|
4
|
+
|
5
|
+
class CrvError < StandardError
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
class CrvRequestError < CrvError
|
10
|
+
attr_reader :data, :code, :type
|
11
|
+
def initialize(code, data, type)
|
12
|
+
@data = data
|
13
|
+
@code = code
|
14
|
+
@type = type
|
15
|
+
end
|
16
|
+
end
|
17
|
+
# General animal error class
|
18
|
+
class AnimalError < CrvError; end
|
19
|
+
# General keeper error class
|
20
|
+
class KeeperError < CrvError; end
|
21
|
+
# General Request error class
|
22
|
+
class RequestError < CrvError; end
|
23
|
+
# General Authorization error
|
24
|
+
class AuthorizationError < CrvError; end
|
25
|
+
# General Authentication error
|
26
|
+
class AuthenticationError < CrvError; end
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
#code 9
|
31
|
+
class AnimalUnknownError < AnimalError; end
|
32
|
+
#code 10
|
33
|
+
class AnimalDeadError < AnimalError; end
|
34
|
+
#code 11
|
35
|
+
class AnimalExportedError < AnimalError; end
|
36
|
+
#code 12
|
37
|
+
class AnimalUnknownKeeperOnReferenceDateError < AnimalError; end
|
38
|
+
|
39
|
+
|
40
|
+
#code 13
|
41
|
+
class KeeperUnknownError < KeeperError; end
|
42
|
+
#code 14
|
43
|
+
class KeeperNoAccessInvalidCustomerError < KeeperError; end
|
44
|
+
#code 15
|
45
|
+
class KeeperNoAccessInvalidOrganizationError < KeeperError; end
|
46
|
+
#code 16
|
47
|
+
class KeeperNoAccessNoEmployeeRelationship < KeeperError; end
|
48
|
+
|
49
|
+
class InvalidValueInMessageError < RequestError; end
|
50
|
+
#code 19
|
51
|
+
class UsernamePasswordInvalid < AuthenticationError; end
|
52
|
+
#code 22
|
53
|
+
class UserNotAuthorized < AuthenticationError; end
|
54
|
+
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module CrvApiClient
|
2
|
+
module Helpers
|
3
|
+
module Attributes
|
4
|
+
|
5
|
+
#defines an public attribute reader and a private writer
|
6
|
+
#name: the instance variable name for which a get method has to be created
|
7
|
+
#type: The object type.
|
8
|
+
def attr_reader_with_type(name, type)
|
9
|
+
define_attribute_methods(name, type)
|
10
|
+
class_eval { private "#{name}=" }
|
11
|
+
end
|
12
|
+
|
13
|
+
#defines an public attribute writer and reader.
|
14
|
+
#name: the instance variable name for which a get method has to be created
|
15
|
+
#type: The object type.
|
16
|
+
def attr_accessor_with_type(name, type)
|
17
|
+
define_attribute_methods(name, type)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
#defines the attribute set and get methods and
|
22
|
+
def define_attribute_methods(name, type)
|
23
|
+
define_method(name) do
|
24
|
+
instance_variable_get("@#{name}")
|
25
|
+
end
|
26
|
+
|
27
|
+
define_method("#{name}=") do |value|
|
28
|
+
raise ArgumentError.new("Invalid Type, #{value.class.name} is not a #{type.name} ") unless (value.is_a?(type) || value.nil?)
|
29
|
+
instance_variable_set("@#{name}", value)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module CrvApiClient
|
2
|
+
module Helpers
|
3
|
+
module Crv
|
4
|
+
include Endpoint
|
5
|
+
|
6
|
+
def get_keeper(crv_id, country)
|
7
|
+
keeper = endpoint_participant_id.new
|
8
|
+
keeper.participantCode = crv_id
|
9
|
+
country = country.upcase unless country.nil?
|
10
|
+
case(country)
|
11
|
+
when nil, "NL" # Netherlands
|
12
|
+
keeper.participantCodeType = "UBN"
|
13
|
+
keeper.countryCode = "NLD"
|
14
|
+
when "BE" # Belgium
|
15
|
+
keeper.participantCodeType = "UVN"
|
16
|
+
keeper.countryCode = "BE"
|
17
|
+
when "DE" # Germany
|
18
|
+
keeper.participantCodeType = "LDE"
|
19
|
+
keeper.countryCode = "DE"
|
20
|
+
when "CZ" # Czech
|
21
|
+
keeper.participantCodeType = "LCZ"
|
22
|
+
keeper.countryCode = "CZ"
|
23
|
+
end
|
24
|
+
keeper
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_crv_organisation_code(country)
|
28
|
+
country = country.upcase unless country.nil?
|
29
|
+
value = case country
|
30
|
+
when nil, "NL" then "crv.nl" # Netherlands
|
31
|
+
when "BE" then "crv.be" # Belgium
|
32
|
+
when "DE" then "crv.de" # Germany
|
33
|
+
when "CZ" then "crv.cz" # Czech
|
34
|
+
end
|
35
|
+
value
|
36
|
+
end
|
37
|
+
|
38
|
+
def context_message(keeper,
|
39
|
+
context_message_detail: [],
|
40
|
+
username: "",
|
41
|
+
password: "",
|
42
|
+
provider: nil,
|
43
|
+
customer: nil,
|
44
|
+
animal: nil,
|
45
|
+
process_code: "",
|
46
|
+
organisation: nil)
|
47
|
+
context = endpoint_context_message.new
|
48
|
+
context.sessionId = ""
|
49
|
+
context.processId = ""
|
50
|
+
context.instanceId = ""
|
51
|
+
context.username = username
|
52
|
+
context.userType = "C"
|
53
|
+
context.password = password
|
54
|
+
context.organisation = organisation
|
55
|
+
context.provider = provider
|
56
|
+
context.customer = customer
|
57
|
+
context.keeper = keeper
|
58
|
+
context.animal = animal
|
59
|
+
context.processCode = process_code
|
60
|
+
context.messageSource = ""
|
61
|
+
context.languageCode = ""
|
62
|
+
context.timeZone = ""
|
63
|
+
context.contextMessageDetail = context_message_detail
|
64
|
+
context
|
65
|
+
end
|
66
|
+
protected
|
67
|
+
|
68
|
+
def perform_service_message_validation(serviceMessage)
|
69
|
+
case(serviceMessage.serviceStatus.to_i)
|
70
|
+
when 1..200
|
71
|
+
raise ::CrvApiClient::Errors::CrvRequestError.new(serviceMessage.serviceStatus,
|
72
|
+
serviceMessage.messageText,
|
73
|
+
serviceMessage.messageType)
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
|
82
|
+
def keeper_and_context_message_detail(crv_id,countryCode= nil)
|
83
|
+
keeper = get_keeper("#{crv_id}", countryCode)
|
84
|
+
contextMessageDetail = endpoint_context_message_detail.new("organisation", get_crv_organisation_code(countryCode))
|
85
|
+
[keeper,contextMessageDetail]
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module CrvApiClient
|
2
|
+
module Helpers
|
3
|
+
module Endpoint
|
4
|
+
|
5
|
+
private
|
6
|
+
##
|
7
|
+
# Calculates api endpoint path based on class who includes this module
|
8
|
+
# it adds the string '::Api' before the last '::' match.
|
9
|
+
# Regex splits the class name and modules by the last '::' match
|
10
|
+
# \1 is the string before the last '::' match
|
11
|
+
# \2 contains the last :: match
|
12
|
+
# \3 contains the string after the '::' match.
|
13
|
+
# Returns a string
|
14
|
+
# example::
|
15
|
+
# class CrvApiClient::Animals returns CrvApiClient::Api::Animals
|
16
|
+
# class CrvApiClient::Base::Before::Animals returns CrvApiClient::Base::Before::Api::Animals
|
17
|
+
##
|
18
|
+
def class_api_endpoint
|
19
|
+
self.class.name.gsub(/(.*)(::)(.*)/, '\1\2Api\2\3\2')
|
20
|
+
end
|
21
|
+
|
22
|
+
##
|
23
|
+
# Returns the Api Participant Id of the included class.
|
24
|
+
##
|
25
|
+
def endpoint_participant_id
|
26
|
+
Object.const_get(class_api_endpoint << "ParticipantId")
|
27
|
+
end
|
28
|
+
|
29
|
+
##
|
30
|
+
# Returns the Api ContextMessageDetail of the included class.
|
31
|
+
##
|
32
|
+
def endpoint_context_message_detail
|
33
|
+
Object.const_get(class_api_endpoint << "ContextMessageDetail")
|
34
|
+
end
|
35
|
+
|
36
|
+
def endpoint_context_message
|
37
|
+
Object.const_get(class_api_endpoint << "ContextMessage")
|
38
|
+
end
|
39
|
+
|
40
|
+
def endpoint_animal_id
|
41
|
+
Object.const_get(class_api_endpoint << "AnimalId")
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module CrvApiClient
|
2
|
+
class Reproduction
|
3
|
+
extend ::CrvApiClient::Helpers::Attributes
|
4
|
+
include ::CrvApiClient::Helpers::Crv
|
5
|
+
|
6
|
+
attr_reader :endpoint_url
|
7
|
+
attr_reader :username
|
8
|
+
attr_reader :password
|
9
|
+
attr_reader_with_type :customer, ::CrvApiClient::Api::Reproduction::ParticipantId
|
10
|
+
attr_reader_with_type :provider, ::CrvApiClient::Api::Reproduction::ParticipantId
|
11
|
+
|
12
|
+
def initialize(endpoint_url= ::CrvApiClient.configuration.endpoint_reproduction,
|
13
|
+
username: ::CrvApiClient.configuration.username,
|
14
|
+
password: ::CrvApiClient.configuration.password,
|
15
|
+
customer: ::CrvApiClient.configuration.customer,
|
16
|
+
provider: ::CrvApiClient.configuration.provider)
|
17
|
+
|
18
|
+
@endpoint_url = endpoint_url
|
19
|
+
@username = username
|
20
|
+
@password = password
|
21
|
+
self.customer= ::CrvApiClient::Api::Reproduction::ParticipantId.new(customer[:participant_code], customer[:participant_code_type], customer[:country_code])
|
22
|
+
self.provider= ::CrvApiClient::Api::Reproduction::ParticipantId.new(provider[:participant_code], provider[:participant_code_type], provider[:country_code])
|
23
|
+
end
|
24
|
+
|
25
|
+
def list_reproduction_last_parity(crv_id, country_code, context_message_detail: nil,process_code: "", options: {})
|
26
|
+
keeper, context_message_detail = keeper_and_context_message_detail(crv_id,country_code)
|
27
|
+
context = context_message(keeper,
|
28
|
+
username: @username,
|
29
|
+
password: @password,
|
30
|
+
context_message_detail: context_message_detail,
|
31
|
+
customer: customer,
|
32
|
+
provider: provider,
|
33
|
+
process_code: process_code,
|
34
|
+
animal: nil,
|
35
|
+
organisation: nil)
|
36
|
+
|
37
|
+
|
38
|
+
animal_request = [ participant_animal_request("TRP","PED") ]
|
39
|
+
animal_request_list = list_participant_animal_request("SHORT", animal_request)
|
40
|
+
requestType = list_reproduction_last_parity_request_type(keeper, animal_request_list)
|
41
|
+
request = CrvApiClient::Api::Reproduction::ListReproductionLastParityRequest.new
|
42
|
+
request.contextMessage = context
|
43
|
+
request.requestMessage = requestType
|
44
|
+
|
45
|
+
result = driver.listReproductionLastParity(request)
|
46
|
+
|
47
|
+
perform_service_message_validation(result.serviceMessage) unless options[:validate] == false
|
48
|
+
|
49
|
+
result
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def participant_animal_request(number_type, number_sub_type)
|
56
|
+
animal_request = CrvApiClient::Api::Reproduction::ParticipantAnimalRequest.new
|
57
|
+
animal_request.numberType = number_type
|
58
|
+
animal_request.numberSubType = number_sub_type
|
59
|
+
animal_request
|
60
|
+
end
|
61
|
+
|
62
|
+
def list_participant_animal_request(list_type, participant_animal_request)
|
63
|
+
animal_request_list = CrvApiClient::Api::Reproduction::ListParticipantAnimalRequest.new
|
64
|
+
animal_request_list.listType = list_type
|
65
|
+
animal_request_list.participantAnimalRequest = participant_animal_request
|
66
|
+
animal_request_list
|
67
|
+
end
|
68
|
+
|
69
|
+
def list_reproduction_last_parity_request_type(keeper, participant_animal_request)
|
70
|
+
requestType = CrvApiClient::Api::Reproduction::ListReproductionLastParityRequestType.new
|
71
|
+
requestType.keeper = keeper
|
72
|
+
requestType.participantAnimalRequest = participant_animal_request
|
73
|
+
requestType
|
74
|
+
end
|
75
|
+
|
76
|
+
def driver
|
77
|
+
@driver ||= begin
|
78
|
+
animal_soap_driver = CrvApiClient::Api::Reproduction::RsReproductionPortType.new(@endpoint_url)
|
79
|
+
animal_soap_driver.options['protocol.http.connect_timeout'] = CrvApiClient.configuration.http_connect_timeout || 220
|
80
|
+
animal_soap_driver.options['protocol.http.receive_timeout'] = CrvApiClient.configuration.http_receive_timeout || 220
|
81
|
+
animal_soap_driver.options['protocol.http.ssl_config.verify_mode'] = nil
|
82
|
+
animal_soap_driver.wiredump_file_base = CrvApiClient.configuration.log_file
|
83
|
+
animal_soap_driver
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module CrvApiClient
|
2
|
+
module Utils
|
3
|
+
class Configuration
|
4
|
+
|
5
|
+
attr_accessor :endpoint_reproduction
|
6
|
+
attr_accessor :endpoint_animals
|
7
|
+
attr_accessor :http_connect_timeout
|
8
|
+
attr_accessor :http_receive_timeout
|
9
|
+
attr_accessor :username
|
10
|
+
attr_accessor :password
|
11
|
+
attr_accessor :log_file
|
12
|
+
|
13
|
+
attr_accessor :customer
|
14
|
+
attr_accessor :provider
|
15
|
+
|
16
|
+
|
17
|
+
def customer=(customer={})
|
18
|
+
@customer_participant_code = customer[:participant_code] || ""
|
19
|
+
@customer_participant_code_type = customer[:participant_code_type] || ""
|
20
|
+
@customer_country_code = customer[:country_code] || ""
|
21
|
+
customer
|
22
|
+
end
|
23
|
+
|
24
|
+
def customer
|
25
|
+
{participant_code: @customer_participant_code || "", participant_code_type: @customer_participant_code_type|| "", country_code: @customer_country_code|| ""}
|
26
|
+
end
|
27
|
+
|
28
|
+
def provider=(provider={})
|
29
|
+
@provider_participant_code = provider[:participant_code] || ""
|
30
|
+
@provider_participant_code_type = provider[:participant_code_type] || ""
|
31
|
+
@provider_country_code = provider[:country_code] || ""
|
32
|
+
provider
|
33
|
+
end
|
34
|
+
|
35
|
+
def provider
|
36
|
+
{participant_code: @provider_participant_code|| "", participant_code_type: @provider_participant_code_type|| "", country_code: @provider_country_code|| ""}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "crv_api_client/version"
|
2
|
+
|
3
|
+
module CrvApiClient
|
4
|
+
class << self
|
5
|
+
attr_writer :configuration
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.configuration
|
9
|
+
@configuration ||= Utils::Configuration.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.configure
|
13
|
+
yield(configuration)
|
14
|
+
end
|
15
|
+
|
16
|
+
require 'soap/mapping'
|
17
|
+
require 'xsd/qname'
|
18
|
+
require 'soap/rpc/driver'
|
19
|
+
autoload :Helpers, 'crv_api_client/helpers'
|
20
|
+
autoload :Errors, 'crv_api_client/errors'
|
21
|
+
autoload :Api, 'crv_api_client/api'
|
22
|
+
autoload :Animals, 'crv_api_client/animals'
|
23
|
+
autoload :Reproduction, 'crv_api_client/reproduction'
|
24
|
+
autoload :Utils, 'crv_api_client/utils'
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
describe CrvApiClient::Animals do
|
2
|
+
let(:endpoint) { "https://localhost/animals" }
|
3
|
+
let(:default_content_type) { 'application/json' }
|
4
|
+
|
5
|
+
let(:animal) {::CrvApiClient::Api::Animals::AnimalId.new("b","c")}
|
6
|
+
let(:config_customer) { {participant_code:"10106605",participant_code_type:"PAR", country_code:"NLD"} }
|
7
|
+
let(:config_provider) { {participant_code:"2323",participant_code_type:"test", country_code:"asd"} }
|
8
|
+
let(:crv_customer) { ::CrvApiClient::Api::Animals::ParticipantId.new("10106605","PAR","NLD")}
|
9
|
+
let(:crv_provider) { ::CrvApiClient::Api::Animals::ParticipantId.new("2323","test","asd")}
|
10
|
+
let(:username) {"Username"}
|
11
|
+
let(:password) {"password"}
|
12
|
+
|
13
|
+
let(:client) { CrvApiClient::Animals.new }
|
14
|
+
let(:configured_client) { ::CrvApiClient::Animals.new(endpoint, username: username, password: password, customer: config_customer, provider: config_provider ) }
|
15
|
+
context 'initialization' do
|
16
|
+
|
17
|
+
it "should initalize the client with given parameters" do
|
18
|
+
expect(configured_client.endpoint_url).to eq(endpoint)
|
19
|
+
expect(configured_client.username).to eq(username)
|
20
|
+
expect(configured_client.password).to eql(password)
|
21
|
+
expect(configured_client.customer).to be_a(::CrvApiClient::Api::Animals::ParticipantId)
|
22
|
+
expect(configured_client.provider).to be_a(::CrvApiClient::Api::Animals::ParticipantId)
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should initialize with the configured attributes as default" do
|
27
|
+
CrvApiClient.configure do |conf|
|
28
|
+
conf.endpoint_animals = endpoint
|
29
|
+
conf.username = username
|
30
|
+
conf.password = password
|
31
|
+
conf.customer = config_customer
|
32
|
+
end
|
33
|
+
|
34
|
+
expect(client.endpoint_url).to eq(endpoint)
|
35
|
+
expect(client.username).to eq(username)
|
36
|
+
expect(client.password).to eq(password)
|
37
|
+
expect(client.customer).to be_a(::CrvApiClient::Api::Animals::ParticipantId)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'list_animals' do
|
42
|
+
it 'should list animals' do
|
43
|
+
crv_id = 20
|
44
|
+
country_code = "nl"
|
45
|
+
process_code = "2838"
|
46
|
+
context_message = CrvApiClient::Api::Animals::ContextMessage.new
|
47
|
+
keeper = ::CrvApiClient::Api::Animals::ParticipantId.new(crv_id,"",country_code)
|
48
|
+
context_message_detail = ::CrvApiClient::Api::Animals::ContextMessageDetail.new("a","b")
|
49
|
+
service_message = ::CrvApiClient::Api::Animals::ServiceMessage
|
50
|
+
response = ::CrvApiClient::Api::Animals::ListHerdPedigreeResponse.new(nil,service_message)
|
51
|
+
|
52
|
+
|
53
|
+
expect(configured_client).to receive(:keeper_and_context_message_detail).with(crv_id, country_code).and_return([keeper,context_message_detail])
|
54
|
+
expect(configured_client).to receive(:context_message).with(keeper, username: username, password: password, customer: instance_of(CrvApiClient::Api::Animals::ParticipantId), provider: instance_of(CrvApiClient::Api::Animals::ParticipantId), animal: nil, context_message_detail: context_message_detail, process_code: process_code, organisation: nil).and_return(context_message)
|
55
|
+
driver = configured_client.send(:driver)
|
56
|
+
expect(driver).to receive(:listHerdPedigree).with(satisfy { |message|
|
57
|
+
expect(message).to be_a(CrvApiClient::Api::Animals::ListHerdPedigreeRequest)
|
58
|
+
expect(message.requestMessage).to be_a(CrvApiClient::Api::Animals::ListHerdPedigreeRequestType)
|
59
|
+
expect(message.requestMessage.keeper).to be(keeper)
|
60
|
+
expect(message.contextMessage).to be(context_message)
|
61
|
+
}).and_return(response)
|
62
|
+
expect(configured_client).to receive(:perform_service_message_validation).with(service_message)
|
63
|
+
|
64
|
+
response = configured_client.list_animals(crv_id,country_code,process_code: process_code)
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should not handle message validations when option is given.' do
|
69
|
+
crv_id = 20
|
70
|
+
country_code = "nl"
|
71
|
+
process_code = "2838"
|
72
|
+
context_message = CrvApiClient::Api::Animals::ContextMessage.new
|
73
|
+
keeper = ::CrvApiClient::Api::Animals::ParticipantId.new(crv_id,"",country_code)
|
74
|
+
context_message_detail = ::CrvApiClient::Api::Animals::ContextMessageDetail.new("a","b")
|
75
|
+
service_message = ::CrvApiClient::Api::Animals::ServiceMessage
|
76
|
+
response = ::CrvApiClient::Api::Animals::ListHerdPedigreeResponse.new(nil,service_message)
|
77
|
+
|
78
|
+
|
79
|
+
expect(configured_client).to receive(:keeper_and_context_message_detail).with(crv_id, country_code).and_return([keeper,context_message_detail])
|
80
|
+
expect(configured_client).to receive(:context_message).with(keeper, username: username, password: password, customer: instance_of(CrvApiClient::Api::Animals::ParticipantId), provider: instance_of(CrvApiClient::Api::Animals::ParticipantId), animal: nil, context_message_detail: context_message_detail, process_code: process_code, organisation: nil).and_return(context_message)
|
81
|
+
driver = configured_client.send(:driver)
|
82
|
+
expect(driver).to receive(:listHerdPedigree).with(satisfy { |message|
|
83
|
+
expect(message).to be_a(CrvApiClient::Api::Animals::ListHerdPedigreeRequest)
|
84
|
+
expect(message.requestMessage).to be_a(CrvApiClient::Api::Animals::ListHerdPedigreeRequestType)
|
85
|
+
expect(message.requestMessage.keeper).to be(keeper)
|
86
|
+
expect(message.contextMessage).to be(context_message)
|
87
|
+
}).and_return(response)
|
88
|
+
expect(configured_client).to receive(:perform_service_message_validation).with(service_message).never
|
89
|
+
|
90
|
+
response = configured_client.list_animals(crv_id,country_code,process_code: process_code, options: {validate: false})
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CrvApiClient::Api::Animals::RsAnimalPortType do
|
4
|
+
|
5
|
+
describe "configure" do
|
6
|
+
it "should assign endpoints as default" do
|
7
|
+
animals = "EndpointAnimals"
|
8
|
+
|
9
|
+
CrvApiClient.configure do |config|
|
10
|
+
config.endpoint_animals = animals
|
11
|
+
end
|
12
|
+
driver = CrvApiClient::Api::Animals::RsAnimalPortType.new
|
13
|
+
|
14
|
+
expect(driver.proxy.endpoint_url).to be(animals)
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should accept custom endpoints " do
|
19
|
+
|
20
|
+
animals = "MyEndpointAnimals"
|
21
|
+
|
22
|
+
driver = CrvApiClient::Api::Animals::RsAnimalPortType.new animals
|
23
|
+
|
24
|
+
expect(driver.proxy.endpoint_url).to be(animals)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should load with the default url" do
|
28
|
+
|
29
|
+
CrvApiClient.configure do |config|
|
30
|
+
config.endpoint_animals = nil
|
31
|
+
end
|
32
|
+
|
33
|
+
driver = CrvApiClient::Api::Animals::RsAnimalPortType.new
|
34
|
+
|
35
|
+
expect(driver.proxy.endpoint_url).to be(CrvApiClient::Api::Animals::RsAnimalPortType::DefaultEndpointUrl)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CrvApiClient::Api::Reproduction::RsReproductionPortType do
|
4
|
+
|
5
|
+
describe "configure" do
|
6
|
+
it "should assign endpoints as default" do
|
7
|
+
reproduction = "ReproductionEndpoint"
|
8
|
+
|
9
|
+
CrvApiClient.configure do |config|
|
10
|
+
config.endpoint_reproduction = reproduction
|
11
|
+
end
|
12
|
+
driver = CrvApiClient::Api::Reproduction::RsReproductionPortType.new
|
13
|
+
|
14
|
+
expect(driver.proxy.endpoint_url).to be(reproduction)
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should accept custom endpoints " do
|
19
|
+
|
20
|
+
reproduction = "MyReproductionEndpoint"
|
21
|
+
|
22
|
+
driver = CrvApiClient::Api::Reproduction::RsReproductionPortType.new reproduction
|
23
|
+
|
24
|
+
expect(driver.proxy.endpoint_url).to be(reproduction)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should load with the default url" do
|
28
|
+
|
29
|
+
CrvApiClient.configure do |config|
|
30
|
+
config.endpoint_reproduction = nil
|
31
|
+
end
|
32
|
+
|
33
|
+
driver = CrvApiClient::Api::Reproduction::RsReproductionPortType.new
|
34
|
+
|
35
|
+
expect(driver.proxy.endpoint_url).to be(CrvApiClient::Api::Reproduction::RsReproductionPortType::DefaultEndpointUrl)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ::CrvApiClient::Helpers::Attributes do
|
4
|
+
|
5
|
+
let(:tested_class) { Class.new {
|
6
|
+
extend ::CrvApiClient::Helpers::Attributes
|
7
|
+
}.new }
|
8
|
+
context "attr_reader_with_type" do
|
9
|
+
it "should create a reader that is public" do
|
10
|
+
tested_class.class.attr_reader_with_type :foo , String
|
11
|
+
expect(tested_class).to respond_to(:foo).with(0).argument
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should create a writer that is private" do
|
15
|
+
tested_class.class.attr_reader_with_type :foo , String
|
16
|
+
expect(tested_class.private_methods).to include(:foo=)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
context "attr_accessor_with_type" do
|
22
|
+
it "should create a reader that is public" do
|
23
|
+
tested_class.class.attr_accessor_with_type :foo , String
|
24
|
+
expect(tested_class).to respond_to(:foo).with(0).argument
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should create a writer that is public" do
|
28
|
+
tested_class.class.attr_accessor_with_type :foo , String
|
29
|
+
expect(tested_class).to respond_to(:foo=).with(1).argument
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
context "general assignment" do
|
35
|
+
it "should throw an error when type does not match the assigned type" do
|
36
|
+
tested_class.class.attr_accessor_with_type :foo , String
|
37
|
+
expect{tested_class.foo = 1}.to raise_error(ArgumentError, /Invalid Type/)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should accept a matching type" do
|
41
|
+
tested_class.class.attr_accessor_with_type :foo , String
|
42
|
+
expect{tested_class.foo = "some string"}.not_to raise_error
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should return the given argument" do
|
46
|
+
argument = "Some string"
|
47
|
+
tested_class.class.attr_accessor_with_type :foo , String
|
48
|
+
expect{tested_class.foo = argument}.not_to raise_error
|
49
|
+
expect(tested_class.foo).to be(argument)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|