-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathDbDeployCommandLineParserTest.java
More file actions
107 lines (83 loc) · 3.78 KB
/
DbDeployCommandLineParserTest.java
File metadata and controls
107 lines (83 loc) · 3.78 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
105
106
package com.dbdeploy;
import com.dbdeploy.database.DelimiterType;
import com.dbdeploy.database.LineEnding;
import org.junit.Test;
import java.io.File;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.*;
public class DbDeployCommandLineParserTest {
UserInputReader userInputReader = mock(UserInputReader.class);
private final DbDeploy dbDeploy = new DbDeploy();
private final DbDeployCommandLineParser parser = new DbDeployCommandLineParser(userInputReader);
@Test
public void canParseUserIdFromCommandLine() throws Exception {
parser.parse("-U myuserid".split(" "), dbDeploy);
assertEquals("myuserid", dbDeploy.getUserid());
}
@Test
public void thisIsntReallyATestBecuaseThereIsNoAssertButItsVeryUsefulToLookAtTheResult() throws Exception {
parser.printUsage();
}
@Test
public void checkAllOfTheOtherFieldsParseOkHere() throws Exception {
parser.parse(("-U userid -Ppassword --driver a.b.c --url b:c:d " +
"--scriptdirectory . -o output.sql " +
"--changeLogTableName my-change-log " +
"--dbms ora " +
"--templatedir /tmp/mytemplates " +
"--fake " +
"--lastChangeToApply 2345 " +
"--delimiter \\ --delimitertype row").split(" "), dbDeploy);
assertThat(dbDeploy.getUserid(), is("userid"));
assertThat(dbDeploy.getPassword(), is("password"));
assertThat(dbDeploy.getDriver(), is("a.b.c"));
assertThat(dbDeploy.getUrl(), is("b:c:d"));
assertThat(dbDeploy.getScriptdirectory().getName(), is("."));
assertThat(dbDeploy.getOutputfile().getName(), is("output.sql"));
assertThat(dbDeploy.getDbms(), is("ora"));
assertThat(dbDeploy.getChangeLogTableName(), is("my-change-log"));
assertThat(dbDeploy.getDelimiter(), is("\\"));
assertThat(dbDeploy.getDelimiterType(), is(DelimiterType.row));
assertThat(dbDeploy.getTemplatedir().getPath(), is(File.separator + "tmp" + File.separator + "mytemplates"));
assertThat(dbDeploy.getLastChangeToApply(), is(2345L));
assertThat(dbDeploy.getFake(), is(true));
}
@Test
public void delimiterTypeWorksOk() throws Exception {
parser.parse("--delimitertype normal".split(" "), dbDeploy);
assertThat(dbDeploy.getDelimiterType(), is(DelimiterType.normal));
parser.parse("--delimitertype row".split(" "), dbDeploy);
assertThat(dbDeploy.getDelimiterType(), is(DelimiterType.row));
}
@Test
public void lineEndingWorksOk() throws Exception {
assertThat(dbDeploy.getLineEnding(), is(LineEnding.platform));
parser.parse("--lineending cr".split(" "), dbDeploy);
assertThat(dbDeploy.getLineEnding(), is(LineEnding.cr));
parser.parse("--lineending crlf".split(" "), dbDeploy);
assertThat(dbDeploy.getLineEnding(), is(LineEnding.crlf));
parser.parse("--lineending lf".split(" "), dbDeploy);
assertThat(dbDeploy.getLineEnding(), is(LineEnding.lf));
parser.parse("--lineending platform".split(" "), dbDeploy);
assertThat(dbDeploy.getLineEnding(), is(LineEnding.platform));
}
@Test
public void shouldPromptFromStdinForPasswordIfPasswordParamSuppliedWithNoArg() throws Exception {
when(userInputReader.read("Password")).thenReturn("user entered password");
parser.parse(new String[] { "-P" }, dbDeploy);
assertThat(dbDeploy.getPassword(), is("user entered password"));
}
@Test
public void shouldNotPromptForPasswordWhenSupplied() throws Exception {
parser.parse(new String[]{"-P", "password"}, dbDeploy);
verifyZeroInteractions(userInputReader);
}
@Test
public void shouldNotPromptForPasswordNotSpecifiedOnCommandLine() throws Exception {
// this is important: not all databases require passwords :)
parser.parse(new String[] {}, dbDeploy);
verifyZeroInteractions(userInputReader);
}
}