This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
ClientToServerTest.java
81 lines (72 loc) · 2.86 KB
/
ClientToServerTest.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
package org.zanata.client;
import java.io.IOException;
import java.io.StringWriter;
import java.net.InetSocketAddress;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.simpleframework.http.Status;
import org.simpleframework.http.core.ContainerServer;
import org.simpleframework.transport.connect.SocketConnection;
import org.zanata.client.commands.AppAbortStrategy;
import static org.hamcrest.MatcherAssert.*;
/**
* @author Patrick Huang <a
* href="mailto:pahuang@redhat.com">pahuang@redhat.com</a>
*/
public class ClientToServerTest {
private ZanataClient client;
@Mock
private AppAbortStrategy mockAbortStrategy;
@Captor
private ArgumentCaptor<Throwable> throwableCapture;
@Before
public void before() {
MockitoAnnotations.initMocks(this);
StringWriter out = new StringWriter();
StringWriter err = new StringWriter();
client =
new ZanataClient(mockAbortStrategy, out, err);
}
@Test
@Ignore("this will talk to live server")
public void testDisableSSLCertOption() {
String command = "stats";
String url = "https://translate.engineering.redhat.com/";
String project = "iok";
String version = "6.4";
client.processArgs(command, "--url", url, "--project", project,
"--project-version", version, "--disable-ssl-cert", "--details");
}
@Test
public void test503ResponseHandling() throws IOException {
// https://bugzilla.redhat.com/show_bug.cgi?id=874983
HTTPMockContainer mockContainer =
HTTPMockContainer.notOkResponse(Status.SERVICE_UNAVAILABLE);
ContainerServer server = new ContainerServer(mockContainer);
try (SocketConnection connection = new SocketConnection(server)) {
InetSocketAddress address = (InetSocketAddress) connection
.connect(new InetSocketAddress(0));
int port = address.getPort();
String command = "stats";
String url = "http://localhost:" + port + "/";
String project = "iok";
String version = "6.4";
// client.setErrors(true);
client.processArgs(command, "--url", url, "--project", project,
"--project-version", version, "--username", "admin",
"--key",
"abcdeabcdeabcdeabcdeabcdeabcde12");
server.stop();
Mockito.verify(mockAbortStrategy).abort(throwableCapture.capture());
assertThat("Client will display meaningful message for 503",
throwableCapture.getValue().getMessage()
.contains("503 Service Unavailable"));
}
}
}