Skip to content

Commit

Permalink
#10532 backward compatibility and test for GetNTP
Browse files Browse the repository at this point in the history
  • Loading branch information
paoloo committed Jul 17, 2024
1 parent b776642 commit 9f8026e
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/device.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ defmodule Onvif.Device do
field(:firmware_version, :string)
field(:serial_number, :string)
field(:hardware_id, :string)
field(:ntp, :string)
field(:media_ver10_service_path, :string)
field(:media_ver20_service_path, :string)
embeds_one(:system_date_time, Onvif.Devices.SystemDateAndTime)
embeds_one(:ntp, Onvif.Devices.NTP)
embeds_many(:services, Onvif.Device.Service)

field(:auth_type, Ecto.Enum,
Expand Down Expand Up @@ -87,7 +87,6 @@ defmodule Onvif.Device do
device
|> cast(attrs, @required ++ @optional)
|> cast_embed(:system_date_time, with: &Onvif.Devices.SystemDateAndTime.changeset/2)
|> cast_embed(:ntp, with: &Onvif.Devices.NTP.changeset/2)
|> cast_embed(:services, with: &Onvif.Device.Service.changeset/2)
|> validate_required(@required)
end
Expand Down
51 changes: 51 additions & 0 deletions test/devices/fixtures/get_ntp_response.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<env:Envelope
xmlns:env="http://www.w3.org/2003/05/soap-envelope"
xmlns:soapenc="http://www.w3.org/2003/05/soap-encoding"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tt="http://www.onvif.org/ver10/schema"
xmlns:tds="http://www.onvif.org/ver10/device/wsdl"
xmlns:trt="http://www.onvif.org/ver10/media/wsdl"
xmlns:timg="http://www.onvif.org/ver20/imaging/wsdl"
xmlns:tev="http://www.onvif.org/ver10/events/wsdl"
xmlns:tptz="http://www.onvif.org/ver20/ptz/wsdl"
xmlns:tan="http://www.onvif.org/ver20/analytics/wsdl"
xmlns:tst="http://www.onvif.org/ver10/storage/wsdl"
xmlns:ter="http://www.onvif.org/ver10/error"
xmlns:dn="http://www.onvif.org/ver10/network/wsdl"
xmlns:tns1="http://www.onvif.org/ver10/topics"
xmlns:tmd="http://www.onvif.org/ver10/deviceIO/wsdl"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl"
xmlns:wsoap12="http://schemas.xmlsoap.org/wsdl/soap12"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http"
xmlns:d="http://schemas.xmlsoap.org/ws/2005/04/discovery"
xmlns:wsadis="http://schemas.xmlsoap.org/ws/2004/08/addressing"
xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2"
xmlns:wsa="http://www.w3.org/2005/08/addressing"
xmlns:wstop="http://docs.oasis-open.org/wsn/t-1"
xmlns:wsrf-bf="http://docs.oasis-open.org/wsrf/bf-2"
xmlns:wsntw="http://docs.oasis-open.org/wsn/bw-2"
xmlns:wsrf-rw="http://docs.oasis-open.org/wsrf/rw-2"
xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"
xmlns:wsrf-r="http://docs.oasis-open.org/wsrf/r-2"
xmlns:trc="http://www.onvif.org/ver10/recording/wsdl"
xmlns:tse="http://www.onvif.org/ver10/search/wsdl"
xmlns:trp="http://www.onvif.org/ver10/replay/wsdl"
xmlns:tnshik="http://www.hikvision.com/2011/event/topics"
xmlns:hikwsd="http://www.onvifext.com/onvif/ext/ver10/wsdl"
xmlns:hikxsd="http://www.onvifext.com/onvif/ext/ver10/schema"
xmlns:tas="http://www.onvif.org/ver10/advancedsecurity/wsdl"
xmlns:tr2="http://www.onvif.org/ver20/media/wsdl"
xmlns:axt="http://www.onvif.org/ver20/analytics">
<env:Body>
<tds:GetNTPResponse>
<tds:NTPInformation>
<tt:FromDHCP>false</tt:FromDHCP>
<tt:NTPManual>
<tt:Type>DNS</tt:Type>
<tt:DNSname>time.windows.com</tt:DNSname>
</tt:NTPManual>
</tds:NTPInformation>
</tds:GetNTPResponse>
</env:Body>
</env:Envelope>
30 changes: 30 additions & 0 deletions test/devices/get_ntp.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
defmodule Onvif.Devices.GetNTPTest do
use ExUnit.Case, async: true

@moduletag capture_log: true

describe "GetNTP/1" do
test "check ntp configuration" do
xml_response = File.read!("test/devices/fixtures/get_ntp_response.xml")

device = Onvif.Factory.device()

Mimic.expect(Tesla, :request, fn _client, _opts ->
{:ok, %{status: 200, body: xml_response}}
end)

{:ok, service_capabilities} = Onvif.Devices.GetNTP.request(device)

assert service_capabilities == %Onvif.Devices.NTP{
from_dhcp: false,
ntp_from_dhcp: nil,
ntp_manual: %Onvif.Devices.NTP.NTPManual{
dns_name: "time.windows.com",
ipv4_address: nil,
ipv6_address: nil,
type: :dns
}
}
end
end
end

0 comments on commit 9f8026e

Please sign in to comment.