File: test_ServiceProvider.R

package info (click to toggle)
r-cran-rsdmx 0.5.7%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 940 kB
  • sloc: makefile: 2
file content (82 lines) | stat: -rw-r--r-- 2,497 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# test_ServiceProvider.R
# Author: Emmanuel Blondel <emmanuel.blondel1@gmail.com>
#
# Description: Unit tests for SDMX Service Provider
#=======================
require(rsdmx, quietly = TRUE)
require(testthat)
context("SDMXServiceProvider")

test_that("SDMXServiceProvider - constructor",{
  
  requestBuilder <- SDMXRequestBuilder(
    regUrl = "http://www.myorg.org/registry",
    repoUrl = "http://www.myorg.org/repository",
    formatter = list(
      dataflow = function(obj){return(obj)},
      datastructure = function(obj){return(obj)},
      data = function(obj){return(obj)}
    ),
    handler = list(
      dataflow = function(obj){return(obj@regUrl)},
      datastructure = function(obj){return(obj@regUrl)},
      data = function(obj){return(obj@repoUrl)}
    ),
    compliant = TRUE)
  
  
  provider <- SDMXServiceProvider(
    agencyId = "MYORG", name = "My Organization",
    builder = requestBuilder
  )
  
  expect_is(provider, "SDMXServiceProvider")
  expect_equal(provider@agencyId, "MYORG")
  expect_equal(provider@name, "My Organization")
  expect_equal(provider@scale, "international")
  expect_true(is.na(provider@country))
  expect_is(provider@builder, "SDMXRequestBuilder")
  
})


test_that("SDMXServiceProvider - methods",{
    
  providers <- getSDMXServiceProviders()
  expect_is(providers, "SDMXServiceProviders")
  nbOfProviders <- length(providers@providers)
  expect_true(nbOfProviders > 0)
  expect_is(as.data.frame(providers), "data.frame")
  
  #add a provider
  requestBuilder <- SDMXRequestBuilder(
    regUrl = "http://www.myorg.org/registry",
    repoUrl = "http://www.myorg.org/repository",
    formatter = list(
      dataflow = function(obj){return(obj)},
      datastructure = function(obj){return(obj)},
      data = function(obj){return(obj)}
    ),
    handler = list(
      dataflow = function(obj){return(obj@regUrl)},
      datastructure = function(obj){return(obj@regUrl)},
      data = function(obj){return(obj@repoUrl)}
    ),
    compliant = TRUE)
  
  provider <- SDMXServiceProvider(
    agencyId = "MYORG", name = "My Organization",
    builder = requestBuilder
  )
  
  addSDMXServiceProvider(provider)
  providers <- getSDMXServiceProviders()
  expect_equal(length(providers@providers), nbOfProviders+1)
  
  #find a provider
  oecd <- findSDMXServiceProvider("OECD")
  expect_is(oecd, "SDMXServiceProvider")
  expect_equal(oecd@agencyId, "OECD")
  
})