diff --git a/pom.xml b/pom.xml
index 5c2f8fcde..3c48025f5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -116,6 +116,18 @@
2.7.17
test
+
+ org.hamcrest
+ hamcrest-core
+ 1.3
+ test
+
+
+ org.hamcrest
+ hamcrest-library
+ 1.3
+ test
+
diff --git a/src/main/java/com/google/cloud/tools/libraries/libraries.json b/src/main/java/com/google/cloud/tools/libraries/libraries.json
index 7c9871ef7..4919a8725 100644
--- a/src/main/java/com/google/cloud/tools/libraries/libraries.json
+++ b/src/main/java/com/google/cloud/tools/libraries/libraries.json
@@ -3,24 +3,75 @@
"name": "Google BigQuery API",
"documentation": "https://cloud.google.com/bigquery/docs/reference/libraries",
"description":"Google's fully managed, petabyte scale, serverless data warehouse for analytics",
- "transport": "http",
+ "transports": ["http"],
"icon":"https://cloud.google.com/_static/images/cloud/products/logos/svg/bigquery.svg",
"clients": [
{
+ "name":"Google Cloud Java Client for BigQuery",
"language":"java",
"site":"https://cloud.google.com/bigquery/docs/reference/libraries#client-libraries-install-java",
- "apireference":"https://googlecloudplatform.github.io/google-cloud-java/0.22.0/apidocs/com/google/cloud/bigquery/package-summary.html",
- "version" : "0.22.0",
+ "apireference":"https://googlecloudplatform.github.io/google-cloud-java/latest/apidocs/com/google/cloud/bigquery/package-summary.html",
"infotip":"The com.google.cloud.bigquery packages",
- "status" : "beta",
+ "launchStage" : "beta",
+ "packages" : ["com.google.cloud.bigquery"],
"source" : "https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-bigquery",
"languageLevel" : "1.7.0",
"mavenCoordinates" : {
"groupId" : "com.google.cloud",
"artifactId" : "google-cloud-bigquery",
"version" : "0.22.0-beta"
+ }
}
- }
- ]
+ ]
+ },
+ {
+ "name": "Google Cloud Datastore",
+ "documentation": "https://cloud.google.com/datastore/docs/reference/libraries",
+ "description":"Google Cloud Datastore is a NoSQL key-value database built for automatic scaling.",
+ "transports": ["http"],
+ "icon":"https://cloud.google.com/_static/images/cloud/products/logos/svg/datastore.svg",
+ "clients": [
+ {
+ "name":"Cloud Datastore Client Library for Java",
+ "language":"java",
+ "site":"https://cloud.google.com/datastore/docs/reference/libraries#client-libraries-install-java",
+ "apireference":"https://googlecloudplatform.github.io/google-cloud-java/latest/apidocs/index.html?com/google/cloud/datastore/package-summary.html",
+ "infotip":"The com.google.cloud.datastore packages",
+ "packages" : ["com.google.cloud.datastore"],
+ "launchStage" : "GA",
+ "source" : "https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-bigquery",
+ "languageLevel" : "1.7.0",
+ "mavenCoordinates" : {
+ "groupId" : "com.google.cloud",
+ "artifactId" : "google-cloud-datastore",
+ "version" : "1.4.0"
+ }
+ }
+ ]
+ },
+ {
+ "name": "Google Cloud Storage",
+ "documentation": "https://cloud.google.com/storage/docs/reference/libraries",
+ "description":"Unified BLOB storage for developers and enterprises, from live data serving to data analytics/ML to data archiving.",
+ "transports": ["http"],
+ "icon":"https://cloud.google.com/_static/images/cloud/products/logos/svg/storage.svg",
+ "clients": [
+ {
+ "name":"Google Cloud Storage Client Library for Java",
+ "language":"java",
+ "site":"https://cloud.google.com/storage/docs/reference/libraries#client-libraries-install-java",
+ "apireference" : "https://googlecloudplatform.github.io/google-cloud-java/latest/apidocs/index.html?com/google/cloud/storage/package-summary.html",
+ "packages" : ["com.google.cloud.storage"],
+ "infotip":"The com.google.cloud.storage packages for client side access to GCS",
+ "launchStage" : "GA",
+ "source" : "https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master/google-cloud-storage",
+ "languageLevel" : "1.7.0",
+ "mavenCoordinates" : {
+ "groupId" : "com.google.cloud",
+ "artifactId" : "google-cloud-storage",
+ "version" : "1.4.0"
+ }
+ }
+ ]
}
-]
\ No newline at end of file
+]
diff --git a/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java b/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java
index e15a1b891..09814e825 100644
--- a/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java
+++ b/src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java
@@ -1,4 +1,22 @@
-package com.google.cloud.tools.libraries;
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Licensed 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 com.google.cloud.tools.libraries;
+
+import static org.hamcrest.collection.IsArrayContaining.hasItemInArray;
import java.io.File;
import java.io.FileInputStream;
@@ -7,25 +25,36 @@
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
-import java.util.Iterator;
+import java.util.HashMap;
+import java.util.Map;
+import javax.json.Json;
+import javax.json.JsonArray;
+import javax.json.JsonObject;
+import javax.json.JsonReader;
+import javax.json.JsonReaderFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
import org.xml.sax.SAXException;
-import javax.json.Json;
-import javax.json.JsonArray;
-import javax.json.JsonObject;
-import javax.json.JsonReader;
-import javax.json.JsonReaderFactory;
-import javax.json.JsonValue;
-
public class LibrariesTest {
+ private JsonObject[] apis;
+
+ @Before
+ public void parseJson() throws FileNotFoundException {
+ JsonReaderFactory factory = Json.createReaderFactory(null);
+ InputStream in =
+ new FileInputStream("src/main/java/com/google/cloud/tools/libraries/libraries.json");
+ JsonReader reader = factory.createReader(in);
+ apis = reader.readArray().toArray(new JsonObject[0]);
+ }
+
@Test
public void testWellFormed() throws ParserConfigurationException, SAXException, IOException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
@@ -36,27 +65,59 @@ public void testWellFormed() throws ParserConfigurationException, SAXException,
}
@Test
- public void testJson() throws FileNotFoundException, URISyntaxException {
- JsonReaderFactory factory = Json.createReaderFactory(null);
- InputStream in =
- new FileInputStream("src/main/java/com/google/cloud/tools/libraries/libraries.json");
- JsonReader reader = factory.createReader(in);
- Iterator apis = reader.readArray().iterator();
- Assert.assertTrue(apis.hasNext());
- for (JsonObject api = (JsonObject) apis.next(); apis.hasNext(); api = (JsonObject) apis.next()) {
-
- new URI(api.getString("documentation"));
- if (api.getString("icon") != null) {
- new URI(api.getString("icon"));
+ public void testJson() throws URISyntaxException {
+ Assert.assertTrue(apis.length > 0);
+ for (int i = 0; i < apis.length; i++) {
+ assertApi(apis[i]);
+ }
+ }
+
+ private static final String[] statuses = {"early access", "alpha", "beta", "GA", "deprecated"};
+
+ private static void assertApi(JsonObject api) throws URISyntaxException {
+ Assert.assertFalse(api.getString("name").isEmpty());
+ Assert.assertFalse(api.getString("description").isEmpty());
+ String transports = api.getJsonArray("transports").getString(0);
+ Assert.assertTrue(transports + " is not a recognized transport",
+ "http".equals(transports) || "grpc".equals(transports));
+ new URI(api.getString("documentation"));
+ if (api.getString("icon") != null) {
+ new URI(api.getString("icon"));
+ }
+ JsonArray clients = api.getJsonArray("clients");
+ Assert.assertFalse(clients.isEmpty());
+ for (int i = 0; i < clients.size(); i++) {
+ JsonObject client = (JsonObject) clients.get(i);
+ String launchStage = client.getString("launchStage");
+ Assert.assertThat(statuses, hasItemInArray(launchStage));
+ new URI(client.getString("apireference"));
+ new URI(client.getString("site"));
+ Assert.assertTrue(client.getString("languageLevel").matches("1\\.\\d+\\.\\d+"));
+ Assert.assertFalse(client.getString("name").isEmpty());
+ Assert.assertNotNull(client.getJsonObject("mavenCoordinates"));
+ if (client.getString("source") != null) {
+ new URI(client.getString("source"));
+ }
+ }
+ }
+
+ @Test
+ public void testDuplicates() throws URISyntaxException {
+ Map apiCoordinates = new HashMap<>();
+ for (int i = 0; i < apis.length; i++) {
+ JsonObject api = apis[i];
+ String name = api.getString("name");
+ if (apiCoordinates.containsKey(name)) {
+ Assert.fail(name + " is defined twice");
}
- JsonArray clients = api.getJsonArray("clients");
- Assert.assertFalse(clients.isEmpty());
- for (int i = 0; i < clients.size(); i++) {
- JsonObject client = (JsonObject) clients.get(i);
- String status = client.getString("status");
- Assert.assertTrue(status,
- "beta".equals(status) || "alpha".equals(status) || "GA".equals(status));
+ JsonObject coordinates =
+ ((JsonObject) api.getJsonArray("clients").get(0)).getJsonObject("mavenCoordinates");
+ String mavenCoordinates =
+ coordinates.getString("groupId") + ":" + coordinates.getString("artifactId");
+ if (apiCoordinates.containsValue(mavenCoordinates)) {
+ Assert.fail(mavenCoordinates + " is defined twice");
}
+ apiCoordinates.put(name, mavenCoordinates);
}
}