Search in sources :

Example 6 with APIMWSDLReader

use of org.wso2.carbon.apimgt.impl.utils.APIMWSDLReader in project carbon-apimgt by wso2.

the class WSDLSOAPOperationExtractorImplTestCase method testGetWsdlDefinition.

@Test
public void testGetWsdlDefinition() throws Exception {
    APIMWSDLReader wsdlReader = new APIMWSDLReader(Thread.currentThread().getContextClassLoader().getResource("wsdls/phoneverify.wsdl").toExternalForm());
    byte[] wsdlContent = wsdlReader.getWSDL();
    WSDL11SOAPOperationExtractor processor = new WSDL11SOAPOperationExtractor(wsdlReader);
    Assert.assertTrue("WSDL definition parsing failed", processor.init(wsdlContent));
}
Also used : APIMWSDLReader(org.wso2.carbon.apimgt.impl.utils.APIMWSDLReader) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 7 with APIMWSDLReader

use of org.wso2.carbon.apimgt.impl.utils.APIMWSDLReader in project carbon-apimgt by wso2.

the class WSDLSOAPOperationExtractorImplTestCase method testGetSwaggerModelForSimpleType.

@Test
public void testGetSwaggerModelForSimpleType() throws Exception {
    APIMWSDLReader wsdlReader = new APIMWSDLReader(Thread.currentThread().getContextClassLoader().getResource("wsdls/sample-service.wsdl").toExternalForm());
    byte[] wsdlContent = wsdlReader.getWSDL();
    WSDL11SOAPOperationExtractor processor = SOAPOperationBindingUtils.getWSDL11SOAPOperationExtractor(wsdlContent, wsdlReader);
    Map<String, ModelImpl> parameterModelMap = processor.getWsdlInfo().getParameterModelMap();
    Assert.assertNotNull(parameterModelMap);
    // get simple type
    Assert.assertNotNull(parameterModelMap.get("Condition"));
    Assert.assertEquals("string", parameterModelMap.get("Condition").getType());
    // get simple type inside complex type
    Assert.assertNotNull(parameterModelMap.get("ItemSearchRequest").getProperties().get("Availability"));
    Assert.assertEquals("string", parameterModelMap.get("ItemSearchRequest").getProperties().get("Availability").getType());
}
Also used : APIMWSDLReader(org.wso2.carbon.apimgt.impl.utils.APIMWSDLReader) ModelImpl(io.swagger.models.ModelImpl) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 8 with APIMWSDLReader

use of org.wso2.carbon.apimgt.impl.utils.APIMWSDLReader in project carbon-apimgt by wso2.

the class APIMWSDLReaderTest method testSetServiceDefinitionWithInvalidAPIGatewayEndpoints.

@Test
public void testSetServiceDefinitionWithInvalidAPIGatewayEndpoints() throws Exception {
    PowerMockito.mockStatic(APIUtil.class);
    API api = getAPIForTesting();
    String environmentName = "Default";
    String environmentType = "hybrid";
    APIMWSDLReader wsdlReader = new APIMWSDLReader("");
    byte[] content = IOUtils.toByteArray(Thread.currentThread().getContextClassLoader().getResourceAsStream("wsdls/invalidEndpointURL.wsdl"));
    Definition definition = wsdlReader.getWSDLDefinitionFromByteContent(content, false);
    try {
        wsdlReader.setServiceDefinition(definition, api, environmentName, environmentType);
        wsdlReader.getWSDL(definition);
        Assert.assertNotNull(definition.getServices());
    } catch (APIManagementException e) {
        Assert.fail("Unexpected exception occurred while updating service endpoint address");
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) Definition(javax.wsdl.Definition) API(org.wso2.carbon.apimgt.api.model.API) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 9 with APIMWSDLReader

use of org.wso2.carbon.apimgt.impl.utils.APIMWSDLReader in project carbon-apimgt by wso2.

the class SOAPOperationBindingUtils method getSoapOperationMapping.

/**
 * Gets soap operations to rest resources mapping for a wsdl archive path
 *
 * @param path Path of the extracted WSDL archive
 * @return swagger json string with the soap operation mapping
 * @throws APIManagementException if an error occurs when generating swagger
 */
public static String getSoapOperationMapping(String path) throws APIManagementException {
    APIMWSDLReader wsdlReader = new APIMWSDLReader(path);
    WSDL11SOAPOperationExtractor processor = APIMWSDLReader.getWSDLSOAPOperationExtractor(path, wsdlReader);
    WSDLInfo wsdlInfo = processor.getWsdlInfo();
    return getGeneratedSwaggerFromWSDL(wsdlInfo);
}
Also used : WSDLInfo(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLInfo) APIMWSDLReader(org.wso2.carbon.apimgt.impl.utils.APIMWSDLReader) WSDL11SOAPOperationExtractor(org.wso2.carbon.apimgt.impl.wsdl.WSDL11SOAPOperationExtractor)

Example 10 with APIMWSDLReader

use of org.wso2.carbon.apimgt.impl.utils.APIMWSDLReader in project carbon-apimgt by wso2.

the class WSDLSOAPOperationExtractorImplTestCase method testGetSwaggerModelForCompositeComplexType.

@Test
public void testGetSwaggerModelForCompositeComplexType() throws Exception {
    APIMWSDLReader wsdlReader = new APIMWSDLReader(Thread.currentThread().getContextClassLoader().getResource("wsdls/sample-service.wsdl").toExternalForm());
    byte[] wsdlContent = wsdlReader.getWSDL();
    WSDL11SOAPOperationExtractor processor = SOAPOperationBindingUtils.getWSDL11SOAPOperationExtractor(wsdlContent, wsdlReader);
    Map<String, ModelImpl> parameterModelMap = processor.getWsdlInfo().getParameterModelMap();
    Assert.assertNotNull(parameterModelMap);
    Assert.assertTrue("wsdl complex types has not been properly parsed", parameterModelMap.size() == 12);
    // composite complex type
    Assert.assertNotNull(parameterModelMap.get("ItemSearchRequest"));
    Assert.assertEquals(7, parameterModelMap.get("ItemSearchRequest").getProperties().size());
    Assert.assertNotNull(parameterModelMap.get("ItemSearchRequest").getProperties().get("Tracks"));
    Assert.assertNotNull(parameterModelMap.get("ItemSearchRequest").getProperties().get("Tracks"));
    Assert.assertEquals(ArrayProperty.TYPE, parameterModelMap.get("ItemSearchRequest").getProperties().get("Tracks").getType());
    Assert.assertNotNull(((ArrayProperty) parameterModelMap.get("ItemSearchRequest").getProperties().get("Tracks")).getItems());
}
Also used : APIMWSDLReader(org.wso2.carbon.apimgt.impl.utils.APIMWSDLReader) ModelImpl(io.swagger.models.ModelImpl) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

APIMWSDLReader (org.wso2.carbon.apimgt.impl.utils.APIMWSDLReader)11 Test (org.junit.Test)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)6 ModelImpl (io.swagger.models.ModelImpl)4 Definition (javax.wsdl.Definition)3 API (org.wso2.carbon.apimgt.api.model.API)3 WSDL11SOAPOperationExtractor (org.wso2.carbon.apimgt.impl.wsdl.WSDL11SOAPOperationExtractor)3 Document (org.w3c.dom.Document)2 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)2 WSDLProcessor (org.wso2.carbon.apimgt.impl.wsdl.WSDLProcessor)2 WSDLSOAPOperation (org.wso2.carbon.apimgt.impl.wsdl.model.WSDLSOAPOperation)2 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 OMElement (org.apache.axiom.om.OMElement)1