Unit Service Routes fail when unit measure has '/'
When using routes with inline parameters, slash ("/") is treated as an path terminator (even escaped) and therefore any units of measure such as ft/s cause the unit service to generate 400 errors.
The integration tests are failing for the service as they tests conversion of ft/s to m/s.
Example: abcd unit conversion route failure
The following integration test tries to convert ft/s to m/s:
def test_get_conversion_as_abcd_by_namespace_and_symbols(self):
"""Test get_conversion_as_abcd_by_namespace_and_symbols"""
try:
api_response = self.api_instance.get_conversion_as_abcd_by_namespace_and_symbols(
namespaces='Energistics_UoM,RP66', from_symbol='ft/s', to_symbol='m/s',
data_partition_id=self.env.data_partition_id)
self.assertIsNotNone(api_response)
self.assertIsInstance(api_response, ConversionResult)
self.assertIsNotNone(api_response.abcd)
self.assertIsNone(api_response.scale_offset)
self.assertEqual(0.0, api_response.abcd.a)
self.assertEqual(0.3048, api_response.abcd.b)
self.assertEqual(1.0, api_response.abcd.c)
self.assertEqual(0.0, api_response.abcd.d)
except ApiException as e:
self.fail(str(e))
The following route is expected to be called by the integration test:
@GetMapping("/conversion/abcd/{namespaces}/{fromSymbol}/{toSymbol}")
public ConversionResult getConversionABCDBySymbols(@PathVariable("namespaces") String namespaces,
@PathVariable("fromSymbol") String fromSymbol,
@PathVariable("toSymbol") String toSymbol) {
try {
return catalog.getConversionABCDBySymbols(namespaces, fromSymbol, toSymbol);
}
catch (Exception ex) {
throw AppException.createBadRequest(ex.getMessage());
}
}
The integration test result is as follows:
======================================================================
ERROR [0.006s]: test_get_conversion_as_abcd_by_namespace_and_symbols (unit_test_core.test_unit_service_v2.TestConversions)
Test get_conversion_as_abcd_by_namespace_and_symbols
----------------------------------------------------------------------
Traceback (most recent call last):
File "../unit_test_core/test_unit_service_v2.py", line 122, in test_get_conversion_as_abcd_by_namespace_and_symbols
api_response = self.api_instance.get_conversion_as_abcd_by_namespace_and_symbols(
unit_test_core.v2.swagger_client.rest.ApiException: (400)
Reason:
HTTP response headers: HTTPHeaderDict({'Content-Type': 'text/html;charset=utf-8', 'Content-Language': 'en', 'Content-Length': '435', 'Date': 'Tue, 01 Sep 2020 16:03:40 GMT', 'Connection': 'close'})
HTTP response body: <!doctype html><html lang="en"><head><title>HTTP Status 400 – Bad Request</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 400 – Bad Request</h1></body></html>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "../unit_test_core/test_unit_service_v2.py", line 134, in test_get_conversion_as_abcd_by_namespace_and_symbols
self.fail(str(e))
AssertionError: (400)
Reason:
HTTP response headers: HTTPHeaderDict({'Content-Type': 'text/html;charset=utf-8', 'Content-Language': 'en', 'Content-Length': '435', 'Date': 'Tue, 01 Sep 2020 16:03:40 GMT', 'Connection': 'close'})
HTTP response body: <!doctype html><html lang="en"><head><title>HTTP Status 400 – Bad Request</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 400 – Bad Request</h1></body></html>
I also tested the route via postman and saw the same result: Postman Call: