private void initializeMixIns() { for (TestMixIn mixIn : getMixIns()) { mixIn.initialize(); } }
/** * POST the specified String request to the specified HTTP endpoint and perform an XML compare * between the HTTP response and the specified expected response String. * @param endpointURL The HTTP endpoint URL. * @param request The classpath resource to be posted to the endpoint. * @param expectedResponse The String to use to perform the XML test on the response. * @return The HTTP response payload. */ public String postStringAndTestXML(String endpointURL, String request, String expectedResponse) { String response = postString(endpointURL, request); SwitchYardTestKit.compareXMLToString(response, expectedResponse); return response; }
/** * Undeploy the deployment. */ private final void undeploy() { assertDeployed(); _deployment.stop(); mixInAfter(); _deployment.destroy(); }
/** * Cleanup. */ public void cleanup() { undeploy(); cleanupMixIns(); }
/** * invoke the methods annotated with {@link BeforeDeploy} on test class and deploy SwitchYard application. * * @throws Exception failed to deploy */ public void start() throws Exception { beforeDeploy(); deploy(); }
@Override protected Object createTest() throws Exception { _testInstance = super.createTest(); _testKit = new SwitchYardTestKit(_testInstance); for (TestMixIn mixIn : _testKit.getMixIns()) { set(mixIn, PropertyMatchResolution.EQUALS); } try { _testKit.start(); } catch (Throwable t) { LOG.error("Error while test kit startup", t); _testKit.cleanup(); throw new Exception(t); } set(_testKit, PropertyMatchResolution.EQUALS); set(_testKit.getDeployment(), PropertyMatchResolution.ASSIGNABLE); set(_testKit.getConfigModel(), PropertyMatchResolution.ASSIGNABLE); set(_testKit.getServiceDomain(), PropertyMatchResolution.ASSIGNABLE); set(_testKit.getServiceDomain().getTransformerRegistry(), PropertyMatchResolution.ASSIGNABLE); set(_testKit.getServiceDomain().getProperty(SwitchYardCamelContext.CAMEL_CONTEXT_PROPERTY), PropertyMatchResolution.ASSIGNABLE); setInvokers(); return _testInstance; }
String config = testCaseConfig.config(); if (config != null && !config.equals(NULL_CONFIG)) { InputStream is = getResourceAsStream(config); _configModel = createSwitchYardModel(is, createScanners(testCaseConfig), testCaseConfig.validate()); } finally { try { createMixInInstances(); initializeMixIns();
/** * Read a classpath resource and return as an XML DOM Document. * * @param path The path to the classpath resource. The specified path can be * relative to the test class' location on the classpath. * @return The resource as a Document. */ public Document readResourceDocument(String path) { try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); DocumentBuilder db = dbf.newDocumentBuilder(); return db.parse(getResourceAsStream(path)); } catch (Exception e) { Assert.fail("Unexpected exception reading classpath resource '" + path + "' as a DOM Document." + e.getMessage()); return null; // Keep the compiler happy. } }
/** * Compare an XML string (e.g. a result) against a classpath resource. * @param xml The XML (as a String) to be compared against the XML in the specified * classpath resource. * @param resourcePath The path to the classpath resource against which the XML is to be * compared. The specified path can be relative to the test class' location on the classpath. */ public void compareXMLToResource(String xml, String resourcePath) { XMLUnit.setIgnoreWhitespace(true); try { XMLAssert.assertXMLEqual(readResourceString(resourcePath), xml); } catch (Exception e) { Assert.fail("Unexpected error performing XML comparison: " + e.getMessage()); } }
/** * Get the ServiceDomain. * @return The service domain. */ public ServiceDomain getServiceDomain() { assertDeployed(); return _deployment.getDomain(); }
@Override public void testFinished(Description description) throws Exception { _testKit.cleanup(); } }
@Override protected Object createTest() throws Exception { _testInstance = super.createTest(); _testKit = new SwitchYardTestKit(_testInstance); for (TestMixIn mixIn : _testKit.getMixIns()) { set(mixIn, PropertyMatchResolution.EQUALS); _testKit.start(); } catch (Throwable t) { exceptionFlag = true; if (exceptionFlag) { try { _testKit.cleanup(); } catch (Exception e) { LOG.error("Could not cleanup testkit", e); set(_testKit.getDeployment(), PropertyMatchResolution.ASSIGNABLE); set(_testKit.getConfigModel(), PropertyMatchResolution.ASSIGNABLE); set(_testKit.getServiceDomain(), PropertyMatchResolution.ASSIGNABLE); set(_testKit.getServiceDomain().getTransformerRegistry(), PropertyMatchResolution.ASSIGNABLE); set(_testKit.getServiceDomain().getProperty(SwitchYardCamelContext.CAMEL_CONTEXT_PROPERTY), PropertyMatchResolution.ASSIGNABLE);
String config = testCaseConfig.config(); if (config != null && !config.equals(NULL_CONFIG)) { InputStream is = getResourceAsStream(config); _configModel = createSwitchYardModel(is, createScanners(testCaseConfig), testCaseConfig.validate()); } finally { try { createMixInInstances(); initializeMixIns();
/** * Read a classpath resource and return as an XML DOM Document. * * @param path The path to the classpath resource. The specified path can be * relative to the test class' location on the classpath. * @return The resource as a Document. */ public Document readResourceDocument(String path) { try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); DocumentBuilder db = dbf.newDocumentBuilder(); return db.parse(getResourceAsStream(path)); } catch (Exception e) { Assert.fail("Unexpected exception reading classpath resource '" + path + "' as a DOM Document." + e.getMessage()); return null; // Keep the compiler happy. } }
/** * Compare an XML string (e.g. a result) against a classpath resource. * @param xml The XML (as a String) to be compared against the XML in the specified * classpath resource. * @param resourcePath The path to the classpath resource against which the XML is to be * compared. The specified path can be relative to the test class' location on the classpath. */ public void compareXMLToResource(String xml, String resourcePath) { XMLUnit.setIgnoreWhitespace(true); try { XMLAssert.assertXMLEqual(readResourceString(resourcePath), xml); } catch (Exception e) { Assert.fail("Unexpected error performing XML comparison: " + e.getMessage()); } }
/** * Cleanup. */ public void cleanup() { undeploy(); cleanupMixIns(); }
/** * invoke the methods annotated with {@link BeforeDeploy} on test class and deploy SwitchYard application. * * @throws Exception failed to deploy */ public void start() throws Exception { beforeDeploy(); deploy(); }
/** * Get the ServiceDomain. * @return The service domain. */ public ServiceDomain getServiceDomain() { assertDeployed(); return _deployment.getDomain(); }
@Override public void testFinished(Description description) throws Exception { _testKit.cleanup(); } }
private void initializeMixIns() { for (TestMixIn mixIn : getMixIns()) { mixIn.initialize(); } }