1717import com .google .gcloud .datastore .StructuredQuery .PropertyFilter ;
1818
1919import org .easymock .EasyMock ;
20+ import org .junit .After ;
2021import org .junit .Before ;
2122import org .junit .Test ;
2223import org .junit .runner .RunWith ;
2324import org .junit .runners .JUnit4 ;
2425
26+ import java .io .IOException ;
2527import java .util .Collections ;
2628import java .util .HashMap ;
2729import java .util .Iterator ;
2830import java .util .List ;
2931import java .util .Map ;
3032
3133@ RunWith (JUnit4 .class )
32- public class DatastoreServiceTest {
34+ public class DatastoreServiceIntegrationTest {
3335
34- private static final String DATASET = "dataset1" ;
36+ private static final String DATASET = LocalGcdHelper . DEFAULT_DATASET ;
3537 private static final String KIND1 = "kind1" ;
3638 private static final String KIND2 = "kind2" ;
3739 private static final NullValue NULL_VALUE = NullValue .of ();
@@ -70,19 +72,16 @@ public class DatastoreServiceTest {
7072 private DatastoreServiceOptions options ;
7173 private DatastoreService datastore ;
7274 private DatastoreHelper helper ;
75+ private LocalGcdHelper gcdHelper ;
7376
7477 @ Before
75- public void setUp () {
76- // TODO(ozarov): document that this test depends on a local gcd running.
77- // Unfortunately, the gcd tool is not bundled with the cloud SDK and need
78- // to be downloaded independently from
79- // https://cloud.google.com/datastore/docs/tools/devserver (b/16372095).
80- // To start the gcd run:
81- // gcd.sh create dataset1; gcd.sh start dataset1
82- // We should have an option to start the gcd from maven/ant.
78+ public void setUp () throws IOException , InterruptedException {
79+ if (!LocalGcdHelper .isActive (DATASET )) {
80+ gcdHelper = LocalGcdHelper .start (DATASET );
81+ }
8382 options = DatastoreServiceOptions .builder ()
8483 .dataset (DATASET )
85- .host ("http://localhost:8080" )
84+ .host ("http://localhost:" + LocalGcdHelper . PORT )
8685 .build ();
8786 datastore = DatastoreServiceFactory .getDefault (options );
8887 helper = DatastoreHelper .createFor (datastore );
@@ -91,6 +90,13 @@ public void setUp() {
9190 datastore .add (ENTITY1 , ENTITY2 );
9291 }
9392
93+ @ After
94+ public void tearDown () throws IOException , InterruptedException {
95+ if (gcdHelper != null ) {
96+ gcdHelper .stop ();
97+ }
98+ }
99+
94100 @ Test
95101 public void testGetOptions () {
96102 assertSame (options , datastore .options ());
0 commit comments