@@ -787,22 +787,37 @@ public void testDeleteResourceWithoutPermission() throws Exception {
787787
788788 @ Test
789789 public void testDeleteResourceAsAdmin () throws Exception {
790- String etag = this .mockMvc .perform (get ("/api/v1/dataresources/" + sampleResource .getId ()).header (HttpHeaders .AUTHORIZATION ,
791- "Bearer " + adminToken )).andDo (print ()).andExpect (status ().isOk ()).andReturn ().getResponse ().getHeader ("ETag" );
792-
793- this .mockMvc .perform (delete ("/api/v1/dataresources/" + sampleResource .getId ()).header ("If-Match" , etag ).header (HttpHeaders .AUTHORIZATION ,
794- "Bearer " + adminToken ).contentType ("application/json" )).andExpect (status ().isNoContent ());
795-
796- //try a second time...this should work
797- etag = this .mockMvc .perform (get ("/api/v1/dataresources/" + sampleResource .getId ()).header (HttpHeaders .AUTHORIZATION ,
798- "Bearer " + adminToken )).andDo (print ()).andExpect (status ().isOk ()).andReturn ().getResponse ().getHeader ("ETag" );
799-
800- this .mockMvc .perform (delete ("/api/v1/dataresources/" + sampleResource .getId ()).header ("If-Match" , etag ).header (HttpHeaders .AUTHORIZATION ,
801- "Bearer " + adminToken ).contentType ("application/json" )).andExpect (status ().isNoContent ());
802- //from now on, the resource should be in state GONE...HTTP GET should fail
803- this .mockMvc .perform (get ("/api/v1/dataresources/" + sampleResource .getId ()).header (HttpHeaders .AUTHORIZATION ,
804- "Bearer " + adminToken )).andDo (print ()).andExpect (status ().isNotFound ());
805-
790+ ObjectMapper mapper = createObjectMapper ();
791+ String etag = this .mockMvc .perform (get ("/api/v1/dataresources/" + sampleResource .getId ()).header (HttpHeaders .AUTHORIZATION ,
792+ "Bearer " + adminToken )).andDo (print ()).andExpect (status ().isOk ()).andReturn ().getResponse ().getHeader ("ETag" );
793+
794+ this .mockMvc .perform (delete ("/api/v1/dataresources/" + sampleResource .getId ()).header ("If-Match" , etag ).header (HttpHeaders .AUTHORIZATION ,
795+ "Bearer " + adminToken ).contentType ("application/json" )).andExpect (status ().isNoContent ());
796+ // Test access on revoked resource
797+ //from now on, the resource should be in state REVOKED...HTTP GET should fail for users
798+ this .mockMvc .perform (get ("/api/v1/dataresources/" + sampleResource .getId ()).header (HttpHeaders .AUTHORIZATION ,
799+ "Bearer " + userToken )).andDo (print ()).andExpect (status ().isNotFound ());
800+
801+ //from now on, the resource should be in state REVOKED...HTTP GET should still work for admins
802+ MvcResult result = this .mockMvc .perform (get ("/api/v1/dataresources/" + sampleResource .getId ()).header (HttpHeaders .AUTHORIZATION ,
803+ "Bearer " + adminToken )).andDo (print ()).andExpect (status ().isOk ()).andReturn ();
804+ DataResource resource = mapper .readValue (result .getResponse ().getContentAsString (), DataResource .class );
805+ Assert .assertEquals (DataResource .State .REVOKED , resource .getState ());
806+
807+ //try a second time...this should work
808+ etag = this .mockMvc .perform (get ("/api/v1/dataresources/" + sampleResource .getId ()).header (HttpHeaders .AUTHORIZATION ,
809+ "Bearer " + adminToken )).andDo (print ()).andExpect (status ().isOk ()).andReturn ().getResponse ().getHeader ("ETag" );
810+
811+ this .mockMvc .perform (delete ("/api/v1/dataresources/" + sampleResource .getId ()).header ("If-Match" , etag ).header (HttpHeaders .AUTHORIZATION ,
812+ "Bearer " + adminToken ).contentType ("application/json" )).andExpect (status ().isNoContent ());
813+ //from now on, the resource should be in state GONE...HTTP GET should fail for users
814+ this .mockMvc .perform (get ("/api/v1/dataresources/" + sampleResource .getId ()).header (HttpHeaders .AUTHORIZATION ,
815+ "Bearer " + userToken )).andDo (print ()).andExpect (status ().isNotFound ());
816+ //from now on, the resource should be in state GONE...HTTP GET should still work for admins
817+ result = this .mockMvc .perform (get ("/api/v1/dataresources/" + sampleResource .getId ()).header (HttpHeaders .AUTHORIZATION ,
818+ "Bearer " + adminToken )).andDo (print ()).andExpect (status ().isOk ()).andReturn ();
819+ resource = mapper .readValue (result .getResponse ().getContentAsString (), DataResource .class );
820+ Assert .assertEquals (DataResource .State .GONE , resource .getState ());
806821 }
807822
808823 @ Test
0 commit comments