Search in sources :

Example 46 with LabelDAO

use of org.wso2.carbon.apimgt.core.dao.LabelDAO 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 47 with LabelDAO

use of org.wso2.carbon.apimgt.core.dao.LabelDAO 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 48 with LabelDAO

use of org.wso2.carbon.apimgt.core.dao.LabelDAO 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)

Example 49 with LabelDAO

use of org.wso2.carbon.apimgt.core.dao.LabelDAO 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 50 with LabelDAO

use of org.wso2.carbon.apimgt.core.dao.LabelDAO 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)

Aggregations

LabelDAO (org.wso2.carbon.apimgt.core.dao.LabelDAO)71 Test (org.testng.annotations.Test)70 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)45 API (org.wso2.carbon.apimgt.core.models.API)44 ArrayList (java.util.ArrayList)33 Label (org.wso2.carbon.apimgt.core.models.Label)33 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)28 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)26 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)26 APIBuilder (org.wso2.carbon.apimgt.core.models.API.APIBuilder)26 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)17 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)16 LifecycleState (org.wso2.carbon.lcm.core.impl.LifecycleState)15 HashMap (java.util.HashMap)14 DedicatedGateway (org.wso2.carbon.apimgt.core.models.DedicatedGateway)14 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)14 BeforeTest (org.testng.annotations.BeforeTest)13 IdentityProvider (org.wso2.carbon.apimgt.core.api.IdentityProvider)11 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)11 WorkflowExtensionsConfigBuilder (org.wso2.carbon.apimgt.core.workflow.WorkflowExtensionsConfigBuilder)11