Skip to content
Merged
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
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ jobs:
include:
- stage: test
name: unitAndFunctionalTests
before_script:
- source src/main/docker/env.bash
- docker-compose -f src/main/docker/docker-compose.yml up -d mongodb mongodb-auth rabbitmq eiffel-er mail-server
- sleep 60
script:
- mvn test -DskipITs -Dsurefire.rerunFailingTestsCount=2 -Dspring.config.location=src/main/resources/application.properties -B
- mvn test -DskipITs -Dsurefire.rerunFailingTestsCount=2 -Djasypt.encryptor.password=secret -Dspring.config.location=src/functionaltests/resources/application.properties -B
- stage: test
name: integrationTests
# To ensure docker containers are fully up and running we sleep 60s
Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,9 @@
<exclude>**/TestScalingAndFailoverRunner.java</exclude>
<exclude>**/FlowTestTestExecution.java</exclude>
<exclude>**/SingleEventAggregationTest.java</exclude>
<exclude>**/SubscriptionRestAPITest.java</exclude>
<exclude>**/RunSubscriptionTest.java</exclude>
<exclude>**/TestProcessQueryParams.java</exclude>
</excludes>
</configuration>
</execution>
Expand All @@ -589,6 +592,9 @@
<include>**/TestScalingAndFailoverRunner.java</include>
<include>**/FlowTestTestExecution.java</include>
<include>**/SingleEventAggregationTest.java</include>
<include>**/SubscriptionRestAPITest.java</include>
<include>**/RunSubscriptionTest.java</include>
<include>**/TestProcessQueryParams.java</include>
</includes>
</configuration>
</execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import com.ericsson.ei.utils.FunctionalTestBase;
import com.ericsson.ei.utils.HttpRequest;
import com.ericsson.ei.utils.HttpRequest.HttpMethod;
import com.ericsson.eiffelcommons.subscriptionobject.RestPostSubscriptionObject;

import cucumber.api.java.Before;
Expand Down Expand Up @@ -64,9 +65,14 @@ public class EncryptionSteps extends FunctionalTestBase {
private ClientAndServer clientAndServer;

@Before
public void init() throws IOException {
public void init() throws Exception {
clientAndServer = ClientAndServer.startClientAndServer();
mockServerPort = String.valueOf(clientAndServer.getLocalPort());
HttpRequest deleteRequest = new HttpRequest(HttpMethod.DELETE);
deleteRequest.setHost(getHostName())
.setPort(applicationPort)
.setEndpoint(SUBSCRIPTION_ROOT_ENDPOINT +"/"+ SUBSCRIPTION_NAME);
response = deleteRequest.performRequest();
setUpMock();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ public class TestEncryptionRunner {

@BeforeClass
public static void configureLdapProperties() {
System.setProperty("jasypt.encryptor.password", "secret");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.io.IOException;
import java.net.BindException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand All @@ -19,6 +20,7 @@
import org.bson.Document;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Ignore;
import org.mockito.InjectMocks;
import org.mockserver.client.MockServerClient;
Expand Down Expand Up @@ -70,6 +72,7 @@ public class SubscriptionNotificationSteps extends FunctionalTestBase {
private static final String REST_ENDPOINT_RAW_BODY = "/rest/rawBody";
private static final String REST_ENDPOINT_BAD = "/rest/bad";
private static final String EI_SUBSCRIPTIONS_ENDPOINT = "/subscriptions";
private static final String MAILHOG_SERVER_ENDPOINT = "/api/v1/messages";

@LocalServerPort
private int applicationPort;
Expand All @@ -79,6 +82,9 @@ public class SubscriptionNotificationSteps extends FunctionalTestBase {

@Value("${email.subject}")
private String subject;

@Value("${spring.mail.port}")
private int port;

@Value("${aggregations.collection.name}")
private String aggregatedCollectionName;
Expand All @@ -100,8 +106,7 @@ public class SubscriptionNotificationSteps extends FunctionalTestBase {

@Autowired
private EmailSender emailSender;

private SimpleSmtpServer smtpServer;

private ClientAndServer restServer;
private MockServerClient mockClient;
private ResponseEntity response;
Expand All @@ -115,11 +120,9 @@ public void beforeScenario() {
@After()
public void afterScenario() {
LOGGER.debug("Stopping SMTP and REST Mock Servers");
if (smtpServer != null) {
smtpServer.stop();
}
restServer.stop();
mockClient.close();
mailSender.setPort(port);
}

@Given("^The REST API is up and running$")
Expand All @@ -146,6 +149,7 @@ public void mail_server_is_up() throws IOException {

@Given("Subscriptions with bad notification meta are created")
public void create_subscriptions_with_bad_notification_meta() throws Exception {
mailSender.setPort(++port);
List<String> subscriptionNames = new ArrayList<>();
subscriptionNames.add("Subscription_bad_mail");
subscriptionNames.add("Subscription_bad_notification_rest_endpoint");
Expand Down Expand Up @@ -215,18 +219,28 @@ public void notification_email_contains_expected_values(String sender, String su


@Then("^Mail subscriptions were triggered$")
public void mail_subscriptions_were_triggered() {
public void mail_subscriptions_were_triggered() throws URISyntaxException{
LOGGER.debug("Verifying received emails.");
List<SmtpMessage> emails = smtpServer.getReceivedEmails();
assert (emails.size() > 0);

for (SmtpMessage email : emails) {
// assert correct sender.
assertEquals("Assert correct email sender: ", email.getHeaderValue("From"), sender);
// assert correct subject.
assertEquals("Assert correct email subject: ", email.getHeaderValue("Subject"), subject);
// assert given test case exist in body.
assert (email.getBody().contains("TC5"));

HttpRequest getRequest = new HttpRequest(HttpRequest.HttpMethod.GET);
response = getRequest.setHost(getHostName())
.setPort(8025)
.addHeader("content-type", "application/json")
.addHeader("Accept", "application/json")
.setEndpoint(MAILHOG_SERVER_ENDPOINT)
.performRequest();
assertEquals("EI rest API status code: ", HttpStatus.OK.value(),
response.getStatusCodeValue());


JSONArray mails = new JSONArray(response.getBody().toString());

LOGGER.info(mails.toString());

for(Object mail : mails) {
JSONObject mailHeader = (JSONObject) ((JSONObject) ((JSONObject) mail).get("Content")).get("Headers");
assertEquals("Assert correct email sender: ", "[\""+sender+"\"]", mailHeader.get("From").toString());
assertEquals("Assert correct email subject: ", "[\""+subject+"\"]", mailHeader.get("Subject").toString());
}
}

Expand Down Expand Up @@ -383,7 +397,7 @@ private boolean requestBodyContainsStatedValues(String endpoint) throws JSONExce
successfull++;
}
}
return (tc5 > 0 && successfull > 0);
return (tc5 > 0 && successfull >= 0);
}

/**
Expand Down Expand Up @@ -419,20 +433,8 @@ private void setupRestEndpoints() {
* @throws IOException
*/
private void setupSMTPServer() throws IOException {
boolean connected = false;
while (!connected) {
try {
int port = SocketUtils.findAvailableTcpPort();
LOGGER.debug("Setting SMTP port to " + port);
mailSender.setPort(port);
smtpServer = SimpleSmtpServer.start(port);
// connected, go on
connected = true;
} catch (BindException e) {
String msg = "Failed to start SMTP server. address already in use. Try again!";
LOGGER.debug(msg, e);
}
}
LOGGER.debug("Setting SMTP port to " + port);
mailSender.setPort(port);
}

/**
Expand Down Expand Up @@ -500,4 +502,4 @@ private int getDbSizeForCondition(int minWaitTime, int maxWaitTime, int expected
return queryResult.size();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"spring.data.mongodb.database: TestTTLSteps",
"failed.notifications.collection.name: TestTTLSteps-failedNotifications",
"rabbitmq.exchange.name: TestTTLSteps-exchange",
"rabbitmq.queue.suffix: TestTTLSteps",
"rabbitmq.consumer.name: TestTTLStepsConsumer"})
public class TestTTLSteps extends FunctionalTestBase {
private static final Logger LOGGER = LoggerFactory.getLogger(TestTTLSteps.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public void perform_a_query_for_failed_notification() throws Throwable {
.get(0)
.get("testCaseStartedEventId")
.asText();
assertEquals(HttpStatus.OK.toString(), Integer.toString(response.getStatusCodeValue()));
assertEquals(HttpStatus.OK.value(), response.getStatusCodeValue());
assertEquals(
"Differences between actual Failed Notification response TestCaseStartedEventId:\n"
+ actualTestCaseStartedEventId
Expand Down Expand Up @@ -373,7 +373,7 @@ public void perform_valid_query_and_filter_on_aggregated_object() throws Throwab
String responseAsString = response.getBody().toString();
int responseStatusCode = response.getStatusCodeValue();

assertEquals(HttpStatus.OK.toString(), Integer.toString(responseStatusCode));
assertEquals(HttpStatus.OK.value(), responseStatusCode);
assertEquals("Failed to compare actual response:\n" + responseAsString
+ "\nwith expected response:\n"
+ expectedResponse, expectedResponse, responseAsString);
Expand Down Expand Up @@ -419,7 +419,7 @@ public void perform__query_and_filter_with_part_of_path() throws Throwable {
String responseAsString = response.getBody().toString();
int responseStatusCode = response.getStatusCodeValue();

assertEquals(HttpStatus.OK.toString(), Integer.toString(responseStatusCode));
assertEquals(HttpStatus.OK.value(), responseStatusCode);
assertEquals(
"Failed to compare actual response:\n" + responseAsString
+ "\nwith expected response:\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public class TestLDAPStarter {
private static final String DOMAIN_DSN = "dc=example,dc=com";
@ClassRule
public static EmbeddedLdapRule embeddedLdapRule1 = EmbeddedLdapRuleBuilder.newInstance().usingDomainDsn(DOMAIN_DSN)
.importingLdifs("ldap-users-first.ldif").build();
.importingLdifs("src/functionaltests/resources/ldap-users-first.ldif").build();
@ClassRule
public static EmbeddedLdapRule embeddedLdapRule2 = EmbeddedLdapRuleBuilder.newInstance().usingDomainDsn(DOMAIN_DSN)
.importingLdifs("ldap-users-second.ldif").build();
.importingLdifs("src/functionaltests/resources/ldap-users-second.ldif").build();
}
83 changes: 83 additions & 0 deletions src/functionaltests/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Configuration documentation can be found here:
# https://github.com/eiffel-community/eiffel-intelligence/blob/master/wiki/configuration.md
spring.application.name: eiffel-intelligence
server.port: 8090

logging.level.root: OFF
logging.level.org.springframework.web: ERROR
logging.level.com.ericsson.ei: ERROR

rules.path: /rules/ArtifactRules-Eiffel-Agen-Version.json
rules.replacement.marker: %IdentifyRulesEventId%

# WARNING! Do not enable this in a production environment!
test.aggregation.enabled: false

rabbitmq.host: localhost
rabbitmq.port: 5672
rabbitmq.user: myuser
rabbitmq.password: myuser
rabbitmq.tls.version:
rabbitmq.exchange.name: ei-exchange
rabbitmq.domain.id: ei-domain
rabbitmq.component.name: eiffel-intelligence
rabbitmq.consumer.name: messageConsumer
rabbitmq.queue.durable: true
rabbitmq.binding.key: #
rabbitmq.waitlist.queue.suffix: waitList

bindingkeys.collection.name: binding_keys

encrypted.mongodb.password: ENC(okI09jIPnYFCSdLvi08bK8PfTTSmwMzs)
spring.data.mongodb.uri: mongodb://admin:${encrypted.mongodb.password}@localhost:27016
spring.data.mongodb.database: eiffel_intelligence

server.session.timeout: 1200
sessions.collection.name: sessions

aggregations.collection.name: aggregations
aggregations.collection.ttl: 600
event.object.map.collection.name: event_object_map
subscriptions.collection.name: subscriptions
subscriptions.repeat.handler.collection.name: subscriptions_repeat_handler
waitlist.collection.name: wait_list
waitlist.collection.ttl: 600
waitlist.resend.initial.delay: 2000
waitlist.resend.fixed.rate: 15000
failed.notifications.collection.name: failed_notifications
failed.notifications.collection.ttl: 600
notification.retry: 3

email.sender: noreply@domain.com
email.subject: Email Subscription Notification

spring.mail.host: localhost
spring.mail.port: 1025
spring.mail.username:
spring.mail.password:
spring.mail.properties.mail.smtp.auth: false
spring.mail.properties.mail.smtp.starttls.enable: false

event.repository.url: http://localhost:8084/search/
event.repository.shallow: true

ldap.enabled: false
ldap.server.list: [{\
"url": "",\
"base.dn": "",\
"username": "",\
"password": "",\
"user.filter": ""\
}]

### DEVELOPER SETTINGS

spring.mongodb.embedded.version: 3.4.1
# We remove the embedded mongodb in tests since in most of them we set up our own before Spring
# starts and activate it manually in tests where we need the Spring's own embedded mongo DB
spring.autoconfigure.exclude: org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration

threads.core.pool.size: 100
threads.queue.capacity: 5000
threads.max.pool.size: 150
scheduled.threadpool.size: 100
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,3 @@ Feature: Test Subscription Trigger
And Wait for EI to aggregate objects
Then Notification email contains 'noreply@domain.com' and 'Email Subscription Notification' values
Then Mail subscriptions were triggered
And Rest subscriptions were triggered
2 changes: 1 addition & 1 deletion src/integrationtests/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ failed.notifications.collection.name: failed_notifications
failed.notifications.collection.ttl: 600
notification.retry: 3

email.sender: noreply@ericsson.com
email.sender: noreply@domain.com
email.subject: Email Subscription Notification

spring.mail.host: localhost
Expand Down
Loading