Skip to content

Fix checkstyle errors in BigQuery sample tests. #104

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

Merged
merged 1 commit into from
Mar 7, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions bigquery/pom.xml
Original file line number Diff line number Diff line change
@@ -51,8 +51,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-matchers</artifactId>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<version>0.28</version>
<scope>test</scope>
</dependency>
</dependencies>
4 changes: 2 additions & 2 deletions bigquery/src/main/resources/constants.json
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
"datasetId": "test_dataset_java",
"currentTableId": "test_table_java",
"newTableId": "test_table_java_2",
"cloudStorageInputURI": "gs://cloud-samples-tests/data.csv",
"cloudStorageOutputURI": "gs://cloud-samples-tests/output.csv",
"cloudStorageInputUri": "gs://cloud-samples-tests/data.csv",
"cloudStorageOutputUri": "gs://cloud-samples-tests/output.csv",
"query": "SELECT corpus FROM publicdata:samples.shakespeare GROUP BY corpus;"
}
Original file line number Diff line number Diff line change
@@ -1,49 +1,60 @@
/*
* Copyright (c) 2015 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.bigquery.samples.test;

import static com.google.common.truth.Truth.assertThat;

import com.google.api.services.bigquery.model.GetQueryResultsResponse;
import com.google.cloud.bigquery.samples.AsyncQuerySample;
import com.google.gson.JsonIOException;
import com.google.gson.JsonSyntaxException;

import org.junit.*;

import static org.junit.Assert.*;
import org.junit.Ignore;
import org.junit.Test;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Iterator;

/**
* Tests for asynchronous query sample.
*/
public class AsyncQuerySampleTest extends BigquerySampleTest{

/**
* @throws JsonSyntaxException
* @throws JsonIOException
* @throws FileNotFoundException
*/
public AsyncQuerySampleTest() throws JsonSyntaxException, JsonIOException,
FileNotFoundException {
public AsyncQuerySampleTest() throws JsonSyntaxException, JsonIOException, FileNotFoundException {
super();
// TODO(elibixby): Auto-generated constructor stub
}


@Test
public void testInteractive() throws IOException, InterruptedException{
Iterator<GetQueryResultsResponse> pages = AsyncQuerySample.run(CONSTANTS.getProjectId(), CONSTANTS.getQuery(), false, 5000);
while(pages.hasNext()){
assertTrue(!pages.next().getRows().isEmpty());
public void testInteractive() throws IOException, InterruptedException {
Iterator<GetQueryResultsResponse> pages =
AsyncQuerySample.run(CONSTANTS.getProjectId(), CONSTANTS.getQuery(), false, 5000);
while (pages.hasNext()) {
assertThat(pages.next().getRows()).isNotEmpty();
}
}



@Test
@Ignore // Batches can take up to 3 hours to run, probably shouldn't use this
public void testBatch() throws IOException, InterruptedException{
Iterator<GetQueryResultsResponse> pages = AsyncQuerySample.run(CONSTANTS.getProjectId(), CONSTANTS.getQuery(), true, 5000);
while(pages.hasNext()){
assertTrue(!pages.next().getRows().isEmpty());
public void testBatch() throws IOException, InterruptedException {
Iterator<GetQueryResultsResponse> pages =
AsyncQuerySample.run(CONSTANTS.getProjectId(), CONSTANTS.getQuery(), true, 5000);
while (pages.hasNext()) {
assertThat(pages.next().getRows()).isNotEmpty();
}
}


}
Original file line number Diff line number Diff line change
@@ -1,84 +1,81 @@
/*
* Copyright (c) 2015 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.bigquery.samples.test;

import com.google.cloud.bigquery.samples.BigqueryUtils;
import com.google.gson.Gson;
import com.google.gson.JsonIOException;
import com.google.gson.JsonSyntaxException;

import java.io.*;
import java.nio.file.Path;
import java.nio.file.Paths;

import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
* TODO: Insert description here. (generated by elibixby)
* Superclass for tests for samples.
*/
public class BigquerySampleTest extends BigqueryUtils {

protected static class Constants{
protected static class Constants {
private String projectId;
private String datasetId;
private String currentTableId;
private String newTableId;
private String cloudStorageInputURI;
private String cloudStorageOutputURI;
private String cloudStorageInputUri;
private String cloudStorageOutputUri;
private String query;
/**
* @return the projectId
*/

public String getProjectId() {
return projectId;
}
/**
* @return the datasetId
*/

public String getDatasetId() {
return datasetId;
}
/**
* @return the currentTableId
*/

public String getCurrentTableId() {
return currentTableId;
}
/**
* @return the newTableId
*/

public String getNewTableId() {
return newTableId;
}
/**
* @return the query
*/

public String getQuery() {
return query;
}
/**
* @return the cloudStorageOutputURI
*/
public String getCloudStorageOutputURI() {
return cloudStorageOutputURI;

public String getCloudStorageOutputUri() {
return cloudStorageOutputUri;
}
/**
* @return the cloudStorageInputURI
*/
public String getCloudStorageInputURI() {
return cloudStorageInputURI;

public String getCloudStorageInputUri() {
return cloudStorageInputUri;
}
}

protected static Constants CONSTANTS = null ;
@SuppressWarnings("checkstyle:abbreviationaswordinname")
protected static Constants CONSTANTS = null;

protected BigquerySampleTest() throws JsonSyntaxException, JsonIOException, FileNotFoundException{
if(CONSTANTS == null){
InputStream is = this.getClass().getResourceAsStream
("/constants.json");
CONSTANTS = (new Gson()).<Constants>fromJson(
new InputStreamReader(is),
Constants.class);
protected BigquerySampleTest()
throws JsonSyntaxException, JsonIOException, FileNotFoundException {
if (CONSTANTS == null) {
InputStream is = this.getClass().getResourceAsStream("/constants.json");
CONSTANTS = (new Gson()).<Constants>fromJson(new InputStreamReader(is), Constants.class);
}
}



}
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright (c) 2015 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.bigquery.samples.test;

import com.google.cloud.bigquery.samples.ExportDataCloudStorageSample;
@@ -10,29 +26,22 @@
import java.io.IOException;

/**
* TODO: Insert description here. (generated by elibixby)
* Tests for export data Cloud Storage sample.
*/
public class ExportDataCloudStorageSampleTest extends BigquerySampleTest {

/**
* @throws JsonSyntaxException
* @throws JsonIOException
* @throws FileNotFoundException
*/
public ExportDataCloudStorageSampleTest() throws JsonSyntaxException, JsonIOException,
FileNotFoundException {
public ExportDataCloudStorageSampleTest()
throws JsonSyntaxException, JsonIOException, FileNotFoundException {
super();
}

@Test
public void testExportData() throws IOException, InterruptedException{
ExportDataCloudStorageSample.run(CONSTANTS.getCloudStorageOutputURI(),
public void testExportData() throws IOException, InterruptedException {
ExportDataCloudStorageSample.run(
CONSTANTS.getCloudStorageOutputUri(),
CONSTANTS.getProjectId(),
CONSTANTS.getDatasetId(),
CONSTANTS.getCurrentTableId(),
5000L);
}



}
Original file line number Diff line number Diff line change
@@ -1,35 +1,45 @@
/*
* Copyright (c) 2015 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.bigquery.samples.test;

import com.google.api.services.bigquery.model.GetQueryResultsResponse;
import static com.google.common.truth.Truth.assertThat;

import com.google.cloud.bigquery.samples.GettingStarted;
import com.google.gson.JsonIOException;
import com.google.gson.JsonSyntaxException;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.Test;

import static com.jcabi.matchers.RegexMatchers.*;
import static org.junit.Assert.*;
import static org.junit.matchers.JUnitMatchers.*;

import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Iterator;


/**
* Test for GettingStarted.java
*/
public class GettingStartedTest extends BigquerySampleTest {
private final ByteArrayOutputStream stdout = new ByteArrayOutputStream();
private final ByteArrayOutputStream stderr = new ByteArrayOutputStream();
private static final PrintStream REAL_OUT = System.out;
private static final PrintStream REAL_ERR = System.err;

private final ByteArrayOutputStream stdout = new ByteArrayOutputStream();
private final ByteArrayOutputStream stderr = new ByteArrayOutputStream();

public GettingStartedTest() throws FileNotFoundException {
super();
}
@@ -50,7 +60,7 @@ public void tearDown() {
public void testSyncQuery() throws IOException {
GettingStarted.main(new String[] { CONSTANTS.getProjectId() });
String out = stdout.toString();
assertThat(out, containsPattern("Query Results:"));
assertThat(out, containsString("hamlet"));
assertThat(out).named("stdout").containsMatch("Query Results:");
assertThat(out).named("stdout").contains("hamlet");
}
}
Original file line number Diff line number Diff line change
@@ -16,9 +16,7 @@

package com.google.cloud.bigquery.samples.test;

import static com.jcabi.matchers.RegexMatchers.*;
import static org.junit.Assert.*;
import static org.junit.matchers.JUnitMatchers.*;
import static com.google.common.truth.Truth.assertThat;

import com.google.cloud.bigquery.samples.ListDatasetsProjects;

@@ -31,18 +29,20 @@
import java.io.PrintStream;
import java.lang.Exception;

/** Unit tests for {@link ListDatasetsProjects}. */
/**
* Unit tests for {@link ListDatasetsProjects}.
*/
public class ListDatasetsProjectsTest extends BigquerySampleTest {
private static final PrintStream REAL_OUT = System.out;
private static final PrintStream REAL_ERR = System.err;

private final ByteArrayOutputStream stdout = new ByteArrayOutputStream();
private final ByteArrayOutputStream stderr = new ByteArrayOutputStream();

public ListDatasetsProjectsTest() throws FileNotFoundException {
super();
}

private final ByteArrayOutputStream stdout = new ByteArrayOutputStream();
private final ByteArrayOutputStream stderr = new ByteArrayOutputStream();
private static final PrintStream REAL_OUT = System.out;
private static final PrintStream REAL_ERR = System.err;

@Before
public void setUp() {
System.setOut(new PrintStream(stdout));
@@ -58,22 +58,22 @@ public void tearDown() {
@Test
public void testUsage() throws Exception {
ListDatasetsProjects.main(new String[] {});
assertEquals("Usage: QuickStart <project-id>\n", stderr.toString());
assertThat(stderr.toString()).named("stderr").isEqualTo("Usage: QuickStart <project-id>\n");
}

@Test
public void testMain() throws Exception {
ListDatasetsProjects.main(new String[] { CONSTANTS.getProjectId() });
String out = stdout.toString();
assertThat(out, containsString("Running the asynchronous query"));
assertThat(out, containsPattern("George W. Bush, [0-9]+"));
assertThat(out, containsPattern("Wikipedia, [0-9]+"));
assertThat(out).named("stdout").contains("Running the asynchronous query");
assertThat(out).named("stdout").containsMatch("George W. Bush, [0-9]+");
assertThat(out).named("stdout").containsMatch("Wikipedia, [0-9]+");

assertThat(out, containsString("Listing all the Datasets"));
assertThat(out, containsString("test_dataset"));
assertThat(out).named("stdout").contains("Listing all the Datasets");
assertThat(out).named("stdout").contains("test_dataset");

assertThat(out, containsString("Listing all the Projects"));
assertThat(out, containsString("Project list:"));
assertThat(out, containsPattern("Bigquery Samples|cloud-samples-tests"));
assertThat(out).named("stdout").contains("Listing all the Projects");
assertThat(out).named("stdout").contains("Project list:");
assertThat(out).named("stdout").containsMatch("Bigquery Samples|cloud-samples-tests");
}
}
Original file line number Diff line number Diff line change
@@ -1,39 +1,51 @@
/*
* Copyright (c) 2015 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.bigquery.samples.test;

import com.google.cloud.bigquery.samples.LoadDataCsvSample;
import com.google.gson.JsonIOException;
import com.google.gson.JsonSyntaxException;
import com.google.cloud.bigquery.samples.LoadDataCsvSample;

import org.junit.Test;

import java.io.*;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;

/**
* TODO: Insert description here. (generated by elibixby)
* Tests for sample that loads data from CSV.
*/
public class LoadDataCsvSampleTest extends BigquerySampleTest {

/**
* @throws JsonSyntaxException
* @throws JsonIOException
* @throws FileNotFoundException
*/
public LoadDataCsvSampleTest() throws JsonSyntaxException, JsonIOException, FileNotFoundException {
// TODO(elibixby): Auto-generated constructor stub
public LoadDataCsvSampleTest()
throws JsonSyntaxException, JsonIOException, FileNotFoundException {
super();
}

@Test
public void testLoadData() throws IOException, InterruptedException{

InputStreamReader is = new InputStreamReader(LoadDataCsvSample
.class.getResourceAsStream("/schema.json"));
public void testLoadData() throws IOException, InterruptedException {
InputStreamReader is =
new InputStreamReader(LoadDataCsvSample.class.getResourceAsStream("/schema.json"));
LoadDataCsvSample.run(
CONSTANTS.getCloudStorageInputURI(),
CONSTANTS.getCloudStorageInputUri(),
CONSTANTS.getProjectId(),
CONSTANTS.getDatasetId(),
CONSTANTS.getNewTableId(),
is ,
is,
5000L);
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
/*
* Copyright (c) 2015 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.bigquery.samples.test;

import static org.junit.Assert.*;
import static com.google.common.truth.Truth.assertThat;

import com.google.api.services.bigquery.model.TableDataInsertAllResponse;
import com.google.cloud.bigquery.samples.StreamingSample;
@@ -10,38 +26,35 @@

import org.junit.Test;

import java.io.*;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Iterator;

/**
* TODO: Insert description here. (generated by elibixby)
* Tests for streaming sample.
*/
public class StreamingSampleTest extends BigquerySampleTest {

/**
* @throws JsonSyntaxException
* @throws JsonIOException
* @throws FileNotFoundException
*/
public StreamingSampleTest() throws JsonSyntaxException, JsonIOException, FileNotFoundException {
super();
}

@Test
public void testStream() throws IOException{
JsonReader json = new JsonReader(
new InputStreamReader(BigquerySampleTest
.class.getResourceAsStream("/streamrows.json")));
Iterator<TableDataInsertAllResponse> response = StreamingSample.run(
CONSTANTS.getProjectId(),
CONSTANTS.getDatasetId(),
CONSTANTS.getCurrentTableId(),
json);

while(response.hasNext()){
assertTrue(!response.next().isEmpty());
public void testStream() throws IOException {
JsonReader json =
new JsonReader(
new InputStreamReader(
BigquerySampleTest.class.getResourceAsStream("/streamrows.json")));
Iterator<TableDataInsertAllResponse> response =
StreamingSample.run(
CONSTANTS.getProjectId(),
CONSTANTS.getDatasetId(),
CONSTANTS.getCurrentTableId(),
json);

while (response.hasNext()) {
assertThat(response.next()).isNotEmpty();
}

}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
/*
* Copyright (c) 2015 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.bigquery.samples.test;

import static org.junit.Assert.*;
import static com.google.common.truth.Truth.assertThat;

import com.google.api.services.bigquery.model.GetQueryResultsResponse;
import com.google.cloud.bigquery.samples.SyncQuerySample;
@@ -13,31 +29,25 @@
import java.io.IOException;
import java.util.Iterator;


/**
* TODO: Insert description here. (generated by elibixby)
* Tests for synchronous query sample.
*/
public class SyncQuerySampleTest extends BigquerySampleTest {

/**
* @throws JsonSyntaxException
* @throws JsonIOException
* @throws FileNotFoundException
*/
public SyncQuerySampleTest() throws JsonSyntaxException, JsonIOException,
FileNotFoundException {
public SyncQuerySampleTest()
throws JsonSyntaxException, JsonIOException, FileNotFoundException {
super();
}

@Test
public void testSyncQuery() throws IOException{
Iterator<GetQueryResultsResponse> pages = SyncQuerySample.run(
CONSTANTS.getProjectId(),
CONSTANTS.getQuery(),
10000);
while(pages.hasNext()){
assertTrue(!pages.next().getRows().isEmpty());
public void testSyncQuery() throws IOException {
Iterator<GetQueryResultsResponse> pages =
SyncQuerySample.run(
CONSTANTS.getProjectId(),
CONSTANTS.getQuery(),
10000);
while (pages.hasNext()) {
assertThat(pages.next().getRows()).isNotEmpty();
}
}

}