Skip to content

Commit ecb6527

Browse files
add functional tests framework
add functional tests framework
1 parent 93c88b7 commit ecb6527

24 files changed

+792
-277
lines changed

pom.xml

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,28 @@
215215
<artifactId>jongo</artifactId>
216216
<version>1.3.0</version>
217217
</dependency>
218+
219+
<dependency>
220+
<groupId>info.cukes</groupId>
221+
<artifactId>cucumber-junit</artifactId>
222+
<version>1.2.5</version>
223+
<scope>test</scope>
224+
</dependency>
225+
226+
<dependency>
227+
<groupId>info.cukes</groupId>
228+
<artifactId>cucumber-java</artifactId>
229+
<version>1.2.5</version>
230+
<scope>test</scope>
231+
</dependency>
232+
233+
<dependency>
234+
<groupId>info.cukes</groupId>
235+
<artifactId>cucumber-spring</artifactId>
236+
<version>1.2.5</version>
237+
<scope>test</scope>
238+
</dependency>
239+
218240
</dependencies>
219241
<build>
220242
<plugins>
@@ -254,7 +276,7 @@
254276
</goals>
255277
</execution>
256278
</executions>
257-
</plugin>
279+
</plugin>
258280

259281
<!-- required for adding generated sources -->
260282
<plugin>
@@ -273,6 +295,20 @@
273295
</sources>
274296
</configuration>
275297
</execution>
298+
299+
<execution>
300+
<id>add-test-source</id>
301+
<phase>process-resources</phase>
302+
<goals>
303+
<goal>add-test-source</goal>
304+
</goals>
305+
<configuration>
306+
<sources>
307+
<source>src/functionaltests/java</source>
308+
<source>src/functionaltests/resources</source>
309+
</sources>
310+
</configuration>
311+
</execution>
276312
</executions>
277313
</plugin>
278314

@@ -281,7 +317,7 @@
281317
<artifactId>maven-surefire-plugin</artifactId>
282318
<version>2.20</version>
283319
<configuration>
284-
<forkCount>8</forkCount>
320+
<forkCount>2C</forkCount>
285321
<reuseForks>false</reuseForks>
286322
<excludes>
287323
<exclude>${someModule.test.excludes}</exclude>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.ericsson.ei.subscriptions.crud;
2+
3+
import com.ericsson.ei.utils.FunctionalTestBase;
4+
5+
import org.junit.Ignore;
6+
import org.slf4j.Logger;
7+
import org.slf4j.LoggerFactory;
8+
import org.springframework.test.context.TestExecutionListeners;
9+
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
10+
11+
import cucumber.api.java.en.Given;
12+
import cucumber.api.java.en.Then;
13+
import cucumber.api.java.en.When;
14+
15+
@Ignore
16+
public class SubscriptionCRUDSteps extends FunctionalTestBase {
17+
18+
private static final Logger LOGGER = LoggerFactory.getLogger(SubscriptionCRUDSteps.class);
19+
20+
@Given("^Subscription is created$")
21+
public void subscription_is_created() throws Throwable {
22+
LOGGER.debug("Creating subscription");
23+
System.out.println("MongoDB port for " + this.getClass().getName() + " is: " + getMongoDbPort());
24+
}
25+
26+
@When("^Update the subscription$")
27+
public void update_the_subscription() throws Throwable {
28+
LOGGER.debug("Updating subscription");
29+
}
30+
31+
@Then("^Delete the updated subscription$")
32+
public void delete_the_updated_subscription() throws Throwable {
33+
34+
}
35+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.ericsson.ei.subscriptions.crud;
2+
3+
import org.junit.runner.RunWith;
4+
5+
import cucumber.api.CucumberOptions;
6+
import cucumber.api.junit.Cucumber;
7+
8+
@RunWith(Cucumber.class)
9+
@CucumberOptions(features = "src/functionaltests/resources/features/subscriptionCRUD.feature", glue = {
10+
"com.ericsson.ei.subscriptions.crud" })
11+
public class TestSubscriptionCRUDRunner {
12+
13+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.ericsson.ei.subscriptions.trigger;
2+
3+
import com.ericsson.ei.utils.FunctionalTestBase;
4+
5+
import org.junit.Ignore;
6+
import org.slf4j.Logger;
7+
import org.slf4j.LoggerFactory;
8+
9+
import cucumber.api.java.en.Given;
10+
import cucumber.api.java.en.Then;
11+
import cucumber.api.java.en.When;
12+
13+
@Ignore
14+
public class SubscriptionTriggerSteps extends FunctionalTestBase {
15+
16+
private static final Logger LOGGER = LoggerFactory.getLogger(SubscriptionTriggerSteps.class);
17+
18+
@Given("^Subscription rest trigger is created$")
19+
public void subscription_rest_trigger_is_created() throws Throwable {
20+
LOGGER.debug("Creating subscription rest trigger");
21+
System.out.println("MongoDB port for " + this.getClass().getName() + " is: " + getMongoDbPort());
22+
}
23+
24+
@Given("^Subscription mail trigger is created$")
25+
public void subscription_mail_trigger_is_created() throws Throwable {
26+
LOGGER.debug("Creating subscription mail trigger");
27+
}
28+
29+
@Given("^Subscription rest authenticated trigger is created$")
30+
public void subscription_rest_authenticated_trigger_is_created() throws Throwable {
31+
LOGGER.debug("Subscription rest authenticated trigger is created");
32+
}
33+
34+
@When("^I send events$")
35+
public void send_events() throws Throwable {
36+
LOGGER.debug("Sending events");
37+
}
38+
39+
@Then("^Subscriptions were triggered$")
40+
public void check_subscriptions_were_triggered() throws Throwable {
41+
42+
}
43+
44+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.ericsson.ei.subscriptions.trigger;
2+
3+
import org.junit.runner.RunWith;
4+
5+
import cucumber.api.CucumberOptions;
6+
import cucumber.api.junit.Cucumber;
7+
8+
@RunWith(Cucumber.class)
9+
@CucumberOptions(features = "src/functionaltests/resources/features/subscriptionTrigger.feature", glue = {
10+
"com.ericsson.ei.subscriptions.trigger" })
11+
public class TestSubscriptionTriggerRunner {
12+
13+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.ericsson.ei.utils;
2+
3+
import com.google.common.io.Files;
4+
5+
import org.apache.qpid.server.Broker;
6+
import org.apache.qpid.server.BrokerOptions;
7+
8+
public class AMQPBrokerManager {
9+
10+
private final Broker broker = new Broker();
11+
private String path;
12+
private int port;
13+
14+
public AMQPBrokerManager(String path, int port) {
15+
super();
16+
this.path = path;
17+
this.port = port;
18+
}
19+
20+
public void startBroker() throws Exception {
21+
final BrokerOptions brokerOptions = new BrokerOptions();
22+
brokerOptions.setConfigProperty("qpid.amqp_port", "" + port);
23+
brokerOptions.setConfigProperty("qpid.pass_file", "src/functionaltests/resources/configs/password.properties");
24+
brokerOptions.setConfigProperty("qpid.work_dir", Files.createTempDir().getAbsolutePath());
25+
brokerOptions.setInitialConfigurationLocation(path);
26+
27+
broker.startup(brokerOptions);
28+
}
29+
30+
public void stopBroker() {
31+
broker.shutdown();
32+
}
33+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
Copyright 2017 Ericsson AB.
3+
For a full list of individual contributors, please see the commit history.
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
Unless required by applicable law or agreed to in writing, software
9+
distributed under the License is distributed on an "AS IS" BASIS,
10+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
See the License for the specific language governing permissions and
12+
limitations under the License.
13+
*/
14+
package com.ericsson.ei.utils;
15+
16+
import com.ericsson.ei.App;
17+
import com.ericsson.ei.mongodbhandler.MongoDBHandler;
18+
19+
import org.junit.Ignore;
20+
import org.junit.runner.RunWith;
21+
import org.slf4j.Logger;
22+
import org.slf4j.LoggerFactory;
23+
import org.springframework.beans.factory.annotation.Autowired;
24+
import org.springframework.boot.test.context.SpringBootContextLoader;
25+
import org.springframework.boot.test.context.SpringBootTest;
26+
import org.springframework.test.context.ContextConfiguration;
27+
import org.springframework.test.context.TestExecutionListeners;
28+
import org.springframework.test.context.junit4.SpringRunner;
29+
import org.springframework.test.context.support.AbstractTestExecutionListener;
30+
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
31+
32+
/**
33+
* @author evasiba
34+
*
35+
*/
36+
@Ignore
37+
@RunWith(SpringRunner.class)
38+
@SpringBootTest(classes = App.class)
39+
@ContextConfiguration(classes = App.class, loader = SpringBootContextLoader.class, initializers = TestContextInitializer.class)
40+
@TestExecutionListeners(listeners = { DependencyInjectionTestExecutionListener.class, FunctionalTestBase.class })
41+
public class FunctionalTestBase extends AbstractTestExecutionListener {
42+
43+
private static final Logger LOGGER = LoggerFactory.getLogger(FunctionalTestBase.class);
44+
45+
@Autowired
46+
private MongoDBHandler mongoDBHandler;
47+
48+
public int getMongoDbPort() {
49+
return mongoDBHandler.getPort();
50+
}
51+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package com.ericsson.ei.utils;
2+
3+
import com.mongodb.MongoClient;
4+
import com.rabbitmq.client.Connection;
5+
import com.rabbitmq.client.ConnectionFactory;
6+
7+
import java.io.File;
8+
import java.io.IOException;
9+
10+
import org.slf4j.Logger;
11+
import org.slf4j.LoggerFactory;
12+
import org.springframework.amqp.core.BindingBuilder;
13+
import org.springframework.amqp.core.Queue;
14+
import org.springframework.amqp.core.TopicExchange;
15+
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
16+
import org.springframework.amqp.rabbit.core.RabbitAdmin;
17+
import org.springframework.context.annotation.Bean;
18+
import org.springframework.util.SocketUtils;
19+
20+
import de.flapdoodle.embed.mongo.distribution.Version;
21+
import de.flapdoodle.embed.mongo.tests.MongodForTestsFactory;
22+
import lombok.Getter;
23+
24+
public class TestConfigs {
25+
26+
private static AMQPBrokerManager amqpBroker;
27+
private static ConnectionFactory cf;
28+
29+
final static Logger LOGGER = (Logger) LoggerFactory.getLogger(TestConfigs.class);
30+
31+
@Getter
32+
private Connection conn;
33+
34+
@Getter
35+
private MongoClient mongoClient = null;
36+
37+
@Bean
38+
AMQPBrokerManager amqpBroker() throws Exception {
39+
int port = SocketUtils.findAvailableTcpPort();
40+
System.setProperty("rabbitmq.port", "" + port);
41+
System.setProperty("rabbitmq.user", "guest");
42+
System.setProperty("rabbitmq.password", "guest");
43+
System.setProperty("waitlist.initialDelayResend", "500");
44+
System.setProperty("waitlist.fixedRateResend", "100");
45+
46+
String config = "src/functionaltests/resources/configs/qpidConfig.json";
47+
File qpidConfig = new File(config);
48+
amqpBroker = new AMQPBrokerManager(qpidConfig.getAbsolutePath(), port);
49+
amqpBroker.startBroker();
50+
cf = new ConnectionFactory();
51+
cf.setUsername("guest");
52+
cf.setPassword("guest");
53+
54+
cf.setPort(port);
55+
cf.setHandshakeTimeout(600000);
56+
cf.setConnectionTimeout(600000);
57+
conn = cf.newConnection();
58+
LOGGER.debug("Started embedded message bus for tests on port: " + port);
59+
return amqpBroker;
60+
}
61+
62+
@Bean
63+
MongoClient mongoClient() throws IOException {
64+
try {
65+
MongodForTestsFactory testsFactory = MongodForTestsFactory.with(Version.V3_4_1);
66+
mongoClient = testsFactory.newMongo();
67+
String port = "" + mongoClient.getAddress().getPort();
68+
System.setProperty("spring.data.mongodb.port", port);
69+
LOGGER.debug("Started embedded Mongo DB for tests on port: " + port);
70+
// testsFactory.shutdown();
71+
return mongoClient;
72+
} catch (Exception e) {
73+
LOGGER.error(e.getMessage(), e);
74+
}
75+
76+
return null;
77+
}
78+
79+
public void createExchange(final String exchangeName, final String queueName) {
80+
final CachingConnectionFactory ccf = new CachingConnectionFactory(cf);
81+
RabbitAdmin admin = new RabbitAdmin(ccf);
82+
Queue queue = new Queue(queueName, false);
83+
admin.declareQueue(queue);
84+
final TopicExchange exchange = new TopicExchange(exchangeName);
85+
admin.declareExchange(exchange);
86+
admin.declareBinding(BindingBuilder.bind(queue).to(exchange).with("#"));
87+
ccf.destroy();
88+
}
89+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.ericsson.ei.utils;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
import org.springframework.context.ApplicationContextInitializer;
6+
import org.springframework.context.ConfigurableApplicationContext;
7+
8+
public class TestContextInitializer extends TestConfigs
9+
implements ApplicationContextInitializer<ConfigurableApplicationContext> {
10+
11+
private static final Logger LOGGER = LoggerFactory.getLogger(TestContextInitializer.class);
12+
13+
@Override
14+
public void initialize(ConfigurableApplicationContext ac) {
15+
try {
16+
amqpBroker();
17+
mongoClient();
18+
19+
} catch (Exception e) {
20+
LOGGER.error(e.getMessage(), e);
21+
}
22+
}
23+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
-----BEGIN NEW CERTIFICATE REQUEST-----
2+
MIICrzCCAm0CAQAwezELMAkGA1UEBhMCU0UxFzAVBgNVBAgMDsOWc3RlcmfDtnRs
3+
YW5kMRMwEQYDVQQHDApMaW5rw7ZwaW5nMREwDwYDVQQKEwhFcmljc3NvbjEUMBIG
4+
A1UECxMLRGV2ZWxvcG1lbnQxFTATBgNVBAMTDGVyaWNzc29uLmNvbTCCAbcwggEs
5+
BgcqhkjOOAQBMIIBHwKBgQD9f1OBHXUSKVLfSpwu7OTn9hG3UjzvRADDHj+AtlEm
6+
aUVdQCJR+1k9jVj6v8X1ujD2y5tVbNeBO4AdNG/yZmC3a5lQpaSfn+gEexAiwk+7
7+
qdf+t8Yb+DtX58aophUPBPuD9tPFHsMCNVQTWhaRMvZ1864rYdcq7/IiAxmd0UgB
8+
xwIVAJdgUI8VIwvMspK5gqLrhAvwWBz1AoGBAPfhoIXWmz3ey7yrXDa4V7l5lK+7
9+
+jrqgvlXTAs9B4JnUVlXjrrUWU/mcQcQgYC0SRZxI+hMKBYTt88JMozIpuE8FnqL
10+
VHyNKOCjrh4rs6Z1kW6jfwv6ITVi8ftiegEkO8yk8b6oUZCJqIPf4VrlnwaSi2Ze
11+
gHtVJWQBTDv+z0kqA4GEAAKBgB+UbtdcqNcHqdaHSmJBUn3Z54W7MLqXMcWt+nV6
12+
jUnqw9YDhE6DdjKKpARAvRlhRTsSMbry36svBHarL9ZDJBJ1buAEAuNZus/bcuKs
13+
1Axz9ISqZT9ffHVKXOJfA2gqL7InYU4E4o3uAR9oL7YGpnVPbmCpmqARHzvpPrUx
14+
+mRMoDAwLgYJKoZIhvcNAQkOMSEwHzAdBgNVHQ4EFgQUtZuootj1orMQ/x0XGRCC
15+
rLE0Nh0wCwYHKoZIzjgEAwUAAy8AMCwCFD480dxCGY6pJJP3rZrYBoxzPbUzAhQp
16+
O9SOejgCNH7xAh2bBJFCmK5WRg==
17+
-----END NEW CERTIFICATE REQUEST-----

0 commit comments

Comments
 (0)