View Javadoc
1   package it.perproduct;
2   
3   import com.google.common.io.CharStreams;
4   
5   import java.io.IOException;
6   import java.io.InputStream;
7   import java.io.InputStreamReader;
8   import java.net.URL;
9   import java.net.URLConnection;
10  import java.util.List;
11  
12  public abstract class AbstractInProductTest {
13  
14      /**
15       * If running from maven, the property is set magically via AMPS, from maven-amps-plugin product config in this module.
16       *
17       * The AMPS config also overrides this to be the same for every product, so we don't have to have product-specific defaults
18       * to run these tests in IDEA.
19       */
20      protected static final String BASEURL = System.getProperty("baseurl", "http://localhost:5990/product");
21  
22      protected static List<String> readStringList(String url) throws IOException {
23          final URLConnection connection = new URL(url).openConnection();
24  
25          try (InputStream is = connection.getInputStream();
26               InputStreamReader reader = new InputStreamReader(is)) {
27              return CharStreams.readLines(reader);
28          }
29      }
30  
31      protected static String getUrl(String url) throws IOException {
32          final URLConnection connection = new URL(url).openConnection();
33  
34          try (InputStream is = connection.getInputStream();
35               InputStreamReader reader = new InputStreamReader(is)) {
36              return CharStreams.toString(reader);
37          }
38      }
39  }