Java Code Examples for org.wso2.carbon.apimgt.api.model.API#setAsDefaultVersion()
The following examples show how to use
org.wso2.carbon.apimgt.api.model.API#setAsDefaultVersion() .
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 |
@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 2
Source File: APIGatewayManagerTest.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@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 3
Source File: APIGatewayManagerTest.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@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 4
Source File: APIGatewayManagerTest.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@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 5
Source File: APIMgtDAOTest.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Test public void testAddAndConvertNullThrottlingTiers() throws APIManagementException { //Adding an API with a null THROTTLING_TIER should automatically convert it to Unlimited APIIdentifier apiIdentifier = new APIIdentifier("testAddAndGetApi", "testAddAndGetApi", "1.0.0"); API api = new API(apiIdentifier); api.setContext("/testAddAndGetApi"); api.setContextTemplate("/testAddAndGetApi/{version}"); Set<URITemplate> uriTemplates = new HashSet<URITemplate>(); uriTemplates.add(getUriTemplate("/abc", "GET", "Any", "read", null)); api.setUriTemplates(uriTemplates); api.setScopes(getScopes()); api.setStatus(APIConstants.PUBLISHED); api.setAsDefaultVersion(true); int apiId = apiMgtDAO.addAPI(api, -1234); apiMgtDAO.addURITemplates(apiId, api, -1234); HashMap<String, String> result1 = apiMgtDAO.getURITemplatesPerAPIAsString(apiIdentifier); Assert.assertTrue(result1.containsKey("/abc::GET::Any::Unlimited::abcd defgh fff")); //Change the inserted throttling tier back to Null and test the convertNullThrottlingTier method updateThrottlingTierToNull(); apiMgtDAO.convertNullThrottlingTiers(); HashMap<String, String> result2 = apiMgtDAO.getURITemplatesPerAPIAsString(apiIdentifier); Assert.assertTrue(result2.containsKey("/abc::GET::Any::Unlimited::abcd defgh fff")); }
Example 6
Source File: APIGatewayManagerTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@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 7
Source File: APIGatewayManagerTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@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 8
Source File: APIGatewayManagerTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@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 9
Source File: APIMgtDAOTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void testAddAndGetApi() throws Exception{ APIIdentifier apiIdentifier = new APIIdentifier("testAddAndGetApi", "testAddAndGetApi", "1.0.0"); API api = new API(apiIdentifier); api.setContext("/testAddAndGetApi"); api.setContextTemplate("/testAddAndGetApi/{version}"); api.setUriTemplates(getUriTemplateSet()); api.setScopes(getScopes()); api.setStatus(APIConstants.PUBLISHED); api.setAsDefaultVersion(true); int apiID = apiMgtDAO.addAPI(api, -1234); apiMgtDAO.addURITemplates(apiID, api, -1234); apiMgtDAO.updateAPI(api); apiMgtDAO.updateURITemplates(api, -1234); Set<APIStore> apiStoreSet = new HashSet<APIStore>(); APIStore apiStore = new APIStore(); apiStore.setDisplayName("wso2"); apiStore.setEndpoint("http://localhost:9433/store"); apiStore.setName("wso2"); apiStore.setType("wso2"); apiStoreSet.add(apiStore); apiMgtDAO.addExternalAPIStoresDetails(apiIdentifier,apiStoreSet); assertTrue(apiMgtDAO.getExternalAPIStoresDetails(apiIdentifier).size()>0); apiMgtDAO.deleteExternalAPIStoresDetails(apiIdentifier, apiStoreSet); apiMgtDAO.updateExternalAPIStoresDetails(apiIdentifier, Collections.<APIStore>emptySet()); assertTrue(apiMgtDAO.getExternalAPIStoresDetails(apiIdentifier).size()==0); apiMgtDAO.deleteAPI(apiIdentifier); }
Example 10
Source File: APIGatewayManagerTest.java From carbon-apimgt with Apache License 2.0 | 4 votes |
@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 11
Source File: APIGatewayManagerTest.java From carbon-apimgt with Apache License 2.0 | 4 votes |
@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)); }