Skip to content
This repository has been archived by the owner on Dec 6, 2023. It is now read-only.

Update for API v3 #76

Merged
merged 3 commits into from
Nov 9, 2016
Merged
Show file tree
Hide file tree
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
Binary file removed .gpg-private-key.asc.des
Binary file not shown.
Binary file removed .heroku.test.users.des3
Binary file not shown.
9 changes: 6 additions & 3 deletions .travis.profile
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#!/bin/sh

if test $TRAVIS_PULL_REQUEST == "false"; then
export HEROKU_TEST_USERS=$(openssl des3 -d -salt -in .heroku.test.users.des3 -k $HEROKU_TEST_USERS_DES_KEY)
user1="$CI_TEST_USER1_NAME"
token1="$CI_TEST_USER1_TOKEN"

openssl des3 -d -salt -in .gpg-private-key.asc.des -out gpg-private-key.asc -k $GPG_PRIVATE_KEY_DES_KEY
gpg --import gpg-private-key.asc > /dev/null
user2="$CI_TEST_USER2_NAME"
token2="$CI_TEST_USER2_TOKEN"

export HEROKU_TEST_USERS=\[\{\"username\":\"${user1}\",\"apikey\":\"${token1}\",\"defaultuser\":\"true\"\},\{\"username\":\"${user2}\",\"apikey\":\"${token2}\",\"defaultuser\":\"false\"\}\]
fi
12 changes: 10 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: java
jdk:
- openjdk6
- oraclejdk8
env:
global:
- secure: 4F3gN34XI1iFEkqPY2+bVNUqaw4M2DoeJncOsxQ1YxwCDqs/ploKXcuf9RJ8irjayHw/BUOJQSgGyj0JadxLfgI55rQqSSL5R9OdVChJHNb4I0hUjbDNpb0Fn5m33LYOYKL9OfoGGGojgo8QKYcWTylGRyehPjZFE/f309SQWSg=
Expand All @@ -9,5 +9,13 @@ env:
- secure: 3Ou7HQm/yJ3hq1lahArMymNHbsnEuE6GKDLU9DKfOqLSXqumOzbQXlDIV3QNUkINH95ii+bbEI0IeY8sroA8OOdNsSXvWPkPsvuO7eUAObh4Drnt3UJi7v0Ti41c+fy9WTXBymB4eLgQ0zEExLvFSGcHnr5qRfqUVaWtKelXzX8=
- secure: J2tZhDo9yb/nJm01d21Gy7BmoTw06e4nXskhdBMj/P5xLkGLVHUibXko4/gNbSxqYjPl+ZPq+tyxcJF5ioU6EwWRLvPkMF+UULW6X+CBLBc8fwJVqxnFbOInBicBFzSeHooUqNv8J0PhRO6FSStHo3Lo/M55Y1u6lbU5u8VPGo4=
- secure: 34Gg8t9TwVVeL5k2vsVcLqbTlYWCb4dkNLLSS2FAafEzJmi9s25ptXfmxIBfxzZ/r84Y36Yrt6MvIjpV7CLF7tJrkH8Fm5JkA5wF+jdQMgiMAe9/LinlvFCcF4MqORD6o/KkaO/hUi4QRJfEjcbJUTxu/wa2aS5DN/7aniylKcc=
before_script: . ./.travis.profile
# CI_TEST_USER1_NAME
- secure: "TYqxJs1LBZRjpFI5MPn+ev7BpZ8jEcqAXU7euTdhTEa+ypvc0B80UDbo2d93jo7RhYdMG3AMQMm18xeSEADAXblIddsObGkQTjn8dpEYfPNC0N7pyM8ZAc5F8R6yFUFhV4CKb0KkafOa5AYzQ4tdzp+3P1RcyMoHtYheab6AAqQ="
# CI_TEST_USER1_TOKEN
- secure: "vsBI5Hb+p0ie07sQ4r3EULq873BpsDOm2A8pNXGvnlSeZguEOxmislgnxmSLUhPnE0Xl/mjrb6jL+eAwaRWaf0a67nyafK8sPmQJmgpx4ZRr4qLXZKi78aXDxSL9e8bqdhT8J1HmzvfabGg7RBGPdHZc0V06Th6psXg7GE1ougY="
# CI_TEST_USER2_NAME
- secure: "Qq51xiRhc6yB/ghffCK2xhy3lpDI3NV2MgYd5MZ1haBQDdAFNvYjFr4Eix+iusDfmTrfK2sIVx4nRCzOt3N9APeh5/W2OgPEeYpPSs5Y5Qw4S+vSu03fp2SsftI/KBotNeMNXwB5nqXnFKbOXwHRa/p79lb9bX4qEq4xIJA/mfY="
# CI_TEST_USER2_TOKEN
- secure: "Cppme1KWX4Yty1X824bvVLRJgHcQCSxzu+NdvnnryfkgNXFTDMS9RLkF2aAZEY/+MM5ra649bZE4q/7SzNC2DahiC6fobxmvFzGo0t51BCOjxofLyTh9kHSye9irF15KTDpjV7R4cLmaTtfAAMuCJMKXrcPSsmc+H6TmC9bC7oc="
before_script: ". ./.travis.profile"
after_success: test $TRAVIS_PULL_REQUEST == "false" && test $TRAVIS_BRANCH == "master" && mvn deploy --settings=.travis.settings.xml -P prepare-for-central -DskipTests
30 changes: 18 additions & 12 deletions heroku-api-integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>heroku-api-parent</artifactId>
<groupId>com.heroku.api</groupId>
<version>0.17-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a pretty big jump. Is 3.0 used because you want to match the API versioning?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, 3.0 to match the API. But also because a bump to 1.0 didn't seem right. idk. i don't have a strong opinion on this. got a better suggestion? just 0.18?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong opinion either, just trying to understand. At one point we didn't want to pin the heroku.jar version to the API version, but don't remember why. Also, this library technically works with both v2 and v3 of the API.

</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -66,11 +66,6 @@
<artifactId>heroku-json-jersey-client</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>com.heroku.api</groupId>
<artifactId>heroku-http-play_2.9.1</artifactId>
<version>${project.parent.version}</version>
</dependency>


<!-- Test Deps -->
Expand Down Expand Up @@ -101,18 +96,24 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.4</version>
<version>2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.googlecode.jmockit</groupId>
<groupId>org.jmockit</groupId>
<artifactId>jmockit</artifactId>
<version>0.999.13</version>
<version>1.28</version>
</dependency>

</dependencies>
<properties>
<guava.version>11.0.1</guava.version>
<guava.version>19.0</guava.version>
<heroku-api-integration-tests.skipTests>true</heroku-api-integration-tests.skipTests>
</properties>

Expand All @@ -135,7 +136,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
<version>2.19.1</version>
<configuration>
<skipTests>${heroku-api-integration-tests.skipTests}</skipTests>
<failIfNoTests>true</failIfNoTests>
Expand All @@ -145,9 +146,14 @@
<suiteXmlFile>src/test/resources/testng-asynchttpclient.xml</suiteXmlFile>
<suiteXmlFile>src/test/resources/testng-httpclient-jackson.xml</suiteXmlFile>
<suiteXmlFile>src/test/resources/testng-httpclient-gson.xml</suiteXmlFile>
<suiteXmlFile>src/test/resources/testng-play.xml</suiteXmlFile>
<suiteXmlFile>src/test/resources/testng-jersey-client.xml</suiteXmlFile>
</suiteXmlFiles>
<properties>
<property>
<name>surefire.testng.verbose</name>
<value>2</value>
</property>
</properties>
</configuration>
</plugin>
<plugin>
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.heroku.api.User;
import com.heroku.api.connection.FinagleConnection;
import com.heroku.api.request.user.UserInfo;
import com.twitter.util.Await;
import com.twitter.util.Duration;
import com.twitter.util.Future;
import org.testng.annotations.Guice;
Expand All @@ -28,7 +29,12 @@ public class FinagleConnectionTest {
@SuppressWarnings("unchecked")
public void asyncTests() {
Future<User> jsonArrayResponseFuture = connection.executeAsync(new UserInfo(), apiKey);
User user = (User) jsonArrayResponseFuture.get(Duration.fromTimeUnit(10L, TimeUnit.SECONDS)).get();
User user = null;
try {
user = Await.result(jsonArrayResponseFuture, Duration.fromTimeUnit(10L, TimeUnit.SECONDS));
} catch (Exception e) {
throw new RuntimeException(e);
}
assertEquals(user.getEmail(), IntegrationTestConfig.CONFIG.getDefaultUser().getUsername());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,12 @@
package com.heroku.api.httpclient;

import com.heroku.api.App;
import com.heroku.api.Heroku;
import com.heroku.api.IntegrationTestConfig;
import com.heroku.api.connection.HttpClientConnection;
import com.heroku.api.http.Http;
import com.heroku.api.request.addon.AddonList;
import com.heroku.api.request.app.AppList;
import mockit.Instantiation;
import mockit.Mock;
import mockit.MockClass;
import mockit.Mockit;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.HttpVersion;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.AbstractHttpClient;
import org.apache.http.message.BasicHttpResponse;
import org.apache.http.protocol.HttpContext;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.io.IOException;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
Expand All @@ -43,66 +26,4 @@ public void asyncTests() throws ExecutionException, TimeoutException, Interrupte
List<App> jsonArrayResponse = jsonArrayResponseFuture.get(10L, TimeUnit.SECONDS);
Assert.assertTrue(jsonArrayResponse != null);
}

@Test(singleThreaded = true)
public void userAgentShouldContainHerokuJarWithVersionNumber() {
Mockit.setUpMock(AbstractHttpClient.class, new MockAbstractHttpClient(new MockHooks() {
@Override
public void beforeAssertions(HttpUriRequest request, HttpContext context) {
final String expectedUserAgent = "heroku.jar/" + Heroku.JarProperties.getProperty("heroku.jar.version") + " httpclient";
final String userAgentSent = Http.UserAgent.LATEST.getHeaderValue("httpclient");
final String userAgentReceived = request.getHeaders(Http.UserAgent.LATEST.getHeaderName())[0].getValue();
Assert.assertEquals(expectedUserAgent, userAgentSent);
Assert.assertEquals(expectedUserAgent, userAgentReceived);
}
}));
connection.execute(new AddonList(), apiKey);
Mockit.tearDownMocks(AbstractHttpClient.class);
}

@Test(singleThreaded = true)
public void cookiesShouldBeIgnored() {
// make a call to ensure a Set-Cookie is sent back to the client
Mockit.setUpMock(AbstractHttpClient.class, new MockAbstractHttpClient(new MockHooks() {
@Override
public void responseHook(BasicHttpResponse response) {
response.setHeader("Set-Cookie", "foo=bar; path=/;");
}
}));
connection.execute(new AddonList(), apiKey);

Mockit.setUpMock(AbstractHttpClient.class, new MockAbstractHttpClient(new MockHooks() {
@Override
public void beforeAssertions(HttpUriRequest request, HttpContext context) {
Assert.assertEquals(request.getHeaders("Cookie").length, 0, "Cookies should be ignored, but there are cookies present.");
}
}));
// run this twice to ensure the set-cookie was sent from the first request
connection.execute(new AddonList(), apiKey);
Mockit.tearDownMocks(AbstractHttpClient.class);
}

@MockClass(realClass = AbstractHttpClient.class, instantiation = Instantiation.PerMockSetup)
public static final class MockAbstractHttpClient {
private final MockHooks hooks;

public MockAbstractHttpClient(MockHooks hooks) {
this.hooks = hooks;
}

@Mock
public final HttpResponse execute(HttpUriRequest request, HttpContext context) throws IOException, ClientProtocolException {
hooks.beforeAssertions(request, context);
BasicHttpResponse basicHttpResponse = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
basicHttpResponse.setEntity(new StringEntity("[]"));
hooks.responseHook(basicHttpResponse);
return basicHttpResponse;
}

}

public static abstract class MockHooks {
public void beforeAssertions(HttpUriRequest request, HttpContext context) {}
public void responseHook(BasicHttpResponse response) {}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.heroku.api.parser;

import com.heroku.api.App;
import com.heroku.api.Heroku;
import com.heroku.api.exception.ParseException;
import com.heroku.api.request.app.AppInfo;
import org.testng.Assert;
Expand All @@ -12,7 +13,9 @@
import java.util.List;

import static com.heroku.api.parser.Json.parse;
import static com.heroku.api.parser.Json.encode;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;

/**
* @author mh
Expand All @@ -30,33 +33,31 @@ Object[][] getParsers() {

@Test(dataProvider = "getParsers")
public void testParseAppWithDomainList(Parser parser) throws UnsupportedEncodingException {
String appListWithConfiguredDomain = "[{\"name\":\"app\",\"stack\":\"bamboo-ree-1.8.7\",\"slug_size\":2383872,\"requested_stack\":null,\"created_at\":\"2010/06/01 07:48:24 -0700\",\"web_url\":\"http://app.heroku.com/\",\"owner_email\":\"test@heroku.com\",\"create_status\":\"complete\",\"id\":200120," +
"\"domain_name\":{\"created_at\":\"2010/06/03 19:25:08 -0700\",\"updated_at\":\"2010/06/03 19:25:08 -0700\",\"default\":null,\"domain\":\"herokuapp.com\",\"id\":1234,\"app_id\":200120,\"base_domain\":\"herokuapp.com\"}," +
"\"repo_size\":630784,\"git_url\":\"git@heroku.com:dropphotos.git\",\"repo_migrate_status\":\"complete\",\"dynos\":1,\"workers\":0}" +
String appListWithConfiguredDomain = "[{\"name\":\"app\",\"stack\":{\"name\":\"cedar-14\"},\"slug_size\":2383872,\"requested_stack\":null,\"created_at\":\"2010/06/01 07:48:24 -0700\",\"web_url\":\"http://app.heroku.com/\",\"owner_email\":\"test@heroku.com\",\"create_status\":\"complete\",\"id\":200120," +
"\"domain_name\":{\"created_at\":\"2010/06/03 19:25:08 -0700\",\"updated_at\":\"2010/06/03 19:25:08 -0700\",\"status\":\"pending\",\"hostname\":\"herokuapp.com\",\"id\":1234}," +
"\"repo_size\":630784,\"git_url\":\"git@heroku.com:dropphotos.git\",\"maintenance\":\"false\"}" +
"]";

final List<App> appList = parser.parse(appListWithConfiguredDomain.getBytes("UTF-8"), APP_LIST_TYPE);
Assert.assertEquals(appList.size(), 1);
final App app = appList.get(0);
Assert.assertEquals(app.getName(), "app");
Assert.assertEquals(app.getDomain().getDomain(), "herokuapp.com");
Assert.assertEquals(app.getDomain().getDefault(), null);
Assert.assertEquals(app.getDynos(), 1);
Assert.assertEquals(app.getDomain().getHostname(), "herokuapp.com");
Assert.assertEquals(app.getDomain().getStatus(), "pending");
}

@Test(dataProvider = "getParsers")
public void testParseAppWithoutDomainList(Parser parser) throws UnsupportedEncodingException {
String appListWithConfiguredDomain = "[{\"name\":\"app\",\"stack\":\"bamboo-ree-1.8.7\",\"slug_size\":2383872,\"requested_stack\":null,\"created_at\":\"2010/06/01 07:48:24 -0700\",\"web_url\":\"http://app.heroku.com/\",\"owner_email\":\"test@heroku.com\",\"create_status\":\"complete\",\"id\":200120," +
String appListWithConfiguredDomain = "[{\"name\":\"app\",\"stack\":{\"name\":\"cedar-14\"},\"slug_size\":2383872,\"requested_stack\":null,\"created_at\":\"2010/06/01 07:48:24 -0700\",\"web_url\":\"http://app.heroku.com/\",\"owner_email\":\"test@heroku.com\",\"create_status\":\"complete\",\"id\":200120," +
"\"domain_name\":null," +
"\"repo_size\":630784,\"git_url\":\"git@heroku.com:dropphotos.git\",\"repo_migrate_status\":\"complete\",\"dynos\":1,\"workers\":0}" +
"\"repo_size\":630784,\"git_url\":\"git@heroku.com:dropphotos.git\",\"maintenance\":\"false\"}" +
"]";

final List<App> appList = parser.parse(appListWithConfiguredDomain.getBytes("UTF-8"), APP_LIST_TYPE);
Assert.assertEquals(appList.size(), 1);
final App app = appList.get(0);
Assert.assertEquals(app.getName(), "app");
Assert.assertEquals(app.getDomain(), null);
Assert.assertEquals(app.getDynos(), 1);
}

@Test(dataProvider = "getParsers")
Expand Down Expand Up @@ -88,6 +89,14 @@ public void invalidJSONShouldThrowParseException() {
parse("{{".getBytes(), AppInfo.class);
}

@Test
public void testEncodeApp() {
App a = new App().on(Heroku.Stack.Cedar14);
a.setMaintenance(true);
String json = encode(a);
assertTrue(json.indexOf("true") != 0);
}

public static class SubAppInfo extends AppInfo {
public SubAppInfo(String appName) {
super(appName);
Expand Down
Loading