|
| 1 | +/* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. */ |
| 2 | + |
| 3 | +/****************************************************************************** |
| 4 | + * |
| 5 | + * You may not use the identified files except in compliance with the Apache |
| 6 | + * License, Version 2.0 (the "License.") |
| 7 | + * |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0. |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + * |
| 18 | + * NAME |
| 19 | + * 214. dbObject15.js |
| 20 | + * |
| 21 | + * DESCRIPTION |
| 22 | + * Test DB Object collection methods. |
| 23 | + * |
| 24 | + *****************************************************************************/ |
| 25 | +'use strict'; |
| 26 | + |
| 27 | +const oracledb = require('oracledb'); |
| 28 | +const should = require('should'); |
| 29 | +const dbconfig = require('./dbconfig.js'); |
| 30 | + |
| 31 | +describe('214. dbObject15.js', () => { |
| 32 | + |
| 33 | + let conn, FrisbeeTeam; |
| 34 | + |
| 35 | + const PLAYER_T = 'NODB_TYP_PLAYERTYPE'; |
| 36 | + const TEAM_T = 'NODB_TYP_TEAMTYPE'; |
| 37 | + |
| 38 | + const FrisbeePlayers = [ |
| 39 | + { SHIRTNUMBER: 10, NAME: 'Emma' }, |
| 40 | + { SHIRTNUMBER: 11, NAME: 'Alex' }, |
| 41 | + { SHIRTNUMBER: 12, NAME: 'Dave' }, |
| 42 | + { SHIRTNUMBER: 13, NAME: 'Jack' }, |
| 43 | + { SHIRTNUMBER: 14, NAME: 'Emmet' } |
| 44 | + ]; |
| 45 | + |
| 46 | + before(async () => { |
| 47 | + try { |
| 48 | + conn = await oracledb.getConnection(dbconfig); |
| 49 | + |
| 50 | + let plsql =` |
| 51 | + CREATE OR REPLACE TYPE ${PLAYER_T} AS OBJECT ( |
| 52 | + shirtnumber NUMBER, |
| 53 | + name VARCHAR2(20) |
| 54 | + ); |
| 55 | + `; |
| 56 | + await conn.execute(plsql); |
| 57 | + |
| 58 | + plsql =` |
| 59 | + CREATE OR REPLACE TYPE ${TEAM_T} AS VARRAY(10) OF ${PLAYER_T}; |
| 60 | + `; |
| 61 | + await conn.execute(plsql); |
| 62 | + |
| 63 | + const TeamTypeClass = await conn.getDbObjectClass(TEAM_T); |
| 64 | + FrisbeeTeam = new TeamTypeClass(FrisbeePlayers); |
| 65 | + |
| 66 | + } catch(err) { |
| 67 | + should.not.exist(err); |
| 68 | + } |
| 69 | + }); // before() |
| 70 | + |
| 71 | + after(async () => { |
| 72 | + try { |
| 73 | + |
| 74 | + let sql = `DROP TYPE ${TEAM_T} FORCE`; |
| 75 | + await conn.execute(sql); |
| 76 | + |
| 77 | + sql = `DROP TYPE ${PLAYER_T} FORCE`; |
| 78 | + await conn.execute(sql); |
| 79 | + |
| 80 | + await conn.close(); |
| 81 | + } catch(err) { |
| 82 | + should.not.exist(err); |
| 83 | + } |
| 84 | + }); // after() |
| 85 | + |
| 86 | + it('214.1 Getter() - access collection elements directly', async () => { |
| 87 | + try { |
| 88 | + |
| 89 | + for(let i = 0, element; i < FrisbeePlayers.length; i++) { |
| 90 | + element = FrisbeeTeam[i]; |
| 91 | + should.strictEqual(element.SHIRTNUMBER, FrisbeePlayers[i].SHIRTNUMBER); |
| 92 | + should.strictEqual(element.NAME, FrisbeePlayers[i].NAME); |
| 93 | + } |
| 94 | + |
| 95 | + } catch (err) { |
| 96 | + should.not.exist(err); |
| 97 | + } |
| 98 | + }); // 214.1 |
| 99 | + |
| 100 | + it('214.2 Setter() - access collection element directly', async () => { |
| 101 | + |
| 102 | + // TypeError: 'set' on proxy: trap returned falsish for property '0' |
| 103 | + try { |
| 104 | + const substitute = {SHIRTNUMBER: 15, NAME: 'Chris'}; |
| 105 | + FrisbeeTeam[0] = substitute; |
| 106 | + } catch (err) { |
| 107 | + should.not.exist(err); |
| 108 | + } |
| 109 | + }); // 214.2 |
| 110 | + |
| 111 | + it('214.3 Negative - delete the collection element directly', async () => { |
| 112 | + should.throws( |
| 113 | + function() { |
| 114 | + delete FrisbeeTeam[1]; |
| 115 | + }, |
| 116 | + /OCI-22164/ |
| 117 | + ); |
| 118 | + // OCI-22164: delete element operation is not allowed for variable-length array |
| 119 | + }); // 214.3 |
| 120 | + |
| 121 | + it('214.4 Negative - collection.deleteElement()', async () => { |
| 122 | + should.throws( |
| 123 | + function() { |
| 124 | + let firstIndex = FrisbeeTeam.getFirstIndex(); |
| 125 | + FrisbeeTeam.deleteElement(firstIndex); |
| 126 | + }, |
| 127 | + /OCI-22164/ |
| 128 | + ); |
| 129 | + }); // 214.4 |
| 130 | +}); |
0 commit comments