Search in sources :

Example 61 with Label

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

the class KubernetesGatewayImpl method removeContainerBasedGateway.

/**
 * @see ContainerBasedGatewayGenerator#removeContainerBasedGateway(String, API) (String)
 */
@Override
public void removeContainerBasedGateway(String label, API api) throws ContainerBasedGatewayException {
    try {
        client.services().inNamespace(namespace).withLabel(ContainerBasedGatewayConstants.GATEWAY, label).delete();
        client.extensions().deployments().inNamespace(namespace).withLabel(ContainerBasedGatewayConstants.GATEWAY, label).delete();
        client.extensions().ingresses().inNamespace(namespace).withLabel(ContainerBasedGatewayConstants.GATEWAY, label).delete();
        log.info(String.format("Completed deleting the container gateway related %s deployment, service and " + "ingress resources.", cmsType));
    } catch (KubernetesClientException e) {
        throw new ContainerBasedGatewayException("Error while removing container based gateway", e, ExceptionCodes.CONTAINER_GATEWAY_REMOVAL_FAILED);
    }
}
Also used : ContainerBasedGatewayException(org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 62 with Label

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

the class APIGatewayPublisherImplTestCase method testDeleteAPIForException.

@Test(expected = GatewayException.class)
public void testDeleteAPIForException() throws GatewayException, ContainerBasedGatewayException {
    APIGatewayPublisherImpl apiGatewayPublisher = new APIGatewayPublisherImpl();
    Broker broker = Mockito.mock(BrokerImpl.class, Mockito.RETURNS_DEEP_STUBS);
    BrokerUtil.initialize(broker);
    ContainerBasedGatewayGenerator containerBasedGatewayGenerator = Mockito.mock(ContainerBasedGatewayGenerator.class);
    apiGatewayPublisher.setContainerBasedGatewayGenerator(containerBasedGatewayGenerator);
    Mockito.doThrow(ContainerBasedGatewayException.class).when(containerBasedGatewayGenerator).removeContainerBasedGateway(Mockito.any(), Mockito.any());
    List<String> labels = new ArrayList<>();
    labels.add("label");
    API api = SampleTestObjectCreator.createDefaultAPI().lifeCycleStatus(APIStatus.PUBLISHED.getStatus()).hasOwnGateway(true).labels(labels).build();
    apiGatewayPublisher.deleteAPI(api);
}
Also used : Broker(org.wso2.carbon.apimgt.core.api.Broker) ArrayList(java.util.ArrayList) API(org.wso2.carbon.apimgt.core.models.API) Test(org.junit.Test)

Example 63 with Label

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

the class APIMgtAdminServiceImplTestCase method testRegisterGatewayLabelsException.

@Test(description = "Exception when registering gateway labels", expectedExceptions = APIManagementException.class)
public void testRegisterGatewayLabelsException() throws APIManagementException {
    LabelDAO labelDAO = Mockito.mock(LabelDAO.class);
    List<Label> labels = new ArrayList<>();
    Label label = SampleTestObjectCreator.createLabel("testLabel1", SampleTestObjectCreator.LABEL_TYPE_STORE).build();
    labels.add(label);
    APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(labelDAO);
    Mockito.doThrow(new APIMgtDAOException("Error occurred while adding label information")).when(labelDAO).addLabels(labels);
    adminService.registerGatewayLabels(labels, "false");
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) 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 64 with Label

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

the class APIMgtAdminServiceImplTestCase method testRegisterGatewayLabelsWhenOverwriteLabelsTrue.

@Test(description = "Register gateway labels when overwriteLabels value is true")
public void testRegisterGatewayLabelsWhenOverwriteLabelsTrue() 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);
    List<String> labelNames = new ArrayList<>();
    labelNames.add(label1.getName());
    List<Label> existingLabels = new ArrayList<>();
    existingLabels.add(label1);
    Mockito.when(labelDAO.getLabelsByName(labelNames)).thenReturn(existingLabels);
    APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(labelDAO);
    adminService.registerGatewayLabels(labels, "true");
    Mockito.verify(labelDAO, Mockito.times(1)).addLabels(labels);
    Mockito.verify(labelDAO, Mockito.times(1)).updateLabel(label1);
}
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 65 with Label

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

the class APIPublisherImplTestCase method testGetAllLabels.

@Test(description = "Retrieving all labels")
public void testGetAllLabels() throws APIManagementException {
    LabelDAO labelDAO = Mockito.mock(LabelDAO.class);
    APIPublisherImpl apiPublisher = getApiPublisherImpl(labelDAO);
    Mockito.when(labelDAO.getLabels()).thenReturn(new ArrayList<Label>());
    apiPublisher.getAllLabels();
    Mockito.verify(labelDAO, Mockito.times(1)).getLabels();
}
Also used : Label(org.wso2.carbon.apimgt.core.models.Label) LabelDAO(org.wso2.carbon.apimgt.core.dao.LabelDAO) 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