You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by sf...@apache.org on 2011/04/24 18:12:31 UTC
svn commit: r1096340 [7/7] - in /chemistry/opencmis/trunk:
chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/
chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/j...
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/test/java/org/apache/chemistry/opencmis/jcr/query/QueryTranslatorTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/test/java/org/apache/chemistry/opencmis/jcr/query/QueryTranslatorTest.java?rev=1096340&r1=1096339&r2=1096340&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/test/java/org/apache/chemistry/opencmis/jcr/query/QueryTranslatorTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/test/java/org/apache/chemistry/opencmis/jcr/query/QueryTranslatorTest.java Sun Apr 24 16:12:27 2011
@@ -19,7 +19,6 @@
package org.apache.chemistry.opencmis.jcr.query;
-import org.antlr.runtime.RecognitionException;
import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
import org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException;
@@ -28,7 +27,6 @@ import org.apache.chemistry.opencmis.jcr
import org.apache.chemistry.opencmis.server.support.query.CalendarHelper;
import org.junit.Test;
-import java.io.IOException;
import java.util.GregorianCalendar;
import static org.junit.Assert.*;
@@ -197,7 +195,7 @@ public class QueryTranslatorTest {
assertEquals(
"/jcr:root/jcr:folderId//element(*,jcr:document)[@jcr:primaryType = nt:base]",
queryTranslator.translateToXPath("select * from cmis:document where not(not(IN_TREE('folderId')))"));
-
+
assertEquals(
"/jcr:root/jcr:folderId/element(*,jcr:document)[@jcr:primaryType = nt:base and @jcr:name <= 1]",
queryTranslator.translateToXPath(
@@ -250,7 +248,7 @@ public class QueryTranslatorTest {
}
@Test
- public void testNotImplemented() throws IOException, RecognitionException {
+ public void testNotImplemented() {
try {
queryTranslator.translateToXPath("select * from cmis:document where cmis:name in (1,2,3)");
fail();
@@ -265,30 +263,30 @@ public class QueryTranslatorTest {
}
@Test
- public void testInvalidQuery() throws IOException, RecognitionException {
+ public void testInvalidQuery() {
try {
queryTranslator.translateToXPath("");
fail();
+ } catch (CmisInvalidArgumentException expected) {
}
- catch (CmisInvalidArgumentException expected) {}
try {
queryTranslator.translateToXPath("select * from cmis:something");
fail();
+ } catch (CmisInvalidArgumentException expected) {
}
- catch (CmisInvalidArgumentException expected) {}
try {
queryTranslator.translateToXPath("select * from cmis:document WHERE");
fail();
+ } catch (CmisInvalidArgumentException expected) {
}
- catch (CmisInvalidArgumentException expected) {}
try {
queryTranslator.translateToXPath("select * from cmis:document WHERE cmis:something = 'foo'");
fail();
+ } catch (CmisInvalidArgumentException expected) {
}
- catch (CmisInvalidArgumentException expected) {}
}
}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/test/java/org/apache/chemistry/opencmis/jcr/query/XPathBuilderTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/test/java/org/apache/chemistry/opencmis/jcr/query/XPathBuilderTest.java?rev=1096340&r1=1096339&r2=1096340&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/test/java/org/apache/chemistry/opencmis/jcr/query/XPathBuilderTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-jcr/src/test/java/org/apache/chemistry/opencmis/jcr/query/XPathBuilderTest.java Sun Apr 24 16:12:27 2011
@@ -19,7 +19,6 @@
package org.apache.chemistry.opencmis.jcr.query;
-import org.antlr.runtime.RecognitionException;
import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
import org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException;
import org.apache.chemistry.opencmis.jcr.JcrTypeManager;
@@ -29,7 +28,6 @@ import org.apache.chemistry.opencmis.ser
import org.apache.chemistry.opencmis.server.support.query.QueryUtil;
import org.junit.Test;
-import java.io.IOException;
import java.util.Arrays;
import java.util.GregorianCalendar;
import java.util.Iterator;
@@ -40,7 +38,7 @@ import static org.junit.Assert.*;
public class XPathBuilderTest {
@Test
- public void testValidQuery() throws IOException, RecognitionException {
+ public void testValidQuery() {
check("select * from cmis:document",
null,
list(),
@@ -140,7 +138,7 @@ public class XPathBuilderTest {
}
@Test
- public void testTooSpecificQuery() throws RecognitionException, IOException {
+ public void testTooSpecificQuery() {
check("select * from cmis:document where NOT IN_FOLDER('folderId')",
"false()",
list("folderId/"),
@@ -173,7 +171,7 @@ public class XPathBuilderTest {
}
@Test
- public void testNotImplemented() throws IOException, RecognitionException {
+ public void testNotImplemented() {
try {
execute("select * from cmis:document where cmis:name in (1,2,3)");
fail();
@@ -188,7 +186,7 @@ public class XPathBuilderTest {
}
@Test
- public void testInvalidQuery() throws IOException, RecognitionException {
+ public void testInvalidQuery() {
try {
execute("");
fail();
@@ -229,12 +227,10 @@ public class XPathBuilderTest {
}
private static void check(String query, String result, List<String> folderPredicates, Boolean evaluation) {
-
XPathBuilder queryBuilder = execute(query);
if (result == null) {
assertEquals(null, queryBuilder);
- }
- else {
+ } else {
assertEquals(result, queryBuilder.xPath());
Iterator<XPathBuilder> folderPredicatesBuilder = queryBuilder.folderPredicates().iterator();
@@ -246,7 +242,6 @@ public class XPathBuilderTest {
assertEquals(evaluation, queryBuilder.eval(false));
}
-
}
}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeValidator.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeValidator.java?rev=1096340&r1=1096339&r2=1096340&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeValidator.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/TypeValidator.java Sun Apr 24 16:12:27 2011
@@ -48,11 +48,13 @@ import org.apache.chemistry.opencmis.com
public class TypeValidator {
public static void validateRequiredSystemProperties(Properties properties) {
- if (properties == null || properties.getProperties() == null)
+ if (properties == null || properties.getProperties() == null) {
throw new RuntimeException("Cannot create object, no properties are given");
+ }
- if (!properties.getProperties().containsKey(PropertyIds.OBJECT_TYPE_ID))
+ if (!properties.getProperties().containsKey(PropertyIds.OBJECT_TYPE_ID)) {
throw new RuntimeException("Cannot create object, type id is missing");
+ }
}
@@ -87,9 +89,10 @@ public class TypeValidator {
public void validate(PropertyDefinition<T> propDef, PropertyData<T> prop) {
// check general constraints for all property types
- if (propDef.getCardinality() == Cardinality.SINGLE && prop.getValues().size() > 1)
+ if (propDef.getCardinality() == Cardinality.SINGLE && prop.getValues().size() > 1) {
throw new CmisConstraintException("The property with id " + propDef.getId()
+ " is single valued, but multiple values are passed " + prop.getValues());
+ }
if (propDef.getChoices() != null && propDef.getChoices().size() > 0) {
validateChoices(propDef, prop);
@@ -100,8 +103,9 @@ public class TypeValidator {
boolean isAllowedValue = true;
boolean hasMultiValueChoiceLists = false;
for (Choice<?> allowedValue : propDef.getChoices()) {
- if (allowedValue.getValue() != null && allowedValue.getValue().size() > 1)
+ if (allowedValue.getValue() != null && allowedValue.getValue().size() > 1) {
hasMultiValueChoiceLists = true;
+ }
}
// check if value is in list
@@ -126,8 +130,9 @@ public class TypeValidator {
}
}
- if (isAllowedValue)
+ if (isAllowedValue) {
break;
+ }
}
} else {
@@ -142,15 +147,16 @@ public class TypeValidator {
}
}
- if (!isAllowedValue)
+ if (!isAllowedValue) {
throw new CmisConstraintException("The property with id " + propDef.getId()
+ " has a fixed set of values. Value(s) " + prop.getValues() + " are not listed.");
+ }
}
/**
* Calculate the list of allowed values for this property definition by
* recursively collecting all choice values from property definition
- *
+ *
* @param propDef
* property definition
* @return list of possible values in complete hierarchy
@@ -158,8 +164,9 @@ public class TypeValidator {
private List<T> getAllowedValues(List<Choice<T>> choices) {
List<T> allowedValues = new ArrayList<T>(choices.size());
for (Choice<T> choice : choices) {
- if (choice.getValue() != null)
+ if (choice.getValue() != null) {
allowedValues.add(choice.getValue().get(0));
+ }
if (choice.getChoice() != null) {
List<Choice<T>> x = choice.getChoice();
allowedValues.addAll(getAllowedValues(x));
@@ -171,6 +178,7 @@ public class TypeValidator {
static class PropertyValidatorInteger extends PropertyValidator<BigInteger> {
+ @Override
public void validate(PropertyDefinition<BigInteger> propDef, PropertyData<BigInteger> property) {
super.validate(propDef, property);
@@ -193,6 +201,7 @@ public class TypeValidator {
static class PropertyValidatorDecimal extends PropertyValidator<BigDecimal> {
+ @Override
public void validate(PropertyDefinition<BigDecimal> propDef, PropertyData<BigDecimal> property) {
super.validate(propDef, property);
@@ -215,6 +224,7 @@ public class TypeValidator {
static class PropertyValidatorString extends PropertyValidator<String> {
+ @Override
public void validate(PropertyDefinition<String> propDef, PropertyData<String> property) {
super.validate(propDef, property);
@@ -242,11 +252,14 @@ public class TypeValidator {
BaseTypeId baseTypeId = typeDef.getBaseTypeId();
// check that all mandatory attributes are present
- if (checkMandatory && propDefsRequired.contains(propertyId))
+ if (checkMandatory && propDefsRequired.contains(propertyId)) {
propDefsRequired.remove(propertyId);
+ }
if (isSystemProperty(baseTypeId, propertyId))
+ {
continue; // ignore system properties for validation
+ }
// Check if all properties are known in the type
if (!typeContainsProperty(typeDef, propertyId)) {
@@ -259,13 +272,15 @@ public class TypeValidator {
validator.validate(propDef, (PropertyData<T>) prop);
}
- if (checkMandatory && !propDefsRequired.isEmpty())
+ if (checkMandatory && !propDefsRequired.isEmpty()) {
throw new CmisConstraintException("The following mandatory properties are missing: " + propDefsRequired);
+ }
}
public static void validateVersionStateForCreate(DocumentTypeDefinition typeDef, VersioningState verState) {
- if (null == verState)
+ if (null == verState) {
return;
+ }
if (typeDef.isVersionable() && verState.equals(VersioningState.NONE) || !typeDef.isVersionable()
&& !verState.equals(VersioningState.NONE)) {
throw new CmisConstraintException("The versioning state flag is imcompatible to the type definition.");
@@ -276,11 +291,14 @@ public class TypeValidator {
public static void validateAllowedChildObjectTypes(TypeDefinition childTypeDef, List<String> allowedChildTypes) {
if (null == allowedChildTypes)
+ {
return; // all types are allowed
+ }
for (String allowedChildType : allowedChildTypes) {
- if (allowedChildType.equals(childTypeDef.getId()))
+ if (allowedChildType.equals(childTypeDef.getId())) {
return;
+ }
}
throw new RuntimeException("The requested type " + childTypeDef.getId() + " is not allowed in this folder");
}
@@ -289,8 +307,9 @@ public class TypeValidator {
List<String> res = new ArrayList<String>();
if (null != propDefs) {
for (PropertyDefinition<?> propDef : propDefs.values()) {
- if (propDef.isRequired() && !isMandatorySystemProperty(propDef.getId()))
+ if (propDef.isRequired() && !isMandatorySystemProperty(propDef.getId())) {
res.add(propDef.getId());
+ }
}
}
return res;
@@ -299,28 +318,32 @@ public class TypeValidator {
public static boolean typeContainsProperty(TypeDefinition typeDef, String propertyId) {
Map<String, PropertyDefinition<?>> propDefs = typeDef.getPropertyDefinitions();
- if (null == propDefs)
+ if (null == propDefs) {
return false;
+ }
PropertyDefinition<?> propDef = propDefs.get(propertyId);
- if (null == propDef)
+ if (null == propDef) {
return false; // unknown property id in this type
- else
+ } else {
return true;
+ }
}
public static boolean typeContainsPropertyWithQueryName(TypeDefinition typeDef, String propertyQueryName) {
Map<String, PropertyDefinition<?>> propDefs = typeDef.getPropertyDefinitions();
- if (null == propDefs)
+ if (null == propDefs) {
return false;
+ }
for (PropertyDefinition<?> propDef : propDefs.values()) {
- if (propDef.getQueryName().toLowerCase().equals(propertyQueryName.toLowerCase()))
+ if (propDef.getQueryName().toLowerCase().equals(propertyQueryName.toLowerCase())) {
return true;
+ }
}
-
+
return false; // unknown property query name in this type
}
@@ -328,15 +351,17 @@ public class TypeValidator {
private static <T> PropertyDefinition<T> getPropertyDefinition(TypeDefinition typeDef, String propertyId) {
Map<String, PropertyDefinition<?>> propDefs = typeDef.getPropertyDefinitions();
- if (null == propDefs)
+ if (null == propDefs) {
return null;
+ }
PropertyDefinition<?> propDef = propDefs.get(propertyId);
- if (null == propDef)
+ if (null == propDef) {
return null; // not found
- else
+ } else {
return (PropertyDefinition<T>) propDef;
+ }
}
private static boolean isSystemProperty(BaseTypeId baseTypeId, String propertyId) {
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/AbstractPredicateWalker.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/AbstractPredicateWalker.java?rev=1096340&r1=1096339&r2=1096340&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/AbstractPredicateWalker.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/AbstractPredicateWalker.java Sun Apr 24 16:12:27 2011
@@ -230,22 +230,25 @@ public abstract class AbstractPredicateW
}
public Boolean walkContains(Tree opNode, Tree qualNode, Tree queryNode) {
- if (qualNode != null)
+ if (qualNode != null) {
walkExpr(qualNode);
+ }
walkExpr(queryNode);
return false;
}
public Boolean walkInFolder(Tree opNode, Tree qualNode, Tree paramNode) {
- if (qualNode != null)
+ if (qualNode != null) {
walkExpr(qualNode);
+ }
walkExpr(paramNode);
return false;
}
public Boolean walkInTree(Tree opNode, Tree qualNode, Tree paramNode) {
- if (qualNode != null)
+ if (qualNode != null) {
walkExpr(qualNode);
+ }
walkExpr(paramNode);
return false;
}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/QueryObject.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/QueryObject.java?rev=1096340&r1=1096339&r2=1096340&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/QueryObject.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/query/QueryObject.java Sun Apr 24 16:12:27 2011
@@ -33,6 +33,7 @@ import org.apache.chemistry.opencmis.ser
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
/**
* QueryObject is a class used to encapsulate a CMIS query. It is created from
* an ANTLR parser on an incoming query string. During parsing various
@@ -239,7 +240,9 @@ public class QueryObject {
ColumnReference colRef = (ColumnReference) sel;
String key = colRef.getPropertyId();
if (null == key)
+ {
key = colRef.getPropertyQueryName(); // happens for *
+ }
String propDescr = colRef.getAliasName() == null ? colRef.getPropertyQueryName() : colRef
.getAliasName();
res.put(key, propDescr);
@@ -330,8 +333,9 @@ public class QueryObject {
public boolean resolveTypes() {
try {
LOG.debug("First pass of query traversal is complete, resolving types");
- if (null == typeMgr)
+ if (null == typeMgr) {
return true;
+ }
// First resolve all alias names defined in SELECT:
for (CmisSelector alias : colOrFuncAlias.values()) {
@@ -364,12 +368,14 @@ public class QueryObject {
// } else
// columnReferences.put(obj,
// colOrFuncAlias.get(selector.getAliasName()));
- if (whereReferences.remove(selector))
+ if (whereReferences.remove(selector)) {
// replace unresolved by resolved reference
whereReferences.add(resolvedReference);
- if (joinReferences.remove(selector))
+ }
+ if (joinReferences.remove(selector)) {
// replace unresolved by resolved reference
joinReferences.add(resolvedReference);
+ }
}
}
@@ -426,9 +432,9 @@ public class QueryObject {
TypeDefinition tdFound = null;
for (String typeQueryName : froms.values()) {
TypeDefinition td = typeMgr.getTypeByQueryName(typeQueryName);
- if (null == td)
+ if (null == td) {
throw new CmisQueryException(typeQueryName + " is neither a type query name nor an alias.");
- else if (isStar) {
+ } else if (isStar) {
++noFound;
tdFound = null;
} else if (TypeValidator.typeContainsPropertyWithQueryName(td, propName)) {
@@ -436,15 +442,16 @@ public class QueryObject {
tdFound = td;
}
}
- if (noFound == 0)
+ if (noFound == 0) {
throw new CmisQueryException(propName
+ " is not a property query name in any of the types in from ...");
- else if (noFound > 1 && !isStar)
+ } else if (noFound > 1 && !isStar) {
throw new CmisQueryException(propName
+ " is not a unique property query name within the types in from ...");
- else {
- if (null != tdFound) // can be null in select * from t1 JOIN t2....
+ } else {
+ if (null != tdFound) {
validateColumnReferenceAndResolveType(tdFound, colRef);
+ }
}
}
@@ -454,9 +461,10 @@ public class QueryObject {
// either same name or mapped alias
String typeQueryName = getReferencedTypeQueryName(colRef.getQualifier());
TypeDefinition td = typeMgr.getTypeByQueryName(typeQueryName);
- if (null == td)
+ if (null == td) {
throw new CmisQueryException(colRef.getQualifier()
+ " is neither a type query name nor an alias.");
+ }
validateColumnReferenceAndResolveType(td, colRef);
}
@@ -465,13 +473,15 @@ public class QueryObject {
// type found, check if property exists
boolean hasProp;
- if (colRef.getPropertyQueryName().equals("*"))
+ if (colRef.getPropertyQueryName().equals("*")) {
hasProp = true;
- else
+ } else {
hasProp = TypeValidator.typeContainsPropertyWithQueryName(td, colRef.getPropertyQueryName());
- if (!hasProp)
+ }
+ if (!hasProp) {
throw new CmisQueryException(colRef.getPropertyQueryName()
+ " is not a valid property query name in type " + td.getId() + ".");
+ }
colRef.setTypeDefinition(typeMgr.getPropertyIdForQueryName(td, colRef.getPropertyQueryName()), td);
}
@@ -484,12 +494,14 @@ public class QueryObject {
// if an alias was defined but still the original is used we have to
// search case: SELECT T.p FROM T AS TAlias
for (String tqn : froms.values()) {
- if (typeQueryNameOrAlias.equals(tqn))
+ if (typeQueryNameOrAlias.equals(tqn)) {
return tqn;
+ }
}
return null;
- } else
+ } else {
return typeQueryName;
+ }
}
}
Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/query/AbstractParserTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/query/AbstractParserTest.java?rev=1096340&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/query/AbstractParserTest.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/query/AbstractParserTest.java Sun Apr 24 16:12:27 2011
@@ -0,0 +1,202 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.server.support.query;
+
+import static org.junit.Assert.fail;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+
+import org.antlr.runtime.ANTLRStringStream;
+import org.antlr.runtime.BaseRecognizer;
+import org.antlr.runtime.CharStream;
+import org.antlr.runtime.CommonTokenStream;
+import org.antlr.runtime.Lexer;
+import org.antlr.runtime.TokenStream;
+import org.antlr.runtime.tree.CommonTree;
+import org.antlr.stringtemplate.StringTemplate;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * This class is clone of org.antlr.gunit.gUnitBase class adapted to Java style
+ * Because the original class can't deal with composite grammar this is a replacement
+ * working around this antlr bug.
+ *
+ */
+public class AbstractParserTest{
+
+ private static final Log log = LogFactory.getLog(AbstractParserTest.class);
+
+ protected String superGrammarName;
+ Class<?> lexer;
+ Class<?> parser;
+ protected String treeParserPath;
+
+ protected void setUp(Class<?> lexerClass, Class<?> parserClass, String baseGrammar) {
+ lexer = lexerClass;
+ parser = parserClass;
+ this.superGrammarName = baseGrammar;
+ }
+
+ protected void tearDown() {
+ }
+
+ protected void testLexerOk(String rule, String statement) {
+ // test input: "a"
+ try {
+ Object retval = execLexer(rule, statement, false);
+ log.debug("testing rule " + rule + " parsed to: " + retval);
+ } catch (Exception e) {
+ fail("testing rule " + rule + ": " + e.toString());
+ }
+ }
+
+ protected void testLexerFail(String rule, String statement) {
+ // test input: "a"
+ try {
+ Object retval = execLexer(rule, statement, false);
+ fail("testing rule should fail " + rule);
+ } catch (Exception e) {
+ log.debug("testing rule " + rule + " parsed with exception: " + e);
+ }
+ }
+
+ protected void testParserOk(String rule, String statement) {
+ try {
+ Object retval = execParser(rule, statement, false);
+ log.debug("testing rule " + rule + " parsed to: " + retval);
+ } catch (Exception e) {
+ fail("testing rule "+rule + " failed: " + e.toString());
+ }
+ }
+
+ protected void testParserFail(String rule, String statement) {
+ try {
+ Object retval = execParser(rule, statement, false);
+ fail("testing rule should fail " + rule);
+ } catch (Exception e) {
+ log.debug("testing rule "+rule + " failed: " + e.toString());
+ }
+ }
+
+ protected void testParser(String rule, String statement, String expectedResult) {
+ try {
+ Object actual = execParser(rule, statement, false);
+ log.debug("testing rule " + rule + " parsed to: " + actual);
+ } catch (Exception e) {
+ fail("testing rule " + rule + " failed: " + e);
+ }
+ }
+
+
+ // Invoke target lexer.rule
+ public String execLexer(String testRuleName, String testInput, boolean isFile) throws Exception {
+ String result = null;
+ CharStream input;
+ /** Set up ANTLR input stream based on input source, file or String */
+ input = new ANTLRStringStream(testInput);
+
+ /** Use Reflection to create instances of lexer and parser */
+ Class<?>[] lexArgTypes = new Class[]{CharStream.class}; // assign type to lexer's args
+ Constructor<?> lexConstructor = lexer.getConstructor(lexArgTypes);
+ Object[] lexArgs = new Object[]{input}; // assign value to lexer's args
+ Object lexObj = lexConstructor.newInstance(lexArgs); // makes new instance of lexer
+
+ Method ruleName = lexer.getMethod("m"+testRuleName, new Class[0]);
+
+ /** Invoke lexer rule, and get the current index in CharStream */
+ ruleName.invoke(lexObj, new Object[0]);
+ Method ruleName2 = lexer.getMethod("getCharIndex", new Class[0]);
+ int currentIndex = (Integer) ruleName2.invoke(lexObj, new Object[0]);
+ if ( currentIndex!=input.size() ) {
+ throw new RuntimeException("extra text found, '"+input.substring(currentIndex, input.size()-1)+"'");
+// System.out.println("extra text found, '"+input.substring(currentIndex, input.size()-1)+"'");
+ }
+
+ return result;
+ }
+
+ // Invoke target parser.rule
+ public Object execParser(String testRuleName, String testInput, boolean isFile) throws Exception {
+ String result = null;
+ CharStream input;
+ /** Set up ANTLR input stream based on input source, file or String */
+ input = new ANTLRStringStream(testInput);
+
+ /** Use Reflection to create instances of lexer and parser */
+ Class<?>[] lexArgTypes = new Class[]{CharStream.class}; // assign type to lexer's args
+ Constructor<?> lexConstructor = lexer.getConstructor(lexArgTypes);
+ Object[] lexArgs = new Object[]{input}; // assign value to lexer's args
+ Object lexObj = lexConstructor.newInstance(lexArgs); // makes new instance of lexer
+
+ CommonTokenStream tokens = new CommonTokenStream((Lexer) lexObj);
+ Class<?>[] parArgTypes = new Class[]{TokenStream.class}; // assign type to parser's args
+ Constructor<?> parConstructor = parser.getConstructor(parArgTypes);
+ Object[] parArgs = new Object[]{tokens}; // assign value to parser's args
+ Object parObj = parConstructor.newInstance(parArgs); // makes new instance of parser
+
+ Method ruleName = parser.getMethod(testRuleName);
+
+ /** Invoke grammar rule, and store if there is a return value */
+ Object ruleReturn = ruleName.invoke(parObj);
+
+ /** If rule has return value, determine if it contains an AST or a ST */
+ if ( ruleReturn!=null ) {
+ if ( ruleReturn.getClass().toString().indexOf(testRuleName+"_return")>0 ) {
+ try { // NullPointerException may happen here...
+ String classPath = parser.getName();
+ if (null != superGrammarName) {
+ classPath += "_" + superGrammarName;
+ }
+ Class<?> _return = Class.forName(classPath+"$"+testRuleName+"_return");
+ Method[] methods = _return.getDeclaredMethods();
+ for(Method method : methods) {
+ if ( method.getName().equals("getTree") ) {
+ Method returnName = _return.getMethod("getTree");
+ CommonTree tree = (CommonTree) returnName.invoke(ruleReturn);
+ result = tree.toStringTree();
+ }
+ else if ( method.getName().equals("getTemplate") ) {
+ Method returnName = _return.getMethod("getTemplate");
+ StringTemplate st = (StringTemplate) returnName.invoke(ruleReturn);
+ result = st.toString();
+ }
+ }
+ }
+ catch(Exception e) {
+ throw(e); // Note: If any exception occurs, the test is viewed as failed.
+ }
+ }
+ }
+
+
+ /** Invalid input */
+ if ( tokens.index()!=tokens.size() ) {
+ throw new RuntimeException("Invalid input.");
+ }
+
+ /** Check for syntax errors */
+ if (((BaseRecognizer)parObj).getNumberOfSyntaxErrors() > 0) {
+ throw new RuntimeException("Syntax error occured");
+ }
+ return result;
+ }
+
+ }
Propchange: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/query/AbstractParserTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/query/AbstractParserTest.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/query/TestParserExt.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/query/TestParserExt.java?rev=1096340&r1=1096339&r2=1096340&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/query/TestParserExt.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/query/TestParserExt.java Sun Apr 24 16:12:27 2011
@@ -24,7 +24,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-public class TestParserExt extends AbstractParserTst {
+public class TestParserExt extends AbstractParserTest {
private static final Log log = LogFactory.getLog(TestParserStrict.class);
@@ -33,24 +33,25 @@ public class TestParserExt extends Abstr
super.setUp(CmisQlStrictLexer.class, CmisQlExtParser.class, null);
}
+ @Override
@After
- public void tearDown() throws Exception {
+ public void tearDown() {
super.tearDown();
}
@Test
- public void test_predicate1() throws Exception {
+ public void test_predicate1() {
testParser("value_expression", "LOWER(foo)", "(FUNC LOWER (COL foo))");
}
@Test
- public void test_query1() throws Exception {
+ public void test_query1() {
testParser("query", "SELECT DISTINCT a, b, c FROM Document", "(SELECT DISTINCT (LIST (COL a) (COL b) (COL c)) (FROM (TABLE Document)))");
}
-
+
@Test
- public void test_query2() throws Exception {
- testParserOk("query",
+ public void test_query2() {
+ testParserOk("query",
"SELECT Y.CLAIM_NUM, X.PROPERTY_ADDRESS, Y.DAMAGE_ESTIMATES " +
"FROM POLICY AS X JOIN CLAIMS AS Y ON X.POLICY_NUM = Y.POLICY_NUM " +
" WHERE ( 100000 <= ANY Y.DAMAGE_ESTIMATES ) AND ( Y.CAUSE NOT LIKE '%Katrina%' )");
@@ -58,10 +59,10 @@ public class TestParserExt extends Abstr
@Test
- public void test_query3() throws Exception {
- testParserOk("query",
+ public void test_query3() {
+ testParserOk("query",
"SELECT OBJECT_ID, SCORE() AS X, DESTINATION, DEPARTURE_DATES " +
"FROM TRAVEL_BROCHURE " +
- "WHERE ( CONTAINS('CARIBBEAN CENTRAL AMERICA CRUISE TOUR') ) AND( '2010-1-1' < ANY DEPARTURE_DATES )");
+ "WHERE ( CONTAINS('CARIBBEAN CENTRAL AMERICA CRUISE TOUR') ) AND( '2010-1-1' < ANY DEPARTURE_DATES )");
}
}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/query/TestParserStrict.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/query/TestParserStrict.java?rev=1096340&r1=1096339&r2=1096340&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/query/TestParserStrict.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/test/java/org/apache/chemistry/opencmis/server/support/query/TestParserStrict.java Sun Apr 24 16:12:27 2011
@@ -28,37 +28,37 @@ import org.junit.Test;
* @author Jens
*
*/
-public class TestParserStrict extends AbstractParserTst{
+public class TestParserStrict extends AbstractParserTest{
private static final Log log = LogFactory.getLog(TestParserStrict.class);
@Before
- public void setUp() throws Exception {
+ public void setUp() {
super.setUp(CmisQlStrictLexer.class, CmisQlStrictParser.class, "CmisBaseGrammar");
}
+ @Override
@After
- public void tearDown() throws Exception {
+ public void tearDown() {
super.tearDown();
}
-
// ----- Lexer tests -----
// ID:
@Test
- public void testID1() throws Exception {
+ public void testID1() {
testLexerOk("ID", "a");
}
-
+
// "toto" OK
@Test
- public void testID2() throws Exception {
+ public void testID2() {
testLexerFail("ID", "!");
}
@Test
- public void testID3() throws Exception {
+ public void testID3() {
testLexerOk("ID", "toto");
}
@@ -73,7 +73,7 @@ public class TestParserStrict extends Ab
public void testID5() throws Exception {
testLexerOk("ID", "toto123_");
}
-
+
// "_foo" OK
@Test
public void testID6() throws Exception {
@@ -103,133 +103,133 @@ public class TestParserStrict extends Ab
public void testNUM_LIT1() throws Exception {
testLexerOk("NUM_LIT", "123");
}
-
+
// "0" OK
@Test
public void testNUM_LIT2() throws Exception {
testLexerOk("NUM_LIT", "0");
}
-
+
// "-0" OK
@Test
public void testNUM_LIT3() throws Exception {
testLexerOk("NUM_LIT", "-0");
}
-
+
// "1" OK
@Test
public void testNUM_LIT4() throws Exception {
testLexerOk("NUM_LIT", "1");
}
-
+
// "-1" OK
@Test
public void testNUM_LIT5() throws Exception {
testLexerOk("NUM_LIT", "-1");
}
-
+
// "-123" OK
@Test
public void testNUM_LIT6() throws Exception {
testLexerOk("NUM_LIT", "123");
}
-
+
// "0123" OK
@Test
public void testNUM_LIT7() throws Exception {
testLexerOk("NUM_LIT", "0123");
}
-
+
// "-0123" OK
@Test
public void testNUM_LIT8() throws Exception {
testLexerOk("NUM_LIT", "-0123");
}
-
+
// "123abc" FAIL
@Test
public void testNUM_LIT9() throws Exception {
testLexerFail("NUM_LIT", "123abc");
}
-
+
// "123E" FAIL
@Test
public void testNUM_LIT10() throws Exception {
testLexerFail("NUM_LIT", "123E");
}
-
+
// "123.456" OK
@Test
public void testNUM_LIT11() throws Exception {
testLexerOk("NUM_LIT", "123.456");
}
-
+
// "+123.456" OK
@Test
public void testNUM_LIT12() throws Exception {
testLexerOk("NUM_LIT", "+123.456");
}
-
+
// "-123.456" OK
@Test
public void testNUM_LIT13() throws Exception {
testLexerOk("NUM_LIT", "-123.456");
}
-
+
// ".456" OK
@Test
public void testNUM_LIT14() throws Exception {
testLexerOk("NUM_LIT", ".456");
}
-
+
// "+.456" OK
@Test
public void testNUM_LIT15() throws Exception {
testLexerOk("NUM_LIT", "+.456");
}
-
+
// "-.456" OK
@Test
public void testNUM_LIT16() throws Exception {
testLexerOk("NUM_LIT", "-.456");
}
-
+
// "123." OK
@Test
public void testNUM_LIT17() throws Exception {
testLexerOk("NUM_LIT", "123.");
}
-
+
// "+123." OK
@Test
public void testNUM_LIT18() throws Exception {
testLexerOk("NUM_LIT", "+123.");
}
-
+
// "-123." OK
@Test
public void testNUM_LIT19() throws Exception {
testLexerOk("NUM_LIT", "-123.");
}
-
+
// "+123.456E78" OK
@Test
public void testNUM_LIT20() throws Exception {
testLexerOk("NUM_LIT", "+123.456E78");
}
-
+
// "-123.456E-78" OK
@Test
public void testNUM_LIT21() throws Exception {
testLexerOk("NUM_LIT", "-123.456E-78");
}
-
+
// ".456E78" OK
@Test
public void testNUM_LIT22() throws Exception {
testLexerOk("NUM_LIT", ".456E78");
}
-
+
// "+123.E+78" OK
@Test
public void testNUM_LIT23() throws Exception {
@@ -242,31 +242,31 @@ public class TestParserStrict extends Ab
public void testSTRING_LIT1() throws Exception {
testLexerOk("STRING_LIT", "'abc'");
}
-
+
// "'a''bc'" OK
@Test
public void testSTRING_LIT2() throws Exception {
testLexerOk("STRING_LIT", "'a''bc'");
}
-
+
// "'abc" FAIL
@Test
public void testSTRING_LIT3() throws Exception {
testLexerFail("STRING_LIT", "'abc");
}
-
+
// "abc'" FAIL
@Test
public void testSTRING_LIT4() throws Exception {
testLexerFail("STRING_LIT", "abc'");
}
-
+
// "'ab'c'" FAIL
@Test
public void testSTRING_LIT5() throws Exception {
testLexerFail("STRING_LIT", "'ab'c'");
}
-
+
// BOOL_LIT:
// "TRUE" OK
@@ -274,25 +274,25 @@ public class TestParserStrict extends Ab
public void testBOOL_LIT1() throws Exception {
testLexerOk("BOOL_LIT", "TRUE");
}
-
+
// "true" OK
@Test
public void testSBOOL_LIT2() throws Exception {
testLexerOk("BOOL_LIT", "true");
}
-
+
// "FALSE" OK
@Test
public void testBOOL_LIT3() throws Exception {
testLexerOk("BOOL_LIT", "FALSE");
}
-
+
// "false" OK
@Test
public void testBOOL_LIT4() throws Exception {
testLexerOk("BOOL_LIT", "false");
}
-
+
// TIME_LIT:
// "TIMESTAMP '2010-01-01Z01:01:01.000Z'" OK
@@ -300,19 +300,19 @@ public class TestParserStrict extends Ab
public void testTIME_LIT1() throws Exception {
testLexerOk("TIME_LIT", "TIMESTAMP '2010-01-01Z01:01:01.000Z'");
}
-
+
// "timestamp '123'" OK
@Test
public void testTIME_LIT2() throws Exception {
testLexerOk("TIME_LIT", "timestamp '123'");
}
-
+
// "TIMESTAMP 123" FAIL
@Test
public void testTIME_LIT3() throws Exception {
testLexerFail("TIME_LIT", "TIMESTAMP 123");
}
-
+
// ----- Parser tests -----
@@ -322,44 +322,44 @@ public class TestParserStrict extends Ab
public void testLiteral1() throws Exception {
testParserOk("literal", "123");
}
-
+
// "-123" OK
@Test
public void testLiteral2() throws Exception {
testParserOk("literal", "123");
}
-
+
// "0" OK
@Test
public void testLiteral3() throws Exception {
testParserOk("literal", "0");
}
-
+
// "0123" OK
@Test
public void testLiteral4() throws Exception {
testParserOk("literal", "0123");
}
-
+
// "abc123" OK
// "123abc" FAIL
@Test
public void testLiteral5() throws Exception {
testParserFail("literal", "123abc");
}
-
+
// "'abc'" OK
@Test
public void testLiteral6() throws Exception {
testParserOk("literal", "'abc'");
}
-
+
// "123.345E78" OK
@Test
public void testLiteral7() throws Exception {
testParserOk("literal", "123.345E78");
}
-
+
// order_by_clause:
// "ORDER BY foo" -> (ORDER_BY (COL foo) ASC)
@@ -367,25 +367,25 @@ public class TestParserStrict extends Ab
public void testOrderBy1() throws Exception {
testParser("order_by_clause", "ORDER BY foo", "(ORDER_BY (COL foo) ASC)");
}
-
+
// "ORDER BY foo ASC" -> (ORDER_BY (COL foo) ASC)
@Test
public void testOrderBy2() throws Exception {
testParser("order_by_clause", "ORDER BY foo ASC", "ORDER_BY (COL foo) ASC)");
}
-
+
// "ORDER BY foo DESC" -> (ORDER_BY (COL foo) DESC)
@Test
public void testOrderBy3() throws Exception {
testParser("order_by_clause", "ORDER BY foo DESC", "(ORDER_BY (COL foo) DESC)");
}
-
+
// "ORDER BY t.foo, bar DESC" -> (ORDER_BY (COL t foo) ASC (COL bar) DESC)
@Test
public void testOrderBy4() throws Exception {
testParser("order_by_clause", "ORDER BY t.foo, bar DESC", "(ORDER_BY (COL t foo) ASC (COL bar) DESC)");
}
-
+
// column_reference:
// "foo" -> (COL foo)
@@ -393,13 +393,13 @@ public class TestParserStrict extends Ab
public void test_column_reference1() throws Exception {
testParser("column_reference", "foo", "(COL foo)");
}
-
+
// "bar.foo" -> (COL bar foo)
@Test
public void test_column_reference2() throws Exception {
testParser("column_reference", "bar.foo", "(COL bar foo)");
}
-
+
// from_clause:
// "FROM foo JOIN bar ON x = y" -> (FROM (TABLE foo) (JOIN INNER (TABLE bar) (ON (COL x) = (COL y))))
@@ -414,26 +414,26 @@ public class TestParserStrict extends Ab
public void test_column_reference11() throws Exception {
testParser("table_join", "LEFT OUTER JOIN foo ON x = y", "(JOIN LEFT (TABLE foo) (ON (COL x) = (COL y)))");
}
-
+
// "INNER JOIN foo" -> (JOIN INNER (TABLE foo))
@Test
public void test_column_reference12() throws Exception {
testParser("table_join", "INNER JOIN foo" , "(JOIN INNER (TABLE foo))");
}
-// one_table:
+// one_table:
// "foo" -> (TABLE foo)
@Test
public void test_column_reference3() throws Exception {
testParser("one_table", "foo", "(TABLE foo)");
}
-
+
// "foo bar" -> (TABLE foo bar)
@Test
public void test_column_reference4() throws Exception {
testParser("one_table", "foo bar", "(TABLE foo bar)");
}
-
+
// "foo AS bar" -> (TABLE foo bar)
@Test
public void test_column_reference5() throws Exception {
@@ -635,7 +635,7 @@ public class TestParserStrict extends Ab
// >> -> (SELECT * (FROM (TABLE Document)) (WHERE (= (COL foo) 1)))
@Test
public void query1() throws Exception {
- testParser("query", "SELECT * FROM Document WHERE foo = 1",
+ testParser("query", "SELECT * FROM Document WHERE foo = 1",
"(SELECT * (FROM (TABLE Document)) (WHERE (= (COL foo) 1)))");
}
@@ -659,7 +659,7 @@ public class TestParserStrict extends Ab
// >> -> (SELECT (SEL_LIST (COL TITLE) (COL AUTHORS) (COL DATE)) (FROM (TABLE WHITE_PAPER)) (WHERE (AND (IN_TREE 'ID00093854763') (EQ_ANY 'SMITH' (COL AUTHORS)))))
@Test
public void query3() throws Exception {
- testParser("query",
+ testParser("query",
"SELECT TITLE, AUTHORS, DATE " +
"FROM WHITE_PAPER " +
"WHERE ( IN_TREE('ID00093854763') ) AND ( 'SMITH' = ANY AUTHORS )",
@@ -674,7 +674,7 @@ public class TestParserStrict extends Ab
// >> OK
@Test
public void query4() throws Exception {
- testParserOk("query",
+ testParserOk("query",
"SELECT Y.CLAIM_NUM, X.PROPERTY_ADDRESS, Y.DAMAGE_ESTIMATES " +
"FROM POLICY AS X JOIN CLAIMS AS Y ON X.POLICY_NUM = Y.POLICY_NUM " +
"WHERE ( 100000 = ANY Y.DAMAGE_ESTIMATES ) AND ( Y.CAUSE NOT LIKE '%Katrina%' )");
@@ -688,7 +688,7 @@ public class TestParserStrict extends Ab
// >> FAIL
@Test
public void query5() throws Exception {
- testParserFail("query",
+ testParserFail("query",
"SELECT Y.CLAIM_NUM, X.PROPERTY_ADDRESS, Y.DAMAGE_ESTIMATES " +
"FROM POLICY AS X JOIN CLAIMS AS Y ON X.POLICY_NUM = Y.POLICY_NUM " +
" WHERE ( 100000 <= ANY Y.DAMAGE_ESTIMATES ) AND ( Y.CAUSE NOT LIKE '%Katrina%' )");
@@ -715,9 +715,9 @@ public class TestParserStrict extends Ab
// >> OK
@Test
public void query7() throws Exception {
- testParserOk("query",
+ testParserOk("query",
"SELECT OBJECT_ID, SCORE() AS X, DESTINATION, DEPARTURE_DATES " +
"FROM TRAVEL_BROCHURE " +
- "WHERE ( CONTAINS('CARIBBEAN CENTRAL AMERICA CRUISE TOUR') ) AND( '2010-1-1' = ANY DEPARTURE_DATES )");
+ "WHERE ( CONTAINS('CARIBBEAN CENTRAL AMERICA CRUISE TOUR') ) AND( '2010-1-1' = ANY DEPARTURE_DATES )");
}
}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-browser/src/main/java/org/apache/chemistry/opencmis/browser/BrowseServlet.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-browser/src/main/java/org/apache/chemistry/opencmis/browser/BrowseServlet.java?rev=1096340&r1=1096339&r2=1096340&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-browser/src/main/java/org/apache/chemistry/opencmis/browser/BrowseServlet.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-browser/src/main/java/org/apache/chemistry/opencmis/browser/BrowseServlet.java Sun Apr 24 16:12:27 2011
@@ -387,7 +387,7 @@ public class BrowseServlet extends HttpS
* Prints a HTML error message.
*/
private void printError(HttpServletRequest req, HttpServletResponse resp, String message, Exception e)
- throws ServletException, IOException {
+ throws IOException {
resp.setContentType("text/html;charset=utf-8");
PrintWriter pw = resp.getWriter();
@@ -408,7 +408,7 @@ public class BrowseServlet extends HttpS
/**
* Prints an HTML input box.
*/
- private void printInput(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ private void printInput(HttpServletRequest req, HttpServletResponse resp) throws IOException {
resp.setContentType("text/html;charset=utf-8");
PrintWriter pw = resp.getWriter();
Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/MultiThreadedObjectGenerator.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/MultiThreadedObjectGenerator.java?rev=1096340&r1=1096339&r2=1096340&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/MultiThreadedObjectGenerator.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/MultiThreadedObjectGenerator.java Sun Apr 24 16:12:27 2011
@@ -31,6 +31,9 @@ public class MultiThreadedObjectGenerato
CreateDocument, CreateTree, CreateFolders
}
+ private MultiThreadedObjectGenerator() {
+ }
+
static class ObjectGeneratorRunner implements Runnable {
private final Action fAction;
ObjectGenerator fObjGen;
@@ -99,8 +102,9 @@ public class MultiThreadedObjectGenerato
RepositoryService repSvc = binding.getRepositoryService();
RepositoryInfo rep = repSvc.getRepositoryInfo(repositoryId, null);
- if (null == rootFolderId || rootFolderId.length() == 0)
+ if (null == rootFolderId || rootFolderId.length() == 0) {
rootFolderId = rep.getRootFolderId();
+ }
return rootFolderId;
}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/ObjGenApp.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/ObjGenApp.java?rev=1096340&r1=1096339&r2=1096340&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/ObjGenApp.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/ObjGenApp.java Sun Apr 24 16:12:27 2011
@@ -40,6 +40,7 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.spi.RepositoryService;
public class ObjGenApp {
+
public static final String DEFAULT_USER = "";
public static final String DEFAULT_PWD = "";
public static final String PROP_ATOMPUB_URL = "opencmis.test.atompub.url";
@@ -128,8 +129,9 @@ public class ObjGenApp {
OptionSet options = parser.parse(args);
- if (options.valueOf(fCmd) == null || options.has("?"))
+ if (options.valueOf(fCmd) == null || options.has("?")) {
usage(parser);
+ }
if (options.valueOf(fBinding).equals(BINDING_WS)) {
fUsingAtom = false;
@@ -172,7 +174,7 @@ public class ObjGenApp {
// logger.printTimes();
// }
- private void usage(OptionParser parser) {
+ private static void usage(OptionParser parser) {
try {
System.out.println();
System.out.println("ObjGenApp is a command line tool for testing a CMIS repository.");
@@ -183,12 +185,11 @@ public class ObjGenApp {
System.out.println("JVM system properties: " + PROP_ATOMPUB_URL + ", " + PROP_WS_URL);
System.out.println();
System.out.println("Example: ");
- System.out
- .println("java -D"
- + PROP_ATOMPUB_URL
- + "=http://localhost:8080/opencmis/atom -cp ... "
- + "org.apache.chemistry.opencmis.util.repository.ObjGenApp --Binding=AtomPub --Command=CreateDocument "
- + "--RepositoryId=A1 --ContentSizeInKB=25");
+ System.out.println("java -D"
+ + PROP_ATOMPUB_URL
+ + "=http://localhost:8080/opencmis/atom -cp ... "
+ + "org.apache.chemistry.opencmis.util.repository.ObjGenApp --Binding=AtomPub --Command=CreateDocument "
+ + "--RepositoryId=A1 --ContentSizeInKB=25");
return;
} catch (IOException e) {
e.printStackTrace();
@@ -231,10 +232,11 @@ public class ObjGenApp {
}
private void printParameters(OptionSet options) {
- if (fUsingAtom)
+ if (fUsingAtom) {
System.out.println("Using AtomPub, connecting to " + getAtomPubUrl());
- else
+ } else {
System.out.println("Using WebService, connecting to " + getWsUrl());
+ }
System.out.println("Repository id is: " + options.valueOf(fRepoId));
System.out.println("Content size: " + options.valueOf(fContentSize));
@@ -250,13 +252,14 @@ public class ObjGenApp {
System.out.println("Creating document with parameters:");
printParameters(options);
int noThreads = options.valueOf(fThreads);
- if (noThreads <= 1)
+ if (noThreads <= 1) {
createSingleDocument(options.valueOf(fRepoId), options.valueOf(fDocType), options.valueOf(fContentSize),
options.valueOf(fRootFolder), options.valueOf(fCount), options.valueOf(fCleanup));
- else
+ } else {
createSingleDocumentMT(noThreads, options.valueOf(fRepoId), options.valueOf(fDocType), options
.valueOf(fContentSize), options.valueOf(fRootFolder), options.valueOf(fCount), options
.valueOf(fCleanup));
+ }
}
private void fillRepository(OptionSet options) {
@@ -269,16 +272,17 @@ public class ObjGenApp {
System.out.println("Folder Type: " + options.valueOf(fFolderType));
int noThreads = options.valueOf(fThreads);
- if (noThreads <= 1)
+ if (noThreads <= 1) {
fillRepository(options.valueOf(fRepoId), options.valueOf(fDocsPerFolder),
options.valueOf(fFolderPerFolder), options.valueOf(fDepth), options.valueOf(fDocType), options
.valueOf(fFolderType), options.valueOf(fContentSize), options.valueOf(fRootFolder), options
.valueOf(fCleanup));
- else
+ } else {
fillRepositoryMT(noThreads, options.valueOf(fRepoId), options.valueOf(fDocsPerFolder), options
.valueOf(fFolderPerFolder), options.valueOf(fDepth), options.valueOf(fDocType), options
.valueOf(fFolderType), options.valueOf(fContentSize), options.valueOf(fRootFolder), options
.valueOf(fCleanup));
+ }
}
@@ -288,12 +292,13 @@ public class ObjGenApp {
printParameters(options);
System.out.println("Folder Type: " + options.valueOf(fFolderType));
int noThreads = options.valueOf(fThreads);
- if (noThreads <= 1)
+ if (noThreads <= 1) {
createFolders(options.valueOf(fRepoId), options.valueOf(fFolderType), options.valueOf(fRootFolder), options
.valueOf(fCount), options.valueOf(fCleanup));
- else
+ } else {
createFoldersMT(noThreads, options.valueOf(fRepoId), options.valueOf(fFolderType), options
.valueOf(fRootFolder), options.valueOf(fCount), options.valueOf(fCleanup));
+ }
}
private void createSingleDocument(String repoId, String documentType, int contentSizeInKB, String rootFolderId,
@@ -309,11 +314,13 @@ public class ObjGenApp {
System.out.println("Document creation succeeded.");
System.out.println("Folder used as root for creation: " + rootFolderId);
System.out.println("Ids of created documents: ");
- if (null == ids)
+ if (null == ids) {
System.out.println("<none>");
- else
- for (int i = 0; i < ids.length; i++)
+ } else {
+ for (int i = 0; i < ids.length; i++) {
System.out.println(ids[i]);
+ }
+ }
gen.printTimings();
gen.resetCounters();
}
@@ -339,11 +346,13 @@ public class ObjGenApp {
System.out.println("Result:");
System.out.println("Folder creation succeeded.");
System.out.println("Ids of created folders: ");
- if (null == ids)
+ if (null == ids) {
System.out.println("<none>");
- else
- for (int i = 0; i < ids.length; i++)
+ } else {
+ for (int i = 0; i < ids.length; i++) {
System.out.println(ids[i]);
+ }
+ }
gen.printTimings();
gen.resetCounters();
}
@@ -378,19 +387,22 @@ public class ObjGenApp {
private CmisBinding getBinding() {
if (binding == null) {
- if (fUsingAtom)
+ if (fUsingAtom) {
binding = createAtomBinding(getAtomPubUrl(), DEFAULT_USER, DEFAULT_PWD);
- else
+ } else {
binding = createWsBinding(getWsUrl(), DEFAULT_USER, DEFAULT_PWD);
+ }
}
return binding;
}
private static void filLoginParams(Map<String, String> parameters, String user, String password) {
- if (user != null && user.length() > 0)
+ if (user != null && user.length() > 0) {
parameters.put(SessionParameter.USER, user);
- if (user != null && user.length() > 0)
+ }
+ if (user != null && user.length() > 0) {
parameters.put(SessionParameter.PASSWORD, password);
+ }
}
private static CmisBinding createAtomBinding(String url, String user, String password) {
@@ -483,8 +495,9 @@ public class ObjGenApp {
r = new BufferedReader(isr);
do {
str = r.readLine();
- if (str != null)
+ if (str != null) {
System.out.println(str);
+ }
} while (str != null);
} catch (MalformedURLException e) {
System.out.println("Must enter a valid URL" + e);
Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/ObjectGenerator.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/ObjectGenerator.java?rev=1096340&r1=1096339&r2=1096340&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/ObjectGenerator.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/ObjectGenerator.java Sun Apr 24 16:12:27 2011
@@ -52,9 +52,9 @@ import org.apache.commons.logging.LogFac
/**
* A simple helper class for the tests that generates a sample folder hierarchy
* and optionally documents in it.
- *
+ *
* @author Jens
- *
+ *
*/
public class ObjectGenerator {
@@ -193,8 +193,9 @@ public class ObjectGenerator {
fTopLevelFoldersCreated.clear();
fTopLevelDocsCreated.clear();
createFolderHierachy(rootFolderId, 0, levels, childrenPerLevel);
- if (fCleanup)
+ if (fCleanup) {
deleteTree();
+ }
}
public void setUseUuidsForNames(boolean useUuids) {
@@ -207,7 +208,7 @@ public class ObjectGenerator {
/**
* retrieve the index-th folder from given level of the hierarchy starting
* at rootId
- *
+ *
* @param rootId
* @param level
* @param index
@@ -231,7 +232,7 @@ public class ObjectGenerator {
/**
* retrieve the index-th document from given folder
- *
+ *
* @param folderId
* folder to retrieve document from
* @param index
@@ -251,10 +252,11 @@ public class ObjectGenerator {
ObjectData child = children.get(i).getObject();
docId = (String) child.getProperties().getProperties().get(PropertyIds.OBJECT_ID).getFirstValue();
if (child.getBaseTypeId().equals(BaseTypeId.CMIS_DOCUMENT)) {
- if (numDocsFound == index)
+ if (numDocsFound == index) {
return docId;
- else
+ } else {
numDocsFound++;
+ }
}
}
return docId;
@@ -262,7 +264,7 @@ public class ObjectGenerator {
/**
* return the total number of documents created
- *
+ *
* @return
*/
public int getDocumentsInTotal() {
@@ -271,7 +273,7 @@ public class ObjectGenerator {
/**
* return the total number of folders created
- *
+ *
* @return
*/
public int getFoldersInTotal() {
@@ -280,8 +282,6 @@ public class ObjectGenerator {
/**
* return the total number of objects created
- *
- * @return
*/
public int getObjectsInTotal() {
return fDocumentsInTotalCount + fFoldersInTotalCount;
@@ -290,8 +290,9 @@ public class ObjectGenerator {
public String createSingleDocument(String folderId) {
fTimeLoggerCreateDoc.reset();
String objectId = createDocument(folderId, 0, 0);
- if (fCleanup)
+ if (fCleanup) {
deleteObject(objectId);
+ }
return objectId;
}
@@ -309,8 +310,9 @@ public class ObjectGenerator {
result = null;
} else {
result = new String[count];
- for (int i = 0; i < fTopLevelDocsCreated.size(); i++)
+ for (int i = 0; i < fTopLevelDocsCreated.size(); i++) {
result[i] = fTopLevelDocsCreated.get(i);
+ }
}
return result;
}
@@ -328,8 +330,9 @@ public class ObjectGenerator {
result = null;
} else {
result = new String[count];
- for (int i = 0; i < fTopLevelFoldersCreated.size(); i++)
+ for (int i = 0; i < fTopLevelFoldersCreated.size(); i++) {
result[i] = fTopLevelFoldersCreated.get(i);
+ }
}
return result;
}
@@ -341,22 +344,25 @@ public class ObjectGenerator {
public void printTimings() {
fTimeLoggerCreateDoc.printTimes();
fTimeLoggerCreateFolder.printTimes();
- if (fCleanup)
+ if (fCleanup) {
fTimeLoggerDelete.printTimes();
+ }
}
public void logTimings() {
fTimeLoggerCreateDoc.logTimes();
fTimeLoggerCreateFolder.logTimes();
- if (fCleanup)
+ if (fCleanup) {
fTimeLoggerDelete.logTimes();
+ }
}
private void createFolderHierachy(String parentId, int level, int levels, int childrenPerLevel) {
String id = null;
- if (level >= levels)
+ if (level >= levels) {
return;
+ }
log.debug(" create folder for parent id: " + parentId + ", in level " + level + ", max levels " + levels);
@@ -365,8 +371,9 @@ public class ObjectGenerator {
try {
fTimeLoggerCreateFolder.start();
id = fObjSvc.createFolder(fRepositoryId, props, parentId, null, null, null, null);
- if (level == 0)
+ if (level == 0) {
fTopLevelFoldersCreated.add(id);
+ }
} finally {
fTimeLoggerCreateFolder.stop();
}
@@ -378,8 +385,9 @@ public class ObjectGenerator {
}
for (int j = 0; j < fNoDocumentsToCreate; j++) {
id = createDocument(parentId, j, level);
- if (level == 0)
+ if (level == 0) {
fTopLevelDocsCreated.add(id);
+ }
}
}
@@ -407,8 +415,9 @@ public class ObjectGenerator {
// log.info("create document in folder " + folderId);
Properties props = createDocumentProperties(no, level);
String id = null;
- if (fContentSizeInK > 0)
+ if (fContentSizeInK > 0) {
contentStream = createContent();
+ }
try {
fTimeLoggerCreateDoc.start();
id = fObjSvc.createDocument(fRepositoryId, props, folderId, contentStream, versioningState, policies,
@@ -417,8 +426,9 @@ public class ObjectGenerator {
fTimeLoggerCreateDoc.stop();
}
- if (null == id)
+ if (null == id) {
throw new RuntimeException("createDocument failed.");
+ }
++fDocumentsInTotalCount;
return id;
}
@@ -462,8 +472,9 @@ public class ObjectGenerator {
try {
for (int j = 0; j < fContentSizeInK; j++) {
// write 1K of data
- for (int i = 0; i < 32; i++)
+ for (int i = 0; i < 32; i++) {
ba.write(b);
+ }
}
} catch (IOException e) {
throw new RuntimeException("Failed to fill content stream with data", e);
@@ -505,17 +516,19 @@ public class ObjectGenerator {
}
private String generateDocNameValue(int no, int level) {
- if (fUseUuids)
+ if (fUseUuids) {
return UUID.randomUUID().toString();
- else
+ } else {
return NAMEPROPVALPREFIXDOC + level + "-" + no;
+ }
}
private String generateFolderNameValue(int no, int level) {
- if (fUseUuids)
+ if (fUseUuids) {
return UUID.randomUUID().toString();
- else
+ } else {
return NAMEPROPVALPREFIXFOLDER + level + "-" + no;
+ }
}
private String generateStringPropValueDoc() {
@@ -546,8 +559,9 @@ public class ObjectGenerator {
// be
// optimized
StringBuilder prefix = new StringBuilder();
- for (int i = 0; i < depth; i++)
+ for (int i = 0; i < depth; i++) {
prefix.append(" ");
+ }
ObjectInFolderList result = fNavSvc.getChildren(fRepositoryId, folderId, propertyFilter, null, false,
IncludeRelationships.NONE, null, true, BigInteger.valueOf(-1), BigInteger.valueOf(-1), null);
@@ -574,8 +588,9 @@ public class ObjectGenerator {
private void dumpObjectProperties(ObjectData object, int depth, String propertyFilter, boolean mustFetchProperties) {
final SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
StringBuilder prefix = new StringBuilder();
- for (int i = 0; i < depth; i++)
+ for (int i = 0; i < depth; i++) {
prefix.append(" ");
+ }
log.info(prefix + "found object id " + object.getId());
Map<String, PropertyData<?>> propMap;
Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/TimeLogger.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/TimeLogger.java?rev=1096340&r1=1096339&r2=1096340&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/TimeLogger.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/TimeLogger.java Sun Apr 24 16:12:27 2011
@@ -25,9 +25,9 @@ import org.apache.commons.logging.LogFac
/**
* Simple utility class for time logging Note: NOT thread safe!
- *
+ *
* @author Jens
- *
+ *
*/
public class TimeLogger {
private static final Log LOG = LogFactory.getLog(TimeLogger.class);
@@ -66,11 +66,11 @@ public class TimeLogger {
public void logTimes() {
long size = fTimeRecs.size();
- if (size == 0)
+ if (size == 0) {
LOG.info("No samples for " + fAction + " available. ");
- else if (size == 1)
+ } else if (size == 1) {
LOG.info("Time elapsed for " + fAction + ": " + getLastTime());
- else {
+ } else {
LOG.info("Timings for " + size + " samples for action " + fAction + ": ");
LOG.info(" Average: " + getAverageTime() + "ms");
LOG.info(" Min : " + getMinTime() + "ms");
@@ -81,11 +81,11 @@ public class TimeLogger {
public void printTimes() {
long size = fTimeRecs.size();
- if (size == 0)
+ if (size == 0) {
System.out.println("No samples for " + fAction + " available. ");
- else if (size == 1)
+ } else if (size == 1) {
System.out.println("Time elapsed for " + fAction + ": " + getLastTime());
- else {
+ } else {
System.out.println("Timings for " + size + " samples for action " + fAction + ": ");
System.out.println(" Average: " + getAverageTime() + "ms");
System.out.println(" Min : " + getMinTime() + "ms");
@@ -96,10 +96,11 @@ public class TimeLogger {
public long getLastTime() {
TimeRecord lastRec = fTimeRecs.getLast();
- if (null != lastRec)
+ if (null != lastRec) {
return lastRec.fStop - lastRec.fStart;
- else
+ } else {
return 0;
+ }
}
private void createAndAddNewRecord() {
@@ -113,8 +114,9 @@ public class TimeLogger {
long sum = 0;
long size = fTimeRecs.size();
- if (0 == fTimeRecs.size())
+ if (0 == fTimeRecs.size()) {
return 0;
+ }
for (TimeRecord tm : fTimeRecs) {
sum += tm.fStop - tm.fStart;
@@ -125,13 +127,15 @@ public class TimeLogger {
private long getMinTime() {
long min = Long.MAX_VALUE;
- if (0 == fTimeRecs.size())
+ if (0 == fTimeRecs.size()) {
return 0;
+ }
for (TimeRecord tm : fTimeRecs) {
long val = tm.fStop - tm.fStart;
- if (val < min)
+ if (val < min) {
min = val;
+ }
}
return min;
@@ -140,13 +144,15 @@ public class TimeLogger {
private long getMaxTime() {
long max = Long.MIN_VALUE;
- if (0 == fTimeRecs.size())
+ if (0 == fTimeRecs.size()) {
return 0;
+ }
for (TimeRecord tm : fTimeRecs) {
long val = tm.fStop - tm.fStart;
- if (val > max)
+ if (val > max) {
max = val;
+ }
}
return max;
}
@@ -167,11 +173,13 @@ public class TimeLogger {
public static void logTimes(TimeLogger[] loggers) {
long size = 0;
- if (null == loggers)
+ if (null == loggers) {
return;
+ }
- for (int i = 0; i < loggers.length; i++)
+ for (int i = 0; i < loggers.length; i++) {
size += loggers[i].fTimeRecs.size();
+ }
LOG.info("Timings for " + size + " samples for action " + loggers[0].fAction + ": ");
LOG.info(" Average: " + getAverageTime(loggers) + "ms");
@@ -182,11 +190,13 @@ public class TimeLogger {
public static void printTimes(TimeLogger[] loggers) {
long size = 0;
- if (null == loggers)
+ if (null == loggers) {
return;
+ }
- for (int i = 0; i < loggers.length; i++)
+ for (int i = 0; i < loggers.length; i++) {
size += loggers[i].fTimeRecs.size();
+ }
System.out.println("Timings for " + size + " samples for action " + loggers[0].fAction + ": ");
System.out.println(" Average: " + getAverageTime(loggers) + "ms");
@@ -200,15 +210,18 @@ public class TimeLogger {
long sum = 0;
long size = 0;
- for (int i = 0; i < loggers.length; i++)
+ for (int i = 0; i < loggers.length; i++) {
size += loggers[i].fTimeRecs.size();
+ }
- if (size == 0)
+ if (size == 0) {
return 0;
+ }
for (int i = 0; i < loggers.length; i++) {
- if (0 == loggers[i].fTimeRecs.size())
+ if (0 == loggers[i].fTimeRecs.size()) {
continue;
+ }
for (TimeRecord tm : loggers[i].fTimeRecs) {
sum += tm.fStop - tm.fStart;
@@ -223,8 +236,9 @@ public class TimeLogger {
for (int i = 0; i < loggers.length; i++) {
long val = loggers[i].getMaxTime();
- if (val > max)
+ if (val > max) {
max = val;
+ }
}
return max;
@@ -235,8 +249,9 @@ public class TimeLogger {
for (int i = 0; i < loggers.length; i++) {
long val = loggers[i].getMinTime();
- if (val < min)
+ if (val < min) {
min = val;
+ }
}
return min;
@@ -247,8 +262,9 @@ public class TimeLogger {
for (int i = 0; i < loggers.length; i++) {
long val = loggers[i].getTotalTime();
- if (val > totalTime)
+ if (val > totalTime) {
totalTime = val;
+ }
}
return totalTime;