-
-
Notifications
You must be signed in to change notification settings - Fork 148
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
1160390
commit a701633
Showing
6 changed files
with
106 additions
and
5 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
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
42 changes: 42 additions & 0 deletions
42
properties/src/test/java/com/fasterxml/jackson/dataformat/javaprop/PrefixTest.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,42 @@ | ||
package com.fasterxml.jackson.dataformat.javaprop; | ||
|
||
import java.util.Map; | ||
import java.util.Properties; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
public class PrefixTest extends ModuleTestBase | ||
{ | ||
private final JavaPropsMapper MAPPER = mapperForProps(); | ||
|
||
public void testPrefixParsing() throws Exception { | ||
final String INPUT = "org.o1.firstName=Bob\n" | ||
+"org.o1.lastName=Palmer\n" | ||
+"org.o2.firstName=Alice\n" | ||
+"org.o2.lastName=Black\n" | ||
+"junk=AQIDBA==\n"; | ||
FiveMinuteUser result1 = _mapFrom(MAPPER.reader(JavaPropsSchema.emptySchema().withPrefix("org.o1")), INPUT, FiveMinuteUser.class, false); | ||
assertEquals("Bob", result1.firstName); | ||
assertEquals("Palmer", result1.lastName); | ||
FiveMinuteUser result2 = _mapFrom(MAPPER.reader(JavaPropsSchema.emptySchema().withPrefix("org.o2")), INPUT, FiveMinuteUser.class, false); | ||
assertEquals("Alice", result2.firstName); | ||
assertEquals("Black", result2.lastName); | ||
} | ||
|
||
public void testPrefixGeneration() throws Exception | ||
{ | ||
FiveMinuteUser input = new FiveMinuteUser("Bob", "Palmer", true, Gender.MALE, | ||
new byte[] { 1, 2, 3, 4 }); | ||
String output = MAPPER.writer(JavaPropsSchema.emptySchema().withPrefix("org.o1")).writeValueAsString(input); | ||
assertEquals("org.o1.firstName=Bob\n" | ||
+"org.o1.lastName=Palmer\n" | ||
+"org.o1.gender=MALE\n" | ||
+"org.o1.verified=true\n" | ||
+"org.o1.userImage=AQIDBA==\n" | ||
,output); | ||
Properties props = MAPPER.writeValueAsProperties(input, JavaPropsSchema.emptySchema().withPrefix("org.o1")); | ||
assertEquals(5, props.size()); | ||
assertEquals("true", props.get("org.o1.verified")); | ||
assertEquals("MALE", props.get("org.o1.gender")); | ||
} | ||
} |
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