Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More replace field tests #1019

Merged
merged 5 commits into from
Aug 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ void setup() {
camelContext = new DefaultCamelContext();
processor = new ReplaceField();
}

@Test
void shouldAddFieldToPlainJson() throws Exception {
void shouldReplaceFieldToPlainJson() throws Exception {
Exchange exchange = new DefaultExchange(camelContext);

exchange.getMessage().setBody(mapper.readTree(baseJson));
Expand All @@ -56,4 +57,59 @@ void shouldAddFieldToPlainJson() throws Exception {
"\"years\":\"29\"" +
"}");
}

@Test
void shouldReplaceFieldWithSpecificRename() throws Exception {
Exchange exchange = new DefaultExchange(camelContext);

exchange.getMessage().setBody(mapper.readTree(baseJson));

JsonNode node = processor.process("name,age", "none", "name:firstName", exchange);

Assertions.assertEquals(node.toString(), "{" +
"\"firstName\":\"Rajesh Koothrappali\"," +
"\"age\":\"29\"" +
"}");
}

@Test
void shouldReplaceFieldWithSpecificRenameAndDisableFields() throws Exception {
Exchange exchange = new DefaultExchange(camelContext);

exchange.getMessage().setBody(mapper.readTree(baseJson));

JsonNode node = processor.process("name", "none", "name:firstName", exchange);

Assertions.assertEquals(node.toString(), "{" +
"\"firstName\":\"Rajesh Koothrappali\"" +
"}");
}

@Test
void shouldReplaceFieldWithSpecificDisableFields() throws Exception {
Exchange exchange = new DefaultExchange(camelContext);

exchange.getMessage().setBody(mapper.readTree(baseJson));

JsonNode node = processor.process("all", "name,age", "name:firstName", exchange);

Assertions.assertEquals(node.toString(), "{" +
"\"name\":\"Rajesh Koothrappali\"," +
"\"age\":\"29\"" +
"}");
}

@Test
void shouldReplaceFieldWithDisableAllFields() throws Exception {
Exchange exchange = new DefaultExchange(camelContext);

exchange.getMessage().setBody(mapper.readTree(baseJson));

JsonNode node = processor.process("none", "all", "name:firstName", exchange);

Assertions.assertEquals(node.toString(), "{" +
"\"name\":\"Rajesh Koothrappali\"," +
"\"age\":\"29\"" +
"}");
}
}