34
34
import java .util .Map ;
35
35
import java .util .concurrent .TimeUnit ;
36
36
37
- // See https://github.com/mongodb/specifications/tree/master/source/connection-string/tests
38
37
@ RunWith (Parameterized .class )
39
- public class AbstractConnectionStringTest extends TestCase {
38
+ public abstract class AbstractConnectionStringTest extends TestCase {
40
39
private final String filename ;
41
40
private final String description ;
42
41
private final String input ;
@@ -50,47 +49,15 @@ public AbstractConnectionStringTest(final String filename, final String descript
50
49
this .definition = definition ;
51
50
}
52
51
53
- @ Test
54
- public void shouldPassAllOutcomes () {
55
- if (filename .equals ("invalid-uris.json" )) {
56
- testInvalidUris ();
57
- } else if (filename .equals ("valid-auth.json" )) {
58
- testValidAuth ();
59
- } else if (filename .equals ("valid-db-with-dotted-name.json" )) {
60
- testValidHostIdentifiers ();
61
- testValidAuth ();
62
- } else if (filename .equals ("valid-host_identifiers.json" )) {
63
- testValidHostIdentifiers ();
64
- } else if (filename .equals ("valid-options.json" )) {
65
- testValidOptions ();
66
- } else if (filename .equals ("valid-unix_socket-absolute.json" )) {
67
- testValidHostIdentifiers ();
68
- } else if (filename .equals ("valid-unix_socket-relative.json" )) {
69
- testValidHostIdentifiers ();
70
- } else if (filename .equals ("valid-warnings.json" )) {
71
- testValidHostIdentifiers ();
72
- if (!definition .get ("options" ).isNull ()) {
73
- testValidOptions ();
74
- }
75
- } else {
76
- throw new IllegalArgumentException ("Unsupported file: " + filename );
77
- }
52
+ protected String getFilename () {
53
+ return filename ;
78
54
}
79
55
80
- @ Parameterized .Parameters (name = "{1}" )
81
- public static Collection <Object []> data () throws URISyntaxException , IOException {
82
- List <Object []> data = new ArrayList <Object []>();
83
- for (File file : JsonPoweredTestHelper .getTestFiles ("/connection-string" )) {
84
- BsonDocument testDocument = JsonPoweredTestHelper .getTestDocument (file );
85
- for (BsonValue test : testDocument .getArray ("tests" )) {
86
- data .add (new Object []{file .getName (), test .asDocument ().getString ("description" ).getValue (),
87
- test .asDocument ().getString ("uri" ).getValue (), test .asDocument ()});
88
- }
89
- }
90
- return data ;
56
+ protected BsonDocument getDefinition () {
57
+ return definition ;
91
58
}
92
59
93
- private void testInvalidUris () {
60
+ protected void testInvalidUris () {
94
61
Throwable expectedError = null ;
95
62
96
63
try {
@@ -103,7 +70,7 @@ private void testInvalidUris() {
103
70
expectedError instanceof IllegalArgumentException );
104
71
}
105
72
106
- private void testValidHostIdentifiers () {
73
+ protected void testValidHostIdentifiers () {
107
74
ConnectionString connectionString = null ;
108
75
try {
109
76
connectionString = new ConnectionString (input );
@@ -114,7 +81,7 @@ private void testValidHostIdentifiers() {
114
81
assertExpectedHosts (connectionString .getHosts ());
115
82
}
116
83
117
- private void testValidOptions () {
84
+ protected void testValidOptions () {
118
85
ConnectionString connectionString = null ;
119
86
120
87
try {
@@ -140,7 +107,7 @@ private void testValidOptions() {
140
107
}
141
108
}
142
109
143
- private void testValidAuth () {
110
+ protected void testValidAuth () {
144
111
ConnectionString connectionString = null ;
145
112
146
113
try {
0 commit comments