protected void throwFailureException() throws Exception { StringBuffer buf = new StringBuffer(); for (int c = 0; c < assertions.size(); c++) { TestAssertion assertion = assertions.get(c); Assertable assertable = assertion.getAssertable(); if (assertable instanceof WsdlTestStep) { failedTests.remove(((WsdlTestStep) assertable).getTestCase()); } buf.append( assertion.getName() + " in [" + assertable.getModelItem().getName() + "] failed;\n"); buf.append(Arrays.toString(assertion.getErrors()) + "\n"); WsdlTestStepResult result = assertionResults.get(assertion); StringWriter stringWriter = new StringWriter(); PrintWriter writer = new PrintWriter(stringWriter); result.writeTo(writer); buf.append(stringWriter.toString()); } while (!failedTests.isEmpty()) { buf.append("TestCase [" + failedTests.remove(0).getName() + "] failed without assertions\n"); } throw new Exception(buf.toString()); }
@Override public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { boldFont = getFont().deriveFont(Font.BOLD); AssertionListEntry entry = (AssertionListEntry) value; String type = TestAssertionRegistry.getInstance().getAssertionTypeForName(entry.getName()); boolean canAssert = false; boolean disable = true; JLabel label; JTextArea descText; JLabel disabledInfo; if (type != null && assertable != null && assertable.getModelItem() != null) { canAssert = isAssertionApplicable(type, assertable.getModelItem(), getSelectedPropertyName()); disable = !categoriesListTable.isEnabled() || !canAssert; } String str = entry.getName(); label = new JLabel(str); label.setFont(boldFont); descText = new JTextArea(((AssertionListEntry) value).getDescription()); descText.setSize(new Dimension(80, 20)); descText.setLineWrap(true); descText.setWrapStyleWord(true); disabledInfo = new JLabel("Not applicable with selected Source and Property"); descText.setFont(disabledInfo.getFont()); if (disable) { label.setForeground(Color.LIGHT_GRAY); descText.setForeground(Color.LIGHT_GRAY); disabledInfo.setForeground(Color.LIGHT_GRAY); } SimpleForm form = new SimpleForm(); form.addComponent(label); if (!isHideDescriptionSelected()) { form.addComponent(descText); // if( disable ) // { // form.addComponent( disabledInfo ); // } getAssertionsTable().setRowHeight(70); } else { if (disable) { form.addComponent(disabledInfo); } getAssertionsTable().setRowHeight(40); } if (isSelected) { descText.setBackground(Color.LIGHT_GRAY); form.getPanel().setBackground(Color.LIGHT_GRAY); } else { descText.setBackground(Color.WHITE); form.getPanel().setBackground(Color.WHITE); } return form.getPanel(); }
public boolean canAddAssertion(WsdlMessageAssertion assertion, Assertable assertable) { if (assertion.isAllowMultiple()) { return true; } for (int c = 0; c < assertable.getAssertionCount(); c++) { if (assertion.getClass().equals(assertable.getAssertionAt(c).getClass())) { return false; } } return true; }
public AddAssertionPanel(Assertable assertable) { super( "Add Assertion", "Select the source property and which assertion to apply below ", HelpUrls.ADD_ASSERTION_PANEL); this.assertable = assertable; assertionEntryRenderer.setAssertable(assertable); categoriesListRenderer.setAssertable(assertable); selectionListener = new InternalListSelectionListener(); categoriesAssertionsMap = AssertionCategoryMapping.getCategoriesAssertionsMap(assertable, recentAssertionHandler); // load interfaces or have a issue with table and cell renderer WsdlProject project = (WsdlProject) ModelSupport.getModelItemProject(assertable.getModelItem()); for (Interface inf : project.getInterfaceList()) { try { // There seems to be no good reason to load the definitions for rest interfaces // hence that call has been removed for the time being. if (inf instanceof WsdlInterface) { ((WsdlInterface) inf).getWsdlContext().loadIfNecessary(); } } catch (Exception e) { // TODO Improve this e.printStackTrace(); } } }
@Override protected boolean handleOk() { setVisible(false); int selectedRow = assertionsTable.getSelectedRow(); String selection = ((AssertionListEntry) assertionsListTableModel.getValueAt(selectedRow, 0)).getName(); if (selection == null) { return false; } if (!TestAssertionRegistry.getInstance().canAddMultipleAssertions(selection, assertable)) { UISupport.showErrorMessage("This assertion can only be added once"); return false; } TestAssertion assertion = assertable.addAssertion(selection); if (assertion == null) { UISupport.showErrorMessage("Failed to add assertion"); return false; } recentAssertionHandler.add(selection); if (assertion.isConfigurable()) { assertion.configure(); return true; } return true; }
public boolean canAddMultipleAssertions(String name, Assertable assertable) { for (int c = 0; c < assertable.getAssertionCount(); c++) { TestAssertion assertion = assertable.getAssertionAt(c); if (assertion.isAllowMultiple()) { continue; } if (assertion .getClass() .equals(availableAssertions.get(getAssertionTypeForName(name)).getAssertionClassType())) { return false; } } return true; }
@Override public void afterStep( TestCaseRunner testRunner, TestCaseRunContext runContext, TestStepResult result) { super.afterStep(testRunner, runContext, result); TestStep currentStep = runContext.getCurrentStep(); if (currentStep instanceof Assertable) { Assertable requestStep = (Assertable) currentStep; for (int c = 0; c < requestStep.getAssertionCount(); c++) { TestAssertion assertion = requestStep.getAssertionAt(c); log.info("Assertion [" + assertion.getName() + "] has status " + assertion.getStatus()); if (assertion.getStatus() == AssertionStatus.FAILED) { for (AssertionError error : assertion.getErrors()) { log.error("ASSERTION FAILED -> " + error.getMessage()); } assertions.add(assertion); assertionResults.put(assertion, (WsdlTestStepResult) result); } testAssertionCount++; } } String countPropertyName = currentStep.getName() + " run count"; Long count = (Long) runContext.getProperty(countPropertyName); if (count == null) { count = new Long(0); } runContext.setProperty(countPropertyName, new Long(count.longValue() + 1)); if (result.getStatus() == TestStepStatus.FAILED || exportAll) { try { String exportSeparator = System.getProperty(SOAPUI_EXPORT_SEPARATOR, "-"); TestCase tc = currentStep.getTestCase(); String nameBase = StringUtils.createFileName(tc.getTestSuite().getName(), '_') + exportSeparator + StringUtils.createFileName(tc.getName(), '_') + exportSeparator + StringUtils.createFileName(currentStep.getName(), '_') + "-" + count.longValue() + "-" + result.getStatus(); WsdlTestCaseRunner callingTestCaseRunner = (WsdlTestCaseRunner) runContext.getProperty("#CallingTestCaseRunner#"); if (callingTestCaseRunner != null) { WsdlTestCase ctc = callingTestCaseRunner.getTestCase(); WsdlRunTestCaseTestStep runTestCaseTestStep = (WsdlRunTestCaseTestStep) runContext.getProperty("#CallingRunTestCaseStep#"); nameBase = StringUtils.createFileName(ctc.getTestSuite().getName(), '_') + exportSeparator + StringUtils.createFileName(ctc.getName(), '_') + exportSeparator + StringUtils.createFileName(runTestCaseTestStep.getName(), '_') + exportSeparator + StringUtils.createFileName(tc.getTestSuite().getName(), '_') + exportSeparator + StringUtils.createFileName(tc.getName(), '_') + exportSeparator + StringUtils.createFileName(currentStep.getName(), '_') + "-" + count.longValue() + "-" + result.getStatus(); } String absoluteOutputFolder = getAbsoluteOutputFolder(ModelSupport.getModelItemProject(tc)); String fileName = absoluteOutputFolder + File.separator + nameBase + ".txt"; if (result.getStatus() == TestStepStatus.FAILED) { log.error(currentStep.getName() + " failed, exporting to [" + fileName + "]"); } new File(fileName).getParentFile().mkdirs(); PrintWriter writer = new PrintWriter(fileName); result.writeTo(writer); writer.close(); // write attachments if (result instanceof MessageExchange) { Attachment[] attachments = ((MessageExchange) result).getResponseAttachments(); if (attachments != null && attachments.length > 0) { for (int c = 0; c < attachments.length; c++) { fileName = nameBase + "-attachment-" + (c + 1) + "."; Attachment attachment = attachments[c]; String contentType = attachment.getContentType(); if (!"application/octet-stream".equals(contentType) && contentType != null && contentType.indexOf('/') != -1) { fileName += contentType.substring(contentType.lastIndexOf('/') + 1); } else { fileName += "dat"; } fileName = absoluteOutputFolder + File.separator + fileName; FileOutputStream outFile = new FileOutputStream(fileName); Tools.writeAll(outFile, attachment.getInputStream()); outFile.close(); } } } exportCount++; } catch (Exception e) { log.error("Error saving failed result: " + e, e); } } testStepCount++; }