How to use test method of org.cerberus.servlet.crud.test.DeleteTest class

Best Cerberus-source code snippet using org.cerberus.servlet.crud.test.DeleteTest.test

Source:DeleteTest.java Github

copy

Full Screen

1/**2 * Cerberus Copyright (C) 2013 - 2017 cerberustesting3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4 *5 * This file is part of Cerberus.6 *7 * Cerberus is free software: you can redistribute it and/or modify8 * it under the terms of the GNU General Public License as published by9 * the Free Software Foundation, either version 3 of the License, or10 * (at your option) any later version.11 *12 * Cerberus is distributed in the hope that it will be useful,13 * but WITHOUT ANY WARRANTY; without even the implied warranty of14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15 * GNU General Public License for more details.16 *17 * You should have received a copy of the GNU General Public License18 * along with Cerberus. If not, see <http://www.gnu.org/licenses/>.19 */20package org.cerberus.servlet.crud.test;21import java.io.IOException;22import java.util.Collection;23import java.util.List;24import javax.annotation.Nullable;25import javax.servlet.ServletException;26import javax.servlet.annotation.WebServlet;27import javax.servlet.http.HttpServlet;28import javax.servlet.http.HttpServletRequest;29import javax.servlet.http.HttpServletResponse;30import com.google.common.base.Function;31import com.google.common.base.Predicate;32import com.google.common.collect.Collections2;33import org.apache.logging.log4j.Logger;34import org.apache.logging.log4j.LogManager;35import org.cerberus.crud.entity.TestCaseStep;36import org.cerberus.crud.service.IParameterService;37import org.cerberus.crud.service.ITestCaseStepService;38import org.cerberus.engine.entity.MessageEvent;39import org.cerberus.crud.entity.Test;40import org.cerberus.crud.service.ILogEventService;41import org.cerberus.crud.service.ITestService;42import org.cerberus.crud.service.impl.LogEventService;43import org.cerberus.enums.MessageEventEnum;44import org.cerberus.exception.CerberusException;45import org.cerberus.util.StringUtil;46import org.cerberus.util.answer.Answer;47import org.cerberus.util.answer.AnswerItem;48import org.cerberus.util.servlet.ServletUtil;49import org.json.JSONException;50import org.json.JSONObject;51import org.owasp.html.PolicyFactory;52import org.owasp.html.Sanitizers;53import org.springframework.context.ApplicationContext;54import org.springframework.web.context.support.WebApplicationContextUtils;55/**56 * @author cerberus57 */58@WebServlet(name = "DeleteTest", urlPatterns = {"/DeleteTest"})59public class DeleteTest extends HttpServlet {60 private static Logger LOGGER = LogManager.getLogger(DeleteTest.class);61 /**62 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>63 * methods.64 *65 * @param request servlet request66 * @param response servlet response67 * @throws ServletException if a servlet-specific error occurs68 * @throws IOException if an I/O error occurs69 */70 protected void processRequest(HttpServletRequest request, HttpServletResponse response)71 throws ServletException, IOException, JSONException {72 JSONObject jsonResponse = new JSONObject();73 Answer ans = new Answer();74 PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);75 response.setContentType("application/json");76 // Calling Servlet Transversal Util.77 ServletUtil.servletStart(request);78 // Parsing and securing all required parameters.79 String key = policy.sanitize(request.getParameter("test"));80 // Checking all constrains before calling the services.81 if (StringUtil.isNull(key)) {82 ans.setResultMessage(83 new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED)84 .resolveDescription("ITEM", "Test")85 .resolveDescription("OPERATION", "Delete")86 .resolveDescription("REASON", "Test name is missing.")87 );88 } else {89 // All data seems cleans so we can call the services.90 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());91 ITestService testService = appContext.getBean(ITestService.class);92 IParameterService parameterService = appContext.getBean(IParameterService.class);93 AnswerItem resp = testService.readByKey(key);94 if (!(resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getItem() != null)) {95 // Object could not be found. We stop here and report the error.96 ans.setResultMessage(97 new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED)98 .resolveDescription("ITEM", "Test")99 .resolveDescription("OPERATION", "Delete")100 .resolveDescription("REASON", "Test does not exist")101 );102 } else {103 // The service was able to perform the query and confirm the object exist104 Test testData = (Test) resp.getItem();105 // Check if there is no associated Test Cases defining Step which is used OUTSIDE of the deleting Test106 try {107 final Collection<TestCaseStep> externallyUsedTestCaseSteps = externallyUsedTestCaseSteps(testData);108 if (!externallyUsedTestCaseSteps.isEmpty()) {109 String cerberusUrlTemp = parameterService.getParameterStringByKey("cerberus_gui_url", "", "");110 if (StringUtil.isNullOrEmpty(cerberusUrlTemp)) {111 cerberusUrlTemp = parameterService.getParameterStringByKey("cerberus_url", "", "");112 }113 final String cerberusUrl = cerberusUrlTemp;114// final String cerberusUrl = appContext.getBean(IParameterService.class).findParameterByKey("cerberus_url", "").getValue();115 ans.setResultMessage(116 new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED)117 .resolveDescription("ITEM", "Test")118 .resolveDescription("OPERATION", "Delete")119 .resolveDescription(120 "REASON", "You are trying to remove a Test which contains Test Case Steps which are currently used by other Test Case Steps outside of the removing Test. Please remove this link before to proceed: "121 + Collections2.transform(externallyUsedTestCaseSteps, (@Nullable final TestCaseStep input) -> String.format(122 "<a href='%s/TestCaseScript.jsp?test=%s&testcase=%s&step=%s'>%s/%s#%s</a>",123 cerberusUrl,124 input.getTest(),125 input.getTestcase(),126 input.getStepId(),127 input.getTest(),128 input.getTestcase(),129 input.getStepId()130 ))131 )132 );133 } else {134 // Test seems clean, process to delete135 ans = testService.delete(testData);136 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {137 // Delete was successful. Adding Log entry.138 ILogEventService logEventService = appContext.getBean(LogEventService.class);139 logEventService.createForPrivateCalls("/DeleteTest", "DELETE", "Delete Test : ['" + key + "']", request);140 }141 }142 } catch (final CerberusException e) {143 LOGGER.error(e.getMessage(), e);144 ans.setResultMessage(new MessageEvent(145 MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED)146 .resolveDescription("DESCRIPTION", "Unexpected error: " + e.getMessage())147 );148 }149 }150 }151 // Formating and returning the json result.152 jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());153 jsonResponse.put("message", ans.getResultMessage().getDescription());154 response.getWriter().print(jsonResponse.toString());155 response.getWriter().flush();156 }157 /**158 * Get {@link TestCaseStep} which are using an other {@link TestCaseStep}159 * from the given {@link Test} but which are NOT included into this160 * {@link Test}161 *162 * @param test the {@link Test} from which getting externally used163 * {@link TestCaseStep}s164 * @return a {@link Collection} of {@link TestCaseStep} which are using an165 * other {@link TestCaseStep} from the given {@link Test} but which are NOT166 * included into this {@link Test}167 * @throws CerberusException if an unexpected error occurred168 */169 private Collection<TestCaseStep> externallyUsedTestCaseSteps(final Test test) throws CerberusException {170 // Get the associated ApplicationContext to this servlet171 final ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());172 // Get all TestCaseSteps which are using an other TestCaseSteps from given Test173 final ITestCaseStepService testCaseStepService = applicationContext.getBean(ITestCaseStepService.class);174 final List<TestCaseStep> stepsInUse = testCaseStepService.getTestCaseStepsUsingTestInParameter(test.getTest());175 // Filter the retrieved list to only retain those which are not included from the given Test176 return Collections2.filter(stepsInUse, new Predicate<TestCaseStep>() {177 @Override178 public boolean apply(@Nullable final TestCaseStep input) {179 return !input.getTest().equals(test.getTest());180 }181 @Override182 public boolean test(TestCaseStep t) {183 return Predicate.super.test(t); //To change body of generated methods, choose Tools | Templates.184 }185 });186 }187 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">188 /**189 * Handles the HTTP <code>GET</code> method.190 *191 * @param request servlet request192 * @param response servlet response193 * @throws ServletException if a servlet-specific error occurs194 * @throws IOException if an I/O error occurs195 */196 @Override197 protected void doGet(HttpServletRequest request, HttpServletResponse response)...

Full Screen

Full Screen

test

Using AI Code Generation

copy

Full Screen

1package org.cerberus.servlet.crud.test;2import java.io.IOException;3import java.io.PrintWriter;4import javax.servlet.ServletException;5import javax.servlet.annotation.WebServlet;6import javax.servlet.http.HttpServlet;7import javax.servlet.http.HttpServletRequest;8import javax.servlet.http.HttpServletResponse;9import org.apache.logging.log4j.LogManager;10import org.apache.logging.log4j.Logger;11import org.cerberus.crud.entity.Test;12import org.cerberus.crud.factory.IFactoryTest;13import org.cerberus.crud.service.ITestService;14import org.cerberus.crud.service.impl.TestService;15import org.cerberus.engine.entity.MessageEvent;16import org.cerberus.engine.entity.MessageGeneral;17import org.cerberus.engine.entity.MessageGeneralEnum;18import org.cerberus.exception.CerberusException;19import org.cerberus.exception.FactoryCreationException;20import org.cerberus.factory.impl.FactoryTest;21import org.cerberus.log.MyLogger;22import org.cerberus.util.answer.Answer;23import org.cerberus.util.answer.AnswerItem;24import org.json.JSONException;25import org.json.JSONObject;26import org.springframework.context.ApplicationContext;27import org.springframework.web.context.support.WebApplicationContextUtils;28@WebServlet(name = "DeleteTest", urlPatterns = {"/DeleteTest"})29public class DeleteTest extends HttpServlet {30 private static final Logger LOG = LogManager.getLogger(DeleteTest.class);31 private ITestService testService;32 private IFactoryTest factoryTest;33 public void init() throws ServletException {34 super.init();35 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());36 testService = appContext.getBean(TestService.class);37 factoryTest = appContext.getBean(FactoryTest.class);38 }39 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {40 response.setContentType("application/json");41 PrintWriter out = response.getWriter();42 JSONObject jsonResponse = new JSONObject();43 try {44 String test = request.getParameter("test");45 String system = request.getParameter("system");46 String active = request.getParameter("active");47 String project = request.getParameter("project");48 String description = request.getParameter("description");

Full Screen

Full Screen

test

Using AI Code Generation

copy

Full Screen

1import org.cerberus.servlet.crud.test.DeleteTest;2import org.cerberus.util.answer.AnswerItem;3AnswerItem answer = DeleteTest.test("test1", "cerberus", "cerberus");4System.out.println("Result: " + answer.getResultMessage());5System.out.println("Message: " + answer.getResultMessage());6System.out.println("MessageString: " + answer.getMessageString());7System.out.println("Object: " + answer.getItem());8System.out.println("ObjectClass: " + answer.getItem().getClass().getName());9System.out.println("ObjectString: " + answer.getItem().toString());10System.out.println("ObjectString: " + answer.getItem().toString());11getAnswerItem()12getItem()13getItemClass()14getMessage()15getMessageString()16getResultMessage()17getResultMessage()18setAnswerItem(Object answerItem)19setItem(Object item)20setMessage(Message message)21setMessageString(String messageString)22setResultMessage(ResultMessage resultMessage)23The following code shows how to use the DeleteTest.test(String test, String system, String country) method:24import org.cerberus.servlet.crud.test.DeleteTest;25import org.cerberus.util.answer.AnswerItem;26AnswerItem answer = DeleteTest.test("test1", "cerberus", "cerberus");27System.out.println("Result: " + answer.getResultMessage());28System.out.println("Message: " + answer.getResultMessage());29System.out.println("MessageString: " + answer.getMessageString());30System.out.println("Object: " + answer.getItem());31System.out.println("ObjectClass: " + answer.getItem().getClass().getName());32System.out.println("ObjectString: " + answer.getItem().toString());33System.out.println("ObjectString: " + answer.getItem().toString());

Full Screen

Full Screen

test

Using AI Code Generation

copy

Full Screen

1import org.cerberus.servlet.crud.test.DeleteTest;2import org.cerberus.crud.entity.Test;3import org.cerberus.util.answer.AnswerItem;4import org.cerberus.util.answer.AnswerList;5import org.cerberus.util.answer.Answer;6import java.util.ArrayList;7import java.util.List;8List<String> testList = new ArrayList<String>();9testList = request.getParameterValues("Test");10List<Test> testToDeleteList = new ArrayList<Test>();11for (String test : testList) {12 Test testToDelete = new Test();13 testToDelete.setTest(test);14 testToDeleteList.add(testToDelete);15}16AnswerList answerList = new AnswerList();17for (Test testToDelete : testToDeleteList) {18 AnswerItem answerItem = new AnswerItem();19 answerItem.setItem(testToDelete);20 answerList.getDataList().add(answerItem);21 DeleteTest deleteTest = new DeleteTest();22 Answer deleteAnswer = deleteTest.deleteTest(testToDelete);23 answerItem.setResultMessage(deleteAnswer.getResultMessage());24 answerItem.setResultMessage(deleteAnswer.getResultMessage());

Full Screen

Full Screen

test

Using AI Code Generation

copy

Full Screen

1import org.cerberus.servlet.crud.test.DeleteTest;2import org.cerberus.servlet.crud.test.CreateTest;3import org.cerberus.servlet.crud.test.UpdateTest;4import org.cerberus.servlet.crud.test.ReadTest;5import org.cerberus.util.answer.AnswerItem;6import org.cerberus.util.answer.AnswerList;7import org.cerberus.util.answer.Answer;8import org.cerberus.crud.entity.Test;9import org.cerberus.crud.entity.TestCase;10import org.cerberus.crud.entity.TestDataLibData;11import org.cerberus.crud.entity.TestDataLib;12import java.util.ArrayList;13import java.util.List;14import org.cerberus.servlet.crud.testdata.CreateTestDataLib;15import org.cerberus.servlet.crud.testdata.CreateTestDataLibData;16import org.cerberus.servlet.crud.testdata.UpdateTestDataLib;17import org.cerberus.servlet.crud.testdata.UpdateTestDataLibData;18import org.cerberus.servlet.crud.testdata.ReadTestDataLib;19import org.cerberus.servlet.crud.testdata.ReadTestDataLibData;20import org.cerberus.servlet.crud.testdata.DeleteTestDataLib;21import org.cerberus.servlet.crud.testdata.DeleteTestDataLibData;22import org.cerberus.servlet.crud.testcase.CreateTestCase;23import org.cerberus.servlet.crud.testcase.UpdateTestCase;24import org.cerberus.servlet.crud.testcase.ReadTestCase;25import org.cerberus.servlet.crud.testcase.DeleteTestCase;26import org.cerberus.servlet.crud.testdatalibdata.CreateTestDataLibData;27import org.cerberus.servlet.crud.testdatalibdata.UpdateTestDataLibData;28import org.cerberus.servlet.crud.testdatalibdata.ReadTestDataLibData;29import org.cerberus.servlet.crud.testdatalibdata.DeleteTestDataLibData;30import org.cerberus.servlet.crud.testdatalib.CreateTestDataLib;31import org.cerberus.servlet.crud.testdatalib.UpdateTestDataLib;32import org.cerberus.servlet.crud.testdatalib.ReadTestDataLib;33import org.cerberus.servlet.crud.testdatalib.DeleteTestDataLib

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Cerberus-source automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful