forked from jbossas/jboss-as-maven-plugin
/
AbstractServerConnectionTest.java
180 lines (165 loc) · 5.44 KB
/
AbstractServerConnectionTest.java
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
* File: AbstractServerConnectionTest.java
* Date: Nov 19, 2012
*
* Copyright (c) 2011 by Select Systems - All rights reserved.
*
* By: Select Systems
* 111 Heritage Way, Suite S
* Boalsburg, PA 16827
*
* Revision history:
*
*
*/
package org.jboss.as.plugin.common;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import java.io.File;
import org.apache.maven.plugin.logging.Log;
import org.jboss.as.plugin.deployment.Deploy;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InOrder;
/**
* @author stevemoyer
*
*/
public class AbstractServerConnectionTest extends AbstractJbossMavenPluginMojoTestCase {
Log log;
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
super.setUp();
log = mock(Log.class);
}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {
super.tearDown();
}
/**
* Tests that if there is an <id> provided in the pom.xml file but no
* username and password, and there is no settings.xml file in the
* plugin's context, then the plugin falls back to prompting for
* credentials on the CLI.
*/
@Test
public void testIdProvidedInPomButNoSettingsFile() {
File pom = getTestFileAndVerify("src/test/resources/unit/common/id-provided-pom.xml");
try {
Deploy mojo = (Deploy) lookupMojoAndVerify("deploy", pom);
mojo.setLog(log);
mojo.getCallbackHandler();
verify(log).debug(Deploy.DEBUG_MESSAGE_NO_SETTINGS_FILE);
} catch (Exception e) {
e.printStackTrace();
fail("Couldn't find \"deploy\" mojo");
}
}
/**
* Tests that if there is an <id> provided in the pom.xml file but no
* username and password, and there is a settings.xml file that doesn't
* match the id of the server, then the plugin falls back to prompting
* for credentials on the CLI.
*/
@Test
public void testIdProvidedInPomButNoServerSection() {
File pom = getTestFileAndVerify("src/test/resources/unit/common/id-provided-pom.xml");
File settings = getTestFileAndVerify("src/test/resources/unit/common/missing-id-settings.xml");
try {
Deploy mojo = (Deploy) lookupMojoVerifyAndApplySettings("deploy", pom, settings);
mojo.setLog(log);
mojo.getCallbackHandler();
verify(log).debug(Deploy.DEBUG_MESSAGE_NO_SERVER_SECTION);
} catch (Exception e) {
e.printStackTrace();
fail("Couldn't find \"deploy\" mojo");
}
}
/**
* Tests that if there is an <id> provided in the pom.xml file but no
* username and password, and there is a settings.xml file that has a
* <server> section that matches the id, but there is no username and
* password specified, then the plugin falls back to prompting for
* credentials on the CLI.
*/
@Test
public void testIdProvidedInPomButNoCredentials() {
File pom = getTestFileAndVerify("src/test/resources/unit/common/id-provided-pom.xml");
File settings = getTestFileAndVerify("src/test/resources/unit/common/id-provided-settings.xml");
try {
Deploy mojo = (Deploy) lookupMojoVerifyAndApplySettings("deploy", pom, settings);
mojo.setLog(log);
mojo.getCallbackHandler();
InOrder inOrder = inOrder(log);
inOrder.verify(log).debug(Deploy.DEBUG_MESSAGE_SETTINGS_HAS_ID);
inOrder.verify(log).debug(Deploy.DEBUG_MESSAGE_NO_CREDS);
} catch (Exception e) {
e.printStackTrace();
fail("Couldn't find \"deploy\" mojo");
}
}
/**
* Test that if credentials are provided in the pom.xml file, they are used
* regardless of whether an <id> element is also present.
*/
@Test
public void testCredentialsProvidedInPom() {
File pom = getTestFileAndVerify("src/test/resources/unit/common/credentials-provided-pom.xml");
try {
Deploy mojo = (Deploy) lookupMojoAndVerify("deploy", pom);
mojo.setLog(log);
mojo.getCallbackHandler();
verify(log).debug(Deploy.DEBUG_MESSAGE_POM_HAS_CREDS);
} catch (Exception e) {
e.printStackTrace();
fail("Couldn't find \"deploy\" mojo");
}
}
/**
* Tests that if there is an <id> provided in the pom.xml file but no
* username and password, and there is a settings.xml file that has a
* <server> section that matches the id, and the section includes
* credentials, then they are used by the plugin.
*/
@Test
public void testCredentialsProvidedInSettings() {
File pom = getTestFileAndVerify("src/test/resources/unit/common/id-provided-pom.xml");
File settings = getTestFileAndVerify("src/test/resources/unit/common/credentials-provided-settings.xml");
try {
Deploy mojo = (Deploy) lookupMojoVerifyAndApplySettings("deploy", pom, settings);
mojo.setLog(log);
mojo.getCallbackHandler();
InOrder inOrder = inOrder(log);
inOrder.verify(log).debug(Deploy.DEBUG_MESSAGE_SETTINGS_HAS_ID);
inOrder.verify(log).debug(Deploy.DEBUG_MESSAGE_SETTINGS_HAS_CREDS);
} catch (Exception e) {
e.printStackTrace();
fail("Couldn't find \"deploy\" mojo");
}
}
/**
* Test that if there is no <id> element and no credentials in the pom.xml
* file, then it falls back to prompting for them on the CLI.
*/
@Test
public void testNoCredentialsOrIdInPom() {
File pom = getTestFileAndVerify("src/test/resources/unit/common/missing-id-pom.xml");
try {
Deploy mojo = (Deploy) lookupMojoAndVerify("deploy", pom);
mojo.setLog(log);
mojo.getCallbackHandler();
verify(log).debug(Deploy.DEBUG_MESSAGE_NO_ID);
} catch (Exception e) {
e.printStackTrace();
fail("Couldn't find \"deploy\" mojo");
}
}
}