use of org.wso2.carbon.apimgt.api.model.Subscriber in project carbon-apimgt by wso2.
the class ApplicationCreationWSWorkflowExecutorTest method testWorkflowExecute.
@Test
public void testWorkflowExecute() throws Exception {
ApplicationWorkflowDTO workflowDTO = new ApplicationWorkflowDTO();
Application application = new Application("TestAPP", new Subscriber(null));
application.setTier("Gold");
application.setCallbackUrl("www.wso2.com");
application.setDescription("Description");
workflowDTO.setApplication(application);
workflowDTO.setTenantDomain("wso2");
workflowDTO.setUserName("admin");
workflowDTO.setCallbackUrl("http://localhost:8280/workflow-callback");
workflowDTO.setWorkflowReference("1");
workflowDTO.setExternalWorkflowReference(UUID.randomUUID().toString());
PowerMockito.doNothing().when(apiMgtDAO).updateSubscriptionStatus(Integer.parseInt(workflowDTO.getWorkflowReference()), APIConstants.SubscriptionStatus.REJECTED);
ServiceReferenceHolderMockCreator serviceRefMock = new ServiceReferenceHolderMockCreator(-1234);
ServiceReferenceHolderMockCreator.initContextService();
PowerMockito.whenNew(ServiceClient.class).withArguments(Mockito.any(ConfigurationContext.class), Mockito.any(AxisService.class)).thenReturn(serviceClient);
try {
Assert.assertNotNull(applicationCreationWSWorkflowExecutor.execute(workflowDTO));
} catch (WorkflowException e) {
Assert.fail("Unexpected WorkflowException occurred while executing Subscription creation ws workflow");
}
}
use of org.wso2.carbon.apimgt.api.model.Subscriber in project carbon-apimgt by wso2.
the class ApplicationCreationWSWorkflowExecutorTest method testWorkflowExecuteWithLimitedParam.
@Test
public void testWorkflowExecuteWithLimitedParam() throws Exception {
// application without a callback url
ApplicationWorkflowDTO workflowDTO = new ApplicationWorkflowDTO();
Application application = new Application("TestAPP", new Subscriber(null));
application.setTier("Gold");
application.setDescription("Description");
workflowDTO.setApplication(application);
workflowDTO.setTenantDomain("wso2");
workflowDTO.setUserName("admin");
workflowDTO.setWorkflowReference("1");
workflowDTO.setExternalWorkflowReference(UUID.randomUUID().toString());
PowerMockito.doNothing().when(apiMgtDAO).updateSubscriptionStatus(Integer.parseInt(workflowDTO.getWorkflowReference()), APIConstants.SubscriptionStatus.REJECTED);
ServiceReferenceHolderMockCreator serviceRefMock = new ServiceReferenceHolderMockCreator(-1234);
ServiceReferenceHolderMockCreator.initContextService();
PowerMockito.whenNew(ServiceClient.class).withArguments(Mockito.any(ConfigurationContext.class), Mockito.any(AxisService.class)).thenReturn(serviceClient);
try {
Assert.assertNotNull(applicationCreationWSWorkflowExecutor.execute(workflowDTO));
} catch (WorkflowException e) {
Assert.fail("Unexpected WorkflowException occurred while executing Application creation ws workflow");
}
}
use of org.wso2.carbon.apimgt.api.model.Subscriber in project carbon-apimgt by wso2.
the class ApplicationUtilsTestCase method testRetrieveApplication.
@Test
public void testRetrieveApplication() throws Exception {
String appName = "NewApp";
String owner = "DevX";
String tenant = "wso2.com";
Subscriber subscriber = new Subscriber(owner);
Application newApp = new Application(appName, subscriber);
newApp.setId(3);
newApp.setTier("Gold");
newApp.setDescription("This is a new app");
newApp.setOwner(owner);
newApp.setGroupId("group1");
Mockito.when(apiMgtDAO.getApplicationByName(appName, owner, tenant)).thenReturn(newApp);
Application app = ApplicationUtils.retrieveApplication(appName, owner, tenant);
Assert.assertEquals(newApp, app);
Assert.assertEquals(newApp.getDescription(), app.getDescription());
Assert.assertEquals(newApp.getOwner(), app.getOwner());
Assert.assertEquals(newApp.getGroupId(), app.getGroupId());
Assert.assertEquals(newApp.getTier(), app.getTier());
}
use of org.wso2.carbon.apimgt.api.model.Subscriber in project carbon-apimgt by wso2.
the class SelfSignupUtilTestCase method testGetRoleNames.
@Test
public void testGetRoleNames() {
UserRegistrationConfigDTO userRegistrationConfigDTO = new UserRegistrationConfigDTO();
Map<String, Boolean> roles = new HashMap();
roles.put("subscriber", true);
roles.put("creator", false);
userRegistrationConfigDTO.setRoles(roles);
userRegistrationConfigDTO.setSignUpDomain("foo.com");
List<String> roleList = SelfSignUpUtil.getRoleNames(userRegistrationConfigDTO);
Assert.assertEquals(2, roleList.size());
}
use of org.wso2.carbon.apimgt.api.model.Subscriber in project carbon-apimgt by wso2.
the class SubscriberInfoLoader method handleThrottle.
private boolean handleThrottle(WebhooksDTO subscriber, MessageContext messageContext) {
AuthenticationContext authContext = new AuthenticationContext();
populateAuthContext(subscriber.getTenantDomain(), Integer.parseInt(subscriber.getAppID()), authContext);
messageContext.setProperty(APISecurityUtils.API_AUTH_CONTEXT, authContext);
if (subscriber.isThrottled()) {
if (APIUtil.isAnalyticsEnabled()) {
String errorMessage = "Message throttled out";
String errorDescription = "You have exceeded your quota";
int errorCode = APIThrottleConstants.EVENTS_COUNT_THROTTLE_OUT_ERROR_CODE;
messageContext.setProperty(SynapseConstants.ERROR_CODE, errorCode);
messageContext.setProperty(SynapseConstants.ERROR_MESSAGE, errorMessage);
messageContext.setProperty(SynapseConstants.ERROR_DETAIL, errorDescription);
messageContext.setProperty(Constants.BACKEND_RESPONSE_CODE, APIThrottleConstants.SC_TOO_MANY_REQUESTS);
((Axis2MessageContext) messageContext).getAxis2MessageContext().setProperty(SynapseConstants.HTTP_SC, APIThrottleConstants.SC_TOO_MANY_REQUESTS);
WebhooksUtils.publishAnalyticsData(messageContext);
}
return false;
}
if (doThrottle(subscriber, messageContext, authContext)) {
messageContext.setProperty(APIConstants.Webhooks.SUBSCRIBER_CALLBACK_PROPERTY, subscriber.getCallbackURL());
String errorMessage = "Message throttled out";
String errorDescription = "You have exceeded your quota";
int errorCode = APIThrottleConstants.EVENTS_COUNT_THROTTLE_OUT_ERROR_CODE;
int httpErrorCode = APIThrottleConstants.SC_TOO_MANY_REQUESTS;
messageContext.setProperty(SynapseConstants.ERROR_CODE, errorCode);
messageContext.setProperty(SynapseConstants.ERROR_MESSAGE, errorMessage);
messageContext.setProperty(SynapseConstants.ERROR_DETAIL, errorDescription);
messageContext.setProperty(APIMgtGatewayConstants.HTTP_RESPONSE_STATUS_CODE, httpErrorCode);
org.apache.axis2.context.MessageContext axis2MC = ((Axis2MessageContext) messageContext).getAxis2MessageContext();
// This property need to be set to avoid sending the content in pass-through pipe (request message)
// as the response.
axis2MC.setProperty(PassThroughConstants.MESSAGE_BUILDER_INVOKED, Boolean.TRUE);
try {
RelayUtils.consumeAndDiscardMessage(axis2MC);
} catch (AxisFault axisFault) {
// In case of an error it is logged and the process is continued because we're setting a fault message
// in the payload.
log.error("Error occurred while consuming and discarding the message", axisFault);
}
if (APIUtil.isAnalyticsEnabled()) {
messageContext.setProperty(Constants.BACKEND_RESPONSE_CODE, httpErrorCode);
((Axis2MessageContext) messageContext).getAxis2MessageContext().setProperty(SynapseConstants.HTTP_SC, APIThrottleConstants.SC_TOO_MANY_REQUESTS);
WebhooksUtils.publishAnalyticsData(messageContext);
}
Mediator sequence = messageContext.getSequence(APIThrottleConstants.API_THROTTLE_OUT_HANDLER);
// Invoke the custom error handler specified by the user
if (sequence != null && !sequence.mediate(messageContext)) {
// logic from getting executed
return true;
}
Utils.sendFault(messageContext, httpErrorCode);
}
return true;
}
Aggregations