Skip to content

Commit e73d9fe

Browse files
author
Bill Prin
committed
Fix tests, use resources instead of files
1 parent 0491b31 commit e73d9fe

File tree

8 files changed

+59
-47
lines changed

8 files changed

+59
-47
lines changed

bigquery/pom.xml

+16-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.google.cloud.bigquery.samples</groupId>
5-
<artifactId>bq-gettingstarted</artifactId>
5+
<artifactId>bigquery-samples</artifactId>
66
<packaging>jar</packaging>
7-
<version>1.0-SNAPSHOT</version>
8-
<name>bq-gettingstarted</name>
9-
<url>http://maven.apache.org</url>
107

11-
<repositories>
8+
<parent>
9+
<artifactId>doc-samples</artifactId>
10+
<groupId>com.google.cloud</groupId>
11+
<version>1.0.0</version>
12+
<relativePath>..</relativePath>
13+
</parent>
14+
15+
16+
<repositories>
1217
<repository>
1318
<id>googleapis</id>
1419
<url>https://google-api-client-libraries.appspot.com/mavenrepo</url>
@@ -39,8 +44,6 @@
3944
<dependency>
4045
<groupId>junit</groupId>
4146
<artifactId>junit</artifactId>
42-
<version>4.12</version>
43-
<scope>test</scope>
4447
</dependency>
4548
<dependency>
4649
<groupId>com.google.code.gson</groupId>
@@ -56,6 +59,12 @@
5659
</properties>
5760

5861
<build>
62+
<sourceDirectory>src/main/java</sourceDirectory>
63+
<resources>
64+
<resource>
65+
<directory>src/main/resources</directory>
66+
</resource>
67+
</resources>
5968
<plugins>
6069
<plugin>
6170
<groupId>org.apache.maven.plugins</groupId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"projectId": "bigquery-devrel-samples",
3+
"datasetId": "test_dataset",
4+
"currentTableId": "test_table",
5+
"newTableId": "test_table2",
6+
"cloudStorageInputURI": "gs://bigquery-devrel-samples-bucket/data.csv",
7+
"cloudStorageOutputURI": "gs://bigquery-devrel-samples-bucket/output.csv",
8+
"query": "SELECT corpus FROM publicdata:samples.shakespeare GROUP BY corpus;"
9+
}
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"type": "STRING", "name": "Name"}, {"type": "INTEGER", "name": "Age"}, {"type": "FLOAT", "name": "Weight"}, {"type": "BOOLEAN", "name": "IsMagic"}]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
{"Name": "test", "Age": 0, "Weight": 100.0, "IsMagic": false},
3+
{"Name": "test", "Age": 1, "Weight": 100.0, "IsMagic": false},
4+
{"Name": "test", "Age": 2, "Weight": 100.0, "IsMagic": false},
5+
{"Name": "test", "Age": 3, "Weight": 100.0, "IsMagic": false},
6+
{"Name": "test", "Age": 0, "Weight": 100.0, "IsMagic": false}
7+
]

bigquery/src/test/java/com/google/cloud/bigquery/samples/test/BigquerySampleTest.java

+10-17
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@
55
import com.google.gson.JsonIOException;
66
import com.google.gson.JsonSyntaxException;
77

8-
import java.io.File;
9-
import java.io.FileNotFoundException;
10-
import java.io.FileReader;
8+
import java.io.*;
119
import java.nio.file.Path;
1210
import java.nio.file.Paths;
1311

1412

1513
/**
1614
* TODO: Insert description here. (generated by elibixby)
1715
*/
18-
public class BigquerySampleTest extends BigqueryUtils{
16+
public class BigquerySampleTest extends BigqueryUtils {
1917

2018
protected static class Constants{
2119
private String projectId;
@@ -69,23 +67,18 @@ public String getCloudStorageInputURI() {
6967
}
7068
}
7169

72-
73-
protected static final Path RESOURCE_PATH = Paths.get(System.getProperty("user.dir"))
74-
.getParent().resolve("resources");
75-
76-
protected static final File CONSTANTS_FILE = new File(RESOURCE_PATH.resolve("constants.json").toString());
77-
7870
protected static Constants CONSTANTS = null ;
79-
71+
8072
protected BigquerySampleTest() throws JsonSyntaxException, JsonIOException, FileNotFoundException{
8173
if(CONSTANTS == null){
74+
InputStream is = this.getClass().getResourceAsStream
75+
("/constants.json");
8276
CONSTANTS = (new Gson()).<Constants>fromJson(
83-
new FileReader(CONSTANTS_FILE),
84-
Constants.class);
85-
77+
new InputStreamReader(is),
78+
Constants.class);
8679
}
8780
}
88-
89-
90-
81+
82+
83+
9184
}

bigquery/src/test/java/com/google/cloud/bigquery/samples/test/LoadDataCSVSampleTest.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66

77
import org.junit.Test;
88

9-
import java.io.File;
10-
import java.io.FileNotFoundException;
11-
import java.io.FileReader;
12-
import java.io.IOException;
9+
import java.io.*;
1310

1411
/**
1512
* TODO: Insert description here. (generated by elibixby)
@@ -25,17 +22,20 @@ public LoadDataCSVSampleTest() throws JsonSyntaxException, JsonIOException, File
2522
// TODO(elibixby): Auto-generated constructor stub
2623
super();
2724
}
28-
25+
2926
@Test
3027
public void testLoadData() throws IOException, InterruptedException{
28+
29+
InputStreamReader is = new InputStreamReader(LoadDataCSVSample
30+
.class.getResourceAsStream("/schema.json"));
3131
LoadDataCSVSample.run(
32-
CONSTANTS.getCloudStorageInputURI(),
32+
CONSTANTS.getCloudStorageInputURI(),
3333
CONSTANTS.getProjectId(),
3434
CONSTANTS.getDatasetId(),
3535
CONSTANTS.getNewTableId(),
36-
new FileReader(new File(RESOURCE_PATH.resolve("schema.json").toString())),
36+
is ,
3737
5000L);
3838
}
39-
39+
4040

4141
}

bigquery/src/test/java/com/google/cloud/bigquery/samples/test/StreamingSampleTest.java

+7-10
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010

1111
import org.junit.Test;
1212

13-
import java.io.File;
14-
import java.io.FileNotFoundException;
15-
import java.io.FileReader;
16-
import java.io.IOException;
13+
import java.io.*;
1714
import java.util.Iterator;
1815

1916
/**
@@ -29,22 +26,22 @@ public class StreamingSampleTest extends BigquerySampleTest {
2926
public StreamingSampleTest() throws JsonSyntaxException, JsonIOException, FileNotFoundException {
3027
super();
3128
}
32-
29+
3330
@Test
3431
public void testStream() throws IOException{
3532
JsonReader json = new JsonReader(
36-
new FileReader(
37-
new File(RESOURCE_PATH.resolve("streamrows.json").toString())));
33+
new InputStreamReader(BigquerySampleTest
34+
.class.getResourceAsStream("/streamrows.json")));
3835
Iterator<TableDataInsertAllResponse> response = StreamingSample.run(
3936
CONSTANTS.getProjectId(),
4037
CONSTANTS.getDatasetId(),
4138
CONSTANTS.getCurrentTableId(),
4239
json);
43-
40+
4441
while(response.hasNext()){
4542
assertTrue(!response.next().isEmpty());
4643
}
47-
44+
4845
}
49-
46+
5047
}

pom.xml

+1-5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<modules>
2222
<module>taskqueue/deferred</module>
2323
<module>unittests</module>
24+
<module>bigquery</module>
2425
</modules>
2526

2627
<dependencyManagement>
@@ -68,11 +69,6 @@
6869
<version>${appengine.version}</version>
6970
<scope>test</scope>
7071
</dependency>
71-
<dependency>
72-
<groupId>com.google.appengine</groupId>
73-
<artifactId>appengine-api-1.0-sdk</artifactId>
74-
<version>${appengine.target.version}</version>
75-
</dependency>
7672
</dependencies>
7773
</dependencyManagement>
7874

0 commit comments

Comments
 (0)