Repository navigation
Expand file tree
/
Copy pathMongoDatabaseIT.java
More file actions
88 lines (73 loc) · 3.24 KB
/
Copy pathMongoDatabaseIT.java
File metadata and controls
88 lines (73 loc) · 3.24 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
package dbProcs;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import com.mongodb.MongoClient;
import com.mongodb.MongoCredential;
import java.io.IOException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import testUtils.TestProperties;
public class MongoDatabaseIT {
private static String TEST_PATH = "mongo_challenge_test";
private static final Logger log = LogManager.getLogger(MongoDatabaseIT.class);
@BeforeAll
public static void initAll() throws IOException {
TestProperties.setTestPropertiesFileDirectory(log);
TestProperties.createMysqlResource();
TestProperties.createMongoResource();
}
@Test
@DisplayName("Should Return Type MongoCredentials")
public void getMongoChallengeCredentials_ShouldReturnTypeMongoCredentials() throws IOException {
assertInstanceOf(
MongoCredential.class, MongoDatabase.getMongoChallengeCredentials(null, TEST_PATH));
}
@Test
@DisplayName("Should read properties file for mongo challenge credentials")
public void getMongoChallengeCredentials_ShouldReadPropertiesFileForCreds() throws IOException {
MongoCredential creds = MongoDatabase.getMongoChallengeCredentials(null, TEST_PATH);
String username = creds.getUserName();
char[] password = creds.getPassword();
String databasename = creds.getSource();
assertEquals("test_user", username);
assertArrayEquals("test_password".toCharArray(), password);
assertEquals("test_dbname", databasename);
}
@Test
@DisplayName("Should Return Type String")
public void getMongoChallengeCollName_ShouldReturnTypeString() {
String collName = MongoDatabase.getMongoChallengeCollName(null, TEST_PATH);
assertNotNull(collName);
assertInstanceOf(String.class, collName);
}
@Test
@DisplayName("Should read properties file with connection details to challenge")
public void getMongoChallengeCollName_ReadPropertiesFile() {
String collName = MongoDatabase.getMongoChallengeCollName(null, TEST_PATH);
assertEquals("test_collection", collName);
}
@Test
@DisplayName("Should return a MongoClient instance")
public void getMongoDbConnection_ShouldReturnTypeMongoClient() {
MongoCredential credential =
MongoCredential.createScramSha1Credential("test", "test", "test".toCharArray());
assertInstanceOf(MongoClient.class, MongoDatabase.getMongoDbConnection(null));
assertInstanceOf(MongoClient.class, MongoDatabase.getMongoDbConnection(null, credential));
}
@Test
@DisplayName("Must return type (Mongo) DB")
@Disabled(
"Fongo 2.1.0 is incompatible with mongo-java-driver 3.12.14 (NPE in createOperationExecutor)")
public void getMongoDatabase_ShouldReturnTypeDB() {}
@Test
@DisplayName("Read properties file for db name")
@Disabled(
"Fongo 2.1.0 is incompatible with mongo-java-driver 3.12.14 (NPE in createOperationExecutor)")
public void getMongoDatabase_ReadDbName() {}
}