yarn-node-container-test.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. import { moduleFor, test } from 'ember-qunit';
  19. moduleFor('adapter:yarn-node-container', 'Unit | Adapter | NodeContainer', {
  20. });
  21. test('Basic creation', function(assert) {
  22. let adapter = this.subject();
  23. assert.expect(11);
  24. assert.ok(adapter);
  25. assert.ok(adapter.urlForQueryRecord);
  26. assert.ok(adapter.queryRecord);
  27. assert.ok(adapter.urlForQuery);
  28. assert.ok(adapter.query);
  29. assert.ok(adapter.ajax);
  30. assert.ok(adapter.headers);
  31. assert.ok(adapter.host);
  32. assert.ok(adapter.namespace);
  33. assert.equal("application/json", adapter.headers.Accept);
  34. assert.equal("ws/v1/node", adapter.namespace);
  35. });
  36. test('urlForQueryRecord test', function(assert) {
  37. let adapter = this.subject();
  38. let host = adapter.host;
  39. assert.equal(host + "localhost:8042/ws/v1/node/containers/" +
  40. "container_e27_11111111111_0001_01_000001",
  41. adapter.urlForQueryRecord(
  42. {nodeHttpAddr: "localhost:8042",
  43. containerId: "container_e27_11111111111_0001_01_000001"}));
  44. });
  45. test('urlForQuery test', function(assert) {
  46. let adapter = this.subject();
  47. let host = adapter.host;
  48. assert.equal(host + "localhost:8042/ws/v1/node/containers",
  49. adapter.urlForQuery({nodeHttpAddr: "localhost:8042"}));
  50. });
  51. test('query test', function(assert) {
  52. let adapter = this.subject(),
  53. testModel = { modelName: "testModel" },
  54. testStore = {},
  55. testQuery = {nodeHttpAddr: "localhost:8042"};
  56. let host = adapter.host;
  57. assert.expect(3);
  58. adapter.ajax = function (url, method, hash) {
  59. assert.equal(host + "localhost:8042/ws/v1/node/containers", url);
  60. assert.equal('GET', method);
  61. assert.equal(null, hash.data);
  62. };
  63. adapter.query(testStore, testModel, testQuery);
  64. });
  65. test('queryRecord test', function(assert) {
  66. let adapter = this.subject(),
  67. testModel = { modelName: "testModel" },
  68. testStore = {},
  69. testQuery = {
  70. nodeHttpAddr: "localhost:8042",
  71. containerId: "container_e27_11111111111_0001_01_000001"
  72. };
  73. let host = adapter.host;
  74. assert.expect(3);
  75. adapter.ajax = function (url, method, hash) {
  76. assert.equal(host + "localhost:8042/ws/v1/node/containers/" +
  77. "container_e27_11111111111_0001_01_000001", url);
  78. assert.equal('GET', method);
  79. assert.equal(null, hash.data);
  80. };
  81. adapter.queryRecord(testStore, testModel, testQuery);
  82. });