use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.Application in project carbon-apimgt by wso2.
the class GatewaysApiServiceImplTestCase method gatewaysRegisterPostTest.
@Test
public void gatewaysRegisterPostTest() throws Exception {
APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
RegistrationDTO registrationDTO = Mockito.mock(RegistrationDTO.class);
LabelInfoDTO labelInfoDTO = Mockito.mock(LabelInfoDTO.class);
Mockito.when(registrationDTO.getLabelInfo()).thenReturn(labelInfoDTO);
RegistrationSummary registrationSummary = Mockito.mock(RegistrationSummary.class);
Mockito.when(adminService.getRegistrationSummary()).thenReturn(registrationSummary);
RegistrationSummary.AnalyticsInfo analyticsInfo = Mockito.mock(RegistrationSummary.AnalyticsInfo.class);
Mockito.when(registrationSummary.getAnalyticsInfo()).thenReturn(analyticsInfo);
RegistrationSummary.Credentials dssCredentials = Mockito.mock(RegistrationSummary.Credentials.class);
Mockito.when(registrationSummary.getAnalyticsInfo().getDasServerCredentials()).thenReturn(dssCredentials);
Mockito.when(dssCredentials.getUsername()).thenReturn(DSS_USERNAME);
Mockito.when(dssCredentials.getPassword()).thenReturn(DSS_PASSWORD);
RegistrationSummary.JWTInfo jwtInfo = Mockito.mock(RegistrationSummary.JWTInfo.class);
Mockito.when(registrationSummary.getJwtInfo()).thenReturn(jwtInfo);
RegistrationSummary.KeyManagerInfo keyManagerInfo = Mockito.mock(RegistrationSummary.KeyManagerInfo.class);
Mockito.when(registrationSummary.getKeyManagerInfo()).thenReturn(keyManagerInfo);
RegistrationSummary.Credentials keyManagerCredentials = Mockito.mock(RegistrationSummary.Credentials.class);
Mockito.when(registrationSummary.getKeyManagerInfo().getCredentials()).thenReturn(keyManagerCredentials);
Mockito.when(keyManagerCredentials.getUsername()).thenReturn(KEY_MANAGER_USERNAME);
Mockito.when(keyManagerCredentials.getPassword()).thenReturn(KEY_MANAGER_PASSWORD);
RegistrationSummary.ThrottlingInfo throttlingInfo = Mockito.mock(RegistrationSummary.ThrottlingInfo.class);
Mockito.when(registrationSummary.getThrottlingInfo()).thenReturn(throttlingInfo);
RegistrationSummary.ThrottlingInfo.DataPublisher dataPublisher = Mockito.mock(RegistrationSummary.ThrottlingInfo.DataPublisher.class);
Mockito.when(registrationSummary.getThrottlingInfo().getDataPublisher()).thenReturn(dataPublisher);
RegistrationSummary.Credentials throttlingServerCredentials = Mockito.mock(RegistrationSummary.Credentials.class);
Mockito.when(registrationSummary.getThrottlingInfo().getDataPublisher().getCredentials()).thenReturn(throttlingServerCredentials);
Mockito.when(throttlingServerCredentials.getUsername()).thenReturn(THROTTLE_SERVER_USERNAME);
Mockito.when(throttlingServerCredentials.getPassword()).thenReturn(THROTTLE_SERVER_PASSWORD);
RegistrationSummary.GoogleAnalyticsTrackingInfo googleAnalyticsTrackingInfo = Mockito.mock(RegistrationSummary.GoogleAnalyticsTrackingInfo.class);
Mockito.when(registrationSummary.getGoogleAnalyticsTrackingInfo()).thenReturn(googleAnalyticsTrackingInfo);
GatewaysApiServiceImpl gatewaysApiService = new GatewaysApiServiceImpl();
Response response = gatewaysApiService.gatewaysRegisterPost(registrationDTO, "application/json", getRequest());
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
CredentialsDTO analyticsInfoResponseCredentials = ((RegistrationSummaryDTO) response.getEntity()).getAnalyticsInfo().getCredentials();
CredentialsDTO keyManagerInfoResponseCredentials = ((RegistrationSummaryDTO) response.getEntity()).getKeyManagerInfo().getCredentials();
CredentialsDTO throttleServerInfoResponseCredentials = ((RegistrationSummaryDTO) response.getEntity()).getThrottlingInfo().getCredentials();
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
Assert.assertEquals(analyticsInfoResponseCredentials.getUsername(), DSS_USERNAME);
Assert.assertEquals(analyticsInfoResponseCredentials.getPassword(), DSS_PASSWORD);
Assert.assertEquals(keyManagerInfoResponseCredentials.getUsername(), KEY_MANAGER_USERNAME);
Assert.assertEquals(keyManagerInfoResponseCredentials.getPassword(), KEY_MANAGER_PASSWORD);
Assert.assertEquals(throttleServerInfoResponseCredentials.getUsername(), THROTTLE_SERVER_USERNAME);
Assert.assertEquals(throttleServerInfoResponseCredentials.getPassword(), THROTTLE_SERVER_PASSWORD);
}
use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.Application in project carbon-apimgt by wso2.
the class MappingUtilTestCase method convertToApplicationDtoListTest.
@Test
public void convertToApplicationDtoListTest() {
List<Application> applicationList = new ArrayList<>();
applicationList.add(SampleTestObjectCreator.createRandomApplication());
applicationList.add(SampleTestObjectCreator.createRandomApplication());
applicationList.add(SampleTestObjectCreator.createRandomApplication());
List<ApplicationDTO> applicationDTOList = MappingUtil.convertToApplicationDtoList(applicationList);
Assert.assertEquals(applicationList.size(), applicationDTOList.size());
for (int i = 0; i < applicationList.size(); i++) {
Assert.assertEquals(applicationList.get(i).getName(), applicationDTOList.get(i).getName());
Assert.assertEquals(applicationList.get(i).getId(), applicationDTOList.get(i).getApplicationId());
Assert.assertEquals(applicationList.get(i).getPolicy().getUuid(), applicationDTOList.get(i).getThrottlingTier());
Assert.assertEquals(applicationList.get(i).getCreatedUser(), applicationDTOList.get(i).getSubscriber());
}
}
use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.Application in project carbon-apimgt by wso2.
the class SubscriptionsApiServiceImpl method subscriptionsPost.
/**
* Adds a new subscription
*
* @param body Subscription details to be added
* @param request msf4j request object
* @return Newly added subscription as the response
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response subscriptionsPost(SubscriptionDTO body, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
SubscriptionDTO subscriptionDTO = null;
URI location = null;
try {
APIStore apiStore = RestApiUtil.getConsumer(username);
String applicationId = body.getApplicationId();
String apiId = body.getApiIdentifier();
String tier = body.getPolicy();
Application application = apiStore.getApplicationByUuid(applicationId);
if (application != null && !ApplicationStatus.APPLICATION_APPROVED.equals(application.getStatus())) {
String errorMessage = "Application " + applicationId + " is not active";
ExceptionCodes exceptionCode = ExceptionCodes.APPLICATION_INACTIVE;
APIManagementException e = new APIManagementException(errorMessage, exceptionCode);
Map<String, String> paramList = new HashMap<>();
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
if (application != null) {
SubscriptionResponse addSubResponse = apiStore.addApiSubscription(apiId, applicationId, tier);
String subscriptionId = addSubResponse.getSubscriptionUUID();
Subscription subscription = apiStore.getSubscriptionByUUID(subscriptionId);
location = new URI(RestApiConstants.RESOURCE_PATH_SUBSCRIPTION + "/" + subscriptionId);
subscriptionDTO = SubscriptionMappingUtil.fromSubscriptionToDTO(subscription);
// be in either pending or approved state) send back the workflow response
if (SubscriptionStatus.ON_HOLD == subscription.getStatus()) {
WorkflowResponseDTO workflowResponse = MiscMappingUtil.fromWorkflowResponseToDTO(addSubResponse.getWorkflowResponse());
return Response.status(Response.Status.ACCEPTED).header(RestApiConstants.LOCATION_HEADER, location).entity(workflowResponse).build();
}
} else {
String errorMessage = null;
ExceptionCodes exceptionCode = null;
exceptionCode = ExceptionCodes.APPLICATION_NOT_FOUND;
errorMessage = "Application not found";
APIMgtResourceNotFoundException e = new APIMgtResourceNotFoundException(errorMessage, exceptionCode);
Map<String, String> paramList = new HashMap<>();
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
} catch (GatewayException e) {
String errorMessage = "Failed to add subscription of API : " + body.getApiIdentifier() + " to gateway";
log.error(errorMessage, e);
return Response.status(Response.Status.ACCEPTED).build();
} catch (APIManagementException e) {
String errorMessage = "Error while adding subscriptions";
Map<String, String> paramList = new HashMap<>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, body.getApiIdentifier());
paramList.put(APIMgtConstants.ExceptionsConstants.APPLICATION_ID, body.getApplicationId());
paramList.put(APIMgtConstants.ExceptionsConstants.TIER, body.getPolicy());
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
} catch (URISyntaxException e) {
String errorMessage = "Error while adding location header in response for subscription : " + body.getSubscriptionId();
Map<String, String> paramList = new HashMap<>();
paramList.put(APIMgtConstants.ExceptionsConstants.SUBSCRIPTION_ID, body.getSubscriptionId());
ErrorHandler errorHandler = ExceptionCodes.LOCATION_HEADER_INCORRECT;
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(errorHandler, paramList);
log.error(errorMessage, e);
return Response.status(errorHandler.getHttpStatusCode()).entity(errorDTO).build();
}
return Response.status(Response.Status.CREATED).header(RestApiConstants.LOCATION_HEADER, location).entity(subscriptionDTO).build();
}
use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.Application in project carbon-apimgt by wso2.
the class ApplicationImportExportManager method updateApplication.
/**
* Update details of an existing Application when imported
*
* @param importedApplication
* @param username
* @throws APIManagementException
*/
public Application updateApplication(Application importedApplication, String username) throws APIManagementException {
Application updatedApp = null;
try {
if (getApplicationDAO().isApplicationNameExists(importedApplication.getName())) {
Application existingApplication = apiStore.getApplicationByName(importedApplication.getName(), username);
apiStore.updateApplication(existingApplication.getUuid(), importedApplication);
updatedApp = apiStore.getApplication(existingApplication.getUuid(), username);
}
return updatedApp;
} catch (APIMgtDAOException e) {
String errorMsg = "Error occurred while finding application matching the provided name";
log.error(errorMsg, e);
throw new APIManagementException(errorMsg, e, e.getErrorHandler());
}
}
use of org.wso2.carbon.apimgt.common.analytics.publishers.dto.Application in project carbon-apimgt by wso2.
the class FileBasedApplicationImportExportManager method importApplication.
/**
* Import a given Application from an InputStream
*
* @param uploadedAppArchiveInputStream Content stream of the zip file which contains exported Application
* @return the imported application
* @throws APIMgtEntityImportExportException
*/
public Application importApplication(InputStream uploadedAppArchiveInputStream) throws APIMgtEntityImportExportException {
String appArchiveLocation = path + File.separator + IMPORTED_APPLICATIONS_DIRECTORY_NAME + ".zip";
String archiveExtractLocation = null;
try {
archiveExtractLocation = extractUploadedArchiveApplication(uploadedAppArchiveInputStream, IMPORTED_APPLICATIONS_DIRECTORY_NAME, appArchiveLocation, path);
} catch (APIManagementException e) {
String errorMsg = "Error in accessing uploaded Application archive" + appArchiveLocation;
log.error(errorMsg, e);
throw new APIMgtEntityImportExportException(errorMsg, e, ExceptionCodes.APPLICATION_IMPORT_ERROR);
}
Application applicationDetails = parseApplicationFile(archiveExtractLocation);
return applicationDetails;
}
Aggregations