View Javadoc

1   package com.atlassian.marketplace.client.impl;
2   
3   import java.net.URI;
4   
5   import com.atlassian.marketplace.client.api.ApplicationKey;
6   import com.atlassian.marketplace.client.util.UriBuilder;
7   
8   import org.junit.Test;
9   
10  import static com.atlassian.marketplace.client.TestObjects.HOST_BASE;
11  import static com.atlassian.marketplace.client.api.ApplicationKey.JIRA;
12  import static com.atlassian.marketplace.client.impl.ClientTester.FAKE_APPLICATIONS_PATH;
13  import static org.hamcrest.MatcherAssert.assertThat;
14  import static org.hamcrest.Matchers.contains;
15  import static org.mockito.Mockito.verify;
16  
17  public class ApplicationsImplTest extends ApiImplTestBase implements ApplicationsImplTestBase
18  {
19      @Test
20      public void getByKeyUsesApplicationsResource() throws Exception
21      {
22          setupAppByKeyResource(appByKeyUri(JIRA));
23          tester.client.applications().getByKey(JIRA);
24  
25          verify(tester.httpTransport).get(URI.create(HOST_BASE + FAKE_APPLICATIONS_PATH + "?limit=0"));
26      }
27  
28      @Test
29      public void getByKeyUsesAppByKeyResource() throws Exception
30      {
31          setupAppByKeyResource(appByKeyUri(JIRA));
32  
33          assertThat(tester.client.applications().getByKey(JIRA), contains(APP_REP));
34      }
35  
36      protected UriBuilder appsApi()
37      {
38          return UriBuilder.fromUri(HOST_BASE + FAKE_APPLICATIONS_PATH);
39      }
40      
41      protected UriBuilder appsApiZeroLengthQuery()
42      {
43          return appsApi().queryParam("limit", 0);
44      }
45  
46      protected UriBuilder appByKeyUri(ApplicationKey key)
47      {
48          return UriBuilder.fromUri(HOST_BASE + FAKE_APP_BY_KEY_PATH + key.getKey());
49      }
50  
51      protected void setupAppsResource(UriBuilder appsUri) throws Exception
52      {
53          setupAppsResource(appsUri, APPS_REP);
54      }
55      
56      protected void setupAppsResource(UriBuilder appsUri, InternalModel.Applications rep) throws Exception
57      {
58          tester.mockResource(appsUri.build(), rep);
59      }
60      
61      protected void setupAppByKeyResource(UriBuilder uri) throws Exception
62      {
63          setupAppsResource(appsApiZeroLengthQuery());
64          tester.mockResource(uri.build(), APP_REP);
65      }
66  }