package at.gv.egiz.moazs; import at.gv.egiz.moazs.msg.MsgClient; import at.gv.egiz.moazs.msg.MsgClientFactory; import at.gv.egiz.moazs.msg.StoreSOAPBodyBinaryInRepositoryInterceptor; import at.gv.egiz.moazs.scheme.Marshaller; import at.gv.zustellung.app2mzs.xsd.ConfigType; import at.gv.zustellung.msg.xsd.DeliveryRequestType; import at.gv.zustellung.msg.xsd.ObjectFactory; import org.junit.runner.RunWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import javax.xml.bind.JAXBElement; import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.IOException; import static at.gv.zustellung.app2mzs.xsd.ConfigType.configTypeBuilder; import static at.gv.zustellung.app2mzs.xsd.ServerType.serverTypeBuilder; // @RunWith(SpringRunner.class) // @SpringBootTest public class MsgClientTest { private final static Logger logger = LoggerFactory.getLogger(MsgClient.class); private String httpServiceUri = "http://localhost:8081/services/DeliveryRequest"; private String sslServiceUri = "https://localhost/zusemsg/services/DeliveryRequest"; private final String basePath = "src/test/resources/at/gv/egiz/moazs/MsgClientTest/"; @Autowired private Marshaller msgMarshaller; @Autowired private MsgClientFactory factory; @Autowired private StoreSOAPBodyBinaryInRepositoryInterceptor interceptor; private static final ObjectFactory OF = new ObjectFactory(); // this test requires that a zusemsg service runs under httpServiceUri! // tmp disabled. todo: set up integration tests // @Test public void sendValidMessage() throws IOException { var request = loadFromFile("validDeliveryRequest.xml"); var config = generateConfig(httpServiceUri); var client = factory.create(request, config, interceptor); try{ var status = client.send(); logger.info("status: " + msgMarshaller.marshallXml(OF.createDeliveryResponse(status))); } catch (Exception ex) { System.out.println(ex.getMessage()); } } //@Test public void sendValidMessageToSSL() throws IOException { var request = loadFromFile("validDeliveryRequest.xml"); var config = generateConfig(sslServiceUri); var client = factory.create(request, config, interceptor); var status = client.send(); logger.info("status: " + msgMarshaller.marshallXml(OF.createDeliveryRequestStatus(status))); } private DeliveryRequestType loadFromFile(String fileName) throws IOException { try (var inputStream = new BufferedInputStream(new FileInputStream(basePath + fileName))) { var request = (JAXBElement) msgMarshaller.unmarshallXml(inputStream); return request.getValue(); } } private ConfigType generateConfig(String zuseUrl) { var server = serverTypeBuilder() .withZUSEUrlID(zuseUrl) .build(); return configTypeBuilder() .withServer(server) .withPerformQueryPersonRequest(false) .build(); } }