/** * Test a proxy service with recursive imports and without a {@link ResourceMap}. * Regression test for SYNAPSE-442. */ public void testRecursiveImports2() throws Exception { ProxyService testService = new ProxyService("mytest"); SynapseConfiguration synCfg = new SynapseConfiguration(); AxisConfiguration axisCfg = new AxisConfiguration(); testService.setWsdlURI(getClass().getResource("SimpleStockService.wsdl").toURI()); testService.buildAxisService(synCfg, axisCfg); }
/** * Test that a proxy service without publishWSDL will produce a meaningful WSDL. * This is a regression test for SYNAPSE-366. */ public void testWSDLWithoutPublishWSDL() throws Exception { // Build the proxy service SynapseConfiguration synCfg = new SynapseConfiguration(); AxisConfiguration axisCfg = new AxisConfiguration(); ProxyService proxyService = new ProxyService("Test"); AxisService axisService = proxyService.buildAxisService(synCfg, axisCfg); // Serialize the WSDL ByteArrayOutputStream baos = new ByteArrayOutputStream(); axisService.printWSDL(baos); // Check that the produced WSDL can be read by WSDL4J WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader(); wsdlReader.readWSDL(null, new InputSource(new ByteArrayInputStream(baos.toByteArray()))); }
/** * Test proxyServiceAdded method by hash generation. */ @Test public void testProxyServiceAdded() { ProxyService proxyService = new ProxyService("test"); observer.proxyServiceAdded(proxyService); Assert.assertNotNull("New hash must be set by the method", proxyService.getAspectConfiguration().getHashCode()); }
/** * Tests building a proxy service with an unreachable URI specified as the published wsdl url with the * 'enablePublishWSDLSafeMode' set to true. * * @throws URISyntaxException if an error occurs when converting the URI string to a URI */ public void testBuildAxisServiceWithUnreachableWsdlUriWithPublishWSDLSafeModeEnabled() throws Exception { SynapseConfiguration synCfg = new SynapseConfiguration(); AxisConfiguration axisCfg = new AxisConfiguration(); ProxyService proxyService = new ProxyService ("unreachableWsdlUriWithPublishWSDLSafeModeEnabledProxy"); proxyService.addParameter("enablePublishWSDLSafeMode", true); URI wsdlUri = new URI("http://invalid-host/SimpleStockService.wsdl"); proxyService.setWsdlURI(wsdlUri); Assert.assertNull("Axis service returned should be null", proxyService.buildAxisService(synCfg, axisCfg)); }
/** * Tests building a proxy service with a malformed URI specified as the published wsdl url. * * @throws Exception if an error occurs due to the malformed url */ public void testBuildAxisServiceWithMalformedWsdlUri() throws Exception { SynapseConfiguration synCfg = new SynapseConfiguration(); AxisConfiguration axisCfg = new AxisConfiguration(); ProxyService proxyService = new ProxyService("testBuildAxisServiceWithInvalidWsdlUriProxy"); //note incorrect protocol, 'files' URI wsdlUri = new URI("files:/home/sasikala/Documents/ei/git/wso2-synapse/modules/core/target/test-classes" + "/org/apache/synapse/core/axis2/SimpleStockService.wsdl"); proxyService.setWsdlURI(wsdlUri); try { proxyService.buildAxisService(synCfg, axisCfg); Assert.fail("Axis service should not be built with malformed publish wsdl URI: " + wsdlUri.toString()); } catch (SynapseException e) { Assert.assertEquals("Unexpected exception thrown: " + e, "Malformed URI for wsdl", e.getMessage()); } }
/** * Test serializeConfigurationMethod with proxyServices added for SynapseConfiguration and assert OMElement returned */ @Test public void testSerializeConfiguration4() { SynapseXMLConfigurationSerializer serializer = new SynapseXMLConfigurationSerializer(); SynapseConfiguration synapseConfiguration = new SynapseConfiguration(); ProxyService proxyService = new ProxyService("testProxyService"); synapseConfiguration.addProxyService(proxyService.getName(), proxyService); OMElement element = serializer.serializeConfiguration(synapseConfiguration); Assert.assertNotNull("OMElement is not returned", element); Assert.assertEquals("definitions", element.getLocalName()); Assert.assertTrue("ProxyService added is not serialized.", element.getChildren().next(). toString().contains("name=\"testProxyService\"")); }
/** * Tests starting a proxy service without proving an axis configuration. The proxy service should not start by this. */ public void testStartWithoutAxisConfiguration() { SynapseConfiguration synCfg = new SynapseConfiguration(); synCfg.setAxisConfiguration(null); ProxyService proxyService = new ProxyService("TestStartWithoutAxisConfigurationProxy"); proxyService.start(synCfg); Assert.assertFalse("Proxy service is running without axis configuration", proxyService.isRunning()); proxyService.stop(synCfg); }
/** * Test serializeSynapseXML method with proxyServices added for SynapseConfiguration and * assert synapse.xml is created. */ @Test public void testSerializeSynapseXML3() throws Exception { MultiXMLConfigurationSerializer serializer = new MultiXMLConfigurationSerializer(TEST_DIRECTORY_NAME); SynapseConfiguration configuration = new SynapseConfiguration(); configuration.setTaskManager(new QuartzTaskManager()); ProxyService proxyService = new ProxyService("testProxyService"); configuration.addProxyService(proxyService.getName(), proxyService); serializer.serializeSynapseXML(configuration); Assert.assertTrue("Error in serializing Synapse configuration.", new File(TEST_DIRECTORY_NAME + File.separator + SYNAPSE_XML).exists()); removeTestFolder(TEST_DIRECTORY_NAME); }
/** * Tests building a proxy service with an unreachable URI specified as the published wsdl url with the * 'enablePublishWSDLSafeMode' set to false. * * @throws Exception if an error occurs when converting the URI string to a URI */ public void testBuildAxisServiceWithUnreachableWsdlUriWithPublishWSDLSafeModeDisabled() throws Exception { SynapseConfiguration synCfg = new SynapseConfiguration(); AxisConfiguration axisCfg = new AxisConfiguration(); ProxyService proxyService = new ProxyService("unreachableWsdlUriWithPublishWSDLSafeModeDisabledProxy"); proxyService.addParameter("enablePublishWSDLSafeMode", false); URI wsdlUri = new URI("http://invalid-host/SimpleStockService.wsdl"); proxyService.setWsdlURI(wsdlUri); try { proxyService.buildAxisService(synCfg, axisCfg); Assert.fail("Axis service should not be built with malformed publish wsdl URI: " + wsdlUri); } catch (SynapseException e) { Assert.assertEquals("Unexpected exception thrown: " + e, "Error reading from wsdl URI", e.getMessage()); } }
/** * Tests building a proxy service with an unreachable endpoint specified as the published wsdl url with the * 'enablePublishWSDLSafeMode' set to true. * * @throws Exception if an error occurs when converting the URI string to a URI */ public void testBuildAxisServiceWithUnreachableWsdlEndpointWithPublishWSDLSafeModeDisabled() throws Exception { SynapseConfiguration synCfg = new SynapseConfiguration(); AxisConfiguration axisCfg = new AxisConfiguration(); ProxyService proxyService = new ProxyService("faultyPublishWsdlEndpointProxyWithPublishWSDLSafeModeDisabled"); proxyService.setPublishWSDLEndpoint("wsdlEndPoint"); AddressEndpoint wsdlEndpoint = new AddressEndpoint(); EndpointDefinition endpointDefinition = new EndpointDefinition(); endpointDefinition.setAddress((new URI("http://invalid-host/SimpleStockService.wsdl")).toString()); wsdlEndpoint.setDefinition(endpointDefinition); proxyService.addParameter("enablePublishWSDLSafeMode", false); synCfg.addEndpoint("wsdlEndPoint", wsdlEndpoint); try { proxyService.buildAxisService(synCfg, axisCfg); Assert.fail("Axis service built with an unreachable wsdl endpoint should throw fault"); } catch (SynapseException e) { Assert.assertTrue("Unexpected exception thrown: " + e, e.getMessage().contains("Error reading from wsdl URI")); } }
/** * Tests building a proxy service with an unreachable endpoint specified as the published wsdl url with the * 'enablePublishWSDLSafeMode' set to false. * * @throws Exception if an error occurs when converting the URI string to a URI */ public void testBuildAxisServiceWithUnreachableWsdlEndpointWithPublishWSDLSafeModeEnabled() throws Exception { MessageContext synCtx = new TestMessageContext(); SynapseConfiguration synCfg = new SynapseConfiguration(); synCtx.setConfiguration(synCfg); AxisConfiguration axisCfg = new AxisConfiguration(); ProxyService proxyService = new ProxyService("faultyPublishWsdlEndpointProxyWithPublishWSDLSafeModeEnabled"); proxyService.setPublishWSDLEndpoint("wsdlEndPoint"); AddressEndpoint wsdlEndpoint = new AddressEndpoint(); EndpointDefinition endpointDefinition = new EndpointDefinition(); endpointDefinition.setAddress((new URI("http://invalid-host/SimpleStockService.wsdl")).toString()); wsdlEndpoint.setDefinition(endpointDefinition); proxyService.addParameter("enablePublishWSDLSafeMode", true); synCfg.addEndpoint("wsdlEndPoint", wsdlEndpoint); Assert.assertNull("Axis service built with an unreachable wsdl endpoint be null", proxyService.buildAxisService(synCfg, axisCfg)); }
/** * Test message receipt by ProxyServiceMessageReceiver. * * @throws Exception on a message receipt issue */ @Test public void testReceive() throws Exception { //create ProxyServiceMessageReceiver instance ProxyServiceMessageReceiver proxyServiceMessageReceiver = new ProxyServiceMessageReceiver(); ProxyService proxyService = new ProxyService("TestProxy"); //create an inSequence and set OMElement sequenceAsOM = AXIOMUtil.stringToOM("<inSequence xmlns=\"http://ws.apache.org/ns/synapse\">\n" + " <property name=\"TEST\" scope=\"axis2\" type=\"STRING\" value=\"WSO2\"/>\n" + " </inSequence>"); proxyService.setTargetInLineInSequence(new SequenceMediatorFactory(). createAnonymousSequence(sequenceAsOM, null)); proxyServiceMessageReceiver.setProxy(proxyService); MessageContext messageContext = createMessageContext(); Axis2SynapseEnvironment synapseEnvironment = getMockedSynapseEnvironment(); //set required values MessageContextCreatorForAxis2.setSynConfig(new SynapseConfiguration()); MessageContextCreatorForAxis2.setSynEnv(synapseEnvironment); messageContext.setEnvironment(synapseEnvironment); //invoke proxyServiceMessageReceiver.receive(((Axis2MessageContext) messageContext).getAxis2MessageContext()); String propertySet = (String) ((Axis2MessageContext) messageContext).getAxis2MessageContext().getProperty("TEST"); Assert.assertEquals("property is not set after delegating to proxy", "WSO2", propertySet); }
/** * Tests starting a proxy service with correct axis configuration provided. * * @throws Exception if an exception occurs while configuring the axis configuration */ public void testStart() throws Exception { String proxyServiceName = "TestStartProxy"; SynapseConfiguration synCfg = new SynapseConfiguration(); AxisConfiguration axisCfg = new AxisConfiguration(); SynapseEnvironment synEnv = new Axis2SynapseEnvironment(new ConfigurationContext(axisCfg), synCfg); axisCfg.addParameter(SynapseConstants.SYNAPSE_ENV, synEnv); synCfg.setAxisConfiguration(axisCfg); ProxyService proxyService = new ProxyService(proxyServiceName); AxisService axisServiceForActivation = new AxisService(); axisServiceForActivation.setName(proxyServiceName); axisCfg.addToAllServicesMap(axisServiceForActivation); proxyService.setTargetInLineInSequence(new SequenceMediator()); proxyService.setTargetInLineOutSequence(new SequenceMediator()); proxyService.setTargetInLineFaultSequence(new SequenceMediator()); proxyService.start(synCfg); Assert.assertTrue("Underlying Axis service is not activated", axisServiceForActivation.isActive()); Assert.assertTrue("Proxy service is not running", proxyService.isRunning()); proxyService.stop(synCfg); }
public void testDebugManagerProcessCommandSetBreakPointProxyInSequence() throws Exception { ProxyService ps = new ProxyService("test_proxy_1"); TestMediator in1 = new TestMediator(); TestMediator in2 = new TestMediator(); TestMediator in3 = new TestMediator(); SequenceMediator inSeq = new SequenceMediator(); inSeq.addChild(in1); inSeq.addChild(in2); inSeq.addChild(in3); TestMediator out1 = new TestMediator(); TestMediator out2 = new TestMediator(); TestMediator out3 = new TestMediator(); SequenceMediator outSeq = new SequenceMediator(); outSeq.addChild(out1); outSeq.addChild(out2); outSeq.addChild(out3); ps.setTargetInLineInSequence(inSeq); ps.setTargetInLineOutSequence(inSeq); synConfig.addProxyService(ps.getName(), ps); String debug_command = "{\"command\":\"set\",\"command-argument\":\"breakpoint\",\"mediation-component\":\"sequence\"," + "\"sequence\":{\"proxy\":{\"proxy-key\":\"test_proxy_1\",\"sequence-type\":\"proxy_inseq\",\"mediator-position\":\"0\"}}}"; dm.processDebugCommand(debug_command); assertTrue(((AbstractMediator) ps.getTargetInLineInSequence().getChild(0)).isBreakPoint()); }
public void testDebugManagerProcessCommandSetSkipProxyInSequence() throws Exception { ProxyService ps = new ProxyService("test_proxy_5"); TestMediator in1 = new TestMediator(); TestMediator in2 = new TestMediator(); TestMediator in3 = new TestMediator(); SequenceMediator inSeq = new SequenceMediator(); inSeq.addChild(in1); inSeq.addChild(in2); inSeq.addChild(in3); TestMediator out1 = new TestMediator(); TestMediator out2 = new TestMediator(); TestMediator out3 = new TestMediator(); SequenceMediator outSeq = new SequenceMediator(); outSeq.addChild(out1); outSeq.addChild(out2); outSeq.addChild(out3); ps.setTargetInLineInSequence(inSeq); ps.setTargetInLineOutSequence(inSeq); synConfig.addProxyService(ps.getName(), ps); String debug_command = "{\"command\":\"set\",\"command-argument\":\"skip\",\"mediation-component\":\"sequence\"," + "\"sequence\":{\"proxy\":{\"proxy-key\":\"test_proxy_5\",\"sequence-type\":\"proxy_inseq\"," + "\"mediator-position\":\"0\"}}}"; dm.processDebugCommand(debug_command); assertTrue(((AbstractMediator) ps.getTargetInLineInSequence().getChild(0)).isSkipEnabled()); }
public void testDebugManagerProcessCommandSetSkipProxyOutSequence() throws Exception { ProxyService ps = new ProxyService("test_proxy_6"); TestMediator in1 = new TestMediator(); TestMediator in2 = new TestMediator(); TestMediator in3 = new TestMediator(); SequenceMediator inSeq = new SequenceMediator(); inSeq.addChild(in1); inSeq.addChild(in2); inSeq.addChild(in3); TestMediator out1 = new TestMediator(); TestMediator out2 = new TestMediator(); TestMediator out3 = new TestMediator(); SequenceMediator outSeq = new SequenceMediator(); outSeq.addChild(out1); outSeq.addChild(out2); outSeq.addChild(out3); ps.setTargetInLineInSequence(inSeq); ps.setTargetInLineOutSequence(inSeq); synConfig.addProxyService(ps.getName(), ps); String debug_command = "{\"command\":\"set\",\"command-argument\":\"skip\",\"mediation-component\":\"sequence\"," + "\"sequence\":{\"proxy\":{\"proxy-key\":\"test_proxy_6\",\"sequence-type\":\"proxy_outseq\"," + "\"mediator-position\":\"0\"}}}"; dm.processDebugCommand(debug_command); assertTrue(((AbstractMediator) ps.getTargetInLineOutSequence().getChild(0)).isSkipEnabled()); }
public void testDebugManagerProcessCommandClearBreakPointProxyInSequence() throws Exception { ProxyService ps = new ProxyService("test_proxy_3"); TestMediator in1 = new TestMediator(); TestMediator in2 = new TestMediator(); TestMediator in3 = new TestMediator(); SequenceMediator inSeq = new SequenceMediator(); inSeq.addChild(in1); inSeq.addChild(in2); inSeq.addChild(in3); TestMediator out1 = new TestMediator(); TestMediator out2 = new TestMediator(); TestMediator out3 = new TestMediator(); SequenceMediator outSeq = new SequenceMediator(); outSeq.addChild(out1); outSeq.addChild(out2); outSeq.addChild(out3); ps.setTargetInLineInSequence(inSeq); ps.setTargetInLineOutSequence(inSeq); synConfig.addProxyService(ps.getName(), ps); String debug_command = "{\"command\":\"set\",\"command-argument\":\"breakpoint\"," + "\"mediation-component\":\"sequence\",\"sequence\":{\"proxy\":{\"proxy-key\":\"test_proxy_3\"," + "\"sequence-type\":\"proxy_inseq\",\"mediator-position\":\"0\"}}}"; dm.processDebugCommand(debug_command); debug_command = "{\"command\":\"clear\",\"command-argument\":\"breakpoint\",\"mediation-component\":\"sequence\"," + "\"sequence\":{\"proxy\":{\"proxy-key\":\"test_proxy_3\"," + "\"sequence-type\":\"proxy_inseq\",\"mediator-position\":\"0\"}}}"; dm.processDebugCommand(debug_command); assertTrue(!((AbstractMediator) ps.getTargetInLineInSequence().getChild(0)).isBreakPoint()); }
public void testDebugManagerProcessCommandClearBreakPointProxyOutSequence() throws Exception { ProxyService ps = new ProxyService("test_proxy_4"); TestMediator in1 = new TestMediator(); TestMediator in2 = new TestMediator(); TestMediator in3 = new TestMediator(); SequenceMediator inSeq = new SequenceMediator(); inSeq.addChild(in1); inSeq.addChild(in2); inSeq.addChild(in3); TestMediator out1 = new TestMediator(); TestMediator out2 = new TestMediator(); TestMediator out3 = new TestMediator(); SequenceMediator outSeq = new SequenceMediator(); outSeq.addChild(out1); outSeq.addChild(out2); outSeq.addChild(out3); ps.setTargetInLineInSequence(inSeq); ps.setTargetInLineOutSequence(inSeq); synConfig.addProxyService(ps.getName(), ps); String debug_command = "{\"command\":\"set\",\"command-argument\":\"breakpoint\",\"mediation-component\":\"sequence\"," + "\"sequence\":{\"proxy\":{\"proxy-key\":\"test_proxy_4\",\"sequence-type\":\"proxy_outseq\"," + "\"mediator-position\":\"0\"}}}"; dm.processDebugCommand(debug_command); debug_command = "{\"command\":\"clear\",\"command-argument\":\"breakpoint\",\"mediation-component\":\"sequence\"," + "\"sequence\":{\"proxy\":{\"proxy-key\":\"test_proxy_4\",\"sequence-type\":\"proxy_outseq\"," + "\"mediator-position\":\"0\"}}}"; dm.processDebugCommand(debug_command); assertTrue(!((AbstractMediator) ps.getTargetInLineOutSequence().getChild(0)).isBreakPoint()); }
public void testDebugManagerProcessCommandSetBreakPointProxyOutSequence() throws Exception { ProxyService ps = new ProxyService("test_proxy_2"); TestMediator in1 = new TestMediator(); TestMediator in2 = new TestMediator(); TestMediator in3 = new TestMediator(); SequenceMediator inSeq = new SequenceMediator(); inSeq.addChild(in1); inSeq.addChild(in2); inSeq.addChild(in3); TestMediator out1 = new TestMediator(); TestMediator out2 = new TestMediator(); TestMediator out3 = new TestMediator(); SequenceMediator outSeq = new SequenceMediator(); outSeq.addChild(out1); outSeq.addChild(out2); outSeq.addChild(out3); ps.setTargetInLineInSequence(inSeq); ps.setTargetInLineOutSequence(inSeq); synConfig.addProxyService(ps.getName(), ps); String debug_command = "{\"command\":\"set\",\"command-argument\":\"breakpoint\",\"mediation-component\":\"sequence\"," + "\"sequence\":{\"proxy\":{\"proxy-key\":\"test_proxy_2\",\"sequence-type\":\"proxy_outseq\"," + "\"mediator-position\":\"0\"}}}"; dm.processDebugCommand(debug_command); assertTrue(((AbstractMediator) ps.getTargetInLineOutSequence().getChild(0)).isBreakPoint()); }
public void testDebugManagerProcessCommandClearSkipProxyOutSequence() throws Exception { ProxyService ps = new ProxyService("test_proxy_8"); TestMediator in1 = new TestMediator(); TestMediator in2 = new TestMediator(); TestMediator in3 = new TestMediator(); SequenceMediator inSeq = new SequenceMediator(); inSeq.addChild(in1); inSeq.addChild(in2); inSeq.addChild(in3); TestMediator out1 = new TestMediator(); TestMediator out2 = new TestMediator(); TestMediator out3 = new TestMediator(); SequenceMediator outSeq = new SequenceMediator(); outSeq.addChild(out1); outSeq.addChild(out2); outSeq.addChild(out3); ps.setTargetInLineInSequence(inSeq); ps.setTargetInLineOutSequence(inSeq); synConfig.addProxyService(ps.getName(), ps); String debug_command = "{\"command\":\"set\",\"command-argument\":\"skip\",\"mediation-component\":\"sequence\"," + "\"sequence\":{\"proxy\":{\"proxy-key\":\"test_proxy_8\",\"sequence-type\":\"proxy_outseq\"," + "\"mediator-position\":\"0\"}}}"; dm.processDebugCommand(debug_command); debug_command = "{\"command\":\"clear\",\"command-argument\":\"skip\",\"mediation-component\":\"sequence\"," + "\"sequence\":{\"proxy\":{\"proxy-key\":\"test_proxy_8\",\"sequence-type\":\"proxy_outseq\"," + "\"mediator-position\":\"0\"}}}"; dm.processDebugCommand(debug_command); assertTrue(!((AbstractMediator) ps.getTargetInLineOutSequence().getChild(0)).isSkipEnabled()); }