-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
expand JSON test coverage; add datastore and cloud storage #443
Changes from 12 commits
833b073
41e8f29
896ac8f
500ee93
eb8283a
568fd0e
653117f
4de1ae1
6146737
4e6949f
26e02d9
a29e993
ec13151
7ec06f6
6e23e11
fd5b606
867bd07
abaf735
7517ae3
88a622e
2c8e5d8
05e0d09
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
|
@@ -7,8 +25,16 @@ | |
import java.io.InputStream; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.util.HashMap; | ||
import java.util.Iterator; | ||
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.json.JsonValue; | ||
import javax.xml.parsers.DocumentBuilder; | ||
import javax.xml.parsers.DocumentBuilderFactory; | ||
import javax.xml.parsers.ParserConfigurationException; | ||
|
@@ -17,13 +43,6 @@ | |
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 { | ||
|
||
@Test | ||
|
@@ -43,20 +62,66 @@ public void testJson() throws FileNotFoundException, URISyntaxException { | |
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()) { | ||
while (apis.hasNext()) { | ||
JsonObject api = (JsonObject) apis.next(); | ||
verifyApi(api); | ||
} | ||
} | ||
|
||
private static final String[] statuses = {"alpha", "beta", "GA"}; | ||
|
||
private static void verifyApi(JsonObject api) throws URISyntaxException { | ||
Assert.assertFalse(api.getString("name").isEmpty()); | ||
Assert.assertFalse(api.getString("description").isEmpty()); | ||
String transport = api.getString("transport"); | ||
Assert.assertTrue("http".equals(transport) || "grpc".equals(transport)); | ||
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 status = client.getString("status"); | ||
|
||
Assert.assertThat(statuses, hasItemInArray(status)); | ||
new URI(client.getString("apireference")); | ||
new URI(client.getString("site")); | ||
Assert.assertTrue(client.getString("languageLevel").matches("1\\.\\d+\\.\\d+")); | ||
String versionString = client.getString("version"); | ||
Assert.assertTrue(versionString.matches("\\d+\\.\\d+\\.\\d+")); | ||
Assert.assertNotNull(client.getJsonObject("mavenCoordinates")); | ||
if (client.getString("source") != null) { | ||
new URI(client.getString("source")); | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
public void testMavenCoordinates() throws FileNotFoundException, URISyntaxException { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could this be named testMavenCoordinate_fileIsValid or something? It's hard for me to tell (since I didn't really look at the previous CL) what this test is doing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
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()); | ||
|
||
new URI(api.getString("documentation")); | ||
if (api.getString("icon") != null) { | ||
new URI(api.getString("icon")); | ||
Map<String, String> map = new HashMap<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. name of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
while (apis.hasNext()) { | ||
JsonObject api = (JsonObject) apis.next(); | ||
String name = api.getString("name"); | ||
if (map.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 (map.containsValue(mavenCoordinates)) { | ||
Assert.fail(mavenCoordinates + " is defined twice"); | ||
} | ||
map.put(name, mavenCoordinates); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit : would using assertApi instead of verifyApi clarify that the intention of the method is to make assertions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done