Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/main/java/com/teragrep/cfe_16/config/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,26 @@ public Configuration() {

}

public Configuration(
final String syslogHost,
final int syslogPort,
final int maxAckValue,
final int maxAckAge,
final int maxSessionAge,
final int maxChannels,
final long pollTime,
final boolean printTimes
) {
this.syslogHost = syslogHost;
this.syslogPort = syslogPort;
this.maxAckValue = maxAckValue;
this.maxAckAge = maxAckAge;
this.maxSessionAge = maxSessionAge;
this.maxChannels = maxChannels;
this.pollTime = pollTime;
this.printTimes = printTimes;
}

@Bean
public String syslogHost() {
return this.syslogHost;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ synchronized private void autoConnect() {
this.connect();
}

synchronized private void connect() {
synchronized public void connect() {
boolean notConnected = true;
while (notConnected) {
boolean connected = false;
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/com/teragrep/cfe_16/rest/HECRestController.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,15 @@ public class HECRestController {

private static final Logger LOGGER = LoggerFactory.getLogger(HECRestController.class);
private final ObjectMapper objectMapper = new ObjectMapper();
@Autowired
private HECService service;

private final HECService service;
private final Configuration configuration;

@Autowired
private Configuration configuration;
public HECRestController(final HECService service, final Configuration configuration) {
this.service = service;
this.configuration = configuration;
}

@RequestMapping(
value = "services/collector",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
/**
* Tests the functionality of the eventData.toSyslogMessage method
*/
public class EventDataToSyslogMessageTest {
class EventDataToSyslogMessageTest {

@Test
@DisplayName("test fields when time is provided in HECRecord")
Expand Down
30 changes: 21 additions & 9 deletions src/test/java/com/teragrep/cfe_16/HECBatchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@
import org.junit.jupiter.api.Test;
import org.springframework.mock.web.MockHttpServletRequest;

class HECBatchTest {

private static final String channel1 = "CHANNEL_11111";
private static final String authToken1 = "AUTH_TOKEN_12223";
final class HECBatchTest {

@Test
public void toHECRecordListTest() {
void toHECRecordListTest() {
final String channel1 = "CHANNEL_11111";
final String authToken1 = "AUTH_TOKEN_12223";

final String allEventsInJson = "{\"sourcetype\": \"mysourcetype\", \"event\": \"Hello, world!\", \"host\": \"localhost\", \"source\": \"mysource\", \"index\": \"myindex\", \"time\": 123456}";
final HECRecord supposedResponse = new HECRecordImpl(
channel1,
Expand Down Expand Up @@ -105,7 +105,10 @@ public void toHECRecordListTest() {
* Tests for JsonSyntaxException
*/
@Test
public void toHECRecordListUsesAStubIfParsingFailsWithMalformedJSONTest() {
void toHECRecordListUsesAStubIfParsingFailsWithMalformedJSONTest() {
final String channel1 = "CHANNEL_11111";
final String authToken1 = "AUTH_TOKEN_12223";

final String allEventsInJson = "{\"sourcetype\": \"mysourcetype\", \"event\": {{{{}}}}";
final HECBatch HECBatch = new HECBatch(
authToken1,
Expand All @@ -121,7 +124,10 @@ public void toHECRecordListUsesAStubIfParsingFailsWithMalformedJSONTest() {
* Tests for EventStub existence, since the Event should not be valid
*/
@Test
public void toHECRecordListUsesAStubIfParsingFailsWithEmptyJSONTest() {
void toHECRecordListUsesAStubIfParsingFailsWithEmptyJSONTest() {
final String channel1 = "CHANNEL_11111";
final String authToken1 = "AUTH_TOKEN_12223";

final String allEventsInJson = "{\"sourcetype\": \"mysourcetype\", \"event\": null}";
final String supposedResponse = "Event field was not textual";
final HECBatch HECBatch = new HECBatch(
Expand All @@ -139,7 +145,10 @@ public void toHECRecordListUsesAStubIfParsingFailsWithEmptyJSONTest() {
}

@Test
public void noEventFieldInRequestTest() {
void noEventFieldInRequestTest() {
final String channel1 = "CHANNEL_11111";
final String authToken1 = "AUTH_TOKEN_12223";

final String allEventsInJson = "{\"sourcetype\": \"mysourcetype\", \"host\": \"localhost\", \"source\": \"mysource\", \"index\": \"myindex\"}";
final HECBatch HECBatch = new HECBatch(
authToken1,
Expand All @@ -152,7 +161,10 @@ public void noEventFieldInRequestTest() {
}

@Test
public void eventFieldBlankInRequestTest() {
void eventFieldBlankInRequestTest() {
final String channel1 = "CHANNEL_11111";
final String authToken1 = "AUTH_TOKEN_12223";

final String allEventsInJson = "{\"sourcetype\": \"mysourcetype\", \"event\": \"\", \"host\": \"localhost\", \"source\": \"mysource\", \"index\": \"myindex\"}";
final HECBatch HECBatch = new HECBatch(
authToken1,
Expand Down
20 changes: 6 additions & 14 deletions src/test/java/com/teragrep/cfe_16/SessionManagerTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,20 @@
import com.teragrep.cfe_16.bo.Session;
import com.teragrep.cfe_16.config.Configuration;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

/*
* Tests the functionality of SessionManager
*/
public class SessionManagerTests {

private SessionManager sessionManager;

/*
* A SessionManager is initialized
*/
@BeforeEach
public void initialize() {
sessionManager = new SessionManager(new Configuration());
}
final class SessionManagerTests {

/*
* Tests creating a session with SessionManager and getting that same session
* from SessionManager
*/
@Test
public void createSessionAndGetItWithAuthTokenTest() {
void createSessionAndGetItWithAuthTokenTest() {
final SessionManager sessionManager = new SessionManager(new Configuration());

String authToken1 = "AUTH_TOKEN_12345";
String authToken2 = "AUTH_TOKEN_54321";
Expand All @@ -92,7 +82,9 @@ public void createSessionAndGetItWithAuthTokenTest() {
}

@Test
public void sessionCreationAndDeletionTests() {
void sessionCreationAndDeletionTests() {
final SessionManager sessionManager = new SessionManager(new Configuration());

Session session = sessionManager.createSession("AUTH");
Assertions.assertTrue(session.addChannel(Session.DEFAULT_CHANNEL));
Assertions.assertFalse(session.addChannel(Session.DEFAULT_CHANNEL));
Expand Down
15 changes: 9 additions & 6 deletions src/test/java/com/teragrep/cfe_16/TokenManagerTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,15 @@
/*
* Tests the functionality of TokenManager
*/
public class TokenManagerTests {

TokenManager manager = new TokenManager();
final class TokenManagerTests {

/*
* Tests TokenManager's tokenIsMissing() method which checks if
* HttpServletRequest's header has an authentication token in it.
*/
@Test
public void tokenCheckingTest() {
void tokenCheckingTest() {
final TokenManager manager = new TokenManager();

MockHttpServletRequest requestWithHttpHeaderAuth = new MockHttpServletRequest();
MockHttpServletRequest requestWithBasicAuth = new MockHttpServletRequest();
Expand All @@ -84,7 +83,9 @@ public void tokenCheckingTest() {
* format.
*/
@Test
public void basicAuthCheckingTest() {
void basicAuthCheckingTest() {
final TokenManager manager = new TokenManager();

String authToken = "AUTH_TOKEN_11111";
String basicAuthHeader = "Basic x:" + authToken;

Expand All @@ -99,7 +100,9 @@ public void basicAuthCheckingTest() {
* authentication token when it is given in basic authentication format.
*/
@Test
public void getTokenFromBasicAuthTest() {
void getTokenFromBasicAuthTest() {
final TokenManager manager = new TokenManager();

String authToken = "AUTH_TOKEN_11111";
String basicAuthCredentials = "x:" + authToken;
String credentialsEncoded = Base64.getEncoder().encodeToString(basicAuthCredentials.getBytes());
Expand Down
Loading