Skip to content

Commit e20682f

Browse files
committed
Add mock phoenixd service
1 parent 4d32399 commit e20682f

2 files changed

Lines changed: 60 additions & 0 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package xyz.tcheeric.gateway.phoenixd.service;
2+
3+
import xyz.tcheeric.phoenixd.mock.MockLnServer;
4+
5+
import java.io.IOException;
6+
7+
/**
8+
* PhoenixdService implementation that starts a {@link MockLnServer}
9+
* and delegates requests to the mock gateway endpoints.
10+
*/
11+
public class PhoenixdMockServiceImpl extends PhoenixdServiceImpl {
12+
13+
private final MockLnServer server;
14+
15+
public PhoenixdMockServiceImpl() {
16+
this(9740);
17+
}
18+
19+
public PhoenixdMockServiceImpl(int port) {
20+
server = new MockLnServer(port);
21+
System.setProperty("phoenixd.base_url", "http://localhost:" + port);
22+
try {
23+
server.start();
24+
} catch (IOException e) {
25+
throw new IllegalStateException("Unable to start MockLnServer", e);
26+
}
27+
}
28+
29+
public void stop() {
30+
server.stop();
31+
}
32+
}
33+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package xyz.tcheeric.gateway.phoenixd.service;
2+
3+
import org.junit.jupiter.api.Assertions;
4+
import org.junit.jupiter.api.Test;
5+
import xyz.tcheeric.phoenixd.model.param.CreateInvoiceParam;
6+
import xyz.tcheeric.phoenixd.model.response.CreateInvoiceResponse;
7+
8+
/**
9+
* Verifies that PhoenixdMockServiceImpl can create an invoice using the mock server.
10+
*/
11+
public class PhoenixdMockServiceImplTest {
12+
13+
/**
14+
* Starts the mock server and ensures a non-null response when creating an invoice.
15+
*/
16+
@Test
17+
public void testCreateInvoice() {
18+
PhoenixdMockServiceImpl service = new PhoenixdMockServiceImpl();
19+
CreateInvoiceParam param = new CreateInvoiceParam();
20+
param.setAmountSat(1);
21+
param.setDescription("test");
22+
CreateInvoiceResponse response = service.createInvoice(param);
23+
Assertions.assertNotNull(response);
24+
service.stop();
25+
}
26+
}
27+

0 commit comments

Comments
 (0)