RemoveServlet extends TransformationServlet { @Override protected void doPost(WorkbenchRequest req, HttpServletResponse resp, String xslPath) throws IOException, RepositoryException, QueryResultHandlerException { String objectParameter = req.getParameter("obj"); try { try (RepositoryConnection con = repository.getConnection()) { Resource subj = req.getResource("subj"); IRI pred = req.getURI("pred"); Value obj = req.getValue("obj"); if (subj == null && pred == null && obj == null && !req.isParameterPresent(CONTEXT)) { throw new BadRequestException("No values"); } remove(con, subj, pred, obj, req); if (obj instanceof Literal && obj.stringValue().contains("\r\n")) { obj = Protocol.decodeValue(objectParameter.replace("\r\n", "\n"), con.getValueFactory()); remove(con, subj, pred, obj, req); } } catch (ClassCastException exc) { throw new BadRequestException(exc.getMessage(), exc); } resp.sendRedirect("summary"); } catch (BadRequestException exc) { logger.warn(exc.toString(), exc); TupleResultBuilder builder = getTupleResultBuilder(req, resp, resp.getOutputStream()); builder.transform(xslPath, "remove.xsl"); builder.start("error-message", "subj", "pred", "obj", CONTEXT); builder.link(Arrays.asList(INFO)); builder.result(exc.getMessage(), req.getParameter("subj"), req.getParameter("pred"), objectParameter, req.getParameter(CONTEXT)); builder.end(); } }  @Override void service(TupleResultBuilder builder, String xslPath);  }
@Test public void testSES1958regression() throws RepositoryException, QueryResultHandlerException, IOException, BadRequestException { WorkbenchRequest request = mock(WorkbenchRequest.class); when(request.isParameterPresent(CONTEXT)).thenReturn(true); IRI context = SimpleValueFactory.getInstance().createIRI("<http: when(request.getResource(CONTEXT)).thenReturn(context); Repository repository = mock(Repository.class); servlet.setRepository(repository); RepositoryConnection connection = mock(RepositoryConnection.class); when(repository.getConnection()).thenReturn(connection); servlet.doPost(request, mock(HttpServletResponse.class), ""); verify(connection).clear(eq(context)); }