http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/371bf9a5/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java index 8c6e4ed..db88062 100644 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java +++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentXmlSerializerTest.java @@ -6,9 +6,9 @@ * 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 @@ -205,18 +205,18 @@ public class MetadataDocumentXmlSerializerTest { "<edmx:Reference " + "Uri=\"http://localhost/odata/odata/v4.0/referenceWithInclude\">" + "<edmx:Include Namespace=\"Org.OData.Core.V1\" Alias=\"Core\"/>" + - "</edmx:Reference>")); + "</edmx:Reference>")); assertTrue(metadataString.contains( "<edmx:Reference " + "Uri=\"http://localhost/odata/odata/v4.0/referenceWithTwoIncludes\">" + "<edmx:Include Namespace=\"Org.OData.Core.2\" Alias=\"Core2\"/>" + "<edmx:Include Namespace=\"Org.OData.Core.3\" Alias=\"Core3\"/>" + - "</edmx:Reference>")); + "</edmx:Reference>")); assertTrue(metadataString.contains( "<edmx:Reference Uri=\"http://localhost/odata/odata/v4.0/referenceWithIncludeAnnos\">" + "<edmx:IncludeAnnotations TermNamespace=\"TermNs.2\" Qualifier=\"Q.2\" TargetNamespace=\"TargetNS.2\"/>" + "<edmx:IncludeAnnotations TermNamespace=\"TermNs.3\" Qualifier=\"Q.3\" TargetNamespace=\"TargetNS.3\"/>" + - "</edmx:Reference>")); + "</edmx:Reference>")); assertTrue(metadataString.contains( "<edmx:Reference Uri=\"http://localhost/odata/odata/v4.0/referenceWithAll\">" + "<edmx:Include Namespace=\"ReferenceWithAll.1\" Alias=\"Core1\"/>" + @@ -225,7 +225,7 @@ public class MetadataDocumentXmlSerializerTest { "Qualifier=\"Q.4\" TargetNamespace=\"TargetNS.4\"/>" + "<edmx:IncludeAnnotations TermNamespace=\"ReferenceWithAllTermNs.5\" " + "Qualifier=\"Q.5\" TargetNamespace=\"TargetNS.5\"/>" + - "</edmx:Reference>")); + "</edmx:Reference>")); assertTrue(metadataString.contains( "<edmx:Reference Uri=\"http://localhost/odata/odata/v4.0/referenceWithAllAndNull\">" + "<edmx:Include Namespace=\"referenceWithAllAndNull.1\"/>" + @@ -235,7 +235,7 @@ public class MetadataDocumentXmlSerializerTest { "<edmx:IncludeAnnotations TermNamespace=\"ReferenceWithAllTermAndNullNs.6\" " + "TargetNamespace=\"TargetNS\"/>" + "<edmx:IncludeAnnotations TermNamespace=\"ReferenceWithAllTermAndNullNs.7\"/>" + - "</edmx:Reference>")); + "</edmx:Reference>")); } @Test @@ -404,12 +404,12 @@ public class MetadataDocumentXmlSerializerTest { private final FullQualifiedName nameString = EdmPrimitiveTypeKind.String.getFullQualifiedName(); private final FullQualifiedName nameUARTPrimParam = new FullQualifiedName(nameSpace, "UARTPrimParam"); private final CsdlProperty propertyInt16_NotNullable = new CsdlProperty() - .setName("PropertyInt16") - .setType(nameInt16) - .setNullable(false); + .setName("PropertyInt16") + .setType(nameInt16) + .setNullable(false); private final CsdlProperty propertyString = new CsdlProperty() - .setName("PropertyString") - .setType(nameString); + .setName("PropertyString") + .setType(nameString); private final FullQualifiedName nameCTTwoPrim = new FullQualifiedName(nameSpace, "CTTwoPrim"); private final FullQualifiedName nameCTTwoPrimBase = new FullQualifiedName(nameSpace, "CTTwoPrimBase"); @@ -426,10 +426,10 @@ public class MetadataDocumentXmlSerializerTest { public CsdlEnumType getEnumType(final FullQualifiedName enumTypeName) throws ODataException { if (nameENString.equals(enumTypeName)) { return new CsdlEnumType() - .setName(nameENString.getName()) - .setFlags(true) - .setUnderlyingType(EdmPrimitiveTypeKind.Int16.getFullQualifiedName()) - .setMembers(Collections.singletonList(new CsdlEnumMember().setName("String1").setValue("1"))); + .setName(nameENString.getName()) + .setFlags(true) + .setUnderlyingType(EdmPrimitiveTypeKind.Int16.getFullQualifiedName()) + .setMembers(Collections.singletonList(new CsdlEnumMember().setName("String1").setValue("1"))); } return null; } @@ -438,16 +438,16 @@ public class MetadataDocumentXmlSerializerTest { public CsdlEntityType getEntityType(final FullQualifiedName entityTypeName) throws ODataException { if (entityTypeName.equals(nameETAbstract)) { return new CsdlEntityType() - .setName("ETAbstract") - .setAbstract(true) - .setProperties(Collections.singletonList(propertyString)); + .setName("ETAbstract") + .setAbstract(true) + .setProperties(Collections.singletonList(propertyString)); } else if (entityTypeName.equals(nameETAbstractBase)) { return new CsdlEntityType() - .setName("ETAbstractBase") - .setBaseType(nameETAbstract) - .setKey(Collections.singletonList(new CsdlPropertyRef().setName("PropertyInt16"))) - .setProperties(Collections.singletonList(propertyInt16_NotNullable)); + .setName("ETAbstractBase") + .setBaseType(nameETAbstract) + .setKey(Collections.singletonList(new CsdlPropertyRef().setName("PropertyInt16"))) + .setProperties(Collections.singletonList(propertyInt16_NotNullable)); } return null; } @@ -456,15 +456,15 @@ public class MetadataDocumentXmlSerializerTest { public CsdlComplexType getComplexType(final FullQualifiedName complexTypeName) throws ODataException { if (complexTypeName.equals(nameCTTwoPrim)) { return new CsdlComplexType() - .setName("CTTwoPrim") - .setProperties(Arrays.asList(propertyInt16_NotNullable, propertyString)); + .setName("CTTwoPrim") + .setProperties(Arrays.asList(propertyInt16_NotNullable, propertyString)); } if (complexTypeName.equals(nameCTTwoPrimBase)) { return new CsdlComplexType() - .setName("CTTwoPrimBase") - .setBaseType(nameCTTwoPrim) - .setProperties(Arrays.asList(propertyInt16_NotNullable, propertyString)); + .setName("CTTwoPrimBase") + .setBaseType(nameCTTwoPrim) + .setProperties(Arrays.asList(propertyInt16_NotNullable, propertyString)); } return null; @@ -475,8 +475,8 @@ public class MetadataDocumentXmlSerializerTest { if (actionName.equals(nameUARTPrimParam)) { return Collections.singletonList( new CsdlAction().setName("UARTPrimParam") - .setParameters(Collections.singletonList( - new CsdlParameter().setName("ParameterInt16").setType(nameInt16))) + .setParameters(Collections.singletonList( + new CsdlParameter().setName("ParameterInt16").setType(nameInt16))) .setReturnType(new CsdlReturnType().setType(nameString))); } return null; @@ -487,9 +487,9 @@ public class MetadataDocumentXmlSerializerTest { if (functionName.equals(nameUFNRTInt16)) { return Collections.singletonList( new CsdlFunction() - .setName("UFNRTInt16") - .setParameters(Collections.<CsdlParameter> emptyList()) - .setReturnType(new CsdlReturnType().setType(nameInt16))); + .setName("UFNRTInt16") + .setParameters(Collections.<CsdlParameter> emptyList()) + .setReturnType(new CsdlReturnType().setType(nameInt16))); } return null; } @@ -499,8 +499,8 @@ public class MetadataDocumentXmlSerializerTest { throws ODataException { if (entitySetName.equals("ESAllPrim")) { return new CsdlEntitySet() - .setName("ESAllPrim") - .setType(nameETAbstractBase); + .setName("ESAllPrim") + .setType(nameETAbstractBase); } return null; } @@ -510,8 +510,8 @@ public class MetadataDocumentXmlSerializerTest { throws ODataException { if (singletonName.equals("SI")) { return new CsdlSingleton() - .setName("SI") - .setType(nameETAbstractBase); + .setName("SI") + .setType(nameETAbstractBase); } return null; } @@ -522,8 +522,8 @@ public class MetadataDocumentXmlSerializerTest { if (entityContainer.equals(nameContainer)) { if (actionImportName.equals("AIRTPrimParam")) { return new CsdlActionImport() - .setName("AIRTPrimParam") - .setAction(nameUARTPrimParam); + .setName("AIRTPrimParam") + .setAction(nameUARTPrimParam); } } return null; @@ -532,13 +532,13 @@ public class MetadataDocumentXmlSerializerTest { @Override public CsdlFunctionImport getFunctionImport(final FullQualifiedName entityContainer, final String functionImportName) - throws ODataException { + throws ODataException { if (entityContainer.equals(nameContainer)) { if (functionImportName.equals("FINRTInt16")) { return new CsdlFunctionImport() - .setName("FINRTInt16") - .setFunction(nameUFNRTInt16) - .setIncludeInServiceDocument(true); + .setName("FINRTInt16") + .setFunction(nameUFNRTInt16) + .setIncludeInServiceDocument(true); } } return null; @@ -576,9 +576,9 @@ public class MetadataDocumentXmlSerializerTest { // EntityContainer schema.setEntityContainer(getEntityContainer()); - //Terms + // Terms schema.setTerms(Arrays.asList( - getTerm(new FullQualifiedName("ns","term")), + getTerm(new FullQualifiedName("ns", "term")), getTerm(new FullQualifiedName("namespace", "Term1")), getTerm(new FullQualifiedName("ns", "Term2")), getTerm(new FullQualifiedName("ns", "Term3")), @@ -621,27 +621,27 @@ public class MetadataDocumentXmlSerializerTest { } @Override - public CsdlTypeDefinition getTypeDefinition(FullQualifiedName typeDefinitionName) throws ODataException { + public CsdlTypeDefinition getTypeDefinition(final FullQualifiedName typeDefinitionName) throws ODataException { return null; } @Override - public CsdlTerm getTerm(FullQualifiedName termName) throws ODataException { + public CsdlTerm getTerm(final FullQualifiedName termName) throws ODataException { if (new FullQualifiedName("ns", "term").equals(termName)) { return new CsdlTerm().setType("Edm.String").setName("term"); - } else if(new FullQualifiedName("namespace", "Term1").equals(termName)){ + } else if (new FullQualifiedName("namespace", "Term1").equals(termName)) { return new CsdlTerm().setType("Edm.String").setName("Term1"); - } else if(new FullQualifiedName("ns", "Term2").equals(termName)){ + } else if (new FullQualifiedName("ns", "Term2").equals(termName)) { return new CsdlTerm().setType("Edm.String").setName("Term2") .setNullable(false).setDefaultValue("default").setMaxLength(1).setPrecision(2).setScale(3); - } else if(new FullQualifiedName("ns", "Term3").equals(termName)){ + } else if (new FullQualifiedName("ns", "Term3").equals(termName)) { return new CsdlTerm().setType("Edm.String").setName("Term3") .setAppliesTo(Arrays.asList("Property", "EntitySet", "Schema")); - } else if(new FullQualifiedName("ns", "Term4").equals(termName)){ + } else if (new FullQualifiedName("ns", "Term4").equals(termName)) { return new CsdlTerm().setType("Edm.String").setName("Term4").setBaseTerm("namespace.Term1"); } @@ -649,7 +649,8 @@ public class MetadataDocumentXmlSerializerTest { } @Override - public CsdlAnnotations getAnnotationsGroup(FullQualifiedName targetName, String qualifier) throws ODataException { + public CsdlAnnotations getAnnotationsGroup(final FullQualifiedName targetName, final String qualifier) + throws ODataException { if (new FullQualifiedName("Alias", "ETAbstract").equals(targetName) && "Tablett".equals(qualifier)) { CsdlAnnotations annoGroup = new CsdlAnnotations(); annoGroup.setTarget("Alias.ETAbstract"); @@ -690,50 +691,50 @@ public class MetadataDocumentXmlSerializerTest { // logical expressions annotationsList.add(new CsdlAnnotation().setTerm("ns.term") .setExpression(new CsdlLogicalOrComparisonExpression(LogicalOrComparisonExpressionType.And) - .setLeft(new CsdlConstantExpression(ConstantExpressionType.Bool, "true")) - .setRight(new CsdlConstantExpression(ConstantExpressionType.Bool, "false")) - .setAnnotations(innerAnnotations))); + .setLeft(new CsdlConstantExpression(ConstantExpressionType.Bool, "true")) + .setRight(new CsdlConstantExpression(ConstantExpressionType.Bool, "false")) + .setAnnotations(innerAnnotations))); annotationsList.add(new CsdlAnnotation().setTerm("ns.term") .setExpression(new CsdlLogicalOrComparisonExpression(LogicalOrComparisonExpressionType.Or) - .setLeft(new CsdlConstantExpression(ConstantExpressionType.Bool, "true")) - .setRight(new CsdlConstantExpression(ConstantExpressionType.Bool, "false")) - .setAnnotations(innerAnnotations))); + .setLeft(new CsdlConstantExpression(ConstantExpressionType.Bool, "true")) + .setRight(new CsdlConstantExpression(ConstantExpressionType.Bool, "false")) + .setAnnotations(innerAnnotations))); annotationsList.add(new CsdlAnnotation().setTerm("ns.term") .setExpression(new CsdlLogicalOrComparisonExpression(LogicalOrComparisonExpressionType.Not) - .setLeft(new CsdlConstantExpression(ConstantExpressionType.Bool, "true")) - .setAnnotations(innerAnnotations))); + .setLeft(new CsdlConstantExpression(ConstantExpressionType.Bool, "true")) + .setAnnotations(innerAnnotations))); // comparison annotationsList.add(new CsdlAnnotation().setTerm("ns.term") .setExpression(new CsdlLogicalOrComparisonExpression(LogicalOrComparisonExpressionType.Eq) - .setLeft(new CsdlConstantExpression(ConstantExpressionType.Bool, "true")) - .setRight(new CsdlConstantExpression(ConstantExpressionType.Bool, "false")) - .setAnnotations(innerAnnotations))); + .setLeft(new CsdlConstantExpression(ConstantExpressionType.Bool, "true")) + .setRight(new CsdlConstantExpression(ConstantExpressionType.Bool, "false")) + .setAnnotations(innerAnnotations))); annotationsList.add(new CsdlAnnotation().setTerm("ns.term") .setExpression(new CsdlLogicalOrComparisonExpression(LogicalOrComparisonExpressionType.Ne) - .setLeft(new CsdlConstantExpression(ConstantExpressionType.Bool, "true")) - .setRight(new CsdlConstantExpression(ConstantExpressionType.Bool, "false")) - .setAnnotations(innerAnnotations))); + .setLeft(new CsdlConstantExpression(ConstantExpressionType.Bool, "true")) + .setRight(new CsdlConstantExpression(ConstantExpressionType.Bool, "false")) + .setAnnotations(innerAnnotations))); annotationsList.add(new CsdlAnnotation().setTerm("ns.term") .setExpression(new CsdlLogicalOrComparisonExpression(LogicalOrComparisonExpressionType.Gt) - .setLeft(new CsdlConstantExpression(ConstantExpressionType.Bool, "true")) - .setRight(new CsdlConstantExpression(ConstantExpressionType.Bool, "false")) - .setAnnotations(innerAnnotations))); + .setLeft(new CsdlConstantExpression(ConstantExpressionType.Bool, "true")) + .setRight(new CsdlConstantExpression(ConstantExpressionType.Bool, "false")) + .setAnnotations(innerAnnotations))); annotationsList.add(new CsdlAnnotation().setTerm("ns.term") .setExpression(new CsdlLogicalOrComparisonExpression(LogicalOrComparisonExpressionType.Ge) - .setLeft(new CsdlConstantExpression(ConstantExpressionType.Bool, "true")) - .setRight(new CsdlConstantExpression(ConstantExpressionType.Bool, "false")) - .setAnnotations(innerAnnotations))); + .setLeft(new CsdlConstantExpression(ConstantExpressionType.Bool, "true")) + .setRight(new CsdlConstantExpression(ConstantExpressionType.Bool, "false")) + .setAnnotations(innerAnnotations))); annotationsList.add(new CsdlAnnotation().setTerm("ns.term") .setExpression(new CsdlLogicalOrComparisonExpression(LogicalOrComparisonExpressionType.Lt) - .setLeft(new CsdlConstantExpression(ConstantExpressionType.Bool, "true")) - .setRight(new CsdlConstantExpression(ConstantExpressionType.Bool, "false")) - .setAnnotations(innerAnnotations))); + .setLeft(new CsdlConstantExpression(ConstantExpressionType.Bool, "true")) + .setRight(new CsdlConstantExpression(ConstantExpressionType.Bool, "false")) + .setAnnotations(innerAnnotations))); annotationsList.add(new CsdlAnnotation().setTerm("ns.term") .setExpression(new CsdlLogicalOrComparisonExpression(LogicalOrComparisonExpressionType.Le) - .setLeft(new CsdlConstantExpression(ConstantExpressionType.Bool, "true")) - .setRight(new CsdlConstantExpression(ConstantExpressionType.Bool, "false")) - .setAnnotations(innerAnnotations))); + .setLeft(new CsdlConstantExpression(ConstantExpressionType.Bool, "true")) + .setRight(new CsdlConstantExpression(ConstantExpressionType.Bool, "false")) + .setAnnotations(innerAnnotations))); // Other annotationsList.add(new CsdlAnnotation().setTerm("ns.term") @@ -748,12 +749,12 @@ public class MetadataDocumentXmlSerializerTest { annotationsList.add(new CsdlAnnotation().setTerm("ns.term") .setExpression(new CsdlCast() - .setValue(new CsdlConstantExpression(ConstantExpressionType.String, "value")) - .setMaxLength(1) - .setPrecision(2) - .setScale(3) - .setType("Edm.String") - .setAnnotations(innerAnnotations))); + .setValue(new CsdlConstantExpression(ConstantExpressionType.String, "value")) + .setMaxLength(1) + .setPrecision(2) + .setScale(3) + .setType("Edm.String") + .setAnnotations(innerAnnotations))); List<CsdlExpression> items = new ArrayList<CsdlExpression>(); items.add(new CsdlConstantExpression(ConstantExpressionType.Bool, "true")); @@ -764,25 +765,25 @@ public class MetadataDocumentXmlSerializerTest { annotationsList.add(new CsdlAnnotation().setTerm("ns.term") .setExpression(new CsdlIf() - .setGuard(new CsdlConstantExpression(ConstantExpressionType.Bool, "true")) - .setThen(new CsdlConstantExpression(ConstantExpressionType.String, "Then")) - .setElse(new CsdlConstantExpression(ConstantExpressionType.String, "Else")) - .setAnnotations(innerAnnotations))); + .setGuard(new CsdlConstantExpression(ConstantExpressionType.Bool, "true")) + .setThen(new CsdlConstantExpression(ConstantExpressionType.String, "Then")) + .setElse(new CsdlConstantExpression(ConstantExpressionType.String, "Else")) + .setAnnotations(innerAnnotations))); annotationsList.add(new CsdlAnnotation().setTerm("ns.term") .setExpression(new CsdlIsOf() - .setMaxLength(1) - .setPrecision(2) - .setScale(3) - .setType("Edm.String") - .setValue(new CsdlConstantExpression(ConstantExpressionType.String, "value")) - .setAnnotations(innerAnnotations))); + .setMaxLength(1) + .setPrecision(2) + .setScale(3) + .setType("Edm.String") + .setValue(new CsdlConstantExpression(ConstantExpressionType.String, "value")) + .setAnnotations(innerAnnotations))); annotationsList.add(new CsdlAnnotation().setTerm("ns.term") .setExpression(new CsdlLabeledElement() - .setName("NameAtt") - .setValue(new CsdlConstantExpression(ConstantExpressionType.String, "value")) - .setAnnotations(innerAnnotations))); + .setName("NameAtt") + .setValue(new CsdlConstantExpression(ConstantExpressionType.String, "value")) + .setAnnotations(innerAnnotations))); annotationsList.add(new CsdlAnnotation().setTerm("ns.term") .setExpression(new CsdlLabeledElementReference().setValue("LabeledElementReferenceValue"))); @@ -800,9 +801,9 @@ public class MetadataDocumentXmlSerializerTest { .setExpression(new CsdlPropertyPath().setValue("PropertyPathValue"))); CsdlPropertyValue prop = new CsdlPropertyValue() - .setProperty("PropName") - .setValue(new CsdlConstantExpression(ConstantExpressionType.String, "value")) - .setAnnotations(innerAnnotations); + .setProperty("PropName") + .setValue(new CsdlConstantExpression(ConstantExpressionType.String, "value")) + .setAnnotations(innerAnnotations); annotationsList.add(new CsdlAnnotation().setTerm("ns.term") .setExpression(new CsdlRecord().setType("Alias.ETAbstract") .setPropertyValues(Arrays.asList(prop)) @@ -810,8 +811,8 @@ public class MetadataDocumentXmlSerializerTest { annotationsList.add(new CsdlAnnotation().setTerm("ns.term") .setExpression(new CsdlUrlRef() - .setValue(new CsdlConstantExpression(ConstantExpressionType.String, "URLRefValue")) - .setAnnotations(innerAnnotations))); + .setValue(new CsdlConstantExpression(ConstantExpressionType.String, "URLRefValue")) + .setAnnotations(innerAnnotations))); return annoGroup; }
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/371bf9a5/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/ServerErrorXmlSerializerTest.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/ServerErrorXmlSerializerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/ServerErrorXmlSerializerTest.java index 907228f..ee9618d 100644 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/ServerErrorXmlSerializerTest.java +++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/ServerErrorXmlSerializerTest.java @@ -6,9 +6,9 @@ * 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 @@ -62,13 +62,13 @@ public class ServerErrorXmlSerializerTest { @Test public void singleDetailNothingSet() throws Exception { ODataServerError error = new ODataServerError() - .setCode("code") - .setMessage("err message") - .setTarget("target") - .setDetails(Collections.singletonList( - new ODataErrorDetail() - .setCode("detail code") - .setMessage("detail message"))); + .setCode("code") + .setMessage("err message") + .setTarget("target") + .setDetails(Collections.singletonList( + new ODataErrorDetail() + .setCode("detail code") + .setMessage("detail message"))); InputStream stream = ser.error(error).getContent(); String jsonString = IOUtils.toString(stream); http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/371bf9a5/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializerTest.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializerTest.java index 846efc5..c3e3598 100644 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializerTest.java +++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializerTest.java @@ -6,9 +6,9 @@ * 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 @@ -76,7 +76,7 @@ public class ServiceDocumentXmlSerializerTest { @Test public void writeServiceDocument() throws Exception { CsdlEdmProvider provider = new MetadataDocumentXmlSerializerTest.LocalProvider(); - ServiceMetadata serviceMetadata = new ServiceMetadataImpl(provider, + ServiceMetadata serviceMetadata = new ServiceMetadataImpl(provider, Collections.<EdmxReference> emptyList(), null); InputStream metadataStream = serializer.serviceDocument(serviceMetadata, "http://host/svc").getContent(); String metadata = IOUtils.toString(metadataStream); @@ -87,15 +87,15 @@ public class ServiceDocumentXmlSerializerTest { + "metadata:context=\"http://host/svc/$metadata\">" + "<app:workspace>" + "<atom:title>org.olingo.container</atom:title>" - + "<app:collection href=\"ESAllPrim\" metadata:name=\"ESAllPrim\">" - + "<atom:title>ESAllPrim</atom:title>" - + "</app:collection>" - + "<metadata:function-import href=\"FINRTInt16\" metadata:name=\"FINRTInt16\">" - + "<atom:title>FINRTInt16</atom:title>" - + "</metadata:function-import>" - + "<metadata:singleton href=\"SI\" metadata:name=\"SI\">" - + "<atom:title>SI</atom:title>" - + "</metadata:singleton>" + + "<app:collection href=\"ESAllPrim\" metadata:name=\"ESAllPrim\">" + + "<atom:title>ESAllPrim</atom:title>" + + "</app:collection>" + + "<metadata:function-import href=\"FINRTInt16\" metadata:name=\"FINRTInt16\">" + + "<atom:title>FINRTInt16</atom:title>" + + "</metadata:function-import>" + + "<metadata:singleton href=\"SI\" metadata:name=\"SI\">" + + "<atom:title>SI</atom:title>" + + "</metadata:singleton>" + "</app:workspace>" + "</app:service>", metadata); http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/371bf9a5/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchParserAndTokenizerTest.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchParserAndTokenizerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchParserAndTokenizerTest.java index e028cfe..40c6200 100644 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchParserAndTokenizerTest.java +++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchParserAndTokenizerTest.java @@ -6,9 +6,9 @@ * 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 @@ -35,7 +35,7 @@ public class SearchParserAndTokenizerTest { assertQuery("a AND b AND c").resultsIn("{{'a' AND 'b'} AND 'c'}"); assertQuery("a OR b").resultsIn("{'a' OR 'b'}"); assertQuery("a OR b OR c").resultsIn("{{'a' OR 'b'} OR 'c'}"); - + assertQuery("NOT a NOT b").resultsIn("{{NOT 'a'} AND {NOT 'b'}}"); assertQuery("NOT a AND NOT b").resultsIn("{{NOT 'a'} AND {NOT 'b'}}"); assertQuery("NOT a OR NOT b").resultsIn("{{NOT 'a'} OR {NOT 'b'}}"); @@ -59,16 +59,16 @@ public class SearchParserAndTokenizerTest { assertQuery("a AND (b OR c)").resultsIn("{'a' AND {'b' OR 'c'}}"); assertQuery("(a OR b) AND NOT c").resultsIn("{{'a' OR 'b'} AND {NOT 'c'}}"); assertQuery("(a OR B) AND (c OR d AND NOT e OR (f))") - .resultsIn("{{'a' OR 'B'} AND {{'c' OR {'d' AND {NOT 'e'}}} OR 'f'}}"); + .resultsIn("{{'a' OR 'B'} AND {{'c' OR {'d' AND {NOT 'e'}}} OR 'f'}}"); assertQuery("(a OR B) (c OR d NOT e OR (f))") - .resultsIn("{{'a' OR 'B'} AND {{'c' OR {'d' AND {NOT 'e'}}} OR 'f'}}"); + .resultsIn("{{'a' OR 'B'} AND {{'c' OR {'d' AND {NOT 'e'}}} OR 'f'}}"); assertQuery("((((a))))").resultsIn("'a'"); assertQuery("((((a)))) ((((a))))").resultsIn("{'a' AND 'a'}"); assertQuery("((((a)))) OR ((((a))))").resultsIn("{'a' OR 'a'}"); assertQuery("((((((a)))) ((((c))) OR (((C)))) ((((a))))))").resultsIn("{{'a' AND {'c' OR 'C'}} AND 'a'}"); assertQuery("((((\"a\")))) OR ((((\"a\"))))").resultsIn("{'a' OR 'a'}"); } - + @Test public void parseImplicitAnd() throws Exception { assertQuery("a b").resultsIn("{'a' AND 'b'}"); @@ -103,7 +103,7 @@ public class SearchParserAndTokenizerTest { assertQuery("((a AND b OR c)").resultsIn(SearchParserException.MessageKeys.MISSING_CLOSE); assertQuery("a AND (b OR c").resultsIn(SearchParserException.MessageKeys.MISSING_CLOSE); assertQuery("(a AND ((b OR c)").resultsIn(SearchParserException.MessageKeys.MISSING_CLOSE); - + assertQuery("NOT NOT a").resultsIn(SearchParserException.MessageKeys.INVALID_NOT_OPERAND); assertQuery("NOT (a)").resultsIn(SearchParserException.MessageKeys.TOKENIZER_EXCEPTION); } @@ -119,83 +119,81 @@ public class SearchParserAndTokenizerTest { */ @Test public void searchQueryPhraseAbnfTestcases() throws Exception { - // <TestCase Name="5.1.7 Search - simple phrase" Rule="queryOptions"> + // <TestCase Name="5.1.7 Search - simple phrase" Rule="queryOptions"> assertQuery("\"blue green\"").resultsIn("'blue green'"); - // <TestCase Name="5.1.7 Search - simple phrase" Rule="queryOptions"> + // <TestCase Name="5.1.7 Search - simple phrase" Rule="queryOptions"> assertQuery("\"blue green\"").resultsIn("'blue green'"); - // <TestCase Name="5.1.7 Search - phrase with escaped double-quote" Rule="queryOptions"> - // <Input>$search="blue\"green"</Input> + // <TestCase Name="5.1.7 Search - phrase with escaped double-quote" Rule="queryOptions"> + // <Input>$search="blue\"green"</Input> assertQuery("\"blue\\\"green\"").resultsIn("'blue\"green'"); - // <TestCase Name="5.1.7 Search - phrase with escaped backslash" Rule="queryOptions"> - // <Input>$search="blue\\green"</Input> + // <TestCase Name="5.1.7 Search - phrase with escaped backslash" Rule="queryOptions"> + // <Input>$search="blue\\green"</Input> assertQuery("\"blue\\\\green\"").resultsIn("'blue\\green'"); - // <TestCase Name="5.1.7 Search - phrase with unescaped double-quote" Rule="queryOptions" FailAt="14"> + // <TestCase Name="5.1.7 Search - phrase with unescaped double-quote" Rule="queryOptions" FailAt="14"> assertQuery("\"blue\"green\"").resultsIn(SearchParserException.MessageKeys.TOKENIZER_EXCEPTION); - // <TestCase Name="5.1.7 Search - phrase with unescaped double-quote" Rule="queryOptions" FailAt="16"> + // <TestCase Name="5.1.7 Search - phrase with unescaped double-quote" Rule="queryOptions" FailAt="16"> assertQuery("\"blue\"green\"").resultsIn(SearchParserException.MessageKeys.TOKENIZER_EXCEPTION); - // <TestCase Name="5.1.7 Search - implicit AND" Rule="queryOptions"> - // <Input>$search=blue green</Input> + // <TestCase Name="5.1.7 Search - implicit AND" Rule="queryOptions"> + // <Input>$search=blue green</Input> assertQuery("blue green").resultsIn("{'blue' AND 'green'}"); - // <TestCase Name="5.1.7 Search - implicit AND, encoced" Rule="queryOptions"> + // <TestCase Name="5.1.7 Search - implicit AND, encoced" Rule="queryOptions"> assertQuery("blue green").resultsIn("{'blue' AND 'green'}"); - // <TestCase Name="5.1.7 Search - AND" Rule="queryOptions"> - // <Input>$search=blue AND green</Input> + // <TestCase Name="5.1.7 Search - AND" Rule="queryOptions"> + // <Input>$search=blue AND green</Input> assertQuery("blue AND green").resultsIn("{'blue' AND 'green'}"); - // <TestCase Name="5.1.7 Search - OR" Rule="queryOptions"> - // <Input>$search=blue OR green</Input> + // <TestCase Name="5.1.7 Search - OR" Rule="queryOptions"> + // <Input>$search=blue OR green</Input> assertQuery("blue OR green").resultsIn("{'blue' OR 'green'}"); - // <TestCase Name="5.1.7 Search - NOT" Rule="queryOptions"> - // <Input>$search=blue NOT green</Input> + // <TestCase Name="5.1.7 Search - NOT" Rule="queryOptions"> + // <Input>$search=blue NOT green</Input> assertQuery("blue NOT green").resultsIn("{'blue' AND {NOT 'green'}}"); - // <TestCase Name="5.1.7 Search - only NOT" Rule="queryOptions"> - // <Input>$search=NOT blue</Input> + // <TestCase Name="5.1.7 Search - only NOT" Rule="queryOptions"> + // <Input>$search=NOT blue</Input> assertQuery("NOT blue").resultsIn("{NOT 'blue'}"); - // <TestCase Name="5.1.7 Search - multiple" Rule="queryOptions"> - // <Input>$search=foo AND bar OR foo AND baz OR that AND bar OR that AND baz</Input> + // <TestCase Name="5.1.7 Search - multiple" Rule="queryOptions"> + // <Input>$search=foo AND bar OR foo AND baz OR that AND bar OR that AND baz</Input> assertQuery("foo AND bar OR foo AND baz OR that AND bar OR that AND baz") - .resultsIn("{{{{'foo' AND 'bar'} OR {'foo' AND 'baz'}} OR {'that' AND 'bar'}} OR {'that' AND 'baz'}}"); + .resultsIn("{{{{'foo' AND 'bar'} OR {'foo' AND 'baz'}} OR {'that' AND 'bar'}} OR {'that' AND 'baz'}}"); - // <TestCase Name="5.1.7 Search - multiple" Rule="queryOptions"> - // <Input>$search=(foo OR that) AND (bar OR baz)</Input> + // <TestCase Name="5.1.7 Search - multiple" Rule="queryOptions"> + // <Input>$search=(foo OR that) AND (bar OR baz)</Input> assertQuery("(foo OR that) AND (bar OR baz)").resultsIn("{{'foo' OR 'that'} AND {'bar' OR 'baz'}}"); - // <TestCase Name="5.1.7 Search - grouping" Rule="queryOptions"> - // <Input>$search=foo AND (bar OR baz)</Input> + // <TestCase Name="5.1.7 Search - grouping" Rule="queryOptions"> + // <Input>$search=foo AND (bar OR baz)</Input> assertQuery("foo AND (bar OR baz)").resultsIn("{'foo' AND {'bar' OR 'baz'}}"); - // <TestCase Name="5.1.7 Search - grouping" Rule="queryOptions"> - // <Input>$search=(foo AND bar) OR baz</Input> + // <TestCase Name="5.1.7 Search - grouping" Rule="queryOptions"> + // <Input>$search=(foo AND bar) OR baz</Input> assertQuery("(foo AND bar) OR baz").resultsIn("{{'foo' AND 'bar'} OR 'baz'}"); - // <TestCase Name="5.1.7 Search - grouping" Rule="queryOptions"> - // <Input>$search=(NOT foo) OR baz</Input> + // <TestCase Name="5.1.7 Search - grouping" Rule="queryOptions"> + // <Input>$search=(NOT foo) OR baz</Input> assertQuery("(NOT foo) OR baz").resultsIn("{{NOT 'foo'} OR 'baz'}"); - // <TestCase Name="5.1.7 Search - grouping" Rule="queryOptions"> - // <Input>$search=(NOT foo)</Input> + // <TestCase Name="5.1.7 Search - grouping" Rule="queryOptions"> + // <Input>$search=(NOT foo)</Input> assertQuery("(NOT foo)").resultsIn("{NOT 'foo'}"); - // <TestCase Name="5.1.7 Search - on entity set" Rule="odataUri"> - // <Input>http://serviceRoot/Products?$search=blue</Input> + // <TestCase Name="5.1.7 Search - on entity set" Rule="odataUri"> + // <Input>http://serviceRoot/Products?$search=blue</Input> assertQuery("blue").resultsIn("'blue'"); - // below cases can not be tested here - // <TestCase Name="5.1.7 Search - on entity container" Rule="odataUri"> - // <Input>http://serviceRoot/Model.Container/$all?$search=blue</Input> - // <TestCase Name="5.1.7 Search - on service" Rule="odataUri"> - // <Input>http://serviceRoot/$all?$search=blue</Input> + // <TestCase Name="5.1.7 Search - on entity container" Rule="odataUri"> + // <Input>http://serviceRoot/Model.Container/$all?$search=blue</Input> + // <TestCase Name="5.1.7 Search - on service" Rule="odataUri"> + // <Input>http://serviceRoot/$all?$search=blue</Input> } - - private static Validator assertQuery(String searchQuery) { + private static Validator assertQuery(final String searchQuery) { return Validator.init(searchQuery); } @@ -203,28 +201,22 @@ public class SearchParserAndTokenizerTest { private boolean log; private final String searchQuery; - private Validator(String searchQuery) { + private Validator(final String searchQuery) { this.searchQuery = searchQuery; } - private static Validator init(String searchQuery) { + private static Validator init(final String searchQuery) { return new Validator(searchQuery); } - @SuppressWarnings("unused") - private Validator withLogging() { - log = true; - return this; - } - - private void resultsIn(SearchParserException.MessageKey key) - throws SearchTokenizerException { + private void resultsIn(final SearchParserException.MessageKey key) + throws SearchTokenizerException { try { resultsIn(searchQuery); } catch (SearchParserException e) { Assert.assertEquals("SearchParserException with unexpected message '" + e.getMessage() + "' was thrown.", key, e.getMessageKey()); - if(log) { + if (log) { System.out.println("Caught SearchParserException with message key " + e.getMessageKey() + " and message " + e.getMessage()); } @@ -232,17 +224,18 @@ public class SearchParserAndTokenizerTest { } Assert.fail("SearchParserException with message key " + key.getKey() + " was not thrown."); } - + public void resultsInExpectedTerm(final String actualToken) throws SearchTokenizerException { try { resultsIn(searchQuery); - } catch(SearchParserException e) { + } catch (SearchParserException e) { Assert.assertEquals(SearchParserException.MessageKeys.EXPECTED_DIFFERENT_TOKEN, e.getMessageKey()); Assert.assertEquals("Expected PHRASE||WORD found: " + actualToken, e.getMessage()); } } - - private void resultsIn(String expectedSearchExpression) throws SearchTokenizerException, SearchParserException { + + private void resultsIn(final String expectedSearchExpression) throws SearchTokenizerException, + SearchParserException { final SearchExpression searchExpression = getSearchExpression(); Assert.assertEquals(expectedSearchExpression, searchExpression.toString()); } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/371bf9a5/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchParserTest.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchParserTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchParserTest.java index 4d2b560..780c209 100644 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchParserTest.java +++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchParserTest.java @@ -6,9 +6,9 @@ * 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 @@ -176,7 +176,6 @@ public class SearchParserTest extends SearchParser { runEx(SearchParserException.MessageKeys.INVALID_NOT_OPERAND, Token.NOT, Token.AND); } - @Test public void notNotWord() throws Exception { runEx(SearchParserException.MessageKeys.INVALID_NOT_OPERAND, Token.NOT, Token.NOT, Token.WORD); @@ -195,12 +194,12 @@ public class SearchParserTest extends SearchParser { runEx(MessageKeys.EXPECTED_DIFFERENT_TOKEN, Token.NOT, Token.WORD, Token.AND); runEx(MessageKeys.INVALID_END_OF_QUERY, Token.WORD, Token.AND, Token.WORD, Token.CLOSE); } - + @Test public void invalidQueryStarts() throws Exception { run(Token.WORD, Token.AND, Token.WORD, Token.AND, Token.WORD); } - + @Test public void singleAnd() { runEx(SearchParserException.MessageKeys.EXPECTED_DIFFERENT_TOKEN, Token.AND); @@ -222,7 +221,7 @@ public class SearchParserTest extends SearchParser { runEx(SearchParserException.MessageKeys.NO_EXPRESSION_FOUND, emptyArray); } - private void runEx(MessageKeys key, Token... tokenArray) { + private void runEx(final MessageKeys key, final Token... tokenArray) { try { run(tokenArray); fail("Expected UriParserSyntaxException with key " + key); @@ -230,15 +229,15 @@ public class SearchParserTest extends SearchParser { assertEquals(key, e.getMessageKey()); } } - - private SearchExpression run(SearchQueryToken.Token... tokenArray) throws SearchParserException { + + private SearchExpression run(final SearchQueryToken.Token... tokenArray) throws SearchParserException { List<SearchQueryToken> tokenList = prepareTokens(tokenArray); SearchExpression se = parse(tokenList); assertNotNull(se); return se; } - public List<SearchQueryToken> prepareTokens(SearchQueryToken.Token... tokenArray) { + public List<SearchQueryToken> prepareTokens(final SearchQueryToken.Token... tokenArray) { ArrayList<SearchQueryToken> tokenList = new ArrayList<SearchQueryToken>(); int wordNumber = 1; int phraseNumber = 1; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/371bf9a5/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchTokenizerTest.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchTokenizerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchTokenizerTest.java index c2a390a..a6c1375 100644 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchTokenizerTest.java +++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/uri/parser/search/SearchTokenizerTest.java @@ -6,9 +6,9 @@ * 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 @@ -31,7 +31,6 @@ import java.util.Iterator; import java.util.List; import org.junit.Assert; -import org.junit.Ignore; import org.junit.Test; public class SearchTokenizerTest { @@ -58,7 +57,7 @@ public class SearchTokenizerTest { assertQuery("notAw0rd").resultsIn(SearchTokenizerException.MessageKeys.FORBIDDEN_CHARACTER); } - private Validator.Tuple word(String literal) { + private Validator.Tuple word(final String literal) { return Validator.tuple(WORD, literal); } @@ -72,20 +71,20 @@ public class SearchTokenizerTest { // result = tokenizer.tokenize("\"abc\""); Assert.assertNotNull(result); - + Assert.assertEquals(PHRASE, result.get(0).getToken()); // result = tokenizer.tokenize("\"9988 abs\""); Assert.assertNotNull(result); - + Assert.assertEquals(PHRASE, result.get(0).getToken()); Assert.assertEquals("\"9988 abs\"", result.get(0).getLiteral()); // result = tokenizer.tokenize("\"99_88.\""); Assert.assertNotNull(result); - + Assert.assertEquals(PHRASE, result.get(0).getToken()); Assert.assertEquals("\"99_88.\"", result.get(0).getLiteral()); @@ -136,7 +135,7 @@ public class SearchTokenizerTest { assertQuery("abc xyz").resultsIn(WORD, WORD); assertQuery("abc AND xyz AND olingo").resultsIn(WORD, AND, WORD, AND, WORD); assertQuery("abc AND \"x-y_z\" AND olingo") - .resultsIn(WORD, AND, PHRASE, AND, WORD); + .resultsIn(WORD, AND, PHRASE, AND, WORD); } @Test @@ -146,7 +145,6 @@ public class SearchTokenizerTest { assertQuery("abc AND ANDsomething").addExpected(WORD, AND, WORD); } - @Test public void parseCombinations() throws Exception { assertQuery("word O NO").resultsIn(word("word"), word("O"), word("NO")); @@ -156,27 +154,25 @@ public class SearchTokenizerTest { assertQuery("abc AND NOT xyz OR olingo").resultsIn(WORD, AND, NOT, WORD, OR, WORD); assertQuery("foo AND bar OR foo AND baz OR that AND bar OR that AND baz") - .addExpected(WORD, "foo").addExpected(AND) - .addExpected(WORD, "bar").addExpected(OR) - .addExpected(WORD, "foo").addExpected(AND) - .addExpected(WORD, "baz").addExpected(OR) - .addExpected(WORD, "that").addExpected(AND) - .addExpected(WORD, "bar").addExpected(OR) - .addExpected(WORD, "that").addExpected(AND) - .addExpected(WORD, "baz") - .validate(); - + .addExpected(WORD, "foo").addExpected(AND) + .addExpected(WORD, "bar").addExpected(OR) + .addExpected(WORD, "foo").addExpected(AND) + .addExpected(WORD, "baz").addExpected(OR) + .addExpected(WORD, "that").addExpected(AND) + .addExpected(WORD, "bar").addExpected(OR) + .addExpected(WORD, "that").addExpected(AND) + .addExpected(WORD, "baz") + .validate(); assertQuery("(foo OR that) AND (bar OR baz)") - .addExpected(OPEN) - .addExpected(WORD, "foo").addExpected(OR).addExpected(WORD, "that") - .addExpected(CLOSE).addExpected(AND).addExpected(OPEN) - .addExpected(WORD, "bar").addExpected(OR).addExpected(WORD, "baz") - .addExpected(CLOSE) - .validate(); + .addExpected(OPEN) + .addExpected(WORD, "foo").addExpected(OR).addExpected(WORD, "that") + .addExpected(CLOSE).addExpected(AND).addExpected(OPEN) + .addExpected(WORD, "bar").addExpected(OR).addExpected(WORD, "baz") + .addExpected(CLOSE) + .validate(); } - @Test public void parseSpecial() throws Exception { assertQuery("NOT abc AND nothing").resultsIn(NOT, WORD, AND, WORD); @@ -192,23 +188,23 @@ public class SearchTokenizerTest { public void unicodeInWords() throws Exception { // Ll, Lm, Lo, Lt, Lu, Nl assertQuery("abc OR Ll\u01E3Lm\u02B5Lo\u00AALt\u01F2Lu\u03D3Nl\u216F") - .resultsIn(WORD, OR, WORD); + .resultsIn(WORD, OR, WORD); } /** - * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" - * other-delims = "!" / "(" / ")" / "*" / "+" / "," / ";" - * qchar-unescaped = unreserved / pct-encoded-unescaped / other-delims / ":" / "@" / "/" / "?" / "$" / "'" / "=" - * pct-encoded-unescaped = "%" ( "0" / "1" / "3" / "4" / "6" / "7" / "8" / "9" / A-to-F ) HEXDIG - * / "%" "2" ( "0" / "1" / "3" / "4" / "5" / "6" / "7" / "8" / "9" / A-to-F ) - * / "%" "5" ( DIGIT / "A" / "B" / "D" / "E" / "F" ) + * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" + * other-delims = "!" / "(" / ")" / "*" / "+" / "," / ";" + * qchar-unescaped = unreserved / pct-encoded-unescaped / other-delims / ":" / "@" / "/" / "?" / "$" / "'" / "=" + * pct-encoded-unescaped = "%" ( "0" / "1" / "3" / "4" / "6" / "7" / "8" / "9" / A-to-F ) HEXDIG + * / "%" "2" ( "0" / "1" / "3" / "4" / "5" / "6" / "7" / "8" / "9" / A-to-F ) + * / "%" "5" ( DIGIT / "A" / "B" / "D" / "E" / "F" ) * - * qchar-no-AMP-DQUOTE = qchar-unescaped / escape ( escape / quotation-mark ) + * qchar-no-AMP-DQUOTE = qchar-unescaped / escape ( escape / quotation-mark ) * - * escape = "\" / "%5C" ; reverse solidus U+005C - * quotation-mark = DQUOTE / "%22" - * ALPHA = %x41-5A / %x61-7A - * DIGIT = %x30-39 + * escape = "\" / "%5C" ; reverse solidus U+005C + * quotation-mark = DQUOTE / "%22" + * ALPHA = %x41-5A / %x61-7A + * DIGIT = %x30-39 * DQUOTE = %x22 * * @throws Exception @@ -218,7 +214,7 @@ public class SearchTokenizerTest { assertQuery("\"123\" OR \"ALPHA-._~\"").resultsIn(PHRASE, OR, PHRASE); assertQuery("\"100%Olingo\"").resultsIn(new Validator.Tuple(PHRASE, "\"100%Olingo\"")); assertQuery("\"100'Olingo\"").resultsIn(new Validator.Tuple(PHRASE, "\"100'Olingo\"")); - //escaped characters + // escaped characters assertQuery("\"\\\"123\" OR \"\\\\abc\"").resultsIn(new Validator.Tuple(PHRASE, "\"\"123\""), new Validator.Tuple(OR), new Validator.Tuple(PHRASE, "\"\\abc\"")); assertQuery("\"\\\"1\\\\23\"").resultsIn(new Validator.Tuple(PHRASE, "\"\"1\\23\"")); @@ -294,15 +290,15 @@ public class SearchTokenizerTest { assertQuery("abc AND \"something\" )").resultsIn(WORD, AND, PHRASE, CLOSE); } - public void validate(String query) throws SearchTokenizerException { + public void validate(final String query) throws SearchTokenizerException { new Validator(query); } - public Validator assertQuery(String query) throws SearchTokenizerException { + public Validator assertQuery(final String query) throws SearchTokenizerException { return new Validator(query); } - public void validate(String query, SearchQueryToken.Token ... tokens) throws SearchTokenizerException { + public void validate(final String query, final SearchQueryToken.Token... tokens) throws SearchTokenizerException { Validator sv = new Validator(query); for (SearchQueryToken.Token token : tokens) { sv.addExpected(token); @@ -315,32 +311,37 @@ public class SearchTokenizerTest { private boolean log; private final String searchQuery; - public void resultsIn(SearchQueryToken.Token... tokens) throws SearchTokenizerException { + public void resultsIn(final SearchQueryToken.Token... tokens) throws SearchTokenizerException { addExpected(tokens); validate(); } - public void resultsIn(Tuple... tuple) throws SearchTokenizerException { + + public void resultsIn(final Tuple... tuple) throws SearchTokenizerException { for (Tuple t : tuple) { addExpected(t.token, t.literal); } validate(); } - public static Tuple tuple(SearchQueryToken.Token token, String literal) { + + public static Tuple tuple(final SearchQueryToken.Token token, final String literal) { return new Tuple(token, literal); } + private static class Tuple { final SearchQueryToken.Token token; final String literal; - public Tuple(SearchQueryToken.Token token, String literal) { + + public Tuple(final SearchQueryToken.Token token, final String literal) { this.token = token; this.literal = literal; } - public Tuple(SearchQueryToken.Token token) { + + public Tuple(final SearchQueryToken.Token token) { this(token, null); } } - private Validator(String searchQuery) { + private Validator(final String searchQuery) { this.searchQuery = searchQuery; } @@ -348,24 +349,26 @@ public class SearchTokenizerTest { log = true; return this; } - private Validator addExpected(SearchQueryToken.Token token, String literal) { + + private Validator addExpected(final SearchQueryToken.Token token, final String literal) { validations.add(new Tuple(token, literal)); return this; } - private Validator addExpected(SearchQueryToken.Token ... token) { + + private Validator addExpected(final SearchQueryToken.Token... token) { for (SearchQueryToken.Token t : token) { validations.add(new Tuple(t)); } return this; } - private void resultsIn(SearchTokenizerException.MessageKey key) + private void resultsIn(final SearchTokenizerException.MessageKey key) throws SearchTokenizerException { try { validate(); } catch (SearchTokenizerException e) { Assert.assertEquals("SearchTokenizerException with unexpected message was thrown.", key, e.getMessageKey()); - if(log) { + if (log) { System.out.println("Caught SearchTokenizerException with message key " + e.getMessageKey() + " and message " + e.getMessage()); } @@ -378,17 +381,17 @@ public class SearchTokenizerTest { SearchTokenizer tokenizer = new SearchTokenizer(); List<SearchQueryToken> result = tokenizer.tokenize(searchQuery); Assert.assertNotNull(result); - if(log) { + if (log) { System.out.println(result); } - if(validations.size() != 0) { + if (validations.size() != 0) { Assert.assertEquals(validations.size(), result.size()); Iterator<Tuple> validationIt = validations.iterator(); for (SearchQueryToken iToken : result) { Tuple validation = validationIt.next(); Assert.assertEquals(validation.token, iToken.getToken()); - if(validation.literal != null) { + if (validation.literal != null) { Assert.assertEquals(validation.literal, iToken.getLiteral()); } }
