Files
ciimsproxy/internal/codec_test.go
T

137 lines
5.5 KiB
Go

package internal
import (
"testing"
"github.com/stretchr/testify/assert"
)
const (
SendEsp = `<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Header>
<BHIA_CIIMS:AuthenticationToken xmlns:BHIA_CIIMS="http://ciims.bhia.itdcl.com/ExchangeService">
<BHIA_CIIMS:Username xmlns:BHIA_CIIMS="http://ciims.bhia.itdcl.com/ExchangeService">FIMS</BHIA_CIIMS:Username>
<BHIA_CIIMS:Password xmlns:BHIA_CIIMS="http://ciims.bhia.itdcl.com/ExchangeService">FIMSPASS</BHIA_CIIMS:Password>
</BHIA_CIIMS:AuthenticationToken>
</soap:Header>
<soap:Body>
<ns1:send xmlns:ns1="http://ciims.bhia.itdcl.com/ExchangeService">
<ns1:in0>&lt;MSG/&gt;</ns1:in0>
<ns2:in1 xmlns="http://msg.ciims.bhia.itdcl.com" xmlns:ns2="http://ciims.bhia.itdcl.com/ExchangeService">
<ack>false</ack>
<priority>1</priority>
<routeId>FLOP-CHDT-ORMS-FIMS</routeId>
<valXml>false</valXml>
</ns2:in1>
</ns1:send>
</soap:Body>
</soap:Envelope>
`
ReceiveEsp = `<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Header>
<BHIA_CIIMS:AuthenticationToken xmlns:BHIA_CIIMS="http://ciims.bhia.itdcl.com/ExchangeService">
<BHIA_CIIMS:Username xmlns:BHIA_CIIMS="http://ciims.bhia.itdcl.com/ExchangeService">FIMS</BHIA_CIIMS:Username>
<BHIA_CIIMS:Password xmlns:BHIA_CIIMS="http://ciims.bhia.itdcl.com/ExchangeService">FIMSPASS</BHIA_CIIMS:Password>
</BHIA_CIIMS:AuthenticationToken>
</soap:Header>
<soap:Body>
<ns1:receive xmlns:ns1="http://ciims.bhia.itdcl.com/ExchangeService">
<ns1:in0>2</ns1:in0>
</ns1:receive>
</soap:Body>
</soap:Envelope>
`
ReceiveResp string = `<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<ns1:receiveResponse xmlns:ns1="http://ciims.bhia.itdcl.com/ExchangeService">
<ns1:out>
<ns1:string>&lt;?xml version="1.0" encoding="UTF-8"?> &lt;msg xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="unisysaodbsis.xsd"> &lt;meta> &lt;sndr>AODB&lt;/sndr> &lt;seqn>820830&lt;/seqn> &lt;dttm>20180527124442&lt;/dttm> &lt;type>FLOP&lt;/type> &lt;styp>ESTT&lt;/styp> &lt;/meta> &lt;flop> &lt;flid>10725849&lt;/flid> &lt;ffid>CA-CA4242-A-27MAY181955-D&lt;/ffid> &lt;estt>27MAY181945&lt;/estt> &lt;/flop> &lt;/msg></ns1:string>
<ns1:string>&lt;?xml version="1.0" encoding="UTF-8"?> &lt;msg xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="unisysaodbsis.xsd"> &lt;meta> &lt;sndr>AODB&lt;/sndr> &lt;seqn>820830&lt;/seqn> &lt;dttm>20180527124442&lt;/dttm> &lt;type>FLOP&lt;/type> &lt;styp>ESTT&lt;/styp> &lt;/meta> &lt;flop> &lt;flid>10725849&lt;/flid> &lt;ffid>CA-CA4242-A-27MAY181955-D&lt;/ffid> &lt;estt>27MAY181945&lt;/estt> &lt;/flop> &lt;/msg></ns1:string>
</ns1:out>
</ns1:receiveResponse>
</soap:Body>
</soap:Envelope>`
Msg string = `<?xml version="1.0" encoding="UTF-8"?> <msg xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="unisysaodbsis.xsd"> <meta> <sndr>AODB</sndr> <seqn>820830</seqn> <dttm>20180527124442</dttm> <type>FLOP</type> <styp>ESTT</styp> </meta> <flop> <flid>10725849</flid> <ffid>CA-CA4242-A-27MAY181955-D</ffid> <estt>27MAY181945</estt> </flop> </msg>`
ErrMsg string = `<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>invalid route envent id </faultstring><detail><BHIAFault xmlns="http://ciims.bhia.itdcl.com"><code xmlns="http://msg.ciims.bhia.itdcl.com">20</code><errorMessage xmlns="http://msg.ciims.bhia.itdcl.com">Can not find the event [FLOP-ESTT-ATC-ALL1]</errorMessage></BHIAFault></detail></soap:Fault></soap:Body></soap:Envelope>`
SendOk string = `<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body><ns1:sendResponse xmlns:ns1="http://ciims.bhia.itdcl.com/ExchangeService" /></soap:Body></soap:Envelope>`
)
func TestSend(t *testing.T) {
assert := assert.New(t)
// assert equality
// assert.Equal(123, 123, "they should be equal")
msg := CreateSend("FIMS", "FIMSPASS", 1, "FLOP-CHDT-ORMS-FIMS", false, "<MSG/>")
// println(msg)
assert.Equal(SendEsp, msg, "send post should be equal")
}
func TestReceive(t *testing.T) {
assert := assert.New(t)
msg := CreateReceive("FIMS", "FIMSPASS", 2)
assert.Equal(ReceiveEsp, msg, "receive post should be equal")
}
func TestGetMsg(t *testing.T) {
assert := assert.New(t)
msgs := GetMsgs(ReceiveResp)
assert.Equal(2, len(msgs), "should get 2 message")
assert.Equal(Msg, msgs[0], "message")
}
func TestGetErrMsg(t *testing.T) {
assert := assert.New(t)
errMsg := GetErrMsg(ErrMsg)
assert.Equal("Can not find the event [FLOP-ESTT-ATC-ALL1]", errMsg)
}
func TestSendOk(t *testing.T) {
assert := assert.New(t)
errMsg := GetErrMsg(SendOk)
assert.Equal("", errMsg)
}