Search in sources :

Example 6 with SubscriptionDTO

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;
}
Also used : SubscriptionDTO(org.wso2.carbon.apimgt.rest.api.store.dto.SubscriptionDTO)

Example 7 with 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());
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) Response(javax.ws.rs.core.Response) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) Request(org.wso2.msf4j.Request) API(org.wso2.carbon.apimgt.core.models.API) Application(org.wso2.carbon.apimgt.core.models.Application) SubscriptionDTO(org.wso2.carbon.apimgt.rest.api.store.dto.SubscriptionDTO) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with SubscriptionDTO

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;
}
Also used : ArrayList(java.util.ArrayList) SubscriptionValidationData(org.wso2.carbon.apimgt.core.models.SubscriptionValidationData) SubscriptionDTO(org.wso2.carbon.apimgt.rest.api.core.dto.SubscriptionDTO)

Example 9 with SubscriptionDTO

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());
    }
}
Also used : ArrayList(java.util.ArrayList) SubscriptionValidationData(org.wso2.carbon.apimgt.core.models.SubscriptionValidationData) SubscriptionDTO(org.wso2.carbon.apimgt.rest.api.core.dto.SubscriptionDTO) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) Test(org.testng.annotations.Test)

Example 10 with SubscriptionDTO

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());
}
Also used : Policy(org.wso2.carbon.apimgt.core.models.policy.Policy) API(org.wso2.carbon.apimgt.core.models.API) Subscription(org.wso2.carbon.apimgt.core.models.Subscription) Application(org.wso2.carbon.apimgt.core.models.Application) SubscriptionDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.SubscriptionDTO) Test(org.testng.annotations.Test)

Aggregations

Subscription (org.wso2.carbon.apimgt.core.models.Subscription)7 HashMap (java.util.HashMap)5 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)5 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)5 SubscriptionDTO (org.wso2.carbon.apimgt.rest.api.publisher.dto.SubscriptionDTO)5 SubscriptionDTO (org.wso2.carbon.apimgt.rest.api.store.dto.SubscriptionDTO)5 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.core.exception.APIMgtResourceNotFoundException)4 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)3 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)3 GatewayException (org.wso2.carbon.apimgt.core.exception.GatewayException)3 Application (org.wso2.carbon.apimgt.core.models.Application)3 ArrayList (java.util.ArrayList)2 Test (org.testng.annotations.Test)2 API (org.wso2.carbon.apimgt.core.models.API)2 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)2 SubscriptionValidationData (org.wso2.carbon.apimgt.core.models.SubscriptionValidationData)2 SubscriptionDTO (org.wso2.carbon.apimgt.rest.api.core.dto.SubscriptionDTO)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Map (java.util.Map)1