forked from aws/aws-secretsmanager-jdbc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAWSSecretsManagerMSSQLServerDriverTest.java
More file actions
100 lines (81 loc) · 3.41 KB
/
Copy pathAWSSecretsManagerMSSQLServerDriverTest.java
File metadata and controls
100 lines (81 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package com.amazonaws.secretsmanager.sql;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.sql.SQLException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import com.amazonaws.secretsmanager.caching.SecretCache;
import com.amazonaws.secretsmanager.util.TestClass;
/**
* Tests for the MSSQL Driver.
*/
public class AWSSecretsManagerMSSQLServerDriverTest extends TestClass {
private AWSSecretsManagerMSSQLServerDriver sut;
@Mock
private SecretCache cache;
@BeforeEach
public void setup() {
System.setProperty("drivers.sqlserver.realDriverClass", "com.amazonaws.secretsmanager.sql.DummyDriver");
MockitoAnnotations.openMocks(this);
try {
sut = new AWSSecretsManagerMSSQLServerDriver(cache);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Test
public void test_getPropertySubprefix() {
assertEquals("sqlserver", sut.getPropertySubprefix());
}
@Test
public void test_isExceptionDueToAuthenticationError_returnsTrue_correctException() {
SQLException e = new SQLException("", "", 18456);
assertTrue(sut.isExceptionDueToAuthenticationError(e));
}
@Test
public void test_isExceptionDueToAuthenticationError_returnsFalse_wrongSQLException() {
SQLException e = new SQLException("", "", 18457);
assertFalse(sut.isExceptionDueToAuthenticationError(e));
}
@Test
public void test_isExceptionDueToAuthenticationError_returnsFalse_runtimeException() {
RuntimeException e = new RuntimeException("asdf");
assertFalse(sut.isExceptionDueToAuthenticationError(e));
}
@Test
public void test_constructUrl() {
String url = sut.constructUrlFromEndpointPortDatabase("test-endpoint", "1234", "dev");
assertEquals(url, "jdbc:sqlserver://test-endpoint:1234;databaseName=dev;");
}
@Test
public void test_constructUrlNullPort() {
String url = sut.constructUrlFromEndpointPortDatabase("test-endpoint", null, "dev");
assertEquals(url, "jdbc:sqlserver://test-endpoint;databaseName=dev;");
}
@Test
public void test_constructUrlNullDatabase() {
String url = sut.constructUrlFromEndpointPortDatabase("test-endpoint", "1234", null);
assertEquals(url, "jdbc:sqlserver://test-endpoint:1234");
}
@Test
public void test_getDefaultDriverClass() {
System.clearProperty("drivers.sqlserver.realDriverClass");
AWSSecretsManagerMSSQLServerDriver sut2 = new AWSSecretsManagerMSSQLServerDriver(cache);
assertEquals(getFieldFrom(sut2, "realDriverClass"), sut2.getDefaultDriverClass());
}
}