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
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package io.github.project.openubl.quarkus.xsender.it;

import com.sun.net.httpserver.HttpServer;

import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.net.InetSocketAddress;

/**
* Answers like SUNAT's billService: sendBill with a CDR, sendSummary with a
* ticket. The tests check the extension's wiring, so they don't depend on
* SUNAT beta being up (core's SunatBetaTest talks to it, on demand).
* Each integration-test module has its own copy: xsender core's FakeSunat
* routes by path and isn't published as a test-jar.
*/
public class FakeSunat implements AutoCloseable {

/** The ticket of {@code sunat/bill_service_response_ticket.xml} */
public static final String TICKET = "1703154974517";

private final HttpServer server;

public FakeSunat() {
try {
server = HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
server.createContext("/", exchange -> {
exchange.getRequestBody().readAllBytes();
String answer = switch (String.valueOf(exchange.getRequestHeaders().getFirst("SOAPAction"))) {
case "urn:sendBill" -> "/sunat/bill_service_response_ok.xml";
case "urn:sendSummary" -> "/sunat/bill_service_response_ticket.xml";
default -> null;
};
if (answer == null) {
exchange.sendResponseHeaders(500, -1);
exchange.close();
return;
}
byte[] body = resource(answer);
exchange.getResponseHeaders().set("Content-Type", "text/xml");
exchange.sendResponseHeaders(200, body.length);
exchange.getResponseBody().write(body);
exchange.close();
});
server.start();
}

/** The URL of its billService */
public String billServiceUrl() {
return "http://127.0.0.1:" + server.getAddress().getPort() + "/billService";
}

private static byte[] resource(String name) {
try (InputStream is = FakeSunat.class.getResourceAsStream(name)) {
if (is == null) {
throw new IllegalArgumentException("Missing test resource " + name);
}
return is.readAllBytes();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

@Override
public void close() {
server.stop(0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.github.project.openubl.quarkus.xsender.it;

import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;

import java.util.Map;

/** Points the extension at a {@link FakeSunat} */
public class FakeSunatResource implements QuarkusTestResourceLifecycleManager {

private FakeSunat sunat;

@Override
public Map<String, String> start() {
sunat = new FakeSunat();
return Map.of("quarkus.xsender.company.invoice-url", sunat.billServiceUrl());
}

@Override
public void stop() {
sunat.close();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.github.project.openubl.quarkus.xsender.it;

import io.quarkus.test.common.WithTestResource;
import io.quarkus.test.junit.QuarkusIntegrationTest;

@WithTestResource(FakeSunatResource.class)
@QuarkusIntegrationTest
public class QuarkusSenderResourceIT extends QuarkusXSenderResourceTest {
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package io.github.project.openubl.quarkus.xsender.it;

import io.github.project.openubl.xsender.models.Status;
import io.quarkus.test.common.WithTestResource;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;

import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;

@WithTestResource(FakeSunatResource.class)
@QuarkusTest
public class QuarkusXSenderResourceTest {

Expand All @@ -28,6 +29,6 @@ public void sendVoidedDocument() {
.post("/quarkus-xsender/bill-service/send-voided-document")
.then()
.statusCode(200)
.body(is(notNullValue()));
.body(is(FakeSunat.TICKET));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<soap-env:Header/>
<soap-env:Body>
<br:sendBillResponse xmlns:br="http://service.sunat.gob.pe">
<applicationResponse>UEsDBBQAAgAIAEwklVcAAAAAAgAAAA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rgTvLpeKz1e2CRreEbjsKtAYcO20XJ/mo2z72DLTy6iaHeos8x+3Zrmd7nbHj+MXfClpB1hFjfC76DbDCXsDKN37F7bULbtdgN5wbcEPc8dsd3+tuglfcNPJrqq960ZbR3fVgXOuuAnKxvKFCLY2tWIYxbk71mlU0qEEbf16v210TkfejSoeZQh1QrGqVGA/ZQpL3isPDnyiaVg0OlKLRdFZMkvbrkRGMpus7wUzObdg/2NJA20yihiDyp2RkW2f9CSwG8f9ISRoT3EIEyXznnK7X7nSPjj/3XG/nnA0phjzKtQrl4JW1VF/FUK60xBRf8dWwq8le2zcG+4zHONibE13YCtQQZCSSrKjrklpfaYSyU4thHYJbJsE/1pRaMom5RSPIFI2pYavHlj3VC1+3szEzW4VXUjXBjU5JlqB9x704wvNe/fbZjY0spHk/SPN/Nv3/AFBLAQIAABQAAgAIAEwklVcAAAAAAgAAAAAAAAAGAAAAAAAAAAAAAAAAAAAAAABkdW1teS9QSwECAAAUAAIACABMJJVXDAaS4jEEAAAZDQAAGwAAAAAAAAABAAAAAAAmAAAAUi0xMjM0NTY3ODkxMi0wMS1GMDAxLTEueG1sUEsFBgAAAAACAAIAfQAAAJAEAAAAAA==</applicationResponse>
</br:sendBillResponse>
</soap-env:Body>
</soap-env:Envelope>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<soap-env:Header/>
<soap-env:Body>
<br:sendSummaryResponse xmlns:br="http://service.sunat.gob.pe">
<ticket>1703154974517</ticket>
</br:sendSummaryResponse>
</soap-env:Body>
</soap-env:Envelope>
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package io.github.project.openubl.quarkus.xsender.it;

import com.sun.net.httpserver.HttpServer;

import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.net.InetSocketAddress;

/**
* Answers like SUNAT's billService: sendBill with a CDR, sendSummary with a
* ticket. The tests check the extension's wiring, so they don't depend on
* SUNAT beta being up (core's SunatBetaTest talks to it, on demand).
* Each integration-test module has its own copy: xsender core's FakeSunat
* routes by path and isn't published as a test-jar.
*/
public class FakeSunat implements AutoCloseable {

/** The ticket of {@code sunat/bill_service_response_ticket.xml} */
public static final String TICKET = "1703154974517";

private final HttpServer server;

public FakeSunat() {
try {
server = HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
server.createContext("/", exchange -> {
exchange.getRequestBody().readAllBytes();
String answer = switch (String.valueOf(exchange.getRequestHeaders().getFirst("SOAPAction"))) {
case "urn:sendBill" -> "/sunat/bill_service_response_ok.xml";
case "urn:sendSummary" -> "/sunat/bill_service_response_ticket.xml";
default -> null;
};
if (answer == null) {
exchange.sendResponseHeaders(500, -1);
exchange.close();
return;
}
byte[] body = resource(answer);
exchange.getResponseHeaders().set("Content-Type", "text/xml");
exchange.sendResponseHeaders(200, body.length);
exchange.getResponseBody().write(body);
exchange.close();
});
server.start();
}

/** The URL of its billService */
public String billServiceUrl() {
return "http://127.0.0.1:" + server.getAddress().getPort() + "/billService";
}

private static byte[] resource(String name) {
try (InputStream is = FakeSunat.class.getResourceAsStream(name)) {
if (is == null) {
throw new IllegalArgumentException("Missing test resource " + name);
}
return is.readAllBytes();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

@Override
public void close() {
server.stop(0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,35 @@

import io.github.project.openubl.springboot.xsender.it.Application;
import io.github.project.openubl.xsender.models.Status;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;

import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;

@SpringBootTest(
classes = Application.class,
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT
)
public class SpringBootXSenderResourceTest {

private static final FakeSunat SUNAT = new FakeSunat();

/** The extension sends to the fake SUNAT, not to SUNAT beta */
@DynamicPropertySource
static void sunat(DynamicPropertyRegistry registry) {
registry.add("xsender.company.invoice-url", SUNAT::billServiceUrl);
}

@AfterAll
static void stopSunat() {
SUNAT.close();
}

@LocalServerPort
private Integer port;

Expand All @@ -36,6 +51,6 @@ public void sendVoidedDocument() {
.post("http://localhost:" + port + "/springboot-xsender/bill-service/send-voided-document")
.then()
.statusCode(200)
.body(is(notNullValue()));
.body(is(FakeSunat.TICKET));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<soap-env:Header/>
<soap-env:Body>
<br:sendBillResponse xmlns:br="http://service.sunat.gob.pe">
<applicationResponse>UEsDBBQAAgAIAEwklVcAAAAAAgAAAAAAAAAGAAAAZHVtbXkvAwBQSwMEFAACAAgATCSVVwwGkuIxBAAAGQ0AABsAAABSLTEyMzQ1Njc4OTEyLTAxLUYwMDEtMS54bWy1V2FP2zwQ/r5fEZUPk6Y3OElbWKPQqVDGsgFitDC0byY52uhN7WA7peXXv+e4SdMStHbSq/LBuXvuubvHZ1sEXxaz1JqDkAlnJy330GlZwCIeJ2xy0robf7U/t770PwRU+IMsS5OIKgTegsw4k2BhMJMnrVwwn1OZSJ/RGUhfZhAlTyuwnz+mvoymMKP+QsZ+yOY8icD2Wibcp2JPhoZK1mywUHvSnfHZjLPzhQKmVcBPpASm5Jo0eoz+ivQU4VEjIf07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HYJbJsE/1pRaMom5RSPIFI2pYavHlj3VC1+3szEzW4VXUjXBjU5JlqB9x704wvNe/fbZjY0spHk/SPN/Nv3/AFBLAQIAABQAAgAIAEwklVcAAAAAAgAAAAAAAAAGAAAAAAAAAAAAAAAAAAAAAABkdW1teS9QSwECAAAUAAIACABMJJVXDAaS4jEEAAAZDQAAGwAAAAAAAAABAAAAAAAmAAAAUi0xMjM0NTY3ODkxMi0wMS1GMDAxLTEueG1sUEsFBgAAAAACAAIAfQAAAJAEAAAAAA==</applicationResponse>
</br:sendBillResponse>
</soap-env:Body>
</soap-env:Envelope>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<soap-env:Header/>
<soap-env:Body>
<br:sendSummaryResponse xmlns:br="http://service.sunat.gob.pe">
<ticket>1703154974517</ticket>
</br:sendSummaryResponse>
</soap-env:Body>
</soap-env:Envelope>
Loading