2 * Copyright (C) 2009, 2010, 2011 Openismus GmbH
4 * This file is part of gwt-glom
6 * gwt-glom is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
11 * gwt-glom is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with gwt-glom. If not, see <http://www.gnu.org/licenses/>.
20 package org.glom.web.server.libglom;
22 import static org.hamcrest.CoreMatchers.is;
23 import static org.junit.Assert.*;
25 import java.io.IOException;
28 import org.apache.commons.lang3.StringUtils;
29 import org.glom.web.shared.libglom.layout.LayoutItem;
30 import org.glom.web.shared.libglom.layout.LayoutItemField;
31 import org.junit.AfterClass;
32 import org.junit.BeforeClass;
33 import org.junit.Test;
36 * Simple test to ensure that the generated bindings are working.
38 public class DocumentLayoutPathTest {
40 private static Document document;
43 static public void setUp() {
44 final URL url = DocumentLayoutPathTest.class.getResource("example_music_collection.glom");
45 assertTrue(url != null);
46 final String documentUri= url.toString();
47 assertTrue(!StringUtils.isEmpty(documentUri));
49 document = new Document();
50 document.setFileURI(documentUri);
51 final boolean retval = document.load();
56 static public void tearDown() {
60 public void testNormal() throws IOException {
61 // Just an initial sanity check:
62 assertThat(document.getDatabaseTitleOriginal(), is("Music Collection"));
64 final String layoutPath = "1:2";
65 final LayoutItem item = document.getLayoutItemByPath("artists", Document.LAYOUT_NAME_DETAILS, layoutPath);
67 assertTrue(item instanceof LayoutItemField);
69 assertEquals(item.getName(), "comments");
73 public void testOutOfBounds() throws IOException {
74 final String layoutPath = "1:200"; //Check that it does not crash.
75 final LayoutItem item = document.getLayoutItemByPath("artists", Document.LAYOUT_NAME_DETAILS, layoutPath);
80 public void testOutOfBoundsNegative() throws IOException {
81 final String layoutPath = "-1:-50"; //Check that it does not crash.
82 final LayoutItem item = document.getLayoutItemByPath("artists", Document.LAYOUT_NAME_DETAILS, layoutPath);