use of org.wso2.carbon.apimgt.api.model.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.api.model.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.api.model.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());
}
}
use of org.wso2.carbon.apimgt.api.model.Label in project carbon-apimgt by wso2.
the class LabelMappingUtilTestCase method testToLabelListDTO.
@Test
public void testToLabelListDTO() {
List<Label> labelList = new ArrayList<>();
Label label1 = SampleTestObjectCreator.createLabel("label1").build();
Label label2 = SampleTestObjectCreator.createLabel("label2").build();
labelList.add(label1);
labelList.add(label2);
LabelListDTO labelListDTO = LabelMappingUtil.toLabelListDTO(labelList);
assertEquals(labelListDTO.getCount(), (Integer) labelList.size());
assertEquals(labelListDTO.getList().get(0).getName(), label1.getName());
assertEquals(labelListDTO.getList().get(0).getAccessUrls(), label1.getAccessUrls());
assertEquals(labelListDTO.getList().get(0).getLabelId(), label1.getId());
assertEquals(labelListDTO.getList().get(1).getName(), label2.getName());
assertEquals(labelListDTO.getList().get(1).getAccessUrls(), label2.getAccessUrls());
assertEquals(labelListDTO.getList().get(1).getLabelId(), label2.getId());
}
use of org.wso2.carbon.apimgt.api.model.Label in project carbon-apimgt by wso2.
the class LabelsApiServiceImplTestCase method testLabelInfoGetWithNull.
@Test
public void testLabelInfoGetWithNull() throws APIManagementException, NotFoundException {
TestUtil.printTestMethodName();
LabelsApiServiceImpl labelsApiService = new LabelsApiServiceImpl();
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
Request request = TestUtil.getRequest();
PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
List<String> labelNames = new ArrayList<>();
List<Label> labelList = new ArrayList<>();
Mockito.when(apiStore.getAllLabels()).thenReturn(labelList);
Response response = labelsApiService.labelsGet(null, null, null, null, request);
Assert.assertEquals(200, response.getStatus());
}
Aggregations