Skip to content

Commit

Permalink
expand JSON test coverage; add datastore and cloud storage (#443)
Browse files Browse the repository at this point in the history
* expand JSON test coverage

* add test for equals

* hamcrest

* redundant assert removed

* fix loop

* fix loop

* regex versions

* don't make repo a corrdinate

* type to packaging

* verify group ID artifact ID

* checkstyle fixes

* revert metadata for now

* code review

* add datastore api

* toArray

* GCS

* make transport an array

* make transport an array

* launchStage

* pluralize transports

* pluralize transports

* add packages
  • Loading branch information
elharo authored Sep 8, 2017
1 parent a6ec35c commit 8193135
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 35 deletions.
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@
<version>2.7.17</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
65 changes: 58 additions & 7 deletions src/main/java/com/google/cloud/tools/libraries/libraries.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
]
}
]
]
117 changes: 89 additions & 28 deletions src/test/java/com/google/cloud/tools/libraries/LibrariesTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
Expand All @@ -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<JsonValue> 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<String, String> 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);
}
}

Expand Down

0 comments on commit 8193135

Please sign in to comment.