-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSumologicSenderTest.java
More file actions
93 lines (71 loc) · 2.88 KB
/
Copy pathSumologicSenderTest.java
File metadata and controls
93 lines (71 loc) · 2.88 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
package com.sumologic.client;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.Ignore;
import static com.github.tomakehurst.wiremock.client.WireMock.*;
import com.github.tomakehurst.wiremock.client.WireMock;
import com.github.tomakehurst.wiremock.junit.WireMockRule;
import com.sumologic.client.CloudWatchMessageModelSumologicTransformer;
import com.sumologic.client.SumologicSender;
import com.sumologic.client.implementations.SumologicEmitter;
public class SumologicSenderTest {
@Rule
public WireMockRule wireMockRule = new WireMockRule(8089);
private static final String MOCKED_HOST = "http://localhost:8089";
private static final String MOCKED_COLLECTION = "/sumologic/collections/1234";
@Before
public void setUp() {
mockEmitMessages();
}
@Test
public void theSenderShouldReturnFalseWhenFailing () {
String url = MOCKED_HOST + "/sumologic/collections/fake-url";
String data = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
+ "\nIn nisl tortor, dictum nec tristique ut, tincidunt vitae tortor. "
+ "\nNam vitae urna ac sem vulputate dignissim at ac nibh. ";
SumologicSender sender = new SumologicSender(url);
try{
boolean response = sender.sendToSumologic(data);
Assert.assertFalse(response);
} catch (IOException e) {
Assert.fail("Got an exception during test: "+e.getMessage());
}
}
@Test
public void theSenderShouldReturnTrueOnSuccess () {
String url = MOCKED_HOST + MOCKED_COLLECTION;
String data = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
+ "\nIn nisl tortor, dictum nec tristique ut, tincidunt vitae tortor. "
+ "\nNam vitae urna ac sem vulputate dignissim at ac nibh. ";
SumologicSender sender = new SumologicSender(url);
try{
boolean response = sender.sendToSumologic(data);
Assert.assertTrue(response);
} catch (IOException e) {
Assert.fail("Got an exception during test: "+e.getMessage());
}
}
@Test
public void decompressGzipTest() {
String url = MOCKED_HOST + MOCKED_COLLECTION;
String data = "a string of characters";
SumologicSender sender = new SumologicSender(url);
byte[] compressData = sender.compressGzip(data);
String result = CloudWatchMessageModelSumologicTransformer.decompressGzip(compressData);
Assert.assertTrue(data.equals(result));
}
private void mockEmitMessages () {
WireMock.stubFor(WireMock.post(WireMock.urlMatching(MOCKED_COLLECTION))
.willReturn(WireMock.aResponse()
.withStatus(200)
.withHeader("Content-Type", "text/html")
.withBody("")));
}
}