/*
* GeoTools - The Open Source Java GIS Toolkit
* http://geotools.org
*
* (C) 2006-2008, Open Source Geospatial Foundation (OSGeo)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*/
package org.geotools.filter.text.cql2;
import org.geotools.filter.text.commons.CompilerUtil;
import org.geotools.filter.text.commons.Language;
import org.junit.Assert;
import org.junit.Test;
import org.opengis.filter.PropertyIsLike;
import org.opengis.filter.expression.PropertyName;
/**
* Test Attribute
* <p>
*
* <pre>
* <attribute name > ::=
* <simple attribute name >
* | <compound attribute name >
*
* <simple attribute name > ::= <identifier>
*
* <compound attribute name > ::= <identifier > <period > [{ <identifier > <period >}...] <simple attribute name >
*
* <identifier > ::= <identifier start > [ { <colon > | <identifier part > }... ]
* <identifier start > ::= <simple Latin letter >
* <identifier part > ::= <simple Latin letter > | <digit >
* </pre>
*
* @author Mauricio Pazos (Axios Engineering)
* @since 2.7
*
* @source $URL: http://svn.osgeo.org/geotools/trunk/modules/library/cql/src/test/java/org/geotools/filter/text/cql/CQLAttributeNameTest $
* </p>
*/
public class CQLAttributeNameTest {
protected final Language language;
public CQLAttributeNameTest(){
this(Language.CQL);
}
public CQLAttributeNameTest(final Language language){
assert language != null: "language cannot be null value";
this.language = language;
}
@Test
public void simpleAttribute() throws CQLException {
testAttribute("startPart");
}
@Test
public void simpleAttribureWithColon() throws CQLException {
testAttribute("startpart:part1:part2");
}
@Test
public void compoundAttributeName() throws CQLException {
testAttribute("s11:p12:p13.s21:p22.s31:p32");
testAttribute(
"gmd:MD_Metadata.gmd:identificationInfo.gmd:MD_DataIdentification.gmd:abstract");
}
/**
* Invalid attribute names
* @throws CQLException
*/
@Test(expected = CQLException.class)
public void invalidAttribute() throws CQLException {
//Invalid Attribute is expected: the identifier can not begin with number.
testAttribute("1startPart");
//Invalid Attribute is expected: the compound attribute should have \":\"
testAttribute("startpart part1");
}
private void testAttribute(final String attSample) throws CQLException {
PropertyIsLike result;
PropertyName attResult = null;
result = (PropertyIsLike) CompilerUtil.parseFilter(this.language, attSample + " LIKE 'abc%'");
attResult = (PropertyName) result.getExpression();
final String expected = attSample.replace('.', '/');
Assert.assertEquals(expected, attResult.getPropertyName());
}
}