yarn-node-app-test.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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('serializer:yarn-node-app', 'Unit | Serializer | NodeApp', {
  20. });
  21. test('Basic creation test', function(assert) {
  22. let serializer = this.subject();
  23. assert.ok(serializer);
  24. assert.ok(serializer.normalizeSingleResponse);
  25. assert.ok(serializer.normalizeArrayResponse);
  26. assert.ok(serializer.internalNormalizeSingleResponse);
  27. });
  28. test('normalizeArrayResponse test', function(assert) {
  29. let serializer = this.subject(),
  30. modelClass = {
  31. modelName: "yarn-node-app"
  32. },
  33. payload = {
  34. apps: {
  35. app: [{
  36. id:"application_1456251210105_0001", state:"FINISHED", user:"root"
  37. },{
  38. id:"application_1456251210105_0002", state:"RUNNING",user:"root",
  39. containerids:["container_e38_1456251210105_0002_01_000001",
  40. "container_e38_1456251210105_0002_01_000002"]
  41. }]
  42. }
  43. };
  44. assert.expect(15);
  45. var response =
  46. serializer.normalizeArrayResponse({}, modelClass, payload, null, null);
  47. assert.ok(response.data);
  48. assert.equal(response.data.length, 2);
  49. assert.equal(response.data[0].attributes.containers, undefined);
  50. assert.equal(response.data[1].attributes.containers.length, 2);
  51. assert.deepEqual(response.data[1].attributes.containers,
  52. payload.apps.app[1].containerids);
  53. for (var i = 0; i < 2; i++) {
  54. assert.equal(response.data[i].type, modelClass.modelName);
  55. assert.equal(response.data[i].id, payload.apps.app[i].id);
  56. assert.equal(response.data[i].attributes.appId, payload.apps.app[i].id);
  57. assert.equal(response.data[i].attributes.state, payload.apps.app[i].state);
  58. assert.equal(response.data[i].attributes.user, payload.apps.app[i].user);
  59. }
  60. });
  61. test('normalizeArrayResponse no apps test', function(assert) {
  62. let serializer = this.subject(),
  63. modelClass = {
  64. modelName: "yarn-node-app"
  65. },
  66. payload = { apps: null };
  67. assert.expect(5);
  68. var response =
  69. serializer.normalizeArrayResponse({}, modelClass, payload, null, null);
  70. assert.ok(response.data);
  71. assert.equal(response.data.length, 1);
  72. assert.equal(response.data[0].type, modelClass.modelName);
  73. assert.equal(response.data[0].id, "dummy");
  74. assert.equal(response.data[0].attributes.appId, undefined);
  75. });
  76. test('normalizeSingleResponse test', function(assert) {
  77. let serializer = this.subject(),
  78. modelClass = {
  79. modelName: "yarn-node-app"
  80. },
  81. payload = {
  82. app: {id:"application_1456251210105_0001", state:"FINISHED", user:"root"}
  83. };
  84. assert.expect(7);
  85. var response =
  86. serializer.normalizeSingleResponse({}, modelClass, payload, null, null);
  87. assert.ok(response.data);
  88. assert.equal(payload.app.id, response.data.id);
  89. assert.equal(modelClass.modelName, response.data.type);
  90. assert.equal(payload.app.id, response.data.attributes.appId);
  91. assert.equal(payload.app.state, response.data.attributes.state);
  92. assert.equal(payload.app.user, response.data.attributes.user);
  93. assert.equal(response.data.attributes.containers, undefined);
  94. });