Search in sources :

Example 1 with EndpointAdminServiceProxy

use of org.wso2.carbon.apimgt.gateway.utils.EndpointAdminServiceProxy in project carbon-apimgt by wso2.

the class APIGatewayAdminTest method deleteSequenceForTenant.

@Test
public void deleteSequenceForTenant() throws Exception {
    RESTAPIAdminServiceProxy restapiAdminServiceProxy = Mockito.mock(RESTAPIAdminServiceProxy.class);
    EndpointAdminServiceProxy endpointAdminServiceProxy = Mockito.mock(EndpointAdminServiceProxy.class);
    SequenceAdminServiceProxy sequenceAdminServiceProxy = Mockito.mock(SequenceAdminServiceProxy.class);
    APIGatewayAdmin apiGatewayAdmin = new APIGatewayAdminWrapper(restapiAdminServiceProxy, endpointAdminServiceProxy, sequenceAdminServiceProxy);
    apiGatewayAdmin.deleteSequenceForTenant("name", tenantDomain);
}
Also used : RESTAPIAdminServiceProxy(org.wso2.carbon.apimgt.gateway.utils.RESTAPIAdminServiceProxy) EndpointAdminServiceProxy(org.wso2.carbon.apimgt.gateway.utils.EndpointAdminServiceProxy) SequenceAdminServiceProxy(org.wso2.carbon.apimgt.gateway.utils.SequenceAdminServiceProxy) Test(org.junit.Test)

Example 2 with EndpointAdminServiceProxy

use of org.wso2.carbon.apimgt.gateway.utils.EndpointAdminServiceProxy in project carbon-apimgt by wso2.

the class APIGatewayAdminTest method getSequence.

@Test
public void getSequence() throws Exception {
    RESTAPIAdminServiceProxy restapiAdminServiceProxy = Mockito.mock(RESTAPIAdminServiceProxy.class);
    EndpointAdminServiceProxy endpointAdminServiceProxy = Mockito.mock(EndpointAdminServiceProxy.class);
    SequenceAdminServiceProxy sequenceAdminServiceProxy = Mockito.mock(SequenceAdminServiceProxy.class);
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMElement test1 = fac.createOMElement("test1", "", "");
    Mockito.when(sequenceAdminServiceProxy.getSequence(name)).thenReturn(test1);
    APIGatewayAdmin apiGatewayAdmin = new APIGatewayAdminWrapper(restapiAdminServiceProxy, endpointAdminServiceProxy, sequenceAdminServiceProxy);
    Assert.assertEquals(apiGatewayAdmin.getSequence(name), test1);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) RESTAPIAdminServiceProxy(org.wso2.carbon.apimgt.gateway.utils.RESTAPIAdminServiceProxy) OMElement(org.apache.axiom.om.OMElement) EndpointAdminServiceProxy(org.wso2.carbon.apimgt.gateway.utils.EndpointAdminServiceProxy) SequenceAdminServiceProxy(org.wso2.carbon.apimgt.gateway.utils.SequenceAdminServiceProxy) Test(org.junit.Test)

Example 3 with EndpointAdminServiceProxy

use of org.wso2.carbon.apimgt.gateway.utils.EndpointAdminServiceProxy in project carbon-apimgt by wso2.

the class EndpointAdminServiceProxyTestCase method testRemoveEndpointsToUpdate.

@Test
public void testRemoveEndpointsToUpdate() throws Exception {
    EndpointAdminServiceProxy endpointAdminServiceProxy = null;
    APIIdentifier identifier = null;
    API api = null;
    try {
        endpointAdminServiceProxy = new EndpointAdminServiceProxy(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
        EndpointAdmin endpointAdmin = Mockito.mock(EndpointAdmin.class);
        String[] endpointNames = { "API1--v1.0.0_APIproductionEndpoint", "API1--v1.0.0_APIsandboxEndpoint" };
        identifier = new APIIdentifier("P1_API1_1.0.0");
        api = new API(identifier);
        Mockito.when(endpointAdmin.getEndPointsNames()).thenReturn(endpointNames);
        Mockito.when(endpointAdmin.getEndPointsNamesForTenant(Mockito.anyString())).thenReturn(endpointNames);
        Mockito.when(endpointAdmin.deleteEndpoint(Mockito.anyString())).thenReturn(true);
        Mockito.when(endpointAdmin.deleteEndpointForTenant(Mockito.anyString(), Mockito.anyString())).thenReturn(true);
        endpointAdminServiceProxy.setEndpointAdmin(endpointAdmin);
    } catch (Exception e) {
        Assert.fail("Exception while testing removeEndpointsToUpdate");
    }
    try {
        endpointAdminServiceProxy.removeEndpointsToUpdate(api.getId().getApiName(), api.getId().getVersion());
        endpointAdminServiceProxy.removeEndpointsToUpdate(api.getId().getApiName(), api.getId().getVersion());
        endpointAdminServiceProxy.removeEndpointsToUpdate(api.getId().getApiName(), api.getId().getVersion());
    } catch (AxisFault e) {
        Assert.fail("AxisFault while testing removeEndpointsToUpdate");
    }
    try {
        endpointAdminServiceProxy.removeEndpointsToUpdate(api.getId().getApiName(), api.getId().getVersion());
    } catch (AxisFault e) {
        Assert.fail("AxisFault while testing removeEndpointsToUpdate for tenant");
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) API(org.wso2.carbon.apimgt.api.model.API) EndpointAdmin(org.wso2.carbon.endpoint.service.EndpointAdmin) Test(org.junit.Test)

Example 4 with EndpointAdminServiceProxy

use of org.wso2.carbon.apimgt.gateway.utils.EndpointAdminServiceProxy in project carbon-apimgt by wso2.

the class EndpointAdminServiceProxyTestCase method testRemoveEndpointsToUpdateAxisFault.

@Test
public void testRemoveEndpointsToUpdateAxisFault() throws Exception {
    EndpointAdminServiceProxy endpointAdminServiceProxy = null;
    APIIdentifier identifier = null;
    API api = null;
    endpointAdminServiceProxy = new EndpointAdminServiceProxy(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
    identifier = new APIIdentifier("P1_API1_1.0.0");
    api = new API(identifier);
    try {
        endpointAdminServiceProxy.removeEndpointsToUpdate(api.getId().getApiName(), api.getId().getVersion());
    } catch (AxisFault e) {
    // test for AxisFault
    }
    try {
        endpointAdminServiceProxy.removeEndpointsToUpdate(api.getId().getApiName(), api.getId().getVersion());
    } catch (AxisFault e) {
    // test for AxisFault
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) API(org.wso2.carbon.apimgt.api.model.API) Test(org.junit.Test)

Example 5 with EndpointAdminServiceProxy

use of org.wso2.carbon.apimgt.gateway.utils.EndpointAdminServiceProxy in project carbon-apimgt by wso2.

the class APIGatewayAdmin method unDeployAPI.

private void unDeployAPI(CertificateManager certificateManager, SequenceAdminServiceProxy sequenceAdminServiceProxy, RESTAPIAdminServiceProxy restapiAdminServiceProxy, LocalEntryServiceProxy localEntryServiceProxy, EndpointAdminServiceProxy endpointAdminServiceProxy, GatewayAPIDTO gatewayAPIDTO, MediationSecurityAdminServiceProxy mediationSecurityAdminServiceProxy) throws AxisFault {
    if (log.isDebugEnabled()) {
        log.debug("Start to undeploy default api " + gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion());
    }
    // Delete Default API
    String qualifiedDefaultApiName = GatewayUtils.getQualifiedDefaultApiName(gatewayAPIDTO.getName());
    if (restapiAdminServiceProxy.getApi(qualifiedDefaultApiName) != null) {
        restapiAdminServiceProxy.deleteApi(qualifiedDefaultApiName);
    }
    if (log.isDebugEnabled()) {
        log.debug(gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion() + " Default API Definition " + "undeployed successfully");
        log.debug("Start to undeploy API Definition" + gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion());
    }
    // Delete API
    String qualifiedName = GatewayUtils.getQualifiedApiName(gatewayAPIDTO.getName(), gatewayAPIDTO.getVersion());
    if (restapiAdminServiceProxy.getApi(qualifiedName) != null) {
        restapiAdminServiceProxy.deleteApi(qualifiedName);
    }
    if (log.isDebugEnabled()) {
        log.debug(gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion() + " API Definition undeployed " + "successfully");
        log.debug("Start to undeploy custom sequences" + gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion());
    }
    // Remove Sequences to be remove.
    if (gatewayAPIDTO.getSequencesToBeRemove() != null) {
        for (String sequenceName : gatewayAPIDTO.getSequencesToBeRemove()) {
            if (sequenceAdminServiceProxy.isExistingSequence(sequenceName)) {
                sequenceAdminServiceProxy.deleteSequence(sequenceName);
            }
        }
    }
    if (log.isDebugEnabled()) {
        log.debug(gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion() + " custom sequences undeployed " + "successfully");
        log.debug("Start to undeploy endpoints" + gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion());
    }
    // Remove endpoints
    if (gatewayAPIDTO.getEndpointEntriesToBeRemove() != null) {
        for (String endpoint : gatewayAPIDTO.getEndpointEntriesToBeRemove()) {
            if (endpointAdminServiceProxy.isEndpointExist(endpoint)) {
                endpointAdminServiceProxy.deleteEndpoint(endpoint);
            }
        }
    }
    if (log.isDebugEnabled()) {
        log.debug(gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion() + " endpoints undeployed " + "successfully");
        log.debug("Start to undeploy client certificates" + gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion());
    }
    // Remove clientCertificates
    if (gatewayAPIDTO.getClientCertificatesToBeRemove() != null) {
        for (String alias : gatewayAPIDTO.getClientCertificatesToBeRemove()) {
            certificateManager.deleteClientCertificateFromGateway(alias);
        }
    }
    if (log.isDebugEnabled()) {
        log.debug(gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion() + " client certificates undeployed " + "successfully");
        log.debug("Start to undeploy local entries" + gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion());
    }
    // Remove Local Entries if Exist
    if (gatewayAPIDTO.getLocalEntriesToBeRemove() != null) {
        for (String localEntryKey : gatewayAPIDTO.getLocalEntriesToBeRemove()) {
            if (localEntryServiceProxy.isEntryExists(localEntryKey)) {
                localEntryServiceProxy.deleteEntry(localEntryKey);
            }
        }
    }
    if (log.isDebugEnabled()) {
        log.debug(gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion() + " Local entries undeployed " + "successfully");
        log.debug("Start to remove vault entries" + gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion());
    }
    if (gatewayAPIDTO.getCredentialsToBeRemove() != null) {
        for (String alias : gatewayAPIDTO.getCredentialsToBeRemove()) {
            try {
                if (mediationSecurityAdminServiceProxy.isAliasExist(alias)) {
                    GatewayUtils.deleteRegistryProperty(alias, APIConstants.API_SYSTEM_CONFIG_SECURE_VAULT_LOCATION, gatewayAPIDTO.getTenantDomain());
                }
            } catch (APIManagementException e) {
                String msg = "Error while checking existence of vault entry";
                log.error(msg, e);
                throw new AxisFault(msg, e);
            }
        }
    }
    if (log.isDebugEnabled()) {
        log.debug(gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion() + " Vault entries removed " + "successfully");
        log.debug(gatewayAPIDTO.getName() + ":" + gatewayAPIDTO.getVersion() + "undeployed successfully");
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException)

Aggregations

Test (org.junit.Test)17 EndpointAdminServiceProxy (org.wso2.carbon.apimgt.gateway.utils.EndpointAdminServiceProxy)14 RESTAPIAdminServiceProxy (org.wso2.carbon.apimgt.gateway.utils.RESTAPIAdminServiceProxy)10 SequenceAdminServiceProxy (org.wso2.carbon.apimgt.gateway.utils.SequenceAdminServiceProxy)10 AxisFault (org.apache.axis2.AxisFault)7 OMElement (org.apache.axiom.om.OMElement)4 EndpointAdmin (org.wso2.carbon.endpoint.service.EndpointAdmin)4 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)3 OMFactory (org.apache.axiom.om.OMFactory)2 API (org.wso2.carbon.apimgt.api.model.API)2 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)2 LocalEntryServiceProxy (org.wso2.carbon.apimgt.gateway.utils.LocalEntryServiceProxy)2 MediationSecurityAdminServiceProxy (org.wso2.carbon.apimgt.gateway.utils.MediationSecurityAdminServiceProxy)2 CertificateManager (org.wso2.carbon.apimgt.impl.certificatemgt.CertificateManager)2 ArrayList (java.util.ArrayList)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 CredentialDto (org.wso2.carbon.apimgt.api.gateway.CredentialDto)1 GatewayContentDTO (org.wso2.carbon.apimgt.api.gateway.GatewayContentDTO)1