Search in sources :

Example 76 with Label

use of org.wso2.carbon.apimgt.api.model.Label in project carbon-apimgt by wso2.

the class APIMgtAdminServiceImplTestCase method testDeleteLabel.

@Test(description = "Delete a label")
public void testDeleteLabel() throws APIManagementException {
    LabelDAO labelDAO = Mockito.mock(LabelDAO.class);
    APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(labelDAO);
    Label label = SampleTestObjectCreator.createLabel("Public", SampleTestObjectCreator.LABEL_TYPE_STORE).build();
    String labelId = label.getId();
    adminService.deleteLabel(labelId);
    Mockito.verify(labelDAO, Mockito.times(1)).deleteLabel(labelId);
}
Also used : Label(org.wso2.carbon.apimgt.core.models.Label) LabelDAO(org.wso2.carbon.apimgt.core.dao.LabelDAO) Test(org.testng.annotations.Test)

Example 77 with Label

use of org.wso2.carbon.apimgt.api.model.Label in project carbon-apimgt by wso2.

the class APIMgtAdminServiceImplTestCase method testRegisterGatewayLabelsWhenOverwriteLabelsNull.

@Test(description = "Register gateway labels when overwriteLabels value is null")
public void testRegisterGatewayLabelsWhenOverwriteLabelsNull() throws APIManagementException {
    LabelDAO labelDAO = Mockito.mock(LabelDAO.class);
    List<Label> labels = new ArrayList<>();
    Label label1 = SampleTestObjectCreator.createLabel("testLabel1", SampleTestObjectCreator.LABEL_TYPE_STORE).build();
    labels.add(label1);
    APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(labelDAO);
    adminService.registerGatewayLabels(labels, null);
    Mockito.verify(labelDAO, Mockito.times(1)).addLabels(labels);
}
Also used : Label(org.wso2.carbon.apimgt.core.models.Label) ArrayList(java.util.ArrayList) LabelDAO(org.wso2.carbon.apimgt.core.dao.LabelDAO) Test(org.testng.annotations.Test)

Example 78 with Label

use of org.wso2.carbon.apimgt.api.model.Label in project carbon-apimgt by wso2.

the class APIMgtAdminServiceImplTestCase method testDeleteLabelException.

@Test(description = "Exception when deleting a label", expectedExceptions = APIManagementException.class)
public void testDeleteLabelException() throws APIManagementException {
    LabelDAO labelDAO = Mockito.mock(LabelDAO.class);
    APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(labelDAO);
    Label label = SampleTestObjectCreator.createLabel("Public", SampleTestObjectCreator.LABEL_TYPE_STORE).build();
    String labelId = label.getId();
    Mockito.doThrow(new APIMgtDAOException("Error occurred while deleting label [labelId] " + labelId)).when(labelDAO).deleteLabel(labelId);
    adminService.deleteLabel(labelId);
    Mockito.verify(labelDAO, Mockito.times(1)).deleteLabel(labelId);
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) Label(org.wso2.carbon.apimgt.core.models.Label) LabelDAO(org.wso2.carbon.apimgt.core.dao.LabelDAO) Test(org.testng.annotations.Test)

Example 79 with Label

use of org.wso2.carbon.apimgt.api.model.Label in project carbon-apimgt by wso2.

the class KubernetesGatewayImplTestCase method testRemoveContainerBasedGateway.

@Test
public void testRemoveContainerBasedGateway() throws Exception {
    OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
    KubernetesGatewayImpl kubernetesGateway = getKubernetesGatewayImpl(openShiftClient);
    NonNamespaceOperation nonNamespaceOperation = Mockito.mock(NonNamespaceOperation.class);
    BaseOperation baseOperation = Mockito.mock(BaseOperation.class);
    Mockito.when(openShiftClient.services().inNamespace(NAMESPACE)).thenReturn(nonNamespaceOperation);
    Mockito.when(nonNamespaceOperation.withLabel(Mockito.anyString(), Mockito.anyString())).thenReturn(baseOperation);
    Mockito.when(baseOperation.delete()).thenReturn(true);
    Mockito.when(openShiftClient.extensions().deployments().inNamespace(NAMESPACE)).thenReturn(nonNamespaceOperation);
    Mockito.when(openShiftClient.extensions().ingresses().inNamespace(NAMESPACE)).thenReturn(nonNamespaceOperation);
    API api = SampleTestObjectCreator.createDefaultAPI().build();
    kubernetesGateway.removeContainerBasedGateway("label", api);
    Mockito.verify(openShiftClient, Mockito.times(2)).services();
    Mockito.verify(openShiftClient, Mockito.times(4)).extensions();
}
Also used : OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) API(org.wso2.carbon.apimgt.core.models.API) BaseOperation(io.fabric8.kubernetes.client.dsl.base.BaseOperation) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) Test(org.junit.Test)

Example 80 with Label

use of org.wso2.carbon.apimgt.api.model.Label 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)

Aggregations

Label (org.wso2.carbon.apimgt.core.models.Label)65 ArrayList (java.util.ArrayList)60 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)26 PreparedStatement (java.sql.PreparedStatement)25 Connection (java.sql.Connection)20 HashMap (java.util.HashMap)18 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)14 Test (org.junit.Test)13 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)13 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)11 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)11 ResultSet (java.sql.ResultSet)10 IOException (java.io.IOException)9 Map (java.util.Map)9 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 BeforeTest (org.testng.annotations.BeforeTest)9