Skip to content

Commit 947d025

Browse files
geetikabatrarawagner
authored andcommitted
Updated the URl for scale (fabric8-analytics#170)
Updated the URl for 3scale
1 parent f753fb8 commit 947d025

File tree

2 files changed

+22
-35
lines changed

2 files changed

+22
-35
lines changed

plugins/com.redhat.fabric8analytics.lsp.eclipse.core/src/com/redhat/fabric8analytics/lsp/eclipse/core/ThreeScaleAPIProvider.java

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,9 @@
1515

1616
import org.apache.http.HttpResponse;
1717
import org.apache.http.HttpStatus;
18-
import org.apache.http.client.methods.HttpPost;
19-
import org.apache.http.entity.StringEntity;
18+
import org.apache.http.client.methods.HttpGet;
2019
import org.apache.http.impl.client.CloseableHttpClient;
2120
import org.apache.http.impl.client.HttpClients;
22-
import org.apache.http.message.BasicHeader;
23-
import org.apache.http.protocol.HTTP;
2421
import org.apache.http.util.EntityUtils;
2522
import org.json.JSONException;
2623
import org.json.JSONObject;
@@ -33,9 +30,9 @@
3330
*/
3431
public class ThreeScaleAPIProvider {
3532

36-
public static final String THREE_SCALE_URL = "https://3scale-connect.api.openshift.io/get-route";
33+
public static final String THREE_SCALE_URL = "https://f8a-connect-api-2445582058137.production.gw.apicast.io:443/get-endpoints?user_key=%s";
3734

38-
public static final String SERVICE_ID = "2555417754949";
35+
public static final String SERVICE_ID = "ad467b765e5c8a8a5ca745a1f32b8487";
3936

4037
private String token;
4138

@@ -55,17 +52,10 @@ public ThreeScaleAPIProvider(String token) {
5552
public ThreeScaleData register3Scale() throws ThreeScaleAPIException {
5653
CloseableHttpClient client = createClient();
5754
try {
58-
JSONObject urlObject = new JSONObject();
59-
urlObject.put("auth_token", token);
60-
urlObject.put("service_id" , SERVICE_ID);
61-
62-
StringEntity se = new StringEntity(urlObject.toString());
63-
se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
64-
65-
HttpPost post = new HttpPost(THREE_SCALE_URL);
66-
post.setEntity(se);
67-
68-
HttpResponse response = client.execute(post);
55+
String queryUrl = String.format(THREE_SCALE_URL, SERVICE_ID);
56+
HttpGet get = new HttpGet(queryUrl);
57+
get.addHeader("Authorization", token);
58+
HttpResponse response = client.execute(get);
6959

7060
int responseCode = response.getStatusLine().getStatusCode();
7161

tests/com.redhat.fabric8analytics.lsp.eclipse.core.tests/src/com/redhat/fabric8analytics/lsp/eclipse/core/tests/ThreeScaleAPIProviderTest.java

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010
*******************************************************************************/
1111

1212
package com.redhat.fabric8analytics.lsp.eclipse.core.tests;
13-
14-
import static org.hamcrest.CoreMatchers.containsString;
1513
import static org.hamcrest.CoreMatchers.is;
14+
import static org.hamcrest.CoreMatchers.startsWith;
1615
import static org.junit.Assert.assertThat;
1716
import static org.mockito.Matchers.any;
1817
import static org.mockito.Mockito.atLeastOnce;
@@ -23,13 +22,12 @@
2322
import java.io.ByteArrayInputStream;
2423
import java.io.IOException;
2524

26-
import org.apache.commons.io.IOUtils;
2725
import org.apache.http.HttpEntity;
2826
import org.apache.http.HttpStatus;
2927
import org.apache.http.StatusLine;
3028
import org.apache.http.client.ClientProtocolException;
3129
import org.apache.http.client.methods.CloseableHttpResponse;
32-
import org.apache.http.client.methods.HttpPost;
30+
import org.apache.http.client.methods.HttpGet;
3331
import org.apache.http.impl.client.CloseableHttpClient;
3432
import org.eclipse.core.runtime.CoreException;
3533
import org.junit.Before;
@@ -50,6 +48,8 @@ public class ThreeScaleAPIProviderTest {
5048

5149
private static final String TOKEN = "mytoken";
5250

51+
private static final String URL = "www.myurl.com";
52+
5353
private static final String JSON_ENDPOINTS = "{\"prod\":" + PROD + ", \"stage\":"+ STAGE +"}";
5454

5555
private static final String JSON = "{\"endpoints\":" + JSON_ENDPOINTS + ", \"user_key\": "+ USER_KEY +"}";
@@ -80,32 +80,29 @@ public void checkNullToken() {
8080
}
8181

8282
@Test
83-
public void register3Scale_createPost() throws UnsupportedOperationException, IOException, ThreeScaleAPIException {
84-
when(httpClient.execute(any(HttpPost.class))).thenReturn(httpResponse);
83+
public void register3Scale_createGet() throws UnsupportedOperationException, IOException, ThreeScaleAPIException {
84+
when(httpClient.execute(any(HttpGet.class))).thenReturn(httpResponse);
8585
when(httpResponse.getStatusLine()).thenReturn(statusLine);
8686
when(httpResponse.getEntity()).thenReturn(httpEntity);
8787
when(httpEntity.getContent()).thenReturn(new ByteArrayInputStream(JSON.getBytes()));
8888
when(statusLine.getStatusCode()).thenReturn(HttpStatus.SC_OK);
8989

90-
final ArgumentCaptor<HttpPost> argumentCaptor = ArgumentCaptor.forClass(HttpPost.class);
90+
final ArgumentCaptor<HttpGet> argumentCaptor = ArgumentCaptor.forClass(HttpGet.class);
9191

9292
provider.register3Scale();
9393
verify(httpClient).execute(argumentCaptor.capture());
94-
HttpPost httpPost = argumentCaptor.getValue();
95-
String entityString = IOUtils.toString(httpPost.getEntity().getContent());
96-
97-
98-
assertThat(entityString, containsString("auth_token"));
99-
assertThat(entityString, containsString(TOKEN));
100-
assertThat(entityString, containsString("service_id"));
101-
assertThat(entityString, containsString(ThreeScaleAPIProvider.SERVICE_ID));
94+
HttpGet httpGet = argumentCaptor.getValue();
95+
assertThat(httpGet.getURI().toString(), startsWith(String.format(ThreeScaleAPIProvider.THREE_SCALE_URL,ThreeScaleAPIProvider.SERVICE_ID)));
96+
assertThat(httpGet.getHeaders("Authorization")[0].getValue(), is(TOKEN));// might be withoput value
10297
}
10398

10499
@Test
105100
public void register3Scale_responseOK() throws ClientProtocolException, IOException, ThreeScaleAPIException {
106-
when(httpClient.execute(any(HttpPost.class))).thenReturn(httpResponse);
101+
when(httpClient.execute(any(HttpGet.class))).thenReturn(httpResponse);
107102
when(httpResponse.getStatusLine()).thenReturn(statusLine);
108103
when(httpResponse.getEntity()).thenReturn(httpEntity);
104+
105+
109106
when(httpEntity.getContent()).thenReturn(new ByteArrayInputStream(JSON.getBytes()));
110107
when(statusLine.getStatusCode()).thenReturn(HttpStatus.SC_OK);
111108

@@ -120,7 +117,7 @@ public void register3Scale_responseOK() throws ClientProtocolException, IOExcept
120117

121118
@Test(expected=ThreeScaleAPIException.class)
122119
public void register3Scale_responseOther() throws ClientProtocolException, IOException, ThreeScaleAPIException {
123-
when(httpClient.execute(any(HttpPost.class))).thenReturn(httpResponse);
120+
when(httpClient.execute(any(HttpGet.class))).thenReturn(httpResponse);
124121
when(httpResponse.getStatusLine()).thenReturn(statusLine);
125122
when(statusLine.getStatusCode()).thenReturn(HttpStatus.SC_FORBIDDEN);
126123

@@ -131,7 +128,7 @@ public void register3Scale_responseOther() throws ClientProtocolException, IOExc
131128

132129
@Test(expected=ThreeScaleAPIException.class)
133130
public void register3Scale_clientException() throws ClientProtocolException, IOException, ThreeScaleAPIException {
134-
when(httpClient.execute(any(HttpPost.class))).thenThrow(IOException.class);
131+
when(httpClient.execute(any(HttpGet.class))).thenThrow(IOException.class);
135132
when(httpResponse.getStatusLine()).thenReturn(statusLine);
136133
when(statusLine.getStatusCode()).thenReturn(HttpStatus.SC_FORBIDDEN);
137134

0 commit comments

Comments
 (0)