Skip to content

Commit 9100e92

Browse files
authored
Merge pull request #61 from praveenadg/develop
#60
2 parents f2ddcbb + dac5781 commit 9100e92

File tree

4 files changed

+227
-0
lines changed

4 files changed

+227
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.intuit.payment.config;
2+
3+
import org.testng.Assert;
4+
import org.testng.annotations.Test;
5+
6+
/*******************************************************************************
7+
* Copyright (c) 2019 Intuit
8+
*
9+
* Licensed under the Apache License, Version 2.0 (the "License");
10+
* you may not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS,
17+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
* @author praveenadg
21+
*******************************************************************************/
22+
23+
public class ProxyConfigTest {
24+
25+
private static final String HOST = "https://github.com";
26+
private static final String PORT = "8080";
27+
private static final String USERNAME = "username";
28+
private static final String PASSWORD = "password";
29+
private static final String DOMAIN = "domain";
30+
31+
private ProxyConfig init(String host, String port, String username, String password, String domain) {
32+
ProxyConfig.ProxyConfigBuilder proxyConfigBuilder = new ProxyConfig.ProxyConfigBuilder(host, port);
33+
proxyConfigBuilder.username(username);
34+
proxyConfigBuilder.password(password);
35+
proxyConfigBuilder.domain(domain);
36+
return proxyConfigBuilder.buildConfig();
37+
38+
}
39+
40+
@Test
41+
public void testAllGetters() {
42+
ProxyConfig proxyConfig = init(HOST, PORT, USERNAME, PASSWORD, DOMAIN);
43+
Assert.assertEquals(proxyConfig.getHost(), HOST);
44+
Assert.assertEquals(proxyConfig.getPort(), PORT);
45+
Assert.assertEquals(proxyConfig.getUsername(), USERNAME);
46+
Assert.assertEquals(proxyConfig.getPassword(), PASSWORD);
47+
Assert.assertEquals(proxyConfig.getDomain(), DOMAIN);
48+
}
49+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package com.intuit.payment.config;
2+
3+
import org.testng.Assert;
4+
import org.testng.annotations.Test;
5+
6+
/*******************************************************************************
7+
* Copyright (c) 2019 Intuit
8+
*
9+
* Licensed under the Apache License, Version 2.0 (the "License");
10+
* you may not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS,
17+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
* @author praveenadg
21+
*******************************************************************************/
22+
23+
public class RequestContextTest {
24+
private static final String ACCESS_TOKEN = "intuit123";
25+
private static final String REQUEST_ID = "requestId";
26+
private static final String PROD_BASE_URL = "https://api.intuit.com/quickbooks/v4/payments/";
27+
private static final String SANDBOX_BASE_URL = "https://sandbox.api.intuit.com/quickbooks/v4/payments/";
28+
private static final String HOST = "https://github.com";
29+
private static final String PORT = "8080";
30+
31+
private RequestContext init(String accessToken, RequestContext.Environment environment, String requestId) {
32+
RequestContext.Builder builder = new RequestContext.Builder(accessToken, environment);
33+
builder.requestId(requestId);
34+
ProxyConfig.ProxyConfigBuilder proxyConfigBuilder = new ProxyConfig.ProxyConfigBuilder(HOST, PORT);
35+
builder.proxyConfig(proxyConfigBuilder.buildConfig());
36+
return builder.build();
37+
38+
}
39+
40+
@Test
41+
public void testAllGetters() {
42+
RequestContext requestContext = init(ACCESS_TOKEN, RequestContext.Environment.SANDBOX, REQUEST_ID);
43+
Assert.assertEquals(requestContext.getAccessToken(), ACCESS_TOKEN);
44+
Assert.assertEquals(requestContext.getBaseUrl(), SANDBOX_BASE_URL);
45+
Assert.assertEquals(requestContext.getRequestId(), REQUEST_ID);
46+
Assert.assertEquals(requestContext.getProxyConfig().getHost(), HOST);
47+
Assert.assertEquals(requestContext.getProxyConfig().getPort(), PORT);
48+
}
49+
50+
@Test
51+
public void testAllSetters() {
52+
RequestContext requestContext = init("", RequestContext.Environment.PRODUCTION, "");
53+
requestContext.setAccessToken(ACCESS_TOKEN);
54+
requestContext.setBaseUrl(PROD_BASE_URL);
55+
requestContext.setRequestId(REQUEST_ID);
56+
57+
ProxyConfig.ProxyConfigBuilder proxyConfigBuilder = new ProxyConfig.ProxyConfigBuilder(HOST, PORT);
58+
requestContext.setProxyConfig(proxyConfigBuilder.buildConfig());
59+
60+
Assert.assertEquals(requestContext.getAccessToken(), ACCESS_TOKEN);
61+
Assert.assertEquals(requestContext.getBaseUrl(), PROD_BASE_URL);
62+
Assert.assertEquals(requestContext.getRequestId(), REQUEST_ID);
63+
Assert.assertEquals(requestContext.getProxyConfig().getHost(), HOST);
64+
Assert.assertEquals(requestContext.getProxyConfig().getPort(), PORT);
65+
}
66+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.intuit.payment.http;
2+
3+
import com.intuit.payment.config.RequestContext;
4+
import org.testng.Assert;
5+
import org.testng.annotations.Test;
6+
7+
/*******************************************************************************
8+
* Copyright (c) 2019 Intuit
9+
*
10+
* Licensed under the Apache License, Version 2.0 (the "License");
11+
* you may not use this file except in compliance with the License.
12+
* You may obtain a copy of the License at
13+
*
14+
* http://www.apache.org/licenses/LICENSE-2.0
15+
*
16+
* Unless required by applicable law or agreed to in writing, software
17+
* distributed under the License is distributed on an "AS IS" BASIS,
18+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
* See the License for the specific language governing permissions and
20+
* limitations under the License.
21+
* @author praveenadg
22+
*******************************************************************************/
23+
24+
public class RequestTest {
25+
private static final String ACCESS_TOKEN = "intuit123";
26+
private static final String PROD_BASE_URL = "https://api.intuit.com/quickbooks/v4/payments/";
27+
private static final String SANDBOX_BASE_URL = "https://sandbox.api.intuit.com/quickbooks/v4/payments/";
28+
private static final String HOST = "https://github.com";
29+
private static final String PORT = "8080";
30+
31+
private Request init(MethodType methodType, String url, boolean ignoreAuthHeader) {
32+
Request.RequestBuilder builder = new Request.RequestBuilder(methodType, url);
33+
builder.ignoreAuthHeader(ignoreAuthHeader);
34+
RequestContext.Builder requestBuilder = new RequestContext.Builder(ACCESS_TOKEN, RequestContext.Environment.PRODUCTION);
35+
builder.context(requestBuilder.build());
36+
builder.requestObject(HOST);
37+
return builder.build();
38+
39+
}
40+
41+
@Test
42+
public void testAllGetters() {
43+
Request request = init(MethodType.GET, PROD_BASE_URL, Boolean.TRUE);
44+
Assert.assertEquals(request.getMethod(), MethodType.GET);
45+
Assert.assertEquals(request.getUrl(), PROD_BASE_URL);
46+
Assert.assertEquals(request.getRequestObject(), HOST);
47+
Assert.assertNotNull(request.getContext());
48+
Assert.assertTrue(request.isIgnoreAuthHeader());
49+
Assert.assertNull(request.getTypeReference());
50+
}
51+
52+
@Test
53+
public void testAllSetters() {
54+
Request request = init(MethodType.POST, SANDBOX_BASE_URL, Boolean.FALSE);
55+
request.setPostJson(PORT);
56+
Assert.assertEquals(request.getPostJson(), PORT);
57+
Assert.assertFalse(request.isIgnoreAuthHeader());
58+
59+
}
60+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.intuit.payment.http;
2+
3+
import com.intuit.payment.data.Errors;
4+
import org.testng.Assert;
5+
import org.testng.annotations.Test;
6+
7+
/*******************************************************************************
8+
* Copyright (c) 2019 Intuit
9+
*
10+
* Licensed under the Apache License, Version 2.0 (the "License");
11+
* you may not use this file except in compliance with the License.
12+
* You may obtain a copy of the License at
13+
*
14+
* http://www.apache.org/licenses/LICENSE-2.0
15+
*
16+
* Unless required by applicable law or agreed to in writing, software
17+
* distributed under the License is distributed on an "AS IS" BASIS,
18+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
* See the License for the specific language governing permissions and
20+
* limitations under the License.
21+
* @author praveenadg
22+
*******************************************************************************/
23+
24+
public class ResponseTest {
25+
private static final int STATUS_CODE = 200;
26+
private static final String INTUIT_TID = "intuit_tid";
27+
private static final String ERROR_INTUIT_TID = "error_intuit_tid";
28+
private static final String CONTENT = "content";
29+
30+
@Test
31+
public void testAllGetters() {
32+
Response response = new Response(STATUS_CODE, CONTENT, INTUIT_TID);
33+
Assert.assertEquals(response.getStatusCode(), STATUS_CODE);
34+
Assert.assertEquals(response.getContent(), CONTENT);
35+
Assert.assertEquals(response.getIntuit_tid(), INTUIT_TID);
36+
}
37+
38+
@Test
39+
public void testAllSetters() {
40+
Response response = new Response(STATUS_CODE, CONTENT, INTUIT_TID);
41+
response.setResponseObject(INTUIT_TID);
42+
Errors errors = new Errors();
43+
errors.setIntuit_tid(ERROR_INTUIT_TID);
44+
response.setErrors(errors);
45+
Assert.assertEquals(response.getResponseObject(), INTUIT_TID);
46+
Assert.assertEquals(response.getErrors().getIntuit_tid(), ERROR_INTUIT_TID);
47+
Assert.assertEquals(response.getStatusCode(), STATUS_CODE);
48+
Assert.assertEquals(response.getContent(), CONTENT);
49+
Assert.assertEquals(response.getIntuit_tid(), INTUIT_TID);
50+
51+
}
52+
}

0 commit comments

Comments
 (0)