You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2014/10/27 15:18:58 UTC
svn commit: r1634544 - in /sis/branches/JDK8:
core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/
core/sis-metadata/src/test/java/org/apache/sis/test/suite/
core/sis-metadata/src/test/resources/org/apache/sis/metadata/iso/
core/sis-utility/src...
Author: desruisseaux
Date: Mon Oct 27 14:18:58 2014
New Revision: 1634544
URL: http://svn.apache.org/r1634544
Log:
Added a test for verifying API changes.
Added:
sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/APIVerifier.java (with props)
sis/branches/JDK8/core/sis-metadata/src/test/resources/org/apache/sis/metadata/iso/api-changes.properties
- copied, changed from r1634464, sis/trunk/core/sis-metadata/src/test/resources/org/apache/sis/metadata/iso/api-changes.properties
Modified:
sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/TestSuite.java
sis/branches/JDK8/ide-project/NetBeans/build.xml
Added: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/APIVerifier.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/APIVerifier.java?rev=1634544&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/APIVerifier.java (added)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/APIVerifier.java [UTF-8] Mon Oct 27 14:18:58 2014
@@ -0,0 +1,136 @@
+/*
+ * 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.sis.metadata.iso;
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Method;
+import org.opengis.annotation.UML;
+import org.apache.sis.metadata.MetadataStandard;
+import org.apache.sis.test.TestCase;
+import org.apache.sis.util.CharSequences;
+import org.apache.sis.util.Classes;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Verifies the API changes caused by the ISO 19115:2003 to ISO 19115:2014 upgrade.
+ * This class compares the presence of {@link Deprecated} and {@link UML} annotations
+ * against a the content of an automatically generated {@code api-changes.properties} file.
+ * The intend is to ensure that we did not forgot an annotation or put the wrong one.
+ *
+ * <p>The content of the {@code api-changes.properties} files is typically empty on Apache SIS
+ * branches that use a snapshot version of GeoAPI, thus making this test a no-op. However the
+ * {@code api-changes.properties} file content is non-empty on trunk if the GeoAPI release used
+ * by the trunk is behind the snapshot developments.</p>
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.5
+ * @version 0.5
+ * @module
+ */
+public final strictfp class APIVerifier extends TestCase {
+ /**
+ * The method being verified.
+ * This is used in case of errors for providing information about the problematic method.
+ */
+ private Method method;
+
+ /**
+ * Verifies the API changes for the ISO 19115 standard.
+ *
+ * @throws IOException If an error occurred while reading the {@code "api-changes.properties"} file.
+ * @throws ClassNotFoundException If a class declared in {@code "api-changes.properties"} has not been found.
+ * @throws NoSuchMethodException If a method declared in {@code "api-changes.properties"} has not been found.
+ */
+ @Test
+ public void verifyISO1915() throws IOException, ClassNotFoundException, NoSuchMethodException {
+ final Properties changes = new Properties();
+ final InputStream in = APIVerifier.class.getResourceAsStream("api-changes.properties");
+ assertNotNull("Missing test resource file.", in);
+ changes.load(in);
+ in.close();
+ try {
+ verifyAPI(MetadataStandard.ISO_19115, changes);
+ } catch (AssertionError e) {
+ out.println("Method " + method);
+ throw e;
+ }
+ }
+
+ /**
+ * Implementation of {@link #verifyISO1915()}.
+ *
+ * @param standard The metadata standard.
+ * @param changes The list of changes in the given metadata standard.
+ */
+ private void verifyAPI(final MetadataStandard standard, final Properties changes)
+ throws ClassNotFoundException, NoSuchMethodException
+ {
+ final Set<Method> classChanges = new HashSet<Method>();
+ for (final Map.Entry<Object,Object> entry : changes.entrySet()) {
+ final Class<?> implementation = standard.getImplementation(Class.forName((String) entry.getKey()));
+ for (final String change : (String[]) CharSequences.split((String) entry.getValue(), ' ')) {
+ switch (change.charAt(0)) {
+ case '~': {
+ continue;
+ }
+ case '-': {
+ method = implementation.getMethod(change.substring(1));
+ assertTrue("Expected @Deprecated annotation", method.isAnnotationPresent(Deprecated.class));
+ assertFalse("Expected no @UML annotation", method.isAnnotationPresent(UML.class));
+ break;
+ }
+ case '+': {
+ final int s = change.indexOf(':');
+ assertTrue(change, s >= 0);
+ method = implementation.getMethod(change.substring(1, s));
+ assertFalse("Expected no @Deprecated annotation", method.isAnnotationPresent(Deprecated.class));
+ final UML uml = method.getAnnotation(UML.class);
+ assertNotNull("Expected @UML annotation.", uml);
+ assertEquals(change.substring(s+1), uml.identifier());
+ break;
+ }
+ default: {
+ fail("Unrecognized change: " + change);
+ break;
+ }
+ }
+ assertTrue(classChanges.add(method));
+ }
+ /*
+ * At this point all added/removed methods have been verified.
+ * Now verify that remaining methods have no UML or Deprecated annotation.
+ */
+ final Method[] methods = implementation.getDeclaredMethods();
+ for (int i=0; i<methods.length; i++) {
+ method = methods[i];
+ if (!classChanges.remove(method) && Classes.isPossibleGetter(method)) {
+ assertFalse("Expected no @Deprecated annotation", method.isAnnotationPresent(Deprecated.class));
+ assertFalse("Expected no @UML annotation", method.isAnnotationPresent(UML.class));
+ }
+ }
+ assertTrue(classChanges.isEmpty());
+ }
+ }
+}
Propchange: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/APIVerifier.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/APIVerifier.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java?rev=1634544&r1=1634543&r2=1634544&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java [UTF-8] Mon Oct 27 14:18:58 2014
@@ -86,6 +86,7 @@ import org.junit.BeforeClass;
org.apache.sis.metadata.iso.DefaultMetadataTest.class,
org.apache.sis.metadata.iso.CustomMetadataTest.class,
org.apache.sis.metadata.iso.AllMetadataTest.class,
+ org.apache.sis.metadata.iso.APIVerifier.class,
org.apache.sis.io.wkt.ConventionTest.class,
org.apache.sis.io.wkt.SymbolsTest.class,
Copied: sis/branches/JDK8/core/sis-metadata/src/test/resources/org/apache/sis/metadata/iso/api-changes.properties (from r1634464, sis/trunk/core/sis-metadata/src/test/resources/org/apache/sis/metadata/iso/api-changes.properties)
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/resources/org/apache/sis/metadata/iso/api-changes.properties?p2=sis/branches/JDK8/core/sis-metadata/src/test/resources/org/apache/sis/metadata/iso/api-changes.properties&p1=sis/trunk/core/sis-metadata/src/test/resources/org/apache/sis/metadata/iso/api-changes.properties&r1=1634464&r2=1634544&rev=1634544&view=diff
==============================================================================
--- sis/trunk/core/sis-metadata/src/test/resources/org/apache/sis/metadata/iso/api-changes.properties [ISO-8859-1] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/test/resources/org/apache/sis/metadata/iso/api-changes.properties [ISO-8859-1] Mon Oct 27 14:18:58 2014
@@ -9,35 +9,16 @@
# branches implementing latest GeoAPI snapshots, and may be non-empty on the trunk
# when the changes are not yet incorporated in a standard release.
#
-org.opengis.metadata.citation.Citation=-getCollectiveTitle +getGraphics:graphic +getOnlineResources:onlineResource
-org.opengis.metadata.citation.Contact=-getAddress +getAddresses:address +getContactType:contactType -getOnlineResource +getOnlineResources:onlineResource -getPhone +getPhones:phone
-org.opengis.metadata.citation.OnlineResource=+getProtocolRequest:protocolRequest
-org.opengis.metadata.citation.ResponsibleParty=-getContactInfo -getIndividualName -getOrganisationName -getPositionName
-org.opengis.metadata.citation.Telephone=-getFacsimiles +getNumber:number +getNumberType:numberType -getVoices
-org.opengis.metadata.constraint.Constraints=+getConstraintApplicationScope:constraintApplicationScope +getGraphics:graphic +getReferences:reference +getReleasability:releasability +getResponsibleParties:responsibleParty
-org.opengis.metadata.content.Band=+getBoundMax:boundMax +getBoundMin:boundMin +getBoundUnits:boundUnits
-org.opengis.metadata.content.CoverageDescription=+getAttributeGroups:attributeGroup -getContentType -getDimensions +getProcessingLevelCode:processingLevelCode
-org.opengis.metadata.content.FeatureCatalogueDescription=+getFeatureTypeInfo:featureTypes -getFeatureTypes
-org.opengis.metadata.content.RangeDimension=+getDescription:description -getDescriptor +getNames:name
-org.opengis.metadata.distribution.DigitalTransferOptions=+getDistributionFormats:distributionFormat -getOffLine +getOffLines:offLine +getTransferFrequency:transferFrequency
-org.opengis.metadata.distribution.Distribution=+getDescription:description
-org.opengis.metadata.distribution.Format=+getFormatSpecificationCitation:formatSpecificationCitation +getMedia:medium -getName -getSpecification -getVersion
-org.opengis.metadata.distribution.Medium=-getDensities +getDensity:density +getIdentifier:identifier
-org.opengis.metadata.distribution.StandardOrderProcess=+getOrderOptionType:orderOptionType +getOrderOptions:orderOptions
-org.opengis.metadata.ExtendedElementInformation=-getDomainCode +getRationale:rationale -getRationales -getShortName
-org.opengis.metadata.extent.SpatialTemporalExtent=+getVerticalExtent:verticalExtent
-org.opengis.metadata.identification.AggregateInformation=-getAggregateDataSetIdentifier -getAggregateDataSetName +getMetadataReference:metadataReference +getName:name
-org.opengis.metadata.identification.BrowseGraphic=+getImageConstraints:imageContraints +getLinkages:linkage
-org.opengis.metadata.identification.Identification=+getAdditionalDocumentations:additionalDocumentation ~-getAggregationInfo ~+getAssociatedResources:associatedResource +getExtents:extent +getProcessingLevel:processingLevel +getSpatialRepresentationTypes:spatialRepresentationType +getSpatialResolutions:spatialResolution ~+getTemporalResolutions:temporalResolution +getTopicCategories:topicCategory
-org.opengis.metadata.identification.Keywords=+getKeywordClass:keywordClass
-org.opengis.metadata.identification.Resolution=+getAngularDistance:angularDistance +getLevelOfDetail:levelOfDetail +getVertical:vertical
-org.opengis.metadata.identification.ServiceIdentification=+getAccessProperties:accessProperties +getContainsChain:containsChain +getContainsOperations:containsOperations +getCoupledResources:coupledResource +getCouplingType:couplingType +getOperatedDatasets:operatedDataset +getOperatesOn:operatesOn +getProfiles:profile +getServiceStandards:serviceStandard +getServiceType:serviceType +getServiceTypeVersions:serviceTypeVersion
-org.opengis.metadata.identification.Usage=+getAdditionalDocumentation:additionalDocumentation +getIdentifiedIssues:identifiedIssues +getResponses:response
-org.opengis.metadata.Identifier=+getCodeSpace:codeSpace +getDescription:description +getVersion:version
-org.opengis.metadata.lineage.Lineage=+getAdditionalDocumentation:additionalDocumentation +getScope:scope
-org.opengis.metadata.lineage.ProcessStep=+getReferences:reference +getScope:scope
-org.opengis.metadata.lineage.Source=-getScaleDenominator +getScope:scope -getSourceExtents +getSourceMetadata:sourceMetadata +getSourceSpatialResolution:sourceSpatialResolution
-org.opengis.metadata.maintenance.MaintenanceInformation=-getDateOfNextUpdate +getMaintenanceDates:maintenanceDate +getMaintenanceScopes:maintenanceScope -getUpdateScopeDescriptions -getUpdateScopes
-org.opengis.metadata.Metadata=+getAlternativeMetadataReferences:alternativeMetadataReference -getCharacterSet +getCharacterSets:characterSet -getDataSetUri -getDateStamp +getDates:dateInfo -getFileIdentifier -getHierarchyLevelNames -getHierarchyLevels -getLanguage +getLanguages:defaultLocale+otherLocale -getLocales +getMetadataIdentifier:metadataIdentifier +getMetadataLinkages:metadataLinkage +getMetadataProfiles:metadataProfile +getMetadataScopes:metadataScope -getMetadataStandardName -getMetadataStandardVersion +getMetadataStandards:metadataStandard -getParentIdentifier +getParentMetadata:parentMetadata +getResourceLineages:resourceLineage
-org.opengis.metadata.quality.Scope=-getExtent +getExtents:extent
-org.opengis.metadata.spatial.Dimension=+getDimensionDescription:dimensionDescription +getDimensionTitle:dimensionTitle
+# Legend:
+# - Method has been deprecated.
+# + Method has been added in an existing class. Shall be followed by a colon and UML identifier.
+# ~ Comment out the next element (e.g. for a method that should have been deleted, but is kept for now).
+#
+# Example:
+# org.opengis.metadata.citation.Telephone=-getVoices -getFacsimiles +getNumber:number +getNumberType:numberType
+#
+# Above example means that the Telephone interface needs to have its getVoices() and getFacsimiles()
+# methods deprecated, and to have getNumber() and getNumberType() methods added in order to comply
+# with the changes in the international standard. The UML identifiers of added methods are "number"
+# and "numberType" respectively.
+#
Modified: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/TestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/TestSuite.java?rev=1634544&r1=1634543&r2=1634544&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/TestSuite.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/TestSuite.java [UTF-8] Mon Oct 27 14:18:58 2014
@@ -21,6 +21,7 @@ import java.util.Set;
import java.util.HashSet;
import java.util.List;
import java.util.ArrayList;
+import java.util.Iterator;
import java.io.File;
import java.net.URL;
import java.net.URISyntaxException;
@@ -40,7 +41,7 @@ import static org.junit.Assert.*;
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.3 (derived from geotk-3.16)
- * @version 0.4
+ * @version 0.5
* @module
*/
@RunWith(Suite.class)
@@ -55,6 +56,11 @@ public abstract strictfp class TestSuite
};
/**
+ * Expected suffix in name of test classes.
+ */
+ private static final String CLASSNAME_SUFFIX = "Test";
+
+ /**
* {@code true} for disabling the search for missing tests. This is necessary
* when the test suites are executed from an external project, for example during a
* <a href="https://svn.apache.org/repos/asf/sis/release-test/maven">release test</a>.
@@ -119,6 +125,12 @@ public abstract strictfp class TestSuite
assertTrue(declared.removeAll(tests));
fail("Classes defined twice in " + suite.getSimpleName() + ": " + declared);
}
+ // Ignore classes that are not really test, like "APIVerifier".
+ for (final Iterator<Class<?>> it=tests.iterator(); it.hasNext();) {
+ if (!it.next().getName().endsWith(CLASSNAME_SUFFIX)) {
+ it.remove();
+ }
+ }
removeExistingTests(loader, root, new StringBuilder(120).append(root.getName()), tests);
if (!tests.isEmpty()) {
fail("Classes not found. Are they defined in an other module? " + tests);
@@ -141,7 +153,7 @@ public abstract strictfp class TestSuite
if (file.isDirectory()) {
removeExistingTests(loader, file, path, tests);
} else {
- if (name.endsWith("Test.class")) {
+ if (name.endsWith(CLASSNAME_SUFFIX + ".class")) {
path.setLength(path.length() - 6); // Remove trailing ".class"
final String classname = path.toString();
final Class<?> test;
Modified: sis/branches/JDK8/ide-project/NetBeans/build.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/ide-project/NetBeans/build.xml?rev=1634544&r1=1634543&r2=1634544&view=diff
==============================================================================
--- sis/branches/JDK8/ide-project/NetBeans/build.xml (original)
+++ sis/branches/JDK8/ide-project/NetBeans/build.xml Mon Oct 27 14:18:58 2014
@@ -28,8 +28,8 @@
<!--
Called after compilation. Copies the "*.utf" resources files created by Maven.
- Note that the Apache SIS project must have been build by Maven at least once it
- can be built by the NetBeans IDE.
+ Note that the Apache SIS project must have been build by Maven at least once
+ before it can be built by the NetBeans IDE.
-->
<target name="-post-compile">
<copy todir="${build.classes.dir}/org/apache/sis/util/resources">
@@ -95,6 +95,7 @@
<target name="-post-compile-test">
<copy todir="${build.test.classes.dir}">
<fileset dir="${project.root}/core/sis-metadata/src/test/resources">
+ <include name="**/*.properties"/>
<include name="**/*.xml"/>
</fileset>
<fileset dir="${project.root}/core/sis-referencing/src/test/resources">