@@ -49,6 +49,33 @@ public void testConvertInt() throws Exception {
4949 assertThat (ingestDocument .getFieldValue (fieldName , Integer .class ), equalTo (randomInt ));
5050 }
5151
52+ public void testConvertIntHex () throws Exception {
53+ IngestDocument ingestDocument = RandomDocumentPicks .randomIngestDocument (random ());
54+ int randomInt = randomInt ();
55+ String intString = randomInt < 0 ? "-0x" + Integer .toHexString (-randomInt ) : "0x" + Integer .toHexString (randomInt );
56+ String fieldName = RandomDocumentPicks .addRandomField (random (), ingestDocument , intString );
57+ Processor processor = new ConvertProcessor (randomAlphaOfLength (10 ), fieldName , fieldName , Type .INTEGER , false );
58+ processor .execute (ingestDocument );
59+ assertThat (ingestDocument .getFieldValue (fieldName , Integer .class ), equalTo (randomInt ));
60+ }
61+
62+ public void testConvertIntLeadingZero () throws Exception {
63+ IngestDocument ingestDocument = RandomDocumentPicks .randomIngestDocument (random ());
64+ String fieldName = RandomDocumentPicks .addRandomField (random (), ingestDocument , "010" );
65+ Processor processor = new ConvertProcessor (randomAlphaOfLength (10 ), fieldName , fieldName , Type .INTEGER , false );
66+ processor .execute (ingestDocument );
67+ assertThat (ingestDocument .getFieldValue (fieldName , Integer .class ), equalTo (10 ));
68+ }
69+
70+ public void testConvertIntHexError () {
71+ IngestDocument ingestDocument = RandomDocumentPicks .randomIngestDocument (random ());
72+ String value = "0x" + randomAlphaOfLengthBetween (1 , 10 );
73+ String fieldName = RandomDocumentPicks .addRandomField (random (), ingestDocument , value );
74+ Processor processor = new ConvertProcessor (randomAlphaOfLength (10 ), fieldName , fieldName , Type .INTEGER , false );
75+ IllegalArgumentException e = expectThrows (IllegalArgumentException .class , () -> processor .execute (ingestDocument ));
76+ assertThat (e .getMessage (), equalTo ("unable to convert [" + value + "] to integer" ));
77+ }
78+
5279 public void testConvertIntList () throws Exception {
5380 IngestDocument ingestDocument = RandomDocumentPicks .randomIngestDocument (random ());
5481 int numItems = randomIntBetween (1 , 10 );
@@ -92,6 +119,33 @@ public void testConvertLong() throws Exception {
92119 assertThat (ingestDocument .getFieldValue (fieldName , Long .class ), equalTo (randomLong ));
93120 }
94121
122+ public void testConvertLongHex () throws Exception {
123+ IngestDocument ingestDocument = RandomDocumentPicks .randomIngestDocument (random ());
124+ long randomLong = randomLong ();
125+ String longString = randomLong < 0 ? "-0x" + Long .toHexString (-randomLong ) : "0x" + Long .toHexString (randomLong );
126+ String fieldName = RandomDocumentPicks .addRandomField (random (), ingestDocument , longString );
127+ Processor processor = new ConvertProcessor (randomAlphaOfLength (10 ), fieldName , fieldName , Type .LONG , false );
128+ processor .execute (ingestDocument );
129+ assertThat (ingestDocument .getFieldValue (fieldName , Long .class ), equalTo (randomLong ));
130+ }
131+
132+ public void testConvertLongLeadingZero () throws Exception {
133+ IngestDocument ingestDocument = RandomDocumentPicks .randomIngestDocument (random ());
134+ String fieldName = RandomDocumentPicks .addRandomField (random (), ingestDocument , "010" );
135+ Processor processor = new ConvertProcessor (randomAlphaOfLength (10 ), fieldName , fieldName , Type .LONG , false );
136+ processor .execute (ingestDocument );
137+ assertThat (ingestDocument .getFieldValue (fieldName , Long .class ), equalTo (10L ));
138+ }
139+
140+ public void testConvertLongHexError () {
141+ IngestDocument ingestDocument = RandomDocumentPicks .randomIngestDocument (random ());
142+ String value = "0x" + randomAlphaOfLengthBetween (1 , 10 );
143+ String fieldName = RandomDocumentPicks .addRandomField (random (), ingestDocument , value );
144+ Processor processor = new ConvertProcessor (randomAlphaOfLength (10 ), fieldName , fieldName , Type .LONG , false );
145+ IllegalArgumentException e = expectThrows (IllegalArgumentException .class , () -> processor .execute (ingestDocument ));
146+ assertThat (e .getMessage (), equalTo ("unable to convert [" + value + "] to long" ));
147+ }
148+
95149 public void testConvertLongList () throws Exception {
96150 IngestDocument ingestDocument = RandomDocumentPicks .randomIngestDocument (random ());
97151 int numItems = randomIntBetween (1 , 10 );
0 commit comments