aboutsummaryrefslogtreecommitdiffstats
path: root/utils/src/test/java/org/onap/policy/common/utils/coder
AgeCommit message (Collapse)AuthorFilesLines
2021-05-21Enhance toString methods in factory classesJim Hahn1-6/+3
The factory classes in policy-endpoints have toString() methods that return "[]" for their list contents. Updated the code to provide a list of the keys rather than just an empty list. Also replaced some toString() methods with lombok. Also replace StringBuilder with concatenation in some cases. Issue-ID: POLICY-3298 Change-Id: I64fca21a4b009f7e09fcc482b5d156753fb7e680 Signed-off-by: Jim Hahn <jrh3@att.com>
2021-04-13Revert "Modify StandardCoder to handle empty source"Jim Hahn1-33/+2
This reverts commit 04623fef95f2b164d79ad48de2ef3708d02eda80. Reason for revert: prefer consistency with gson Issue-ID: POLICY-3172 Change-Id: Ic2501abcc68ec1186142a7e520e7985c43fd3315 Signed-off-by: Jim Hahn <jrh3@att.com>
2021-04-07Modify StandardCoder to handle empty sourceJim Hahn1-2/+33
Currently, if the source string or source file is empty, the StandardCoder just returns null. Modified it to throw an exception in those cases. However, if the string reference is null, it will still return null. Issue-ID: POLICY-3172 Change-Id: Ie7d5e1b0328a24d94a75af8d18a341faebbe5d5f Signed-off-by: Jim Hahn <jrh3@att.com>
2020-12-14Convert YAML Double to Integer/LongJim Hahn1-0/+6
When a YAML number is decoded directly to type Object.class using the decode() or fromJson() methods of the StandardYamlCoder, the number is left as a Double. It should be converted to an Integer or Long, where possible. Issue-ID: POLICY-2900 Change-Id: I7707ac5c54167cbc3a4b23985c6e5fa1a507324e Signed-off-by: Jim Hahn <jrh3@att.com>
2020-10-29Fix sonar security issue in CryptoUtilsJim Hahn1-2/+16
Sonar reports that CryptoUtils is using AES with CBC, which is known to be insecure. Switched to "AES/GCM/NoPadding". Note: values in any property files using encryption or the "enc:" prefix will have to be re-encrypted. Issue-ID: POLICY-2801 Change-Id: I41f00d4f3ee67a00b92135150120d1faa621655a Signed-off-by: Jim Hahn <jrh3@att.com>
2020-06-29Fix issues in common for new sonar rulesJim Hahn1-1/+4
Addressed issues reported due to updates to the sonar rules: - invoke only one method in a junit lambda - complete the assertion - add DOCTYPE to html Issue-ID: POLICY-2650 Change-Id: Ib8b8a2e4736cc23849c0f7aef972ffa3365a3e00 Signed-off-by: Jim Hahn <jrh3@att.com>
2020-06-17Cleanup various sonar issues in policy-commonJim Hahn1-5/+2
Addressed the following issues: - unused imports - unused method parameters - use assertEquals, assertSame instead of assertTrue - provide the parametrized type for this generic Also fixed some checkstyle issues: - removed blank lines between "import" groups Issue-ID: POLICY-2650 Change-Id: I004bb650ac10c49ccd0fc405f6959896fec39f9b Signed-off-by: Jim Hahn <jrh3@att.com>
2020-03-03Add gson adapters for special field typesJim Hahn1-0/+160
Added type adapters for Instant, LocalDateTime, and ZonedDateTime. UUID seems to work already. Added new Coder that offers an alternative encoding for Instant. Issue-ID: POLICY-1625 Signed-off-by: Jim Hahn <jrh3@att.com> Change-Id: I5230fa7fe955d78c5f2da1316cb1504b5875ea84
2020-02-17Add convert() to CoderJim Hahn2-1/+161
This addresses Liam's review comment about moving the "translate" method from the actor Util class into policy-common. Added a method to Coder to convert from one object type to another (e.g., from a Map to a POJO, or vice versa). Issue-ID: POLICY-2363 Signed-off-by: Jim Hahn <jrh3@att.com> Change-Id: I2a0b5ab4ce4b0eeda216a57cbe23a8bb64f64940
2020-02-08Add enhancements to standard coderJim Hahn1-3/+44
Added support for array indices in StandardCoderObject getString(). Also made it Serializable. Issue-ID: POLICY-1625 Signed-off-by: Jim Hahn <jrh3@att.com> Change-Id: Ia514aed96fdfe7f635c5a6dc3e1f90939654d383
2020-01-31Add pretty() method to CoderJim Hahn3-1/+71
"Pretty" JSON is often needed, so added Coder.pretty() to facilitate that. Incorporated review comment(s): - changed pretty() to encode(object, pretty) Issue-ID: POLICY-1625 Signed-off-by: Jim Hahn <jrh3@att.com> Change-Id: I180fa6de416836008bf1c410132ae30f4dde9271
2020-01-29Convert double to int when decoding JSONJim Hahn1-1/+15
When decoding straight into a List or Map class, StandardCoder was not applying the double-to-int conversion. Fixed it. Issue-ID: POLICY-1625 Signed-off-by: Jim Hahn <jrh3@att.com> Change-Id: I939e3378645d45ac98d2bca6b2a4076870a05626
2020-01-27Schema validation extension to StandardCoderjhh1-0/+143
Issue-ID: POLICY-2331 Signed-off-by: jhh <jorge.hernandez-herrero@att.com> Change-Id: Ic3e8d21715d17a61ea5d07740dd9f4dd0dbb8641 Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
2019-10-29Fix new sonar issues in commonJim Hahn1-2/+2
Issue-ID: POLICY-2204 Signed-off-by: Jim Hahn <jrh3@att.com> Change-Id: If0a11913f614e038ecd3e8c3f0b56d3ac78b03ec Signed-off-by: Jim Hahn <jrh3@att.com>
2019-10-24Integrate CryptoUtils into ONAP commonChou, Joseph (jc2555)1-0/+105
Update junit to add test cases Change-Id: If3236853138a05faac5f51a859b935265c14f0d6 Issue-ID: POLICY-1945 Signed-off-by: Chou, Joseph (jc2555) <jc2555@att.com>
2019-09-13Extract YamlJsonTranslator from StandardYamlCoderJim Hahn3-84/+210
Refactored StandardYamlCoder, extracting a new class, YamlJsonTranslator, from it. This facilitates performing yaml translation when not using a standard "gson" coder. Added YamlJacksonHandler which supports YAML translation layered on top of a JacksonHandler instead of a GsonMessageBodyHandler. Also added junit tests to complete coverage of StandardCoder. Also added public APPLICATION_YAML to YamlMessageBodyHandler. Change-Id: Ia470fa194661fbf1aebeaf0f18b57f2a984cb64b Issue-ID: POLICY-2081 Signed-off-by: Jim Hahn <jrh3@att.com>
2019-09-12Remove YamlException classJim Hahn1-61/+0
After the implementation was finalized, it turned out that YamlException was no longer needed, so it has been deleted. Change-Id: Ie895fc096787f05eff36a6127b08247a7664ff8d Issue-ID: POLICY-2065 Signed-off-by: Jim Hahn <jrh3@att.com>
2019-09-11Create StandardYamlCoderJim Hahn2-0/+212
Created StandardYamlCoder which is like a StandardCoder, except that the original converts to/from JSON, while the new class converts to/from YAML. Also added YamlMessageBodyHandler and incorporated it into the http server so that it supports a media type of */yaml. Change-Id: Ibd83a9f6d355a330f63e435f2bb41affcf1947c2 Issue-ID: POLICY-2065 Signed-off-by: Jim Hahn <jrh3@att.com>
2019-07-17Convert double to int when decoding via gsonJim Hahn1-0/+9
Refactored MapDoubleAdapterFactory, extracting DoubleConverter to be used by code needing to convert Double to Integer/Long after being decoded by GSON. Enhanced StandardCoder to automatically use the above converter if the desired class is a generic Object. Change-Id: I1d4e83910de41ceda383f257bfea706db2b8fbbe Issue-ID: POLICY-1919 Signed-off-by: Jim Hahn <jrh3@att.com>
2019-04-11Don't map JSON values to DoubleJim Hahn1-0/+26
By default, gson treats all numbers as Double when placed into a generic Map. This is not backward compatible with existing policy APIs. Added a type adapter that walks Map objects and converts the Double values to Integer or Long, where possible. Made this the default behavior in the GsonMessageBodyHandler, the JacksonHandler, and the StandardCoder. Also fixed a couple of checkstyle errors in the gson project. Change-Id: I9ac0c77e6592d1c039646f0662c077b77a1e9aaf Issue-ID: POLICY-1542 Signed-off-by: Jim Hahn <jrh3@att.com>
2019-03-01Add StandardCoderObject to hide GSON internalsJim Hahn2-0/+137
Added StandardCoderObject to hide GSON's JsonElement so that classes are not dependent on the use of JsonElement, making it easier to switch out serialization mechanisms in the future. Added a test for field-not-found. Converted tabs to spaces in json test file. Simplified StandardCoderObject and added methods to Coder for translating to and from StandardCoderObject. Removed a test for a method that no longer exists. Added more tests to a test case. Change-Id: I5123dc3f17c940ded431ef7f9ccd8c4bff6b1c5f Issue-ID: POLICY-1444 Signed-off-by: Jim Hahn <jrh3@att.com>
2019-02-27Add additional encode and decode methods to CoderJim Hahn1-14/+140
Also: Updated some comments and renamed a few parameters. Removed a "throws" for a RuntimeException. Short-circuit some calls. Typo in comment. Let gson create the JsonWriter. Renamed a few more parameters. Change-Id: I22e48c2191820c2a3d0743200edca79bd74353e7 Issue-ID: POLICY-1444 Signed-off-by: Jim Hahn <jrh3@att.com>
2019-02-27Add common coder classesJim Hahn2-0/+145
Added coder classes as a common utility that can be used to encode and decode json data. Currently, it uses gson, but that can be changed. Separated the Coder interface from implementation. Used assertSame to compare references. Used numbers instead of strings so don't have to deal with escaping quotes in the test cases. Change-Id: Iea9001d2adc5a3150b3367619b5f43e96b5f8b41 Issue-ID: POLICY-1444 Signed-off-by: Jim Hahn <jrh3@att.com>