+ @Test
+ public void Given_Request_Is_HTTP_PUT_And_AAF_CADI_Is_Enabled_Without_Permissions_Then_Forbidden_Response_Is_Generated() throws Exception {
+ when(request.getHeader("Content-Type")).thenReturn("application/vnd.dmaap-dr.subscription; version=1.0");
+ when(request.getPathInfo()).thenReturn("/3");
+ JSONObject JSObject = buildRequestJsonObject();
+ SubscriptionServlet subscriptionServlet = new SubscriptionServlet() {
+ protected JSONObject getJSONfromInput(HttpServletRequest req) {
+ JSONObject jo = new JSONObject();
+ jo.put("name", "stub_name");
+ jo.put("version", "2.0");
+ jo.put("metadataOnly", true);
+ jo.put("suspend", true);
+ jo.put("delivery", JSObject);
+ jo.put("aaf_instance", "*");
+ jo.put("follow_redirect", false);
+ jo.put("sync", true);
+ jo.put("changeowner", true);
+ return jo;
+ }
+ };
+ subscriptionServlet.doPut(request, response);
+ verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), contains("AAF disallows access"));
+ }
+
+ @Test
+ public void Given_Request_Is_HTTP_PUT_And_AAF_CADI_Is_Enabled_With_Permissions_Then_OK_Response_Is_Generated() throws Exception {
+ ServletOutputStream outStream = mock(ServletOutputStream.class);
+ when(response.getOutputStream()).thenReturn(outStream);
+ when(request.getHeader("X-DMAAP-DR-ON-BEHALF-OF-GROUP")).thenReturn("stub_subjectGroup");
+ when(request.getHeader("Content-Type")).thenReturn("application/vnd.dmaap-dr.subscription; version=1.0");
+ when(request.getPathInfo()).thenReturn("/3");
+ when(request.isUserInRole("org.onap.dmaap-dr.sub|*|edit")).thenReturn(true);
+ PowerMockito.mockStatic(PasswordProcessor.class);
+ JSONObject JSObject = buildRequestJsonObject();
+ SubscriptionServlet subscriptionServlet = new SubscriptionServlet() {
+ protected JSONObject getJSONfromInput(HttpServletRequest req) {
+ JSONObject jo = new JSONObject();
+ jo.put("name", "stub_name");
+ jo.put("version", "2.0");
+ jo.put("metadataOnly", true);
+ jo.put("suspend", true);
+ jo.put("delivery", JSObject);
+ jo.put("aaf_instance", "*");
+ jo.put("follow_redirect", false);
+ jo.put("sync", true);
+ return jo;
+ }
+ };
+ subscriptionServlet.doPut(request, response);
+ verify(response).setStatus(eq(HttpServletResponse.SC_OK));
+ resetAafSubscriptionInDB();
+ addNewSubscriptionInDB();
+ verifyEnteringExitCalled(listAppender);
+ }
+