use of org.wso2.charon3.core.objects.User in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testApiLevelEndpointAddWhileDbGetError.
@Test(description = "Test add api with Api Specific Endpoint", expectedExceptions = { APIManagementException.class })
public void testApiLevelEndpointAddWhileDbGetError() throws APIManagementException, LifecycleException {
/**
* this test method verify the API Add with correct API object get invoked correctly
*/
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
LabelDAO labelDao = Mockito.mock(LabelDAO.class);
GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
Endpoint globalEndpoint = new Endpoint.Builder().id(UUID.randomUUID().toString()).name("testEndpoint").applicableLevel(APIMgtConstants.GLOBAL_ENDPOINT).build();
Endpoint apiEndpoint = new Endpoint.Builder().id(UUID.randomUUID().toString()).name("apiEndpoint").applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).build();
Map<String, Endpoint> endpointMap = new HashMap();
endpointMap.put(APIMgtConstants.PRODUCTION_ENDPOINT, globalEndpoint);
endpointMap.put(APIMgtConstants.SANDBOX_ENDPOINT, apiEndpoint);
API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI().endpoint(endpointMap);
Mockito.when(apiLifecycleManager.addLifecycle(APIMgtConstants.API_LIFECYCLE, USER)).thenReturn(new LifecycleState());
APIGateway gateway = Mockito.mock(APIGateway.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(null, apiDAO, null, null, null, apiLifecycleManager, labelDao, null, null, null, gatewaySourceGenerator, gateway);
Mockito.when(apiDAO.getEndpoint(globalEndpoint.getId())).thenReturn(globalEndpoint);
Mockito.when(apiDAO.getEndpointByName(apiEndpoint.getName())).thenThrow(APIMgtDAOException.class);
Mockito.when(apiDAO.isAPINameExists(apiBuilder.getName(), USER)).thenReturn(false);
apiPublisher.addAPI(apiBuilder);
Mockito.verify(apiDAO, Mockito.times(1)).addAPI(apiBuilder.build());
Mockito.verify(apiDAO, Mockito.times(1)).getEndpointByName(apiEndpoint.getName());
}
use of org.wso2.charon3.core.objects.User in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testAddUpdateAPIFromWSDLArchive.
@Test(description = "Test adding an API from WSDL archive")
public void testAddUpdateAPIFromWSDLArchive() throws APIManagementException, LifecycleException, IOException {
API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI().endpoint(SampleTestObjectCreator.getMockEndpointMap());
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
APIGateway gateway = Mockito.mock(APIGateway.class);
APILifecycleManager apiLifecycleManager = getDefaultMockedAPILifecycleManager();
PolicyDAO policyDAO = getDefaultMockedPolicyDAO();
LabelDAO labelDao = Mockito.mock(LabelDAO.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO, apiLifecycleManager, gatewaySourceGenerator, gateway, policyDAO, labelDao);
String endpointId = apiBuilder.getEndpoint().get("production").getId();
Endpoint endpoint = new Endpoint.Builder().id(endpointId).name("testEndpoint").build();
Mockito.when(apiDAO.getEndpoint(endpointId)).thenReturn(endpoint);
apiPublisher.addAPIFromWSDLArchive(apiBuilder, SampleTestObjectCreator.createDefaultWSDL11ArchiveInputStream(), true);
Mockito.verify(apiDAO, Mockito.times(1)).addAPI(apiBuilder.build());
Mockito.verify(apiDAO, Mockito.times(1)).addOrUpdateWSDLArchive(Mockito.eq(apiBuilder.getId()), Mockito.anyObject(), Mockito.eq(USER));
apiPublisher.updateAPIWSDLArchive(apiBuilder.getId(), SampleTestObjectCreator.createAlternativeWSDL11ArchiveInputStream());
Mockito.verify(apiDAO, Mockito.times(2)).addOrUpdateWSDLArchive(Mockito.eq(apiBuilder.getId()), Mockito.anyObject(), Mockito.eq(USER));
}
use of org.wso2.charon3.core.objects.User in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testCreateNewAPIVersion.
@Test(description = "Create new API version with valid APIID")
public void testCreateNewAPIVersion() throws APIManagementException, LifecycleException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
API api = SampleTestObjectCreator.createDefaultAPI().build();
String uuid = api.getId();
APIGateway gateway = Mockito.mock(APIGateway.class);
APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO, apiSubscriptionDAO, apiLifecycleManager, gateway);
Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
Mockito.when(apiSubscriptionDAO.getAPISubscriptionsByAPI(api.getId())).thenReturn(new ArrayList<>());
Mockito.when(apiLifecycleManager.addLifecycle(APIMgtConstants.API_LIFECYCLE, USER)).thenReturn(new LifecycleState());
String newUUid = apiPublisher.createNewAPIVersion(uuid, "2.0.0");
Mockito.verify(apiDAO, Mockito.times(1)).getAPI(uuid);
Mockito.verify(apiDAO, Mockito.times(0)).addAPI(api);
Assert.assertNotEquals(uuid, newUUid);
}
use of org.wso2.charon3.core.objects.User in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method getDefaultMockedAPILifecycleManager.
private APILifecycleManager getDefaultMockedAPILifecycleManager() throws LifecycleException {
APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
Mockito.when(apiLifecycleManager.addLifecycle(APIMgtConstants.API_LIFECYCLE, USER)).thenReturn(new LifecycleState());
return apiLifecycleManager;
}
use of org.wso2.charon3.core.objects.User in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testAddResourceLevelEndpoint.
@Test(description = "Test add api with Api Specific Endpoint")
public void testAddResourceLevelEndpoint() throws APIManagementException, LifecycleException {
/**
* this test method verify the API Add with correct API object get invoked correctly
*/
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
Endpoint globalEndpoint = new Endpoint.Builder().id(UUID.randomUUID().toString()).name("testEndpoint").applicableLevel(APIMgtConstants.GLOBAL_ENDPOINT).build();
Endpoint apiEndpoint = new Endpoint.Builder().id(UUID.randomUUID().toString()).name("apiEndpoint").applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).build();
Endpoint resourceEndpoint = new Endpoint.Builder().id(UUID.randomUUID().toString()).name("resourceEndpoint").applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).build();
Map<String, Endpoint> endpointMap = new HashMap();
endpointMap.put(APIMgtConstants.PRODUCTION_ENDPOINT, globalEndpoint);
endpointMap.put(APIMgtConstants.SANDBOX_ENDPOINT, apiEndpoint);
Map<String, Endpoint> resourceEndpoints = new HashMap();
resourceEndpoints.put(APIMgtConstants.SANDBOX_ENDPOINT, resourceEndpoint);
Map<String, UriTemplate> uriTemplateMap = SampleTestObjectCreator.getMockUriTemplates();
uriTemplateMap.forEach((k, v) -> {
UriTemplate.UriTemplateBuilder uriTemplateBuilder = new UriTemplate.UriTemplateBuilder(v);
uriTemplateBuilder.endpoint(resourceEndpoints);
uriTemplateMap.replace(k, uriTemplateBuilder.build());
});
API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI().endpoint(endpointMap).uriTemplates(uriTemplateMap);
Mockito.when(apiLifecycleManager.addLifecycle(APIMgtConstants.API_LIFECYCLE, USER)).thenReturn(new LifecycleState());
APIGateway gateway = Mockito.mock(APIGateway.class);
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
LabelDAO labelDao = Mockito.mock(LabelDAO.class);
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.api, APIMgtConstants.DEFAULT_API_POLICY)).thenReturn(new APIPolicy(APIMgtConstants.DEFAULT_API_POLICY));
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, GOLD_TIER)).thenReturn(new SubscriptionPolicy(GOLD_TIER));
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, SILVER_TIER)).thenReturn(new SubscriptionPolicy(SILVER_TIER));
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, BRONZE_TIER)).thenReturn(new SubscriptionPolicy(BRONZE_TIER));
APIPublisherImpl apiPublisher = getApiPublisherImpl(null, apiDAO, null, null, policyDAO, apiLifecycleManager, labelDao, null, null, null, gatewaySourceGenerator, gateway);
Mockito.when(apiDAO.getEndpoint(globalEndpoint.getId())).thenReturn(globalEndpoint);
Mockito.when(apiDAO.getEndpointByName(apiEndpoint.getName())).thenReturn(null);
Mockito.when(apiDAO.getEndpointByName(resourceEndpoint.getName())).thenReturn(null);
Mockito.when(apiDAO.isAPINameExists(apiBuilder.getName(), USER)).thenReturn(false);
apiPublisher.addAPI(apiBuilder);
Mockito.verify(apiDAO, Mockito.times(1)).addAPI(apiBuilder.build());
Mockito.verify(apiDAO, Mockito.times(1)).getEndpointByName(apiEndpoint.getName());
Mockito.verify(apiDAO, Mockito.times(1)).getEndpointByName(resourceEndpoint.getName());
}
Aggregations