|
| 1 | +/* |
| 2 | + * Copyright 2017 Google Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.example.getstarted.basicactions; |
| 18 | + |
| 19 | +import com.google.cloud.datastore.Batch; |
| 20 | +import com.google.cloud.datastore.Datastore; |
| 21 | +import com.google.cloud.datastore.DatastoreOptions; |
| 22 | +import com.google.cloud.datastore.Key; |
| 23 | +import com.google.cloud.datastore.Query; |
| 24 | +import com.google.cloud.datastore.QueryResults; |
| 25 | +import com.google.cloud.datastore.StructuredQuery; |
| 26 | + |
| 27 | +import org.junit.After; |
| 28 | +import org.junit.AfterClass; |
| 29 | +import org.junit.Before; |
| 30 | +import org.junit.BeforeClass; |
| 31 | +import org.junit.Test; |
| 32 | +import org.junit.runner.RunWith; |
| 33 | +import org.junit.runners.JUnit4; |
| 34 | + |
| 35 | +import org.openqa.selenium.WebDriver; |
| 36 | +import org.openqa.selenium.chrome.ChromeDriverService; |
| 37 | +import org.openqa.selenium.remote.DesiredCapabilities; |
| 38 | +import org.openqa.selenium.remote.RemoteWebDriver; |
| 39 | +import org.openqa.selenium.remote.service.DriverService; |
| 40 | + |
| 41 | +@RunWith(JUnit4.class) |
| 42 | +@SuppressWarnings("checkstyle:abbreviationaswordinname") |
| 43 | +public class UserJourneyTestIT { |
| 44 | + |
| 45 | + private static final String TITLE = "mytitle"; |
| 46 | + private static final String AUTHOR = "myauthor"; |
| 47 | + private static final String PUBLISHED_DATE = "1984-02-27"; |
| 48 | + private static final String DESCRIPTION = "mydescription"; |
| 49 | + |
| 50 | + private static DriverService service; |
| 51 | + private WebDriver driver; |
| 52 | + |
| 53 | + @BeforeClass |
| 54 | + public static void setupClass() throws Exception { |
| 55 | + service = ChromeDriverService.createDefaultService(); |
| 56 | + service.start(); |
| 57 | + } |
| 58 | + |
| 59 | + @AfterClass |
| 60 | + public static void tearDownClass() { |
| 61 | + service.stop(); |
| 62 | + |
| 63 | + // Clear the datastore |
| 64 | + Datastore datastore = DatastoreOptions.getDefaultInstance().getService(); |
| 65 | + Batch batch = datastore.newBatch(); |
| 66 | + StructuredQuery<Key> query = Query.newKeyQueryBuilder() |
| 67 | + .setKind("Book3").build(); |
| 68 | + for (QueryResults<Key> keys = datastore.run(query); keys.hasNext(); ) { |
| 69 | + batch.delete(keys.next()); |
| 70 | + } |
| 71 | + batch.submit(); |
| 72 | + } |
| 73 | + |
| 74 | + @Before |
| 75 | + public void setup() { |
| 76 | + driver = new RemoteWebDriver(service.getUrl(), DesiredCapabilities.chrome()); |
| 77 | + } |
| 78 | + |
| 79 | + @After |
| 80 | + public void tearDown() { |
| 81 | + driver.quit(); |
| 82 | + } |
| 83 | + |
| 84 | + @Test |
| 85 | + public void userJourney() throws Exception { |
| 86 | + driver.get("http://localhost:8080"); |
| 87 | + } |
| 88 | +} |
0 commit comments