Skip to content

Commit cd7c214

Browse files
authored
Merge pull request #65 from tarungulati1988/moreTests
ISSUE 60- increased code coverage for serializationinterceptor
2 parents 7aa0bd3 + e31d891 commit cd7c214

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package com.intuit.ipp.interceptors;
2+
3+
import com.intuit.ipp.exception.FMSException;
4+
import com.intuit.ipp.serialization.JSONSerializerTest;
5+
import com.intuit.ipp.util.Config;
6+
import org.testng.Assert;
7+
import org.testng.annotations.Test;
8+
9+
import javax.xml.bind.JAXBElement;
10+
import javax.xml.bind.annotation.XmlElement;
11+
import javax.xml.bind.annotation.XmlRootElement;
12+
import javax.xml.namespace.QName;
13+
import java.util.HashMap;
14+
import java.util.Map;
15+
16+
import static com.intuit.ipp.interceptors.RequestElements.REQ_PARAM_METHOD_TYPE;
17+
import static com.intuit.ipp.util.Config.SERIALIZATION_REQUEST_FORMAT;
18+
import static org.testng.Assert.assertTrue;
19+
20+
public class SerializeInterceptorTest {
21+
22+
private SerializeInterceptor serializeInterceptor = new SerializeInterceptor();
23+
private IntuitMessage message = new IntuitMessage();
24+
25+
@Test(description = "Given a POST request with object for serialization, " +
26+
"the serialized data should be present in the serializedData object")
27+
public void execute_positiveCase1() throws FMSException {
28+
JSONSerializerTest test1 = new JSONSerializerTest();
29+
TestJson json = new TestJson();
30+
json.setFoo("bar");
31+
JAXBElement<TestJson> jaxbElement = new JAXBElement(new QName(TestJson.class.getSimpleName()), TestJson.class, json);
32+
Map<String, String> requestParams = new HashMap<>();
33+
requestParams.put(REQ_PARAM_METHOD_TYPE, "POST");
34+
message.getRequestElements().setRequestParameters(requestParams);
35+
message.getRequestElements().setObjectToSerialize(jaxbElement);
36+
serializeInterceptor.execute(message);
37+
Assert.assertEquals(message.getRequestElements().getSerializedData(), "{\"foo\":\"bar\"}");
38+
}
39+
40+
@Test(description = "Given a POST request with post body for serialization, " +
41+
"the serialized data should be present in the serializedData object")
42+
public void execute_positiveCase2() throws FMSException {
43+
Map<String, String> requestParams = new HashMap<>();
44+
requestParams.put(REQ_PARAM_METHOD_TYPE, "POST");
45+
message.getRequestElements().setRequestParameters(requestParams);
46+
String jsonInput = "{\"foo\":\"bar\"}";
47+
message.getRequestElements().setPostString(jsonInput);
48+
serializeInterceptor.execute(message);
49+
Assert.assertEquals(message.getRequestElements().getSerializedData(), jsonInput);
50+
}
51+
52+
@Test(description = "Given a GET request for serialization, the serialized data should be null")
53+
public void execute_positiveCase3() throws FMSException {
54+
Map<String, String> requestParams = new HashMap<>();
55+
requestParams.put(REQ_PARAM_METHOD_TYPE, "GET");
56+
message.getRequestElements().setRequestParameters(requestParams);
57+
serializeInterceptor.execute(message);
58+
Assert.assertEquals(message.getRequestElements().getSerializedData(), null);
59+
}
60+
61+
@Test(description = "Serialization request format returned should be of " +
62+
"the form: message.request.serialization")
63+
public void getSerializationRequestFormat() {
64+
SerializeInterceptor interceptor = new SerializeInterceptor();
65+
assertTrue(interceptor
66+
.getSerializationRequestFormat()
67+
.equalsIgnoreCase(Config.getProperty(SERIALIZATION_REQUEST_FORMAT)));
68+
}
69+
70+
@XmlRootElement
71+
class TestJson {
72+
73+
String foo;
74+
75+
public String getFoo() {
76+
return foo;
77+
}
78+
79+
@XmlElement
80+
public void setFoo(String foo) {
81+
this.foo = foo;
82+
}
83+
}
84+
}

0 commit comments

Comments
 (0)