@@ -58,38 +58,38 @@ public void successfulResponse() {
5858 // Invoke the App
5959 final APIGatewayProxyResponseEvent result = app .handleRequest (input , context );
6060 // Assert Results
61- assertEquals (result .getStatusCode ().intValue (), 200 );
61+ assertEquals (200 , result .getStatusCode ().intValue ());
6262 }
6363
6464 @ Test
6565 public void testGateXMLToDocument () throws Exception {
6666 final APIGatewayProxyResponseEvent result = app .handleRequest (input , context );
6767
68- assertEquals (result .getHeaders ().get ("Content-Type" ), "application/gate+xml" );
68+ assertEquals ("application/gate+xml" , result .getHeaders ().get ("Content-Type" ));
6969 final String resultBody = result .getBody ();
7070 assertNotNull (resultBody );
7171
7272 Document doc = Utils .xmlToDocument (new StringReader (resultBody ));
73- assertEquals (doc . getContent (). toString (), input . getBody ());
73+ assertEquals (input . getBody (), doc . getContent (). toString ());
7474 }
7575
7676 @ Test
7777 public void testMissingContentType () {
7878 input_headers .remove ("Content-Type" , "text/plain" );
7979 final TestContext context = new TestContext ();
8080 final APIGatewayProxyResponseEvent result = app .handleRequest (input , context );
81- assertEquals (result .getStatusCode ().intValue (), 200 );
81+ assertEquals (200 , result .getStatusCode ().intValue ());
8282 }
8383
8484 @ Test
8585 public void testGateJSONResponse () throws Exception {
8686 input_headers .put ("Accept" , "application/gate+json" );
8787
8888 final APIGatewayProxyResponseEvent result = app .handleRequest (input , context );
89- assertEquals (result .getStatusCode ().intValue (), 200 );
89+ assertEquals (200 , result .getStatusCode ().intValue ());
9090
9191 // Ensure we get back application/gate+json back
92- assertEquals (result .getHeaders ().get ("Content-Type" ), "application/gate+json" );
92+ assertEquals ("application/gate+json" , result .getHeaders ().get ("Content-Type" ));
9393 final JsonFactory factory = new JsonFactory ();
9494 final JsonParser parser = factory .createParser (result .getBody ());
9595 while (!parser .isClosed ()) {
@@ -102,11 +102,11 @@ public void testCache() {
102102 input .withBody (input .getBody () + new Random ().nextInt ());
103103 // Invoke the App
104104 final APIGatewayProxyResponseEvent result = app .handleRequest (input , context );
105- assertEquals (result .getStatusCode ().intValue (), 200 );
105+ assertEquals (200 , result .getStatusCode ().intValue ());
106106 assertEquals ("MISS" , result .getHeaders ().get ("x-zae-gate-cache" ));
107107
108108 final APIGatewayProxyResponseEvent cachedResult = app .handleRequest (input , context );
109- assertEquals (cachedResult .getStatusCode ().intValue (), 200 );
109+ assertEquals (200 , cachedResult .getStatusCode ().intValue ());
110110 assertEquals ("HIT" , cachedResult .getHeaders ().get ("x-zae-gate-cache" ));
111111 }
112112
@@ -132,7 +132,7 @@ public void testGateJsonInput() {
132132 input .getHeaders ().put ("Content-Type" , "text/json" );
133133
134134 final APIGatewayProxyResponseEvent result = app .handleRequest (input , context );
135- assertEquals (result .getStatusCode ().intValue (), 200 );
135+ assertEquals (200 , result .getStatusCode ().intValue ());
136136 }
137137
138138 @ Test
@@ -142,7 +142,7 @@ public void tesTweetJsonInput() {
142142 input .getHeaders ().put ("Accept" , "application/gate+json" );
143143
144144 final APIGatewayProxyResponseEvent result = app .handleRequest (input , context );
145- assertEquals (result .getStatusCode ().intValue (), 200 );
145+ assertEquals (200 , result .getStatusCode ().intValue ());
146146 assertFalse (result .getBody ().contains ("full_text" ));
147147 }
148148
@@ -154,7 +154,28 @@ public void testMediaWikiInput() throws IOException {
154154 input .getHeaders ().put ("Accept" , "application/gate+json" );
155155
156156 final APIGatewayProxyResponseEvent result = app .handleRequest (input , context );
157- assertEquals (result .getStatusCode ().intValue (), 200 );
157+ assertEquals (200 , result .getStatusCode ().intValue ());
158158 assertFalse (result .getBody ().contains ("{{Short Description|" ));
159159 }
160+
161+ @ Test
162+ public void testCacheCoherenceWithContentType () {
163+ final int cacheBust = new Random ().nextInt ();
164+ final String gateJsonBody = "{\" text\" :\" " + input .getBody () + cacheBust + "\" }" ;
165+
166+ // We are going to make a "mistake" and send gateJsonBody as text/x-json-twitter.
167+ input .getHeaders ().put ("Accept" , "application/gate+json" );
168+ input .getHeaders ().put ("Content-Type" , "text/x-json-twitter" );
169+ input .withBody (gateJsonBody );
170+
171+ final APIGatewayProxyResponseEvent result = app .handleRequest (input , context );
172+ assertEquals ("MISS" , result .getHeaders ().get ("x-zae-gate-cache" ));
173+
174+ // Now we fix the mistake, we must *miss* o.w. we are getting the *wrong* entities!
175+ input .getHeaders ().put ("Content-Type" , "text/json" );
176+
177+ final APIGatewayProxyResponseEvent wikiResult = app .handleRequest (input , context );
178+ assertNotEquals (result .getBody (), wikiResult .getBody ());
179+ assertEquals ("MISS" , wikiResult .getHeaders ().get ("x-zae-gate-cache" ));
180+ }
160181}
0 commit comments