Search in sources :

Example 86 with Label

use of org.wso2.carbon.apimgt.core.models.Label in project carbon-apimgt by wso2.

the class LabelMappingUtil method fromLabelArrayToListDTO.

/**
 * Converts an array of label model objects into REST API DTO objects.
 *
 * @param labelList An array of Label model objects
 * @return A List DTO of Label DTOs derived from the array of model objects
 */
public static LabelListDTO fromLabelArrayToListDTO(List<Label> labelList) {
    LabelListDTO listDTO = new LabelListDTO();
    List<LabelDTO> labelDTOList = new ArrayList<>();
    if (labelList != null) {
        for (Label label : labelList) {
            LabelDTO dto = fromLabelToDTO(label);
            labelDTOList.add(dto);
        }
    }
    listDTO.setCount(labelDTOList.size());
    listDTO.setList(labelDTOList);
    return listDTO;
}
Also used : ArrayList(java.util.ArrayList) Label(org.wso2.carbon.apimgt.core.models.Label) LabelDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.LabelDTO) LabelListDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.LabelListDTO)

Example 87 with Label

use of org.wso2.carbon.apimgt.core.models.Label in project carbon-apimgt by wso2.

the class LabelsApiServiceImplTest method testLabelsGetWithoutLabelId.

@Test
public void testLabelsGetWithoutLabelId() throws Exception {
    APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
    List<Label> labels = new ArrayList<>();
    Label label1 = new Label.Builder().id("1").name("label1").type("GATEWAY").build();
    Label label2 = new Label.Builder().id("2").name("label2").type("STORE").build();
    labels.add(label1);
    labels.add(label2);
    LabelsApiServiceImpl labelService = new LabelsApiServiceImpl();
    Mockito.when(labelService.labelsGet(null, null, getRequest())).thenReturn(Response.status(Response.Status.OK).entity(LabelMappingUtil.fromLabelArrayToListDTO(labels)).build());
    Response response = labelService.labelsGet(null, null, getRequest());
    Assert.assertEquals(response.getEntity(), LabelMappingUtil.fromLabelArrayToListDTO(labels));
}
Also used : Response(javax.ws.rs.core.Response) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) Label(org.wso2.carbon.apimgt.core.models.Label) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 88 with Label

use of org.wso2.carbon.apimgt.core.models.Label in project carbon-apimgt by wso2.

the class LabelsApiServiceImplTest method testLabelsGetWithLabelId.

@Test
public void testLabelsGetWithLabelId() throws Exception {
    APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
    List<Label> labels = new ArrayList<>();
    Label label1 = new Label.Builder().id("1").name("label1").type("GATEWAY").build();
    labels.add(label1);
    LabelsApiServiceImpl labelService = new LabelsApiServiceImpl();
    Mockito.when(labelService.labelsGet("1", null, getRequest())).thenReturn(Response.status(Response.Status.OK).entity(LabelMappingUtil.fromLabelArrayToListDTO(labels)).build());
    Response response = labelService.labelsGet(null, null, getRequest());
    Assert.assertEquals(response.getEntity(), LabelMappingUtil.fromLabelArrayToListDTO(labels));
}
Also used : Response(javax.ws.rs.core.Response) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) Label(org.wso2.carbon.apimgt.core.models.Label) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 89 with Label

use of org.wso2.carbon.apimgt.core.models.Label in project carbon-apimgt by wso2.

the class LabelsApiServiceImpl method labelsGet.

/**
 * Get all the labels.
 *
 * @param labelType       the type of the labels to be fetched
 * @param accept          Accept header value
 * @param ifNoneMatch     If-None-Match header value
 * @param ifModifiedSince If-Modified-Since header value
 * @param request         ms4j request object
 * @return Lable List
 * @throws NotFoundException If failed to get the label values
 */
@Override
public Response labelsGet(String labelType, String accept, String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
    String username = RestApiUtil.getLoggedInUsername(request);
    try {
        List<Label> labels;
        if (labelType == null) {
            labels = RestAPIPublisherUtil.getApiPublisher(username).getAllLabels();
        } else {
            labels = RestAPIPublisherUtil.getApiPublisher(username).getLabelsByType(labelType);
        }
        LabelListDTO labelListDTO = MappingUtil.toLabelListDTO(labels);
        return Response.ok().entity(labelListDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error occurred while retrieving Labels";
        HashMap<String, String> paramList = new HashMap<String, String>();
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) HashMap(java.util.HashMap) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) Label(org.wso2.carbon.apimgt.core.models.Label) LabelListDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.LabelListDTO)

Example 90 with Label

use of org.wso2.carbon.apimgt.core.models.Label in project carbon-apimgt by wso2.

the class MappingUtilTestCase method convertToLabelsTest.

@Test
public void convertToLabelsTest() {
    List<LabelDTO> labelDTOList = new ArrayList<>();
    labelDTOList.add(SampleTestObjectCreator.createUniqueLabelDTO());
    labelDTOList.add(SampleTestObjectCreator.createUniqueLabelDTO());
    labelDTOList.add(SampleTestObjectCreator.createUniqueLabelDTO());
    labelDTOList.add(SampleTestObjectCreator.createUniqueLabelDTO());
    List<Label> labelList = MappingUtil.convertToLabels(labelDTOList);
    Assert.assertEquals(labelList.size(), labelDTOList.size());
    for (int i = 0; i < labelDTOList.size(); i++) {
        Assert.assertEquals(labelList.get(i).getName(), labelDTOList.get(i).getName());
        Assert.assertEquals(labelList.get(i).getAccessUrls(), labelDTOList.get(i).getAccessUrls());
    }
}
Also used : ArrayList(java.util.ArrayList) Label(org.wso2.carbon.apimgt.core.models.Label) LabelDTO(org.wso2.carbon.apimgt.rest.api.core.dto.LabelDTO) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) Test(org.testng.annotations.Test)

Aggregations

Label (org.wso2.carbon.apimgt.core.models.Label)65 ArrayList (java.util.ArrayList)52 Test (org.testng.annotations.Test)45 LabelDAO (org.wso2.carbon.apimgt.core.dao.LabelDAO)32 API (org.wso2.carbon.apimgt.core.models.API)29 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)28 SQLException (java.sql.SQLException)21 PreparedStatement (java.sql.PreparedStatement)20 HashMap (java.util.HashMap)16 Connection (java.sql.Connection)15 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)14 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)13 Test (org.junit.Test)12 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)11 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)11 Map (java.util.Map)10 BeforeTest (org.testng.annotations.BeforeTest)9 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)8 Response (javax.ws.rs.core.Response)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8