use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationDTO in project carbon-apimgt by wso2.
the class ApplicationsApiServiceImplTestCase method testApplicationsPostErrorCase.
@Test
public void testApplicationsPostErrorCase() throws APIManagementException, NotFoundException {
TestUtil.printTestMethodName();
String applicationId = UUID.randomUUID().toString();
String accessToken = UUID.randomUUID().toString();
String clientID = UUID.randomUUID().toString();
String clientSecret = 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 application = getSampleApplication(applicationId);
WorkflowResponse workflowResponse = new GeneralWorkflowResponse();
workflowResponse.setWorkflowStatus(WorkflowStatus.APPROVED);
ApplicationCreationResponse creationResponse = new ApplicationCreationResponse(UUID.randomUUID().toString(), workflowResponse);
Mockito.when(apiStore.addApplication(application)).thenReturn(creationResponse);
Mockito.when(apiStore.getApplication(creationResponse.getApplicationUUID(), USER)).thenReturn(application);
ApplicationTokenDTO applicationTokenDTO = new ApplicationTokenDTO();
applicationTokenDTO.setAccessToken(accessToken);
applicationTokenDTO.setTokenScopes("SCOPE1");
applicationTokenDTO.setValidityTime((long) 100000);
List<String> grantTypes = new ArrayList<>();
grantTypes.add("password");
grantTypes.add("jwt");
ApplicationKeysDTO applicationKeysDTO = new ApplicationKeysDTO();
applicationKeysDTO.setConsumerKey(clientID);
applicationKeysDTO.setConsumerSecret(clientSecret);
applicationKeysDTO.setKeyType(ApplicationKeysDTO.KeyTypeEnum.PRODUCTION);
applicationKeysDTO.setCallbackUrl(null);
applicationKeysDTO.setSupportedGrantTypes(grantTypes);
List<ApplicationKeysDTO> applicationKeysDTOList = new ArrayList<>();
applicationKeysDTOList.add(applicationKeysDTO);
ApplicationDTO applicationDTO = new ApplicationDTO();
applicationDTO.setApplicationId(applicationId);
applicationDTO.setDescription("sample application");
applicationDTO.setName("app1");
applicationDTO.setSubscriber("subscriber");
applicationDTO.setPermission("permission");
applicationDTO.setLifeCycleStatus("APPROVED");
applicationDTO.setThrottlingTier("UNLIMITED");
applicationDTO.setToken(applicationTokenDTO);
applicationDTO.setKeys(applicationKeysDTOList);
Response response = applicationsApiService.applicationsPost(applicationDTO, request);
Assert.assertEquals(201, response.getStatus());
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationDTO in project carbon-apimgt by wso2.
the class ApplicationsApiServiceImplTestCase method testApplicationsApplicationIdPut.
@Test
public void testApplicationsApplicationIdPut() throws APIManagementException, NotFoundException {
TestUtil.printTestMethodName();
String applicationId = UUID.randomUUID().toString();
String accessToken = UUID.randomUUID().toString();
String clientID = UUID.randomUUID().toString();
String clientSecret = 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);
ApplicationTokenDTO applicationTokenDTO = new ApplicationTokenDTO();
applicationTokenDTO.setAccessToken(accessToken);
applicationTokenDTO.setTokenScopes("SCOPE1");
applicationTokenDTO.setValidityTime((long) 100000);
List<String> grantTypes = new ArrayList<>();
grantTypes.add("password");
grantTypes.add("jwt");
ApplicationKeysDTO applicationKeysDTO = new ApplicationKeysDTO();
applicationKeysDTO.setConsumerKey(clientID);
applicationKeysDTO.setConsumerSecret(clientSecret);
applicationKeysDTO.setKeyType(ApplicationKeysDTO.KeyTypeEnum.PRODUCTION);
applicationKeysDTO.setCallbackUrl(null);
applicationKeysDTO.setSupportedGrantTypes(grantTypes);
List<ApplicationKeysDTO> applicationKeysDTOList = new ArrayList<>();
applicationKeysDTOList.add(applicationKeysDTO);
ApplicationDTO applicationDTO = new ApplicationDTO();
applicationDTO.setApplicationId(applicationId);
applicationDTO.setDescription("sample application");
applicationDTO.setName("app1");
applicationDTO.setSubscriber("subscriber");
applicationDTO.setPermission("permission");
applicationDTO.setLifeCycleStatus("APPROVED");
applicationDTO.setThrottlingTier("UNLIMITED");
applicationDTO.setToken(applicationTokenDTO);
applicationDTO.setKeys(applicationKeysDTOList);
WorkflowResponse workflowResponse = new GeneralWorkflowResponse();
workflowResponse.setWorkflowStatus(WorkflowStatus.APPROVED);
Mockito.when(apiStore.getApplication(applicationId, USER)).thenReturn(getSampleApplication(applicationId));
Mockito.when(apiStore.updateApplication(applicationId, getSampleApplication(applicationId))).thenReturn(workflowResponse);
Mockito.when(apiStore.getApplication(applicationId, USER)).thenReturn(getSampleApplication(applicationId));
Response response = applicationsApiService.applicationsApplicationIdPut(applicationId, applicationDTO, null, null, request);
Assert.assertEquals(200, response.getStatus());
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationDTO in project carbon-apimgt by wso2.
the class MappingUtil method toApplicationDto.
/**
* This method convert Application model to ApplicationEvent
* @param application Contains application data
* @return DTO containing application data
*/
public static ApplicationDTO toApplicationDto(Application application) {
ApplicationDTO applicationDTO = new ApplicationDTO();
applicationDTO.setApplicationId(application.getId());
applicationDTO.setDescription(application.getDescription());
applicationDTO.setName(application.getName());
applicationDTO.setSubscriber(application.getCreatedUser());
if (application.getPolicy() != null) {
applicationDTO.setThrottlingTier(application.getPolicy().getPolicyName());
}
return applicationDTO;
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationDTO in project product-microgateway by wso2.
the class HTTP2RequestsWithHTTP2BackEndTestCase method setup.
@BeforeClass
public void setup() throws Exception {
String label = "http2TestLabel";
String project = "http2TestProject";
// get mock APIM Instance
MockAPIPublisher pub = MockAPIPublisher.getInstance();
API api = new API();
api.setName("PizzaShackAPI");
api.setContext("/pizzashack");
api.setEndpoint("https://localhost:8443");
api.setVersion("1.0.0");
api.setProvider("admin");
// Register API with label
pub.addApi(label, api);
API api2 = new API();
api2.setName("PizzaShackAPINew");
api2.setContext("/pizzashack1");
api2.setEndpoint(getMockServiceURLHttp("/echo"));
api2.setVersion("2.0.0");
api2.setProvider("admin");
// Register API with label
pub.addApi(label, api);
// Define application info
ApplicationDTO application = new ApplicationDTO();
application.setName("jwtApp");
application.setTier("Unlimited");
application.setId((int) (Math.random() * 1000));
// Register a production token with key validation info
KeyValidationInfo info = new KeyValidationInfo();
info.setApi(api);
info.setApplication(application);
info.setAuthorized(true);
info.setKeyType(TestConstant.KEY_TYPE_PRODUCTION);
info.setSubscriptionTier("Unlimited");
String configPath = "confs/http2-test.conf";
super.init(label, project, configPath);
jwtTokenProd = getJWT(api, application, "Unlimited", TestConstant.KEY_TYPE_PRODUCTION, 3600);
boolean isOpen2 = Utils.isPortOpen(MOCK_HTTP2_SERVER_PORT);
Assert.assertFalse(isOpen2, "Port: " + MOCK_HTTP2_SERVER_PORT + " already in use.");
mockHttp2Server = new MockHttp2Server(MOCK_HTTP2_SERVER_PORT, true);
mockHttp2Server.start();
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationDTO in project product-microgateway by wso2.
the class InterceptorTestCase method start.
@BeforeClass
public void start() throws Exception {
String project = "interceptorProject";
// Define application info
ApplicationDTO application = new ApplicationDTO();
application.setName("jwtApp");
application.setTier("Unlimited");
application.setId((int) (Math.random() * 1000));
jwtTokenProd = TokenUtil.getBasicJWT(application, new JSONObject(), TestConstant.KEY_TYPE_PRODUCTION, 3600);
// generate apis with CLI and start the micro gateway server
super.init(project, new String[] { "interceptor/interceptor.yaml", "interceptor/validateRequest.bal", "interceptor/interceptPerAPIRequest.bal", "interceptor/interceptPerAPIResponse.bal", "interceptor/validateResponse.bal", "interceptor/PerAPIInterceptor.yaml", "mgw-interceptor.jar" });
}
Aggregations