-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ironed out serialization of EntityNameControl descriptor, data and dtos
- Loading branch information
1 parent
76fde71
commit b92f81a
Showing
8 changed files
with
117 additions
and
15 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
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
54 changes: 54 additions & 0 deletions
54
src/test/java/edu/stanford/protege/webprotege/forms/data/EntityNameControlDataDtoTest.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,54 @@ | ||
package edu.stanford.protege.webprotege.forms.data; | ||
|
||
import edu.stanford.protege.webprotege.forms.field.*; | ||
import edu.stanford.protege.webprotege.jackson.WebProtegeJacksonApplication; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.json.JsonTest; | ||
import org.springframework.boot.test.json.JacksonTester; | ||
import org.springframework.context.annotation.Import; | ||
import uk.ac.manchester.cs.owl.owlapi.OWLLiteralImpl; | ||
|
||
import java.io.*; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
@JsonTest | ||
@Import(WebProtegeJacksonApplication.class) | ||
class EntityNameControlDataDtoTest { | ||
|
||
@Autowired | ||
private JacksonTester<FormControlDataDto> tester; | ||
|
||
@Test | ||
void shouldSerialize() throws IOException { | ||
var data = EntityNameControlDataDto.get(EntityNameControlDescriptor.getDefault().getDefault(), | ||
null, | ||
3); | ||
var written = tester.write(data); | ||
System.out.println(written.getJson()); | ||
assertThat(written).hasJsonPathValue("control"); | ||
assertThat(written).hasJsonPath("value"); | ||
assertThat(written).hasJsonPathValue("depth"); | ||
} | ||
|
||
@Test | ||
void shouldDeserialize() throws IOException { | ||
var json = """ | ||
{ | ||
"@type": "EntityNameControlDataDto", | ||
"depth": 3, | ||
"control": { | ||
"@type": "ENTITY_NAME" | ||
}, | ||
"value": null | ||
} | ||
"""; | ||
var read = tester.read(new StringReader(json)); | ||
assertThat(read.getObject()).isInstanceOf(EntityNameControlDataDto.class); | ||
var obj = (EntityNameControlDataDto) read.getObject(); | ||
assertThat(obj.getEntity()).isEmpty(); | ||
assertThat(obj.getDepth()).isEqualTo(3); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
.../java/edu/stanford/protege/webprotege/forms/field/EntityNameControlDescriptorDtoTest.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,43 @@ | ||
package edu.stanford.protege.webprotege.forms.field; | ||
|
||
import edu.stanford.protege.webprotege.common.LanguageMap; | ||
import edu.stanford.protege.webprotege.criteria.*; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.json.*; | ||
import org.springframework.boot.test.json.JacksonTester; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
@JsonTest | ||
@AutoConfigureJsonTesters | ||
class EntityNameControlDescriptorDtoTest { | ||
|
||
|
||
@Autowired | ||
private JacksonTester<EntityNameControlDescriptorDto> tester; | ||
|
||
@Test | ||
public void shouldSerializeNonEmpty() throws IOException { | ||
var descriptor = EntityNameControlDescriptorDto.get(LanguageMap.of("en", "Hello"), | ||
CompositeRootCriteria.get(List.of(), MultiMatchType.ALL)); | ||
var written = tester.write(descriptor); | ||
System.out.println(written.getJson()); | ||
assertThat(written).hasJsonPathValue("placeholder"); | ||
assertThat(written).hasJsonPathValue("criteria"); | ||
} | ||
|
||
@Test | ||
void shouldNotSerializeEmptyFields() throws IOException { | ||
var descriptor = EntityNameControlDescriptorDto.get(LanguageMap.empty(), | ||
null); | ||
var written = tester.write(descriptor); | ||
System.out.println(written.getJson()); | ||
assertThat(written).doesNotHaveJsonPath("placeholder"); | ||
assertThat(written).doesNotHaveJsonPath("criteria"); | ||
} | ||
} |
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