-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f11dac
commit d794162
Showing
10 changed files
with
277 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package ows | ||
|
||
import ( | ||
"encoding/xml" | ||
"testing" | ||
) | ||
|
||
func TestBoundingBoxBuildQueryString(t *testing.T) { | ||
var tests = []struct { | ||
boundingbox BoundingBox | ||
boundingboxstring string | ||
}{ | ||
// While 'not' correct this will we checked in the validation step | ||
0: {boundingbox: BoundingBox{}, boundingboxstring: `0.000000,0.000000,0.000000,0.000000`}, | ||
1: {boundingbox: BoundingBox{LowerCorner: [2]float64{-180.0, -90.0}, UpperCorner: [2]float64{180.0, 90.0}}, boundingboxstring: `-180.000000,-90.000000,180.000000,90.000000`}, | ||
} | ||
for k, a := range tests { | ||
str := a.boundingbox.BuildQueryString() | ||
if str != a.boundingboxstring { | ||
t.Errorf("test: %d, expected: %v+,\n got: %v+", k, a.boundingboxstring, str) | ||
} | ||
} | ||
} | ||
|
||
func TestStripDuplicateAttr(t *testing.T) { | ||
var tests = []struct { | ||
attributes []xml.Attr | ||
expected []xml.Attr | ||
}{ | ||
0: {attributes: []xml.Attr{{Name: xml.Name{Local: "gml"}, Value: "http://www.opengis.net/gml/3.2"}}, expected: []xml.Attr{{Name: xml.Name{Local: "gml"}, Value: "http://www.opengis.net/gml/3.2"}}}, | ||
1: {attributes: []xml.Attr{{Name: xml.Name{Local: "gml"}, Value: "http://www.opengis.net/gml/3.2"}, {Name: xml.Name{Local: "gml"}, Value: "http://www.opengis.net/gml/3.2"}, {Name: xml.Name{Local: "gml"}, Value: "http://www.opengis.net/gml/3.2"}}, | ||
expected: []xml.Attr{{Name: xml.Name{Local: "gml"}, Value: "http://www.opengis.net/gml/3.2"}}}, | ||
} | ||
|
||
for k, a := range tests { | ||
stripped := StripDuplicateAttr(a.attributes) | ||
if len(a.expected) != len(stripped) { | ||
t.Errorf("test: %d, expected: %s,\n got: %s", k, a.expected, stripped) | ||
} else { | ||
c := false | ||
for _, exceptedattr := range a.expected { | ||
for _, result := range stripped { | ||
if exceptedattr == result { | ||
c = true | ||
} | ||
} | ||
if !c { | ||
t.Errorf("test: %d, expected: %s,\n got: %s", k, a.expected, stripped) | ||
} | ||
c = false | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package ows | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestOWSException(t *testing.T) { | ||
var tests = []struct { | ||
exception Exception | ||
exceptionText string | ||
exceptionCode string | ||
locatorCode string | ||
}{ | ||
0: {exception: OWSException{ExceptionCode: "", ExceptionText: "", LocatorCode: ""}, | ||
exceptionText: "", | ||
exceptionCode: "", | ||
locatorCode: "", | ||
}, | ||
1: {exception: OperationNotSupported("GetCoconut"), | ||
exceptionText: "This service does not know the operation: GetCoconut", | ||
exceptionCode: "OperationNotSupported", | ||
locatorCode: "GetCoconut", | ||
}, | ||
2: {exception: MissingParameterValue(), | ||
exceptionText: "Could not determine REQUEST", | ||
exceptionCode: "MissingParameterValue", | ||
locatorCode: "REQUEST", | ||
}, | ||
3: {exception: MissingParameterValue("VERSION"), | ||
exceptionText: "Missing key: VERSION", | ||
exceptionCode: "MissingParameterValue", | ||
locatorCode: "VERSION", | ||
}, | ||
// TODO: ... is this valid | ||
4: {exception: MissingParameterValue("SERVICE", "1.3.0"), | ||
exceptionText: "SERVICE key got incorrect value: 1.3.0", | ||
exceptionCode: "MissingParameterValue", | ||
locatorCode: "SERVICE", | ||
}, | ||
5: {exception: InvalidParameterValue("SERVICE", "WKS"), | ||
exceptionText: "WKS SERVICE does not exist in this server. Please check the capabilities and reformulate your request", | ||
exceptionCode: "InvalidParameterValue", | ||
locatorCode: "SERVICE", | ||
}, | ||
6: {exception: VersionNegotiationFailed("0.0.0"), | ||
exceptionText: "0.0.0 is an invalid version number", | ||
exceptionCode: "VersionNegotiationFailed", | ||
locatorCode: "VERSION", | ||
}, | ||
// TODO: ... | ||
7: {exception: InvalidUpdateSequence(), | ||
exceptionCode: "InvalidUpdateSequence", | ||
}, | ||
// TODO: ... | ||
8: {exception: OptionNotSupported(), | ||
exceptionCode: "OptionNotSupported", | ||
}, | ||
9: {exception: NoApplicableCode("No other exceptionCode specified by this service"), | ||
exceptionText: "No other exceptionCode specified by this service", | ||
exceptionCode: "NoApplicableCode", | ||
}, | ||
} | ||
|
||
for k, a := range tests { | ||
if a.exception.Error() != a.exceptionText { | ||
t.Errorf("test: %d, expected: %s\n got: %s", k, a.exceptionText, a.exception.Error()) | ||
} | ||
if a.exception.Code() != a.exceptionCode { | ||
t.Errorf("test: %d, expected: %s\n got: %s", k, a.exceptionCode, a.exception.Code()) | ||
} | ||
if a.exception.Locator() != a.locatorCode { | ||
t.Errorf("test: %d, expected: %s\n got: %s", k, a.locatorCode, a.exception.Locator()) | ||
} | ||
} | ||
} | ||
|
||
func TestReport(t *testing.T) { | ||
var tests = []struct { | ||
exceptions []Exception | ||
result []byte | ||
err error | ||
}{ | ||
0: {exceptions: []Exception{OWSException{ExceptionCode: "", ExceptionText: "", LocatorCode: ""}}, | ||
result: []byte(`<?xml version="1.0" encoding="UTF-8"?> | ||
<OWSExceptionReport> | ||
<Exception exceptionCode=""></Exception> | ||
</OWSExceptionReport>`)}, | ||
1: {exceptions: []Exception{ | ||
OperationNotSupported(`WKS`), | ||
VersionNegotiationFailed(`0.0.1`), | ||
}, | ||
result: []byte(`<?xml version="1.0" encoding="UTF-8"?> | ||
<OWSExceptionReport> | ||
<Exception exceptionCode="OperationNotSupported" locator="WKS">This service does not know the operation: WKS</Exception> | ||
<Exception exceptionCode="VersionNegotiationFailed" locator="VERSION">0.0.1 is an invalid version number</Exception> | ||
</OWSExceptionReport>`)}, | ||
} | ||
|
||
for k, a := range tests { | ||
report := OWSExceptionReport{} | ||
r := report.Report(a.exceptions) | ||
|
||
if string(r) != string(a.result) { | ||
t.Errorf("test: %d, expected: %s\n got: %s", k, r, a.result) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.