Skip to content

Commit

Permalink
feat: create scenario to convert
Browse files Browse the repository at this point in the history
Signed-off-by: Otavio Santana <otaviopolianasantana@gmail.com>
  • Loading branch information
otaviojava committed Mar 16, 2024
1 parent c184afd commit bbbc675
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Expand Up @@ -30,6 +30,7 @@
import static org.eclipse.jnosql.mapping.metadata.MappingType.COLLECTION;

import static org.eclipse.jnosql.mapping.metadata.MappingType.EMBEDDED;
import static org.eclipse.jnosql.mapping.metadata.MappingType.EMBEDDED_GROUP;
import static org.eclipse.jnosql.mapping.metadata.MappingType.ENTITY;
import static java.util.Collections.singletonList;

Expand Down Expand Up @@ -63,7 +64,7 @@ public <X, Y> List<Element> toElements(EntityConverter converter, Converters con
return singletonList(Element.of(getName(), null));
} else if (EMBEDDED.equals(getType())) {
return converter.toCommunication(value()).elements();
} else if (ENTITY.equals(getType())) {
} else if (ENTITY.equals(getType())|| EMBEDDED_GROUP.equals(getType())) {
return singletonList(Element.of(getName(), converter.toCommunication(value()).elements()));
} else if (isEmbeddableCollection()) {
return singletonList(Element.of(getName(), getColumns(converter)));
Expand Down
Expand Up @@ -635,6 +635,29 @@ void shouldConvertGroupEmbeddable(){
});
}

@Test
void shouldConvertGroupEmbeddableToCommunication(){

Wine wine = Wine.of("id", "Vin Blanc", WineFactory.of("Napa Valley Factory", "Napa Valley"));


var communication = converter.toCommunication(wine);

SoftAssertions.assertSoftly(soft ->{
soft.assertThat(communication).isNotNull();
soft.assertThat(communication.name()).isEqualTo("Wine");
soft.assertThat(communication.find("_id").orElseThrow().get()).isEqualTo("id");
soft.assertThat(communication.find("name").orElseThrow().get()).isEqualTo("Vin Blanc");
communication.find("factory").ifPresent(e -> {
List<Element> elements = e.get(new TypeReference<>(){});
soft.assertThat(elements).hasSize(2);
soft.assertThat(elements.stream().filter(c -> "name".equals(c.name())).findFirst().orElseThrow().get()).isEqualTo("Napa Valley Factory");
soft.assertThat(elements.stream().filter(c -> "location".equals(c.name())).findFirst().orElseThrow().get()).isEqualTo("Napa Valley");
});

});
}


private Object getValue(Optional<Element> column) {
return column.map(Element::value).map(Value::get).orElse(null);
Expand Down

0 comments on commit bbbc675

Please sign in to comment.