Search in sources :

Example 6 with ApplicationList

use of org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationList in project carbon-apimgt by wso2.

the class ApplicationsApiServiceImplTestCase method applicationsGetTestCase.

@Test
public void applicationsGetTestCase() throws Exception {
    ApplicationsApiServiceImpl applicationsApiService = new ApplicationsApiServiceImpl();
    APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
    PowerMockito.mockStatic(APIManagerFactory.class);
    PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
    Mockito.when(instance.getAPIMgtAdminService()).thenReturn(adminService);
    List<Application> applicationList = new ArrayList<>();
    Application applicationOne = SampleTestObjectCreator.createRandomApplication();
    Application applicationTwo = SampleTestObjectCreator.createRandomApplication();
    Application applicationThree = SampleTestObjectCreator.createRandomApplication();
    applicationList.add(applicationOne);
    applicationList.add(applicationTwo);
    applicationList.add(applicationThree);
    Mockito.when(adminService.getAllApplications()).thenReturn(applicationList);
    Response response = applicationsApiService.applicationsGet(null, getRequest());
    Assert.assertEquals(response.getStatus(), 200);
    Assert.assertEquals(((ApplicationListDTO) response.getEntity()).getList().size(), 3);
}
Also used : Response(javax.ws.rs.core.Response) APIManagerFactory(org.wso2.carbon.apimgt.core.impl.APIManagerFactory) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) ArrayList(java.util.ArrayList) Application(org.wso2.carbon.apimgt.core.models.Application) ApplicationListDTO(org.wso2.carbon.apimgt.rest.api.core.dto.ApplicationListDTO) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 7 with ApplicationList

use of org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationList in project carbon-apimgt by wso2.

the class ApiMgtDAO method getApplicationsWithPagination.

/**
 * Retrieve the applications by user/application name
 *
 * @param user
 * @param owner
 * @param tenantId
 * @param limit
 * @param offset
 * @param sortBy
 * @param sortOrder
 * @param appName
 * @return
 * @throws APIManagementException
 */
public Application[] getApplicationsWithPagination(String user, String owner, int tenantId, int limit, int offset, String sortBy, String sortOrder, String appName) throws APIManagementException {
    Connection connection = null;
    PreparedStatement prepStmt = null;
    ResultSet rs = null;
    String sqlQuery = null;
    List<Application> applicationList = new ArrayList<>();
    sqlQuery = SQLConstantManagerFactory.getSQlString("GET_APPLICATIONS_BY_TENANT_ID");
    Application[] applications = null;
    try {
        connection = APIMgtDBUtil.getConnection();
        String driverName = connection.getMetaData().getDriverName();
        if (driverName.contains("Oracle")) {
            limit = offset + limit;
        }
        sqlQuery = sqlQuery.replace("$1", sortBy);
        sqlQuery = sqlQuery.replace("$2", sortOrder);
        prepStmt = connection.prepareStatement(sqlQuery);
        prepStmt.setInt(1, tenantId);
        prepStmt.setString(2, "%" + owner + "%");
        prepStmt.setString(3, "%" + appName + "%");
        prepStmt.setInt(4, offset);
        prepStmt.setInt(5, limit);
        rs = prepStmt.executeQuery();
        Application application;
        while (rs.next()) {
            String applicationName = rs.getString("NAME");
            String subscriberName = rs.getString("CREATED_BY");
            Subscriber subscriber = new Subscriber(subscriberName);
            application = new Application(applicationName, subscriber);
            application.setName(applicationName);
            application.setId(rs.getInt("APPLICATION_ID"));
            application.setUUID(rs.getString("UUID"));
            application.setGroupId(rs.getString("GROUP_ID"));
            subscriber.setTenantId(rs.getInt("TENANT_ID"));
            subscriber.setId(rs.getInt("SUBSCRIBER_ID"));
            application.setStatus(rs.getString("APPLICATION_STATUS"));
            application.setOwner(subscriberName);
            applicationList.add(application);
        }
        applications = applicationList.toArray(new Application[applicationList.size()]);
    } catch (SQLException e) {
        handleException("Error while obtaining details of the Application for tenant id : " + tenantId, e);
    } finally {
        APIMgtDBUtil.closeAllConnections(prepStmt, connection, rs);
    }
    return applications;
}
Also used : Subscriber(org.wso2.carbon.apimgt.api.model.Subscriber) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) Application(org.wso2.carbon.apimgt.api.model.Application)

Example 8 with ApplicationList

use of org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationList in project carbon-apimgt by wso2.

the class ApplicationsApiServiceImplTestCase method testApplicationsGetBlankQuery.

@Test
public void testApplicationsGetBlankQuery() throws APIManagementException, NotFoundException {
    TestUtil.printTestMethodName();
    String applicationId1 = UUID.randomUUID().toString();
    String applicationId2 = UUID.randomUUID().toString();
    ApplicationsApiServiceImpl applicationsApiService = new ApplicationsApiServiceImpl();
    APIStore apiStore = Mockito.mock(APIStoreImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
    Request request = getRequest();
    PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
    Application application1 = getSampleApplication(applicationId1);
    Application application2 = getSampleApplication(applicationId2);
    List<Application> applicationList = new ArrayList<>();
    applicationList.add(application1);
    applicationList.add(application2);
    Mockito.when(apiStore.getApplications(USER)).thenReturn(applicationList);
    Response response = applicationsApiService.applicationsGet(null, 10, 0, null, request);
    Assert.assertEquals(200, response.getStatus());
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) ApplicationCreationResponse(org.wso2.carbon.apimgt.core.workflow.ApplicationCreationResponse) Response(javax.ws.rs.core.Response) Request(org.wso2.msf4j.Request) ArrayList(java.util.ArrayList) Application(org.wso2.carbon.apimgt.core.models.Application) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 9 with ApplicationList

use of org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationList in project carbon-apimgt by wso2.

the class ApplicationsApiServiceImplTestCase method testApplicationsGetQuery.

@Test
public void testApplicationsGetQuery() throws APIManagementException, NotFoundException {
    TestUtil.printTestMethodName();
    String applicationId1 = UUID.randomUUID().toString();
    String applicationId2 = UUID.randomUUID().toString();
    ApplicationsApiServiceImpl applicationsApiService = new ApplicationsApiServiceImpl();
    APIStore apiStore = Mockito.mock(APIStoreImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
    Request request = getRequest();
    PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
    Application application1 = getSampleApplication(applicationId1);
    Application application2 = getSampleApplication(applicationId2);
    List<Application> applicationList = new ArrayList<>();
    applicationList.add(application1);
    applicationList.add(application2);
    // TODO - Seems there is an issue here. Need to check
    Mockito.when(apiStore.getApplications(USER)).thenReturn(applicationList);
    Response response = applicationsApiService.applicationsGet("*", 10, 0, null, request);
    Assert.assertEquals(200, response.getStatus());
}
Also used : WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) ApplicationCreationResponse(org.wso2.carbon.apimgt.core.workflow.ApplicationCreationResponse) Response(javax.ws.rs.core.Response) Request(org.wso2.msf4j.Request) ArrayList(java.util.ArrayList) Application(org.wso2.carbon.apimgt.core.models.Application) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 10 with ApplicationList

use of org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationList in project carbon-apimgt by wso2.

the class ApplicationsApiServiceImpl method applicationsGet.

public Response applicationsGet(String name, String uuid, String tenantDomain, MessageContext messageContext) {
    tenantDomain = GatewayUtils.validateTenantDomain(tenantDomain, messageContext);
    SubscriptionDataStore subscriptionDataStore = SubscriptionDataHolder.getInstance().getTenantSubscriptionStore(tenantDomain);
    if (subscriptionDataStore == null) {
        log.warn("Subscription data store is not initialized for " + tenantDomain);
        return Response.status(Response.Status.NOT_FOUND).build();
    }
    List<Application> applicationList;
    if (StringUtils.isNotEmpty(name)) {
        applicationList = subscriptionDataStore.getApplicationsByName(name);
    } else if (StringUtils.isNotEmpty(uuid)) {
        applicationList = new ArrayList<>();
        if (subscriptionDataStore.getApplicationByUUID(uuid) != null) {
            applicationList.add(subscriptionDataStore.getApplicationByUUID(uuid));
        }
    } else {
        return Response.status(Response.Status.BAD_REQUEST).entity(new ErrorDTO().moreInfo("required parameters " + "are missing")).build();
    }
    if (applicationList == null) {
        return Response.status(Response.Status.NOT_FOUND).build();
    }
    ApplicationListDTO applicationListDTO = GatewayUtils.generateApplicationList(applicationList, subscriptionDataStore);
    return Response.ok().entity(applicationListDTO).build();
}
Also used : ErrorDTO(org.wso2.carbon.apimgt.rest.api.gateway.dto.ErrorDTO) ArrayList(java.util.ArrayList) SubscriptionDataStore(org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore) Application(org.wso2.carbon.apimgt.keymgt.model.entity.Application) ApplicationListDTO(org.wso2.carbon.apimgt.rest.api.gateway.dto.ApplicationListDTO)

Aggregations

ArrayList (java.util.ArrayList)10 Application (org.wso2.carbon.apimgt.core.models.Application)8 Test (org.junit.Test)4 Response (javax.ws.rs.core.Response)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 Application (org.wso2.carbon.apimgt.keymgt.model.entity.Application)3 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)2 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)2 ApplicationCreationResponse (org.wso2.carbon.apimgt.core.workflow.ApplicationCreationResponse)2 GeneralWorkflowResponse (org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse)2 ApplicationDTO (org.wso2.carbon.apimgt.rest.api.core.dto.ApplicationDTO)2 ApplicationListDTO (org.wso2.carbon.apimgt.rest.api.core.dto.ApplicationListDTO)2 ApplicationListDTO (org.wso2.carbon.apimgt.rest.api.gateway.dto.ApplicationListDTO)2 Request (org.wso2.msf4j.Request)2 Gson (com.google.gson.Gson)1 IOException (java.io.IOException)1