|
| 1 | +/* Copyright (c) 2024, Oracle and/or its affiliates. */ |
| 2 | + |
| 3 | +/****************************************************************************** |
| 4 | + * |
| 5 | + * This software is dual-licensed to you under the Universal Permissive License |
| 6 | + * (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License |
| 7 | + * 2.0 as shown at https://www.apache.org/licenses/LICENSE-2.0. You may choose |
| 8 | + * either license. |
| 9 | + * |
| 10 | + * If you elect to accept the software under the Apache License, Version 2.0, |
| 11 | + * the following applies: |
| 12 | + * |
| 13 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 14 | + * you may not use this file except in compliance with the License. |
| 15 | + * You may obtain a copy of the License at |
| 16 | + * |
| 17 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 18 | + * |
| 19 | + * Unless required by applicable law or agreed to in writing, software |
| 20 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 21 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 22 | + * See the License for the specific language governing permissions and |
| 23 | + * limitations under the License. |
| 24 | + * |
| 25 | + * NAME |
| 26 | + * 302. aq10.js |
| 27 | + * |
| 28 | + * DESCRIPTION |
| 29 | + * Test Oracle Advanced Queueing (AQ) condition attribute. |
| 30 | + * condition: A String that defines the condition that must be satisfied |
| 31 | + * in order for a message to be dequeued. |
| 32 | + *****************************************************************************/ |
| 33 | +'use strict'; |
| 34 | + |
| 35 | +const oracledb = require('oracledb'); |
| 36 | +const dbConfig = require('./dbconfig.js'); |
| 37 | +const testsUtil = require('./testsUtil.js'); |
| 38 | +const assert = require('assert'); |
| 39 | + |
| 40 | +describe('302. aq10.js', function() { |
| 41 | + let isRunnable = true; |
| 42 | + let conn; |
| 43 | + const AQ_USER = 'NODB_SCHEMA_AQTEST10'; |
| 44 | + const AQ_USER_PWD = testsUtil.generateRandomPassword(); |
| 45 | + |
| 46 | + const objQueueName = "NODB_ADDR_QUEUE"; |
| 47 | + const objType = "NODB_ADDR_TYP"; |
| 48 | + const objTable = "NODB_TAB_ADDR"; |
| 49 | + |
| 50 | + before(async function() { |
| 51 | + const prerequisites = await testsUtil.checkPrerequisites(2100000000, 2100000000); |
| 52 | + if (!dbConfig.test.DBA_PRIVILEGE || oracledb.thin || !prerequisites) { |
| 53 | + isRunnable = false; |
| 54 | + } |
| 55 | + |
| 56 | + if (!isRunnable) this.skip(); |
| 57 | + |
| 58 | + await testsUtil.createAQtestUser(AQ_USER, AQ_USER_PWD); |
| 59 | + const credential = { |
| 60 | + user: AQ_USER, |
| 61 | + password: AQ_USER_PWD, |
| 62 | + connectString: dbConfig.connectString |
| 63 | + }; |
| 64 | + conn = await oracledb.getConnection(credential); |
| 65 | + |
| 66 | + // Create the Type |
| 67 | + let plsql = ` |
| 68 | + CREATE OR REPLACE TYPE ${objType} AS OBJECT ( |
| 69 | + NAME VARCHAR2(10), |
| 70 | + ADDRESS VARCHAR2(50) |
| 71 | + ); |
| 72 | + `; |
| 73 | + await conn.execute(plsql); |
| 74 | + |
| 75 | + // Create and start a queue |
| 76 | + plsql = ` |
| 77 | + BEGIN |
| 78 | + DBMS_AQADM.CREATE_QUEUE_TABLE( |
| 79 | + QUEUE_TABLE => '${AQ_USER}.${objTable}', |
| 80 | + QUEUE_PAYLOAD_TYPE => '${objType}' |
| 81 | + ); |
| 82 | + DBMS_AQADM.CREATE_QUEUE( |
| 83 | + QUEUE_NAME => '${AQ_USER}.${objQueueName}', |
| 84 | + QUEUE_TABLE => '${AQ_USER}.${objTable}' |
| 85 | + ); |
| 86 | + DBMS_AQADM.START_QUEUE( |
| 87 | + QUEUE_NAME => '${AQ_USER}.${objQueueName}' |
| 88 | + ); |
| 89 | + END; |
| 90 | + `; |
| 91 | + await conn.execute(plsql); |
| 92 | + }); |
| 93 | + |
| 94 | + after (async function() { |
| 95 | + if (!isRunnable) return; |
| 96 | + |
| 97 | + await conn.execute(` |
| 98 | + BEGIN |
| 99 | + DBMS_AQADM.STOP_QUEUE('${AQ_USER}.${objQueueName}'); |
| 100 | + END; `); |
| 101 | + await conn.execute(` |
| 102 | + BEGIN |
| 103 | + DBMS_AQADM.DROP_QUEUE_TABLE( |
| 104 | + QUEUE_TABLE => '${AQ_USER}.${objTable}', |
| 105 | + FORCE => TRUE); |
| 106 | + END; `); |
| 107 | + |
| 108 | + await conn.execute(`DROP TYPE ${objType}`); |
| 109 | + await conn.close(); |
| 110 | + await testsUtil.dropAQtestUser(AQ_USER); |
| 111 | + }); |
| 112 | + |
| 113 | + const addrData1 = { |
| 114 | + NAME: "John", |
| 115 | + ADDRESS: "100 Oracle Parkway Redwood City, CA US 94065" |
| 116 | + }; |
| 117 | + |
| 118 | + const addrData2 = { |
| 119 | + NAME: "Jenny", |
| 120 | + ADDRESS: "200 Oracle Parkway Redwood City, CA US 94065" |
| 121 | + }; |
| 122 | + |
| 123 | + const addrData3 = { |
| 124 | + NAME: "Laura", |
| 125 | + ADDRESS: "300 Oracle Parkway Redwood City, CA US 94065" |
| 126 | + }; |
| 127 | + |
| 128 | + it('302.1 condition attribute in dequeue', async () => { |
| 129 | + // Enqueue |
| 130 | + const queue = await conn.getQueue( |
| 131 | + objQueueName, |
| 132 | + { payloadType: objType } |
| 133 | + ); |
| 134 | + const message1 = new queue.payloadTypeClass(addrData1); |
| 135 | + await queue.enqOne(message1); |
| 136 | + await conn.commit(); |
| 137 | + |
| 138 | + const message2 = new queue.payloadTypeClass(addrData2); |
| 139 | + await queue.enqOne(message2); |
| 140 | + await conn.commit(); |
| 141 | + |
| 142 | + const message3 = new queue.payloadTypeClass(addrData3); |
| 143 | + await queue.enqOne(message3); |
| 144 | + await conn.commit(); |
| 145 | + |
| 146 | + // Dequeue |
| 147 | + const queue2 = await conn.getQueue( |
| 148 | + objQueueName, |
| 149 | + { payloadType: objType } |
| 150 | + ); |
| 151 | + |
| 152 | + queue2.deqOptions.condition = `tab.user_data.NAME = '${addrData2.NAME}'`; |
| 153 | + const msgDeq = await queue2.deqOne(); |
| 154 | + assert.strictEqual(msgDeq.payload.NAME, addrData2.NAME); |
| 155 | + assert.strictEqual(msgDeq.payload.ADDRESS, addrData2.ADDRESS); |
| 156 | + }); // 302.1 |
| 157 | + |
| 158 | + it('302.2 Negative - wrong identifier in condition attribute', async () => { |
| 159 | + // Dequeue |
| 160 | + const queue2 = await conn.getQueue( |
| 161 | + objQueueName, |
| 162 | + { payloadType: objType } |
| 163 | + ); |
| 164 | + |
| 165 | + queue2.deqOptions.condition = `someString.NAME = '${addrData2.NAME}'`; |
| 166 | + await assert.rejects( |
| 167 | + async () => await queue2.deqOne(), |
| 168 | + /ORA-00904:/ //ORA-00904: "SOMESTRING"."NAME": invalid identifier |
| 169 | + ); |
| 170 | + assert.strictEqual(queue2.deqOptions.condition, `someString.NAME = '${addrData2.NAME}'`); |
| 171 | + }); // 302.2 |
| 172 | +}); |
0 commit comments