Search in sources :

Example 1 with MCRWCMSDefaultSectionProvider

use of org.mycore.wcms2.navigation.MCRWCMSDefaultSectionProvider in project mycore by MyCoRe-Org.

the class JSONSectionProviderTest method toJSON.

@Test
public void toJSON() throws Exception {
    Map<String, String> properties = new HashMap<>();
    properties.put("MCR.WCMS2.mycoreTagList", "");
    MCRConfiguration.instance().initialize(properties, true);
    SAXBuilder builder = new SAXBuilder();
    Document doc = builder.build(new File("src/test/resources/navigation/content.xml"));
    MCRWCMSDefaultSectionProvider prov = new MCRWCMSDefaultSectionProvider();
    JsonArray sectionArray = prov.toJSON(doc.getRootElement());
    assertEquals(2, sectionArray.size());
    // test section one
    JsonObject section1 = (JsonObject) sectionArray.get(0);
    assertEquals("Title one", section1.getAsJsonPrimitive("title").getAsString());
    assertEquals("de", section1.getAsJsonPrimitive("lang").getAsString());
    assertEquals("<div><p>Content one</p><br /></div>", section1.getAsJsonPrimitive("data").getAsString());
    // test section two
    JsonObject section2 = (JsonObject) sectionArray.get(1);
    assertEquals("Title two", section2.getAsJsonPrimitive("title").getAsString());
    assertEquals("en", section2.getAsJsonPrimitive("lang").getAsString());
    assertEquals("Content two", section2.getAsJsonPrimitive("data").getAsString());
}
Also used : JsonArray(com.google.gson.JsonArray) SAXBuilder(org.jdom2.input.SAXBuilder) MCRWCMSDefaultSectionProvider(org.mycore.wcms2.navigation.MCRWCMSDefaultSectionProvider) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) Document(org.jdom2.Document) File(java.io.File) Test(org.junit.Test)

Aggregations

JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 File (java.io.File)1 HashMap (java.util.HashMap)1 Document (org.jdom2.Document)1 SAXBuilder (org.jdom2.input.SAXBuilder)1 Test (org.junit.Test)1 MCRWCMSDefaultSectionProvider (org.mycore.wcms2.navigation.MCRWCMSDefaultSectionProvider)1