-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathAWSSecretsManagerMariaDBDriverTest.java
More file actions
105 lines (85 loc) · 3.64 KB
/
AWSSecretsManagerMariaDBDriverTest.java
File metadata and controls
105 lines (85 loc) · 3.64 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
101
102
103
104
/*
* 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 java.sql.SQLException;
import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
import org.powermock.modules.junit4.PowerMockRunner;
import org.junit.Before;
import com.amazonaws.secretsmanager.caching.SecretCache;
import com.amazonaws.secretsmanager.util.TestClass;
/**
* Tests for the MariaDB Driver.
*/
@RunWith(PowerMockRunner.class)
@SuppressStaticInitializationFor({"com.amazonaws.secretsmanager.sql.AWSSecretsManagerMariaDBDriver","com.amazonaws.secretsmanager.sql.*"})
@PowerMockIgnore("jdk.internal.reflect.*")
public class AWSSecretsManagerMariaDBDriverTest extends TestClass {
private AWSSecretsManagerMariaDBDriver sut;
@Mock
private SecretCache cache;
@Before
public void setup() {
System.setProperty("drivers.mariadb.realDriverClass", "com.amazonaws.secretsmanager.sql.DummyDriver");
MockitoAnnotations.initMocks(this);
try {
sut = new AWSSecretsManagerMariaDBDriver(cache);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Test
public void test_getPropertySubprefix() {
assertEquals("mariadb", sut.getPropertySubprefix());
}
@Test
public void test_isExceptionDueToAuthenticationError_returnsTrue_correctException() {
SQLException e = new SQLException("", "", 1045);
assertTrue(sut.isExceptionDueToAuthenticationError(e));
}
@Test
public void test_isExceptionDueToAuthenticationError_returnsFalse_wrongSQLException() {
SQLException e = new SQLException("", "", 1046);
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:mariadb://test-endpoint:1234/dev");
}
@Test
public void test_constructUrlNullPort() {
String url = sut.constructUrlFromEndpointPortDatabase("test-endpoint", null, "dev");
assertEquals(url, "jdbc:mariadb://test-endpoint/dev");
}
@Test
public void test_constructUrlNullDatabase() {
String url = sut.constructUrlFromEndpointPortDatabase("test-endpoint", "1234", null);
assertEquals(url, "jdbc:mariadb://test-endpoint:1234");
}
@Test
public void test_getDefaultDriverClass() {
System.clearProperty("drivers.mariadb.realDriverClass");
assertThrows(IllegalStateException.class, "Could not load real driver with name, \"" + AWSSecretsManagerMariaDBDriver.DEFAULT_DRIVER + "\".", () -> new AWSSecretsManagerMariaDBDriver(cache));
}
}