|
| 1 | +/* |
| 2 | + * Copyright (C) 2020 IBM Corporation |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package io.vertx.db2client; |
| 17 | + |
| 18 | +import org.junit.Ignore; |
| 19 | +import org.junit.Test; |
| 20 | +import org.junit.runner.RunWith; |
| 21 | + |
| 22 | +import io.vertx.db2client.impl.drda.SQLState; |
| 23 | +import io.vertx.db2client.impl.drda.SqlCode; |
| 24 | +import io.vertx.ext.unit.TestContext; |
| 25 | +import io.vertx.ext.unit.junit.VertxUnitRunner; |
| 26 | + |
| 27 | +@RunWith(VertxUnitRunner.class) |
| 28 | +public class DB2ErrorMessageTest extends DB2TestBase { |
| 29 | + |
| 30 | + @Test |
| 31 | + @Ignore // TODO - Need to figure out why this is blowing up in parseACCSECreply() |
| 32 | + public void testConnectInvalidDatabase(TestContext ctx) { |
| 33 | + options.setDatabase("DOES_NOT_EXIST"); |
| 34 | + DB2Connection.connect(vertx, options, ctx.asyncAssertFailure(err -> { |
| 35 | + ctx.assertTrue(err instanceof DB2Exception, "The error message returned is of the wrong type. It should be a DB2Exception, but it was of type " + err.getClass().getSimpleName()); |
| 36 | +// DB2Exception ex = (DB2Exception) err; |
| 37 | +// ctx.assertTrue(ex.getMessage().contains("Invalid database"), "The SQL error message returned is not correct. It should have contained \"Invalid database\", but instead it said \"" + ex.getMessage() + "\""); |
| 38 | + })); |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + public void testConnectInvalidUsername(TestContext ctx) { |
| 43 | + options.setUser("INVALID_USER_FOR_TESTING"); |
| 44 | + DB2Connection.connect(vertx, options, ctx.asyncAssertFailure(err -> { |
| 45 | + ctx.assertTrue(err instanceof DB2Exception, "The error message returned is of the wrong type. It should be a DB2Exception, but it was of type " + err.getClass().getSimpleName()); |
| 46 | + DB2Exception ex = (DB2Exception) err; |
| 47 | + ctx.assertTrue(ex.getMessage().contains("Invalid credentials"), "The SQL error message returned is not correct. It should have contained \"Invalid credentials\", but instead it said \"" + ex.getMessage() + "\""); |
| 48 | + ctx.assertEquals(SqlCode.INVALID_CREDENTIALS, ex.getErrorCode()); |
| 49 | + ctx.assertEquals(SQLState.NET_CONNECT_AUTH_FAILED, ex.getSqlState()); |
| 50 | + System.out.println(err.getMessage()); |
| 51 | + })); |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + public void testConnectInvalidPassword(TestContext ctx) { |
| 56 | + options.setPassword("INVALID_PASSWORD_FOR_TESTING"); |
| 57 | + DB2Connection.connect(vertx, options, ctx.asyncAssertFailure(err -> { |
| 58 | + ctx.assertTrue(err instanceof DB2Exception, "The error message returned is of the wrong type. It should be a DB2Exception, but it was of type " + err.getClass().getSimpleName()); |
| 59 | + DB2Exception ex = (DB2Exception) err; |
| 60 | + ctx.assertTrue(ex.getMessage().contains("Invalid credentials"), "The SQL error message returned is not correct. It should have contained \"Invalid credentials\", but instead it said \"" + ex.getMessage() + "\""); |
| 61 | + ctx.assertEquals(SqlCode.INVALID_CREDENTIALS, ex.getErrorCode()); |
| 62 | + ctx.assertEquals(SQLState.NET_CONNECT_AUTH_FAILED, ex.getSqlState()); |
| 63 | + System.out.println(err.getMessage()); |
| 64 | + })); |
| 65 | + } |
| 66 | + |
| 67 | + @Test |
| 68 | + @Ignore // TODO - @GJW I want to validate we would always want to fail a test for a blank user name. If so, we want to catch this *before* we connect to the DB2 server |
| 69 | + public void testConnectBlankUsername(TestContext ctx) { |
| 70 | + options.setUser(""); |
| 71 | + DB2Connection.connect(vertx, options, ctx.asyncAssertFailure(err -> { |
| 72 | + ctx.assertTrue(err instanceof DB2Exception, "The error message returned is of the wrong type. It should be a DB2Exception, but it was of type " + err.getClass().getSimpleName()); |
| 73 | + ctx.assertTrue("Missing userid, verify a user value was supplied".equalsIgnoreCase(err.getMessage()), "The text of the returned error message is incorrect. It should say \"Missing userid, verify a user value was supplied\", but instead, it says \"" + err.getMessage() + "\""); |
| 74 | + })); |
| 75 | + } |
| 76 | + |
| 77 | + @Test |
| 78 | + @Ignore // TODO - @GJW I want to validate we would always want to fail a test for a blank password. If so, we want to catch this *before* we connect to the DB2 server |
| 79 | + public void testConnectBlankPassword(TestContext ctx) { |
| 80 | + options.setPassword(""); |
| 81 | + DB2Connection.connect(vertx, options, ctx.asyncAssertFailure(err -> { |
| 82 | + ctx.assertTrue(err instanceof DB2Exception, "The error message returned is of the wrong type. It should be a DB2Exception, but it was of type " + err.getClass().getSimpleName()); |
| 83 | + ctx.assertTrue("Missing password, verify a password value was supplied".equalsIgnoreCase(err.getMessage()), "The text of the returned error message is incorrect. It should say \"Missing password, verify a password value was supplied\", but instead, it says \"" + err.getMessage() + "\""); |
| 84 | + })); |
| 85 | + } |
| 86 | + |
| 87 | + @Test |
| 88 | + @Ignore // TODO - complete |
| 89 | + public void testConnectInvalidQuery(TestContext ctx) { |
| 90 | + } |
| 91 | +} |
0 commit comments