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;
}
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));
}
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));
}
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();
}
}
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());
}
}
Aggregations