forked from networknt/light-4j
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updating iteration of FormData item (networknt#408)
* Added missing test * Improving readbility - updating iteration of FormData item
- Loading branch information
Showing
2 changed files
with
70 additions
and
3 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
69 changes: 69 additions & 0 deletions
69
body/src/test/java/com/networknt/body/BodyConverterTest.java
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,69 @@ | ||
package com.networknt.body; | ||
|
||
import io.undertow.server.handlers.form.FormData; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class BodyConverterTest { | ||
|
||
@Test | ||
public void shouldToGetEmptyMapWhenFormDataIsEmpty() { | ||
FormData formData = new FormData(99); | ||
Map<String, Object> bodyMap = BodyConverter.convert(formData); | ||
|
||
Assert.assertEquals(0, bodyMap.size()); | ||
} | ||
|
||
@Test | ||
public void shouldToGetConvertedFormDataInAMap() { | ||
String aKey = "aKey"; | ||
String aValue = "aValue"; | ||
String anotherKey = "anotherKey"; | ||
String anotherValue = "anotherValue"; | ||
|
||
FormData formData = new FormData(99); | ||
formData.add(aKey, aValue); | ||
formData.add(anotherKey, anotherValue); | ||
|
||
Map<String, Object> bodyMap = BodyConverter.convert(formData); | ||
|
||
Assert.assertEquals(2, bodyMap.size()); | ||
|
||
List<Object> aConvertedListvalue = (List<Object>) bodyMap.get(aKey); | ||
Assert.assertEquals(1, aConvertedListvalue.size()); | ||
Assert.assertTrue(aConvertedListvalue.get(0) instanceof FormData.FormValue); | ||
Assert.assertEquals(aValue, ((FormData.FormValue)aConvertedListvalue.get(0)).getValue()); | ||
|
||
List<Object> anotherListvalues = (List<Object>) bodyMap.get(anotherKey); | ||
Assert.assertEquals(1, anotherListvalues.size()); | ||
Assert.assertTrue(anotherListvalues.get(0) instanceof FormData.FormValue); | ||
Assert.assertEquals(anotherValue, ((FormData.FormValue)anotherListvalues.get(0)).getValue()); | ||
} | ||
|
||
@Test | ||
public void shouldToGetConvertedFormDataInAMapGroupedByKey() { | ||
String aKey = "aKey"; | ||
String aValue = "aValue"; | ||
String anotherValue = "anotherValue"; | ||
|
||
FormData formData = new FormData(99); | ||
formData.add(aKey, aValue); | ||
formData.add(aKey, anotherValue); | ||
|
||
Map<String, Object> bodyMap = BodyConverter.convert(formData); | ||
|
||
Assert.assertEquals(1, bodyMap.size()); | ||
|
||
List<Object> aConvertedListvalue = (List<Object>) bodyMap.get(aKey); | ||
Assert.assertEquals(2, aConvertedListvalue.size()); | ||
|
||
Assert.assertTrue(aConvertedListvalue.get(0) instanceof FormData.FormValue); | ||
Assert.assertEquals(aValue, ((FormData.FormValue)aConvertedListvalue.get(0)).getValue()); | ||
|
||
Assert.assertTrue(aConvertedListvalue.get(1) instanceof FormData.FormValue); | ||
Assert.assertEquals(anotherValue, ((FormData.FormValue)aConvertedListvalue.get(1)).getValue()); | ||
} | ||
} |