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);
}
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;
}
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());
}
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());
}
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();
}
Aggregations