use of org.wso2.carbon.apimgt.rest.api.store.dto.SubscriptionDTO in project carbon-apimgt by wso2.
the class SubscriptionMappingUtil method fromSubscriptionToDTO.
/**
* Converts a SubscribedAPI object into SubscriptionDTO
*
* @param subscription SubscribedAPI object
* @return SubscriptionDTO corresponds to SubscribedAPI object
*/
public static SubscriptionDTO fromSubscriptionToDTO(Subscription subscription) {
SubscriptionDTO subscriptionDTO = new SubscriptionDTO();
subscriptionDTO.setSubscriptionId(subscription.getId());
if (subscription.getApi() != null) {
subscriptionDTO.setApiIdentifier(subscription.getApi().getId());
subscriptionDTO.setApiName(subscription.getApi().getName());
subscriptionDTO.setApiVersion(subscription.getApi().getVersion());
}
if (subscription.getApplication() != null) {
subscriptionDTO.setApplicationId(subscription.getApplication().getId());
}
subscriptionDTO.setPolicy(subscription.getPolicy().getPolicyName());
subscriptionDTO.setLifeCycleStatus(SubscriptionDTO.LifeCycleStatusEnum.valueOf(subscription.getStatus().toString()));
return subscriptionDTO;
}
use of org.wso2.carbon.apimgt.rest.api.store.dto.SubscriptionDTO in project carbon-apimgt by wso2.
the class SubscriptionsApiServiceImplTestCase method testSubscriptionsPost.
@Test
public void testSubscriptionsPost() throws APIManagementException, NotFoundException {
TestUtil.printTestMethodName();
String applicationId = UUID.randomUUID().toString();
String apiId = UUID.randomUUID().toString();
String subsID1 = UUID.randomUUID().toString();
String subsID2 = UUID.randomUUID().toString();
SubscriptionsApiServiceImpl subscriptionsApiService = new SubscriptionsApiServiceImpl();
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
Request request = TestUtil.getRequest();
PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
Application application = SampleTestObjectCreator.createDefaultApplication();
Endpoint api1SandBoxEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("abcd").build();
Endpoint api1ProdEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("cdef").build();
API api = TestUtil.createApi("provider1", apiId, "testapi1", "1.0.0", "Test API 1 - version 1.0.0", TestUtil.createEndpointTypeToIdMap(api1SandBoxEndpointId, api1ProdEndpointId)).build();
Mockito.when(apiStore.getApplicationByUuid(applicationId)).thenReturn(application);
Mockito.when(apiStore.getAPIbyUUID(apiId)).thenReturn(api);
SubscriptionDTO subscriptionDTO = SubscriptionMappingUtil.fromSubscriptionToDTO(SampleTestObjectCreator.createSubscription(subsID1));
Response response = subscriptionsApiService.subscriptionsPost(subscriptionDTO, request);
Assert.assertEquals(404, response.getStatus());
}
use of org.wso2.carbon.apimgt.rest.api.store.dto.SubscriptionDTO in project carbon-apimgt by wso2.
the class MappingUtil method convertToSubscriptionListDto.
/**
* This method converts List of SubscriptionValidationData into SubscriptionDTO list.
*
* @param subscriptionValidationData List of Subscription Validation Data
* @return SubscriptionDTO list
*/
public static List<SubscriptionDTO> convertToSubscriptionListDto(List<SubscriptionValidationData> subscriptionValidationData) {
List<SubscriptionDTO> subscriptionDTOList = new ArrayList<>();
for (SubscriptionValidationData subscriptionData : subscriptionValidationData) {
SubscriptionDTO subscriptionDTO = new SubscriptionDTO();
subscriptionDTO.setApiName(subscriptionData.getApiName());
subscriptionDTO.setApiContext(subscriptionData.getApiContext());
subscriptionDTO.setApiVersion(subscriptionData.getApiVersion());
subscriptionDTO.setApiProvider(subscriptionData.getApiProvider());
subscriptionDTO.setConsumerKey(subscriptionData.getConsumerKey());
subscriptionDTO.setSubscriptionPolicy(subscriptionData.getSubscriptionPolicy());
subscriptionDTO.setKeyEnvType(subscriptionData.getKeyEnvType());
subscriptionDTO.setApplicationId(subscriptionData.getApplicationId());
subscriptionDTO.setStatus(subscriptionData.getStatus());
subscriptionDTOList.add(subscriptionDTO);
}
return subscriptionDTOList;
}
use of org.wso2.carbon.apimgt.rest.api.store.dto.SubscriptionDTO in project carbon-apimgt by wso2.
the class MappingUtilTestCase method convertToSubscriptionListDTOTest.
@Test
public void convertToSubscriptionListDTOTest() {
List<SubscriptionValidationData> validationDataList = new ArrayList<>();
validationDataList.add(SampleTestObjectCreator.createSubscriptionValidationData());
validationDataList.add(SampleTestObjectCreator.createSubscriptionValidationData());
validationDataList.add(SampleTestObjectCreator.createSubscriptionValidationData());
validationDataList.add(SampleTestObjectCreator.createSubscriptionValidationData());
List<SubscriptionDTO> subscriptionListDTO = MappingUtil.convertToSubscriptionListDto(validationDataList);
Assert.assertNotNull(subscriptionListDTO);
Assert.assertEquals(validationDataList.size(), subscriptionListDTO.size());
for (int i = 0; i < subscriptionListDTO.size(); i++) {
Assert.assertEquals(subscriptionListDTO.get(i).getApiName(), validationDataList.get(i).getApiName());
Assert.assertEquals(subscriptionListDTO.get(i).getApiContext(), validationDataList.get(i).getApiContext());
Assert.assertEquals(subscriptionListDTO.get(i).getApiProvider(), validationDataList.get(i).getApiProvider());
Assert.assertEquals(subscriptionListDTO.get(i).getApiVersion(), validationDataList.get(i).getApiVersion());
}
}
use of org.wso2.carbon.apimgt.rest.api.store.dto.SubscriptionDTO in project carbon-apimgt by wso2.
the class TestMappingUtilTestCase method testSubscriptionToSubscriptionDTOMapping.
@Test(description = "Subscription to Subscription DTO mapping")
void testSubscriptionToSubscriptionDTOMapping() {
Policy subscriptionPolicy = SampleTestObjectCreator.goldSubscriptionPolicy;
API api = SampleTestObjectCreator.createDefaultAPI().build();
Application application = SampleTestObjectCreator.createDefaultApplication();
String uuid = UUID.randomUUID().toString();
Subscription subscription = new Subscription(uuid, application, api, subscriptionPolicy);
subscription.setStatus(APIMgtConstants.SubscriptionStatus.ACTIVE);
SubscriptionDTO subscriptionDTO = MappingUtil.fromSubscription(subscription);
assertEquals(subscription.getId(), subscriptionDTO.getSubscriptionId());
assertEquals(subscription.getStatus().name(), subscriptionDTO.getSubscriptionStatus().name());
assertEquals(subscription.getApplication().getId(), subscriptionDTO.getApplicationInfo().getApplicationId());
assertEquals(subscription.getPolicy().getPolicyName(), subscriptionDTO.getPolicy());
}
Aggregations