use of org.wso2.carbon.apimgt.core.models.API.APIBuilder in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testAddSubscriptionForInvalidApplication.
@Test(description = "Add subscription without a valid app", expectedExceptions = APIManagementException.class)
public void testAddSubscriptionForInvalidApplication() throws APIManagementException {
ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
APIStore apiStore = getApiStoreImpl(apiDAO, applicationDAO, apiSubscriptionDAO, workflowDAO, apiGateway);
API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI();
API api = apiBuilder.build();
String apiId = api.getId();
/* Application application = new Application("TestApp", USER_ID);
application.setId(UUID);*/
Mockito.when(apiDAO.getAPI(apiId)).thenReturn(api);
Mockito.when(applicationDAO.getApplication(UUID)).thenReturn(null);
SubscriptionResponse subscriptionResponse = apiStore.addApiSubscription(apiId, UUID, TIER);
String subscriptionId = subscriptionResponse.getSubscriptionUUID();
Assert.assertNotNull(subscriptionId);
// subscription should not be added
Mockito.verify(apiSubscriptionDAO, Mockito.times(0)).addAPISubscription(subscriptionId, apiId, UUID, TIER, APIMgtConstants.SubscriptionStatus.ON_HOLD);
}
use of org.wso2.carbon.apimgt.core.models.API.APIBuilder in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testGetAPIWithAllowedLifecycleState.
@Test(description = "Test get API with allowed lifecycle states (Published, Prototyped, Deprecated)")
public void testGetAPIWithAllowedLifecycleState() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
Policy policy = new SubscriptionPolicy(UUID, TIER);
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, TIER)).thenReturn(policy);
APIStore apiStore = getApiStoreImpl(apiDAO, Mockito.mock(ApplicationDAO.class), Mockito.mock(APISubscriptionDAO.class), Mockito.mock(WorkflowDAO.class), Mockito.mock(APIGateway.class), policyDAO);
API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI();
String apiId = apiBuilder.getId();
List<String> allowedStates = new ArrayList<String>() {
{
add(APIStatus.PROTOTYPED.getStatus());
add(APIStatus.PUBLISHED.getStatus());
add(APIStatus.DEPRECATED.getStatus());
}
};
for (String allowedState : allowedStates) {
apiBuilder.lifeCycleStatus(allowedState);
API api = apiBuilder.build();
Mockito.when(apiDAO.getAPI(apiId)).thenReturn(api);
API returnedAPI = apiStore.getAPIbyUUID(apiId);
Assert.assertEquals(returnedAPI.getLifeCycleStatus(), allowedState);
}
}
use of org.wso2.carbon.apimgt.core.models.API.APIBuilder in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testAddSubscription.
@Test(description = "Add subscription to an application")
public void testAddSubscription() throws APIManagementException {
ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
Policy policy = new SubscriptionPolicy(UUID, TIER);
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, TIER)).thenReturn(policy);
APIStore apiStore = getApiStoreImpl(apiDAO, applicationDAO, apiSubscriptionDAO, workflowDAO, apiGateway, policyDAO);
API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI();
apiBuilder.lifeCycleStatus(APIStatus.PUBLISHED.getStatus());
API api = apiBuilder.build();
String apiId = api.getId();
Application application = new Application("TestApp", USER_ID);
application.setId(UUID);
Mockito.when(apiDAO.getAPI(apiId)).thenReturn(api);
Mockito.when(applicationDAO.getApplication(UUID)).thenReturn(application);
SubscriptionResponse subscriptionResponse = apiStore.addApiSubscription(apiId, UUID, TIER);
String subscriptionId = subscriptionResponse.getSubscriptionUUID();
Assert.assertNotNull(subscriptionId);
// before workflow add subscription with blocked state
Mockito.verify(apiSubscriptionDAO, Mockito.times(1)).addAPISubscription(subscriptionId, apiId, UUID, policy.getUuid(), APIMgtConstants.SubscriptionStatus.ON_HOLD);
// after workflow change the state
Mockito.verify(apiSubscriptionDAO, Mockito.times(1)).updateSubscriptionStatus(subscriptionId, APIMgtConstants.SubscriptionStatus.ACTIVE);
}
use of org.wso2.carbon.apimgt.core.models.API.APIBuilder in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testAddCompositeApi.
@Test(description = "Add Composite API")
public void testAddCompositeApi() throws APIManagementException {
CompositeAPI.Builder apiBuilder = SampleTestObjectCreator.createUniqueCompositeAPI();
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
IdentityProvider idp = Mockito.mock(IdentityProvider.class);
KeyManager km = Mockito.mock(KeyManager.class);
APIStore apiStore = getApiStoreImpl(idp, km, apiDAO, apiSubscriptionDAO, gatewaySourceGenerator, apiGateway);
apiStore.addCompositeApi(apiBuilder);
Mockito.verify(apiDAO, Mockito.times(1)).addApplicationAssociatedAPI(apiBuilder.build());
}
use of org.wso2.carbon.apimgt.core.models.API.APIBuilder in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdPutException.
@Test
public void testApisApiIdPutException() throws Exception {
printTestMethodName();
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
String apiId = UUID.randomUUID().toString();
API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI();
API api = apiBuilder.id(apiId).build();
APIDTO apidto = MappingUtil.toAPIDto(api);
Mockito.when(apiPublisher.getApiSwaggerDefinition(apiId)).thenReturn(SampleTestObjectCreator.apiDefinition);
Mockito.doNothing().doThrow(new IllegalArgumentException()).when(apiPublisher).updateAPI(apiBuilder);
Mockito.doThrow(new APIManagementException("Error occurred", ExceptionCodes.API_TYPE_INVALID)).when(apiPublisher).getAPIbyUUID(apiId);
Response response = apisApiService.apisApiIdPut(apiId, apidto, null, null, getRequest());
assertEquals(response.getStatus(), 400);
assertTrue(response.getEntity().toString().contains("API Type specified is invalid"));
}
Aggregations