Java Code Examples for org.wso2.carbon.apimgt.api.model.API#setFaultSequence()

The following examples show how to use org.wso2.carbon.apimgt.api.model.API#setFaultSequence() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: APIGatewayManagerTest.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Test public void testRemovingRESTAPIWithFaultSequenceFromGateway() throws AxisFault {
    API api = new API(apiIdentifier);
    api.setType("HTTP");
    api.setFaultSequence(faultSequenceName);
    api.setInSequence(inSequenceName);
    api.setAsPublishedDefaultVersion(true);
    api.setSwaggerDefinition(swaggerDefinition);
    api.setUUID(apiUUId);
    Set<String> environments = new HashSet<String>();
    environments.add(prodEnvironmentName);
    environments.add(null);
    api.setEnvironments(environments);
    Mockito.when(apiGatewayAdminClient.getApi(null, apiIdentifier)).thenReturn(apiData);
    Mockito.when(apiGatewayAdminClient.getDefaultApi(tenantDomain, apiIdentifier)).thenReturn(defaultAPIdata);

    //Set tenant domain = null, so that 'carbon.super' tenant will be loaded
    Map<String, String> failedEnvironmentsMap = gatewayManager.removeFromGateway(api, null);
    Assert.assertEquals(failedEnvironmentsMap.size(), 0);
}
 
Example 2
Source File: APIGatewayManagerTest.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Test public void testRemovingWebSocketAPIFromGateway() throws AxisFault {
    API api = new API(apiIdentifier);
    api.setType("WS");
    api.setContext(apiContext);
    api.setInSequence(inSequenceName);
    api.setOutSequence(outSequenceName);
    api.setFaultSequence(faultSequenceName);
    api.setSwaggerDefinition(swaggerDefinition);
    api.setUUID(apiUUId);
    Set<String> environments = new HashSet<String>();
    environments.add(prodEnvironmentName);
    environments.add(null);
    api.setEnvironments(environments);
    Mockito.when(apiGatewayAdminClient.getApi(tenantDomain, apiIdentifier)).thenReturn(apiData);
    Map<String, String> failedEnvironmentsMap = gatewayManager.removeFromGateway(api, tenantDomain);
    Assert.assertEquals(failedEnvironmentsMap.size(), 0);
}
 
Example 3
Source File: APIGatewayManagerTest.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Test public void testPublishingNewRESTAPIWithAPIFaultSequence()
        throws AxisFault, APIManagementException, XMLStreamException, RegistryException {
    API api = new API(apiIdentifier);
    api.setType("HTTP");
    api.setAsPublishedDefaultVersion(true);
    api.setImplementation("ENDPOINT");
    api.setEndpointConfig(prodEndpointConfig);
    api.setFaultSequence(faultSequenceName);
    api.setAsDefaultVersion(true);
    api.setSwaggerDefinition(swaggerDefinition);
    api.setUUID(apiUUId);
    APITemplateBuilder apiTemplateBuilder = new APITemplateBuilderImpl(api);
    Set<String> environments = new HashSet<String>();
    environments.add(prodEnvironmentName);
    environments.add(null);
    api.setEnvironments(environments);
    Mockito.when(apiGatewayAdminClient.getApi(tenantDomain, apiIdentifier)).thenReturn(null);
    PowerMockito.when(APIUtil.getCustomSequence(faultSequenceName, tenantID, "fault", api.getId()))
            .thenReturn(AXIOMUtil.stringToOM(testSequenceDefinition));

    //Test deploying per API defined fault sequence with API
    PowerMockito.when(APIUtil.isPerAPISequence(faultSequenceName, tenantID, apiIdentifier, "fault"))
            .thenReturn(true);
    Assert.assertEquals(gatewayManager.publishToGateway(api, apiTemplateBuilder, tenantDomain).size(), 0);

    //Test deploying newly defined global sequence with API
    PowerMockito.when(APIUtil.isPerAPISequence(faultSequenceName, tenantID, apiIdentifier, "fault"))
            .thenReturn(false);
    Assert.assertEquals(gatewayManager.publishToGateway(api, apiTemplateBuilder, tenantDomain).size(), 0);

    //If fault sequence has not been defined for the API, omit deploying/updating and remove if already exists
    api.setFaultSequence(null);
    Assert.assertEquals(gatewayManager.publishToGateway(api, apiTemplateBuilder, tenantDomain).size(), 0);
}
 
Example 4
Source File: APIGatewayManagerTest.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
@Test public void testFailureWhilePublishingNewAPIToGateway() throws Exception {
    API api = new API(apiIdentifier);
    api.setType("HTTP");
    api.setAsPublishedDefaultVersion(true);
    api.setImplementation("ENDPOINT");
    api.setEndpointConfig(prodEndpointConfig);
    api.setInSequence(inSequenceName);
    api.setAsDefaultVersion(true);
    api.setSwaggerDefinition(swaggerDefinition);
    api.setUUID(apiUUId);
    APITemplateBuilder apiTemplateBuilder = new APITemplateBuilderImpl(api);
    Set<String> environments = new HashSet<String>();
    environments.add(prodEnvironmentName);
    environments.add(null);
    OMElement inSequence = AXIOMUtil.stringToOM(testSequenceDefinition);
    OMElement faultSequence = AXIOMUtil.stringToOM(testSequenceDefinition);
    api.setEnvironments(environments);
    Mockito.when(apiGatewayAdminClient.getApi(tenantDomain, apiIdentifier)).thenReturn(null);
    PowerMockito.when(APIUtil.getCustomSequence(inSequenceName, tenantID, "in", api.getId()))
            .thenReturn(inSequence);
    PowerMockito.when(APIUtil.isProductionEndpointsExists(Mockito.anyString())).thenReturn(true);
    PowerMockito.when(APIUtil.isSequenceDefined(Mockito.anyString())).thenReturn(true);

    Map<String, String> failedEnvironmentsMap = gatewayManager
            .publishToGateway(api, apiTemplateBuilder, tenantDomain);
    Assert.assertEquals(failedEnvironmentsMap.size(), 1);
    Assert.assertTrue(failedEnvironmentsMap.keySet().contains(prodEnvironmentName));

    //Test failure to deploy API when setting secure vault property failed
    Mockito.doThrow(new APIManagementException("Failed to set secure vault property for the tenant"))
            .when(apiGatewayAdminClient).setSecureVaultProperty(api, tenantDomain);
    api.setEndpointSecured(true);
    Mockito.when(config.getFirstProperty(APIConstants.API_SECUREVAULT_ENABLE)).thenReturn("true");
    Mockito.when(config.getFirstProperty(APIConstants.ENABLE_MTLS_FOR_APIS)).thenReturn("true");
    Map<String, String> failedEnvironmentsMap2 = gatewayManager
            .publishToGateway(api, apiTemplateBuilder, tenantDomain);
    Assert.assertEquals(failedEnvironmentsMap2.size(), 1);
    Assert.assertTrue(failedEnvironmentsMap2.keySet().contains(prodEnvironmentName ));

    //Test failure to deploy API when fault sequence deployment failed
    api.setFaultSequence(faultSequenceName);
    PowerMockito.when(APIUtil.getCustomSequence(faultSequenceName, tenantID, "fault", api.getId()))
            .thenReturn(faultSequence);
    Map<String, String> failedEnvironmentsMap3 = gatewayManager
            .publishToGateway(api, apiTemplateBuilder, tenantDomain);
    Assert.assertEquals(failedEnvironmentsMap3.size(), 1);
    Assert.assertTrue(failedEnvironmentsMap3.keySet().contains(prodEnvironmentName));

    //Test throwing AxisFault when Gateway client initialisation failed
    Mockito.doThrow(new AxisFault("Error occurred while deploying sequence")).when(apiGatewayAdminClient)
            .getApi(tenantDomain, apiIdentifier);
    Map<String, String> failedEnvironmentsMap4 = gatewayManager
            .publishToGateway(api, apiTemplateBuilder, tenantDomain);
    Assert.assertEquals(failedEnvironmentsMap4.size(), 1);
    Assert.assertTrue(failedEnvironmentsMap4.keySet().contains(prodEnvironmentName));
}