Search in sources :

Example 1 with CredentialsDTO

use of org.wso2.carbon.apimgt.rest.api.core.dto.CredentialsDTO 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);
}
Also used : APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) LabelInfoDTO(org.wso2.carbon.apimgt.rest.api.core.dto.LabelInfoDTO) Response(javax.ws.rs.core.Response) CredentialsDTO(org.wso2.carbon.apimgt.rest.api.core.dto.CredentialsDTO) RegistrationDTO(org.wso2.carbon.apimgt.rest.api.core.dto.RegistrationDTO) RegistrationSummary(org.wso2.carbon.apimgt.core.models.RegistrationSummary) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with CredentialsDTO

use of org.wso2.carbon.apimgt.rest.api.core.dto.CredentialsDTO in project carbon-apimgt by wso2.

the class MappingUtil method toAnalyticsDTO.

/**
 * Converts RegistrationSummary analytics information into AnalyticsInfoDTO
 *
 * @param registrationSummary the registration summary required by gateway
 * @return AnalyticsInfoDTO
 */
private static AnalyticsInfoDTO toAnalyticsDTO(RegistrationSummary registrationSummary) {
    AnalyticsInfoDTO analyticsInfoDTO = new AnalyticsInfoDTO();
    analyticsInfoDTO.serverURL(registrationSummary.getAnalyticsInfo().getDasServerURL());
    analyticsInfoDTO.setEnabled(registrationSummary.getAnalyticsInfo().isEnabled());
    CredentialsDTO analyticsServerCredentials = new CredentialsDTO();
    analyticsServerCredentials.setUsername(registrationSummary.getAnalyticsInfo().getDasServerCredentials().getUsername());
    analyticsServerCredentials.setPassword(registrationSummary.getAnalyticsInfo().getDasServerCredentials().getPassword());
    analyticsInfoDTO.setCredentials(analyticsServerCredentials);
    return analyticsInfoDTO;
}
Also used : CredentialsDTO(org.wso2.carbon.apimgt.rest.api.core.dto.CredentialsDTO) AnalyticsInfoDTO(org.wso2.carbon.apimgt.rest.api.core.dto.AnalyticsInfoDTO)

Example 3 with CredentialsDTO

use of org.wso2.carbon.apimgt.rest.api.core.dto.CredentialsDTO in project carbon-apimgt by wso2.

the class MappingUtil method toThrottlingInfoDTO.

/**
 * Converts RegistrationSummary Throttling information into ThrottlingInfoDTO
 *
 * @param registrationSummary the registration summary required by gateway
 * @return ThrottlingInfoDTO
 */
private static ThrottlingInfoDTO toThrottlingInfoDTO(RegistrationSummary registrationSummary) {
    ThrottlingInfoDTO throttlingInfoDTO = new ThrottlingInfoDTO();
    throttlingInfoDTO.serverURL(registrationSummary.getThrottlingInfo().getDataPublisher().getReceiverURL());
    CredentialsDTO throttlingServerCredentials = new CredentialsDTO();
    throttlingServerCredentials.setUsername(registrationSummary.getThrottlingInfo().getDataPublisher().getCredentials().getUsername());
    throttlingServerCredentials.setPassword(registrationSummary.getThrottlingInfo().getDataPublisher().getCredentials().getPassword());
    throttlingInfoDTO.setCredentials(throttlingServerCredentials);
    return throttlingInfoDTO;
}
Also used : CredentialsDTO(org.wso2.carbon.apimgt.rest.api.core.dto.CredentialsDTO) ThrottlingInfoDTO(org.wso2.carbon.apimgt.rest.api.core.dto.ThrottlingInfoDTO)

Example 4 with CredentialsDTO

use of org.wso2.carbon.apimgt.rest.api.core.dto.CredentialsDTO in project carbon-apimgt by wso2.

the class MappingUtil method toKeyManagerInfoDTO.

/**
 * Converts RegistrationSummary key manager information into KeyManagerInfoDTO
 *
 * @param registrationSummary the registration summary required by gateway
 * @return KeyManagerInfoDTO
 */
private static KeyManagerInfoDTO toKeyManagerInfoDTO(RegistrationSummary registrationSummary) {
    KeyManagerInfoDTO keyManagerInfoDTO = new KeyManagerInfoDTO();
    keyManagerInfoDTO.setDcrEndpoint(registrationSummary.getKeyManagerInfo().getDcrEndpoint());
    keyManagerInfoDTO.setIntrospectEndpoint(registrationSummary.getKeyManagerInfo().getIntrospectEndpoint());
    keyManagerInfoDTO.setRevokeEndpoint(registrationSummary.getKeyManagerInfo().getRevokeEndpoint());
    keyManagerInfoDTO.setTokenEndpoint(registrationSummary.getKeyManagerInfo().getTokenEndpoint());
    CredentialsDTO keyManagerCredentials = new CredentialsDTO();
    keyManagerCredentials.setUsername(registrationSummary.getKeyManagerInfo().getCredentials().getUsername());
    keyManagerCredentials.setPassword(registrationSummary.getKeyManagerInfo().getCredentials().getPassword());
    keyManagerInfoDTO.setCredentials(keyManagerCredentials);
    return keyManagerInfoDTO;
}
Also used : CredentialsDTO(org.wso2.carbon.apimgt.rest.api.core.dto.CredentialsDTO) KeyManagerInfoDTO(org.wso2.carbon.apimgt.rest.api.core.dto.KeyManagerInfoDTO)

Aggregations

CredentialsDTO (org.wso2.carbon.apimgt.rest.api.core.dto.CredentialsDTO)4 Response (javax.ws.rs.core.Response)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 APIMgtAdminServiceImpl (org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl)1 RegistrationSummary (org.wso2.carbon.apimgt.core.models.RegistrationSummary)1 AnalyticsInfoDTO (org.wso2.carbon.apimgt.rest.api.core.dto.AnalyticsInfoDTO)1 KeyManagerInfoDTO (org.wso2.carbon.apimgt.rest.api.core.dto.KeyManagerInfoDTO)1 LabelInfoDTO (org.wso2.carbon.apimgt.rest.api.core.dto.LabelInfoDTO)1 RegistrationDTO (org.wso2.carbon.apimgt.rest.api.core.dto.RegistrationDTO)1 ThrottlingInfoDTO (org.wso2.carbon.apimgt.rest.api.core.dto.ThrottlingInfoDTO)1