Search in sources :

Example 11 with Label

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

the class APIPublisherImplTestCase method getLabelsByType.

@Test(description = "get  labels by STORE type")
public void getLabelsByType() throws Exception {
    LabelDAO labelDao = Mockito.mock(LabelDAO.class);
    APIPublisherImpl apiPublisher = getApiPublisherImpl(labelDao);
    Mockito.when(labelDao.getLabelsByType("GATEWAY")).thenReturn(new ArrayList<Label>());
    apiPublisher.getLabelsByType("GATEWAY");
    Mockito.verify(labelDao, Mockito.times(1)).getLabelsByType("GATEWAY");
}
Also used : Label(org.wso2.carbon.apimgt.core.models.Label) LabelDAO(org.wso2.carbon.apimgt.core.dao.LabelDAO) Test(org.testng.annotations.Test)

Example 12 with Label

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

the class LabelMappingUtil method fromLabelToDTO.

/**
 * Converts a single Label model object into DTO object.
 *
 * @param label Label  model object
 * @return DTO object derived from the label model object
 */
public static LabelDTO fromLabelToDTO(Label label) {
    LabelDTO labelDTO = new LabelDTO();
    labelDTO.accessUrls(label.getAccessUrls());
    labelDTO.description(label.getDescription());
    labelDTO.setName(label.getName());
    labelDTO.labelUUID(label.getId());
    labelDTO.setType(label.getType());
    return labelDTO;
}
Also used : LabelDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.LabelDTO)

Example 13 with Label

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

the class LabelsApiServiceImplTest method testLabelsPost.

@Test
public void testLabelsPost() throws Exception {
    APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
    Label label1 = new Label.Builder().id("1").name("label1").type("GATEWAY").build();
    LabelsApiServiceImpl labelService = new LabelsApiServiceImpl();
    Mockito.when(labelService.labelsPost(LabelMappingUtil.fromLabelToDTO(label1), "application/json", getRequest())).thenReturn(Response.status(Response.Status.CREATED).entity(LabelMappingUtil.fromLabelToDTO(label1)).build());
    Response response = labelService.labelsPost(LabelMappingUtil.fromLabelToDTO(label1), "application/json", getRequest());
    Assert.assertEquals(response.getStatus(), Response.Status.CREATED);
}
Also used : Response(javax.ws.rs.core.Response) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) Label(org.wso2.carbon.apimgt.core.models.Label) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 14 with Label

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

the class LabelsApiServiceImplTest method testLabelsLabelIdPut.

@Test
public void testLabelsLabelIdPut() 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.labelsLabelIdPut("1", LabelMappingUtil.fromLabelToDTO(label1), "application/Json", getRequest())).thenReturn(Response.status(Response.Status.OK).entity(LabelMappingUtil.fromLabelArrayToListDTO(labels)).build());
    Response response = labelService.labelsLabelIdPut("1", LabelMappingUtil.fromLabelToDTO(label1), "application/Json", 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 15 with Label

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

the class TestMappingUtilTestCase method testLabelsListToLabelListDTOMapping.

@Test(description = "Label list to Label list DTO mapping ")
void testLabelsListToLabelListDTOMapping() {
    Label label1 = SampleTestObjectCreator.createLabel("label1").build();
    Label label2 = SampleTestObjectCreator.createLabel("label1").build();
    List<Label> labels = new ArrayList<>();
    labels.add(label1);
    labels.add(label2);
    LabelListDTO labelListDTO = MappingUtil.toLabelListDTO(labels);
    assertEquals((Integer) labels.size(), labelListDTO.getCount());
    assertEquals(label1.getId(), labelListDTO.getList().get(0).getLabelId());
    assertEquals(label1.getName(), labelListDTO.getList().get(0).getName());
    assertEquals(label2.getId(), labelListDTO.getList().get(1).getLabelId());
    assertEquals(label2.getName(), labelListDTO.getList().get(1).getName());
}
Also used : Label(org.wso2.carbon.apimgt.core.models.Label) ArrayList(java.util.ArrayList) LabelListDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.LabelListDTO) 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