use of org.wso2.carbon.apimgt.api.model.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");
}
use of org.wso2.carbon.apimgt.api.model.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);
}
use of org.wso2.carbon.apimgt.api.model.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();
}
use of org.wso2.carbon.apimgt.api.model.Label in project carbon-apimgt by wso2.
the class APIGatewayPublisherImplTestCase method testDeleteAPIWhenLabelAreEmpty.
@Test
public void testDeleteAPIWhenLabelAreEmpty() 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);
List<String> labels = new ArrayList<>();
API api = SampleTestObjectCreator.createDefaultAPI().lifeCycleStatus(APIStatus.PUBLISHED.getStatus()).hasOwnGateway(true).labels(labels).build();
apiGatewayPublisher.deleteAPI(api);
Mockito.verify(containerBasedGatewayGenerator, Mockito.times(0)).removeContainerBasedGateway("label", api);
}
use of org.wso2.carbon.apimgt.api.model.Label in project carbon-apimgt by wso2.
the class APIGatewayPublisherImplTestCase method testDeleteAPIWhenAPIHasOwnGateway.
@Test
public void testDeleteAPIWhenAPIHasOwnGateway() 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);
List<String> labels = new ArrayList<>();
labels.add("label");
API api = SampleTestObjectCreator.createDefaultAPI().lifeCycleStatus(APIStatus.PUBLISHED.getStatus()).hasOwnGateway(true).labels(labels).build();
apiGatewayPublisher.deleteAPI(api);
Mockito.verify(containerBasedGatewayGenerator, Mockito.times(1)).removeContainerBasedGateway("label", api);
}
Aggregations