Search in sources :

Example 1 with LabelInfoDTO

use of org.wso2.carbon.apimgt.rest.api.core.dto.LabelInfoDTO 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 LabelInfoDTO

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

the class GatewaysApiServiceImpl method gatewaysRegisterPost.

/**
 * Register gateway
 *
 * @param body        RegistrationDTO
 * @param contentType Content-Type header value
 * @return Registration summary details
 * @throws NotFoundException If failed to register gateway
 */
@Override
public Response gatewaysRegisterPost(RegistrationDTO body, String contentType, Request request) throws NotFoundException {
    try {
        LabelInfoDTO labelInfoDTO = body.getLabelInfo();
        if (labelInfoDTO != null) {
            APIMgtAdminService adminService = RestApiUtil.getAPIMgtAdminService();
            String overwriteLabels = labelInfoDTO.getOverwriteLabels();
            List<Label> labels = MappingUtil.convertToLabels(labelInfoDTO.getLabelList());
            adminService.registerGatewayLabels(labels, overwriteLabels);
            RegistrationSummary registrationSummary = adminService.getRegistrationSummary();
            return Response.ok().entity(MappingUtil.toRegistrationSummaryDTO(registrationSummary)).build();
        } else {
            String errorMessage = "Label information cannot be null";
            APIMgtResourceNotFoundException e = new APIMgtResourceNotFoundException(errorMessage, ExceptionCodes.LABEL_INFORMATION_CANNOT_BE_NULL);
            HashMap<String, String> paramList = new HashMap<String, String>();
            org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
            log.error(errorMessage, e);
            return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
        }
    } catch (APIManagementException e) {
        String errorMessage = "Error while registering the gateway";
        HashMap<String, String> paramList = new HashMap<String, String>();
        org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : HashMap(java.util.HashMap) Label(org.wso2.carbon.apimgt.core.models.Label) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.core.exception.APIMgtResourceNotFoundException) LabelInfoDTO(org.wso2.carbon.apimgt.rest.api.core.dto.LabelInfoDTO) APIMgtAdminService(org.wso2.carbon.apimgt.core.api.APIMgtAdminService) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) RegistrationSummary(org.wso2.carbon.apimgt.core.models.RegistrationSummary)

Example 3 with LabelInfoDTO

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

the class GatewaysApiServiceImplTestCase method gatewaysRegisterPostExceptionTest.

@Test
public void gatewaysRegisterPostExceptionTest() throws Exception {
    RegistrationDTO registrationDTO = Mockito.mock(RegistrationDTO.class);
    LabelInfoDTO labelInfoDTO = Mockito.mock(LabelInfoDTO.class);
    Mockito.when(registrationDTO.getLabelInfo()).thenReturn(labelInfoDTO);
    GatewaysApiServiceImpl gatewaysApiService = new GatewaysApiServiceImpl();
    Response response = gatewaysApiService.gatewaysRegisterPost(registrationDTO, "application/json", getRequest());
    Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
Also used : LabelInfoDTO(org.wso2.carbon.apimgt.rest.api.core.dto.LabelInfoDTO) Response(javax.ws.rs.core.Response) RegistrationDTO(org.wso2.carbon.apimgt.rest.api.core.dto.RegistrationDTO) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

LabelInfoDTO (org.wso2.carbon.apimgt.rest.api.core.dto.LabelInfoDTO)3 Response (javax.ws.rs.core.Response)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 RegistrationSummary (org.wso2.carbon.apimgt.core.models.RegistrationSummary)2 RegistrationDTO (org.wso2.carbon.apimgt.rest.api.core.dto.RegistrationDTO)2 HashMap (java.util.HashMap)1 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)1 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)1 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.core.exception.APIMgtResourceNotFoundException)1 APIMgtAdminServiceImpl (org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl)1 Label (org.wso2.carbon.apimgt.core.models.Label)1 CredentialsDTO (org.wso2.carbon.apimgt.rest.api.core.dto.CredentialsDTO)1