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

The following examples show how to use org.wso2.carbon.apimgt.api.model.API#setAsPublishedDefaultVersion() . 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 testRemovingRESTAPIWithOutSequenceFromGateway() throws AxisFault {
    API api = new API(apiIdentifier);
    api.setType("HTTP");
    api.setOutSequence(outSequenceName);
    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(tenantDomain, apiIdentifier)).thenReturn(apiData);
    Mockito.when(apiGatewayAdminClient.getDefaultApi(tenantDomain, apiIdentifier)).thenReturn(defaultAPIdata);
    Map<String, String> failedEnvironmentsMap = gatewayManager.removeFromGateway(api, tenantDomain);
    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 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 3
Source File: APIGatewayManagerTest.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Test public void testPublishingNewRESTAPIWithCustomInSequenceToGateway()
        throws AxisFault, APIManagementException, XMLStreamException, RegistryException {
    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);
    api.setEnvironments(environments);
    Mockito.when(apiGatewayAdminClient.getApi(tenantDomain, apiIdentifier)).thenReturn(null);
    PowerMockito.when(APIUtil.getCustomSequence(inSequenceName, tenantID, "in", api.getId()))
            .thenReturn(AXIOMUtil.stringToOM(testSequenceDefinition));
    Assert.assertEquals(gatewayManager.publishToGateway(api, apiTemplateBuilder, tenantDomain).size(), 0);
}
 
Example 4
Source File: APIGatewayManagerTest.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Test public void testPublishingNewRESTAPIWithCustomOutSequenceToGateway()
        throws AxisFault, APIManagementException, XMLStreamException, RegistryException {
    API api = new API(apiIdentifier);
    api.setType("HTTP");
    api.setAsPublishedDefaultVersion(true);
    api.setImplementation("ENDPOINT");
    api.setEndpointConfig(prodEndpointConfig);
    api.setOutSequence(outSequenceName);
    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(outSequenceName, tenantID, "out", api.getId()))
            .thenReturn(AXIOMUtil.stringToOM(testSequenceDefinition));
    Assert.assertEquals(gatewayManager.publishToGateway(api, apiTemplateBuilder, tenantDomain).size(), 0);
}
 
Example 5
Source File: APIGatewayManagerTest.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Test public void testPublishingExistingRESTAPIWithCustomInSequenceToGateway()
        throws AxisFault, APIManagementException, XMLStreamException, RegistryException {
    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);
    api.setEnvironments(environments);
    Mockito.when(apiGatewayAdminClient.getApi(tenantDomain, apiIdentifier)).thenReturn(apiData);
    PowerMockito.when(APIUtil.getCustomSequence(inSequenceName, tenantID, "in", api.getId()))
            .thenReturn(AXIOMUtil.stringToOM(testSequenceDefinition));
    Assert.assertEquals(gatewayManager.publishToGateway(api, apiTemplateBuilder, tenantDomain).size(), 0);
}
 
Example 6
Source File: APIGatewayManagerTest.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Test public void testPublishingExistingRESTAPIWithCustomOutSequenceToGateway()
        throws AxisFault, APIManagementException, XMLStreamException, RegistryException {
    API api = new API(apiIdentifier);
    api.setType("HTTP");
    api.setAsPublishedDefaultVersion(true);
    api.setImplementation("ENDPOINT");
    api.setEndpointConfig(prodEndpointConfig);
    api.setOutSequence(outSequenceName);
    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(apiData);
    PowerMockito.when(APIUtil.getCustomSequence(outSequenceName, tenantID, "out", api.getId()))
            .thenReturn(AXIOMUtil.stringToOM(testSequenceDefinition));
    Assert.assertEquals(gatewayManager.publishToGateway(api, apiTemplateBuilder, tenantDomain).size(), 0);
}
 
Example 7
Source File: APIGatewayManagerTest.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Test public void testRemovingRESTAPIWithInSequenceFromGateway() throws AxisFault {
    API api = new API(apiIdentifier);
    api.setType("HTTP");
    api.setInSequence(inSequenceName);
    api.setAsPublishedDefaultVersion(true);
    Set<String> environments = new HashSet<String>();
    environments.add(prodEnvironmentName);
    environments.add(null);
    api.setEnvironments(environments);
    Mockito.when(apiGatewayAdminClient.getApi(tenantDomain, apiIdentifier)).thenReturn(apiData);
    Mockito.when(apiGatewayAdminClient.getDefaultApi(tenantDomain, apiIdentifier)).thenReturn(defaultAPIdata);
    Map<String, String> failedEnvironmentsMap = gatewayManager.removeFromGateway(api, tenantDomain);
    Assert.assertEquals(failedEnvironmentsMap.size(), 0);
}
 
Example 8
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 9
Source File: APIGatewayManagerTest.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Test public void testPublishingExistingRESTAPIToGateway()
        throws AxisFault, APIManagementException, XMLStreamException, RegistryException {

    API api = new API(apiIdentifier);
    api.setType("HTTP");
    api.setAsPublishedDefaultVersion(true);
    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(apiData);
    Mockito.when(apiGatewayAdminClient.getDefaultApi(tenantDomain, apiIdentifier)).thenReturn(defaultAPIdata);

    //Test deleting existing API from production environment, if matching producntion endpoint configuration is
    // not found in API's endpoint config
    api.setEndpointConfig(sandBoxEndpointConfig);
    Assert.assertEquals(gatewayManager.publishToGateway(api, apiTemplateBuilder, tenantDomain).size(), 0);

    //Test updating 'INLINE' type REST API to gateway
    api.setImplementation("INLINE");
    api.setEndpointConfig(prodEndpointConfig);
    Assert.assertEquals(gatewayManager.publishToGateway(api, apiTemplateBuilder, tenantDomain).size(), 0);

    //Test updating 'ENDPOINT' type REST API to gateway
    api.setImplementation("ENDPOINT");
    Assert.assertEquals(gatewayManager.publishToGateway(api, apiTemplateBuilder, tenantDomain).size(), 0);

    //Test updating default version of the API
    Mockito.when(apiGatewayAdminClient.getDefaultApi(tenantDomain, apiIdentifier)).thenReturn(defaultAPIdata);
    Assert.assertEquals(gatewayManager.publishToGateway(api, apiTemplateBuilder, tenantDomain).size(), 0);

    //Test deploying API, if secure vault is enabled
    api.setEndpointSecured(true);
    Mockito.when(config.getFirstProperty(APIConstants.API_SECUREVAULT_ENABLE)).thenReturn("true");
    Assert.assertEquals(gatewayManager.publishToGateway(api, apiTemplateBuilder, tenantDomain).size(), 0);
}
 
Example 10
Source File: APIGatewayManagerTest.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Test public void testFailureWhilePublishingAPIUpdateToGateway() 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);
    api.setEnvironments(environments);
    Mockito.when(apiGatewayAdminClient.getApi(tenantDomain, apiIdentifier)).thenReturn(apiData);
    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);
    //Test API deployment failure when custom sequence update failed
    Map<String, String> failedEnvironmentsMap = gatewayManager
            .publishToGateway(api, apiTemplateBuilder, tenantDomain);
    Assert.assertEquals(failedEnvironmentsMap.size(), 1);
    Assert.assertTrue(failedEnvironmentsMap.keySet().contains(prodEnvironmentName));
}
 
Example 11
Source File: APIGatewayManagerTest.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
@Test public void testPublishingNewAPIToGateway()
        throws Exception {

    API api = new API(apiIdentifier);
    api.setType("HTTP");
    api.setAsPublishedDefaultVersion(true);
    api.setAsDefaultVersion(true);
    APITemplateBuilder apiTemplateBuilder = new APITemplateBuilderImpl(api);
    Set<String> environments = new HashSet<String>();
    environments.add(prodEnvironmentName);
    environments.add(null);
    Mockito.when(apiGatewayAdminClient.getApi(tenantDomain, apiIdentifier)).thenReturn(null);

    //Test when environments are not defined for API
    Assert.assertEquals(gatewayManager.publishToGateway(api, apiTemplateBuilder, tenantDomain).size(), 0);

    //Test adding LocalEntry
    api.setEnvironments(environments);
    api.setEndpointConfig(sandBoxEndpointConfig);
    api.setSwaggerDefinition(swaggerDefinition);
    api.setUUID(apiUUId);

    //Test when API's environment endpoint configuration is not available
    Assert.assertEquals(gatewayManager.publishToGateway(api, apiTemplateBuilder, tenantDomain).size(), 0);

    //Test deploying 'INLINE' type REST API to gateway
    api.setImplementation("INLINE");
    api.setEndpointConfig(prodEndpointConfig);
    Assert.assertEquals(gatewayManager.publishToGateway(api, apiTemplateBuilder, tenantDomain).size(), 0);

    //Test deploying 'ENDPOINT' type REST API to gateway
    api.setImplementation("ENDPOINT");
    Assert.assertEquals(gatewayManager.publishToGateway(api, apiTemplateBuilder, tenantDomain).size(), 0);

    //Test deploying default version of the API and updating the existing default API
    Mockito.when(apiGatewayAdminClient.getDefaultApi(tenantDomain, apiIdentifier)).thenReturn(defaultAPIdata);
    Assert.assertEquals(gatewayManager.publishToGateway(api, apiTemplateBuilder, tenantDomain).size(), 0);

    //Test deploying API, if secure vault is enabled
    api.setEndpointSecured(true);
    Mockito.when(config.getFirstProperty(APIConstants.API_SECUREVAULT_ENABLE)).thenReturn("true");
    Assert.assertEquals(gatewayManager.publishToGateway(api, apiTemplateBuilder, tenantDomain).size(), 0);

    //Test publishing WebSocket API
    api.setType("WS");
    Assert.assertEquals(gatewayManager.publishToGateway(api, apiTemplateBuilder, tenantDomain).size(), 0);

}
 
Example 12
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));
}