Class: TestJsonWrapper

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/lti2_commons/test/test_jsonwrapper.rb

Constant Summary collapse

ARGV =
['', "--name", "test_select"]

Instance Method Summary collapse

Instance Method Details

#setupObject



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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/lti2_commons/test/test_jsonwrapper.rb', line 13

def setup
  @json_str =
<<PROXY
{
"@context" : [
    "http://www.imsglobal.org/imspurl/lti/v2/ctx/ToolProxy",
    "http://purl.org/blackboard/ctx/v1/iconStyle"
],
"@type" : "ToolProxy",
"@id" : "http://fabericious..com/ToolProxy/869e5ce5-214c-4e85-86c6-b99e8458a592",
"lti_version" : "LTI-2p0",
"tool_proxy_guid" : "869e5ce5-214c-4e85-86c6-b99e8458a592",
"tool_consumer_profile" : "http://lms.example.com/profile/b6ffa601-ce1d-4549-9ccf-145670a964d4",
"tool_profile" : {
  "lti_version" : "LTI-2p0",
  "product_instance" : {
    "guid" : "fd75124a-140e-470f-944c-114d2d92bb40",
    "product_info" : {
      "product_name" : {
        "default_value" : "Acme Assessments",
        "key" : "tool.name"
      },
      "description" : {
        "default_value" : "Acme Assessments provide an interactive test format.",
        "key" : "tool.description"
      },
      "product_version" : "10.3",
      "technical_description" : {
        "default_value" : "Support provided for all LTI 1 extensions as well as LTI 2",
        "key" : "tool.technical"
      },
      "product_family" : {
        "code" : "assessment-tool",
        "vendor" : {
          "code" : "acme.com",
          "name" : {
            "default_value" : "Acme",
            "key" : "tool.vendor.name"
          },
          "description" : {
            "default_value" : "Acme is a leading provider of interactive tools for education",
            "key" : "tool.vendor.description"
          },
          "website" : "http://acme.example.com",
          "timestamp" : "2012-04-05T09:08:16-04:00",
          "contact" : {
            "email" : "[email protected]"
          }
        }
      }
    },
    "support" : {
      "email" : "[email protected]"
    },
    "service_provider" : {
      "guid" : "18e7ea50-3d6d-4f6b-aff2-ed3ab577716c",
      "provider_name" : {
        "default_value" : "Acme Hosting",
        "key" : "service_provider.name"
      },
      "description" : {
        "default_value" : "Provider of high performance managed hosting environments",
        "key" : "service_provider.description"
      },
      "support" : {
        "email" : "[email protected]"
      },
      "timestamp" : "2012-04-05T09:08:16-04:00"
    }
  },
  "base_url_choice" : [
     { "default_base_url" : "http://acme.example.com",
       "secure_base_url" : "https://acme.example.com",
       "selector" : {
         "applies_to" : [
           "IconEndpoint",
           "MessageHandler"
         ]
       }
     }
   ],
  "resource_handler" : [
    {
     "resource_type": "urn:lti:ResourceType:{fabericious.lti.org}/handler/launchRequest",
      "name" : {
        "default_value" : "Acme Assessment",
        "key" : "assessment.resource.name"
      },
      "description" : {
        "default_value" : "An interactive assessment using the Acme scale.",
        "key" : "assessment.resource.description"
      },
      "message" : [{
        "message_type" : "basic-lti-launch-request",
        "path" : "/handler/launchRequest",
        "capability" : [
          "Result.autocreate",
          "Result.sourcedGUID"
        ],
        "parameter" : [
          { "name" : "result_id",
            "variable" : "$Result.sourcedGUID"
          },
          { "name" : "discipline",
            "fixed" : "chemistry"
          }
        ]
      }],
      "icon_info" : [
         {
           "default_location" : {
             "path" : "/images/bb/en/icon.png"
           },
           "key" : "iconStyle.default.path"
         },
         { "icon_style" : "BbListElementIcon",
           "default_location" : {
             "path" : "/images/bb/en/listElement.png"
           },
           "key" : "iconStyle.bb.listElement.path"
         },
         { "icon_style" : "BbPushButtonIcon",
           "default_location" : {
             "path" : "images/bb/en/pushButton.png"
           },
           "key" : "iconStyle.bb.pushButton.path"
         }
       ]
    }
  ]
},
"security_contract" : {
  "shared_secret" : "ThisIsASecret!",
  "tool_service" : [
    { "@type" : "RestServiceProfile",
      "service" : "http://lms.example.com/profile/b6ffa601-ce1d-4549-9ccf-145670a964d4#ToolProxy.collection",
      "action" : "POST"
    },
    { "@type" : "RestServiceProfile",
      "service" : "http://lms.example.com/profile/b6ffa601-ce1d-4549-9ccf-145670a964d4#ToolProxy.item",
      "action" : [
        "GET",
        "PUT"
      ]
    },
    { "@type" : "RestService",
      "service" : "http://lms.example.com/profile/b6ffa601-ce1d-4549-9ccf-145670a964d4#Result.item",
      "action" : [
        "GET",
        "PUT"
      ]
    }
  ]
}
}
PROXY

@json_wrapper = JsonWrapper.new @json_str
end

#test_atObject



177
178
179
# File 'lib/lti2_commons/test/test_jsonwrapper.rb', line 177

def test_at
  assert_equal ["869e5ce5-214c-4e85-86c6-b99e8458a592"], @json_wrapper.at('tool_proxy_guid')
end

#test_constuctorObject



173
174
175
# File 'lib/lti2_commons/test/test_jsonwrapper.rb', line 173

def test_constuctor
  assert_not_nil @json_wrapper.root
end

#test_deep_copyObject



192
193
194
195
196
# File 'lib/lti2_commons/test/test_jsonwrapper.rb', line 192

def test_deep_copy
  new_json_wrapper = @json_wrapper.deep_copy
  assert_not_equal new_json_wrapper.object_id, @json_wrapper.object_id
  assert_equal "869e5ce5-214c-4e85-86c6-b99e8458a592", new_json_wrapper.first_at('tool_proxy_guid')
end

#test_each_deep_with_substitutionObject



219
220
221
222
223
224
225
226
# File 'lib/lti2_commons/test/test_jsonwrapper.rb', line 219

def test_each_deep_with_substitution
  hash = {"root" => {"child1" => "{value}1", "child2" => {"grandchild1" => "{grand}{value}1"}, "child3" => "{value}3"}}
  json_hash = JsonWrapper.new hash
  subst_hash = {'value' => 'VLU', 'great' => 'GRT', 'grand' => 'GRND'}
  json_hash.substitute_text_in_all_nodes '{', '}', subst_hash
  assert_equal "VLU1", json_hash.first_at('$..child1')
  assert_equal "GRNDVLU1", json_hash.first_at('$..grandchild1')
end

#test_each_leafObject



186
187
188
189
190
# File 'lib/lti2_commons/test/test_jsonwrapper.rb', line 186

def test_each_leaf
  counter = 0
  @json_wrapper.each_leaf { |node| counter += 1 }
  assert_equal 70, counter
end

#test_first_atObject



181
182
183
184
# File 'lib/lti2_commons/test/test_jsonwrapper.rb', line 181

def test_first_at
  assert_equal "869e5ce5-214c-4e85-86c6-b99e8458a592", @json_wrapper.first_at('tool_proxy_guid')
  assert_nil @json_wrapper.first_at('asdf')
end

#test_searchObject



198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/lti2_commons/test/test_jsonwrapper.rb', line 198

def test_search
  assert_equal "/handler/launchRequest",
      ( @json_wrapper.search 'tool_profile.resource_handler..message',
          { 'message_type' => "basic-lti-launch-request" },
          "path")
  assert_nil @json_wrapper.search 'tool_profile.resource_handler..message',
          { 'message_type' => "basic-lti-launch-request" },
          "xxxx"
  assert_nil @json_wrapper.search 'tool_profile.resource_handler..message',
          { 'message_type' => "xxx" },
          "path"
end

#test_selectObject



211
212
213
214
215
216
217
# File 'lib/lti2_commons/test/test_jsonwrapper.rb', line 211

def test_select
  assert_equal "http://acme.example.com",
      @json_wrapper.select('tool_profile.base_url_choice',
          "selector.applies_to", "MessageHandler", 'default_base_url')
  assert_equal nil, @json_wrapper.select('tool_profile.xxxxx',
          "selector.applies_to", "MessageHandler", 'default_base_url')
end