Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
*******************************************************************************/
package com.intuit.ipp.interceptors;

import com.intuit.ipp.compression.CompressorFactory;
import com.intuit.ipp.net.ContentTypes;
import com.intuit.ipp.util.StringUtils;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import com.intuit.ipp.core.Context;
Expand All @@ -26,28 +30,30 @@
import com.intuit.ipp.security.OAuthAuthorizer;
import com.intuit.ipp.util.Config;

import java.util.Map;
import java.util.UUID;

import static com.intuit.ipp.interceptors.RequestElements.HEADER_PARAM_ACCEPT;
import static com.intuit.ipp.interceptors.RequestElements.HEADER_PARAM_CONTENT_TYPE;
import static com.intuit.ipp.util.Config.COMPRESSION_REQUEST_FORMAT;


public class PrepareRequestInterceptorTest {

private PrepareRequestInterceptor instance = new PrepareRequestInterceptor();
private IntuitMessage message = new IntuitMessage();
private Context context;

@BeforeClass
@BeforeMethod
public void setUp() throws FMSException {
context = new Context(new OAuthAuthorizer("fakeTicket","fakeToken", "fakeToken", "fakeToken"), ServiceType.QBO, "fakeRealm");
context.setRequestID("anyRequestID");
message = new IntuitMessage();
message.getRequestElements().setAction("fakeAction");
message.getRequestElements().setContext(context);

}

@AfterMethod
public void tearDown() {
message.getRequestElements().getRequestParameters().remove(RequestElements.REQ_PARAM_SENDTO);
message.getRequestElements().getRequestParameters().remove(RequestElements.REQ_PARAM_ENTITY_SELECTOR);
}

@Test
// Unit-like test which verifies URL generation
public void testExecute_QBO_URI() throws FMSException {
Expand All @@ -56,6 +62,32 @@ public void testExecute_QBO_URI() throws FMSException {
Assert.assertEquals(actual, Config.getProperty(Config.BASE_URL_QBO) + "/fakeRealm/fakeAction?requestid=anyRequestID&minorversion=41&");
}

@Test
public void testExecuteWithPlatformService() throws FMSException {
message.setPlatformService(true);
instance.execute(message);
String actual = message.getRequestElements().getRequestParameters().get(RequestElements.REQ_PARAM_RESOURCE_URL);
Assert.assertEquals(actual, Config.getProperty(Config.BASE_URL_PLATFORMSERVICE) + "/null?act=fakeAction&token=null");

}

@Test
public void testExecuteWithEntitlementService() throws FMSException {
String originalCompression = Config.getProperty(COMPRESSION_REQUEST_FORMAT);
try {
Config.setProperty(COMPRESSION_REQUEST_FORMAT, CompressorFactory.GZIP_COMPRESS_FORMAT);
message.setEntitlementService(true);
instance.execute(message);

Assert.assertEquals(message.getRequestElements().getRequestParameters().get(RequestElements.REQ_PARAM_RESOURCE_URL), Config.getProperty(Config.BASE_URL_ENTITLEMENTSERVICE) + "/entitlements/v3/fakeRealm");
Assert.assertEquals(message.getRequestElements().getRequestHeaders().get(RequestElements.HEADER_PARAM_CONTENT_TYPE), "application/xml");
Assert.assertEquals(message.getRequestElements().getRequestHeaders().get(RequestElements.HEADER_PARAM_ACCEPT), "application/xml");
Assert.assertNull(message.getRequestElements().getRequestHeaders().get(Config.COMPRESSION_REQUEST_FORMAT));
Assert.assertEquals(message.getRequestElements().getRequestHeaders().get(RequestElements.HEADER_PARAM_CONTENT_ENCODING), Config.getProperty(Config.COMPRESSION_REQUEST_FORMAT));
} finally {
Config.setProperty(COMPRESSION_REQUEST_FORMAT, originalCompression);
}
}

@Test
public void testPrepareDataServiceRequestForPDF_SmallCaps() throws FMSException{
Expand Down