forked from karatelabs/karate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConsumerUsingProxyHttpTest.java
69 lines (62 loc) · 2.36 KB
/
ConsumerUsingProxyHttpTest.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
package mock.contract;
import com.intuit.karate.FileUtils;
import com.intuit.karate.JsonUtils;
import com.intuit.karate.netty.FeatureServer;
import java.io.File;
import java.util.Collections;
import java.util.Map;
import org.junit.AfterClass;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.BeforeClass;
import org.springframework.context.ConfigurableApplicationContext;
/**
*
* @author pthomas3
*/
public class ConsumerUsingProxyHttpTest {
private static ConfigurableApplicationContext context;
private static FeatureServer server;
private static Consumer consumer;
@BeforeClass
public static void beforeClass() {
// actual service
String queueName = "DEMO.PROXY.HTTP";
context = PaymentService.start(queueName, false);
String paymentServiceUrl = "http://localhost:" + PaymentService.getPort(context);
// proxy
File file = FileUtils.getFileRelativeTo(ConsumerUsingProxyHttpTest.class, "payment-service-proxy.feature");
// setting 'paymentServiceUrl' to null uses request url as-is (no re-writing) - so acts as an http proxy
Map config = Collections.singletonMap("paymentServiceUrl", null);
server = FeatureServer.start(file, 0, false, config);
// consumer (using http proxy)
consumer = new Consumer(paymentServiceUrl, "localhost", server.getPort(), queueName);
}
@Test
public void testPaymentCreate() throws Exception {
Payment payment = new Payment();
payment.setAmount(5.67);
payment.setDescription("test one");
Payment result = consumer.create(payment);
assertTrue(result.getId() > 0);
assertEquals(result.getAmount(), 5.67, 0);
assertEquals(result.getDescription(), "test one");
consumer.listen(json -> {
Shipment shipment = JsonUtils.fromJson(json, Shipment.class);
assertEquals(result.getId(), shipment.getPaymentId());
assertEquals("shipped", shipment.getStatus());
synchronized(this) {
notify();
}
});
synchronized(this) {
wait();
}
}
@AfterClass
public static void afterClass() {
server.stop();
PaymentService.stop(context);
consumer.stopQueueConsumer();
}
}