+ public void Given_Request_Is_HTTP_POST_And_Active_Feeds_Equals_Max_Feeds_Then_Bad_Request_Response_Is_Generated()
+ throws Exception {
+ FieldUtils.writeDeclaredStaticField(BaseServlet.class, "maxFeeds", 0, true);
+ DRFeedsServlet drfeedsServlet = new DRFeedsServlet() {
+ public JSONObject getJSONfromInput(HttpServletRequest req) {
+ return new JSONObject();
+ }
+ };
+ drfeedsServlet.doPost(request, response);
+ verify(response).sendError(eq(HttpServletResponse.SC_CONFLICT), anyString());
+ }
+
+ @Test
+ public void Given_Request_Is_HTTP_POST_And_Feed_Is_Not_Valid_Object_Bad_Request_Response_Is_Generated()
+ throws Exception {
+ DRFeedsServlet drfeedsServlet = new DRFeedsServlet() {
+ public JSONObject getJSONfromInput(HttpServletRequest req) {
+ return new JSONObject();
+ }
+ };
+
+ drfeedsServlet.doPost(request, response);
+ verify(response).sendError(eq(HttpServletResponse.SC_BAD_REQUEST), anyString());
+ }
+
+ @Test
+ public void Given_Request_Is_HTTP_POST_And_Feed_Already_Exists_Bad_Request_Response_Is_Generated()
+ throws Exception {
+ when(request.getParameter("name")).thenReturn("AafFeed");
+ when(request.getParameter("version")).thenReturn("v0.1");
+ when(request.getHeader(DRFeedsServlet.EXCLUDE_AAF_HEADER)).thenReturn("false");
+ when(request.isUserInRole("org.onap.dmaap-dr.feed|*|create")).thenReturn(true);
+ JSONObject JSObject = buildRequestJsonObject();
+ DRFeedsServlet drfeedsServlet = new DRFeedsServlet() {
+ public JSONObject getJSONfromInput(HttpServletRequest req) {
+ JSONObject jo = new JSONObject();
+ jo.put("name", "AafFeed");
+ jo.put("version", "v0.1");
+ jo.put("authorization", JSObject);
+ jo.put("aaf_instance", "*");
+ return jo;
+ }
+ };
+ drfeedsServlet.doPost(request, response);
+ verify(response).sendError(eq(HttpServletResponse.SC_BAD_REQUEST), contains("This feed already exists in the database"));
+ }
+
+ @Test
+ public void Given_Request_Is_HTTP_POST_And_POST_Fails_Bad_Request_Response_Is_Generated() throws Exception {