use of org.wso2.carbon.apimgt.api.model.Label in project carbon-apimgt by wso2.
the class APIGatewayPublisherImplTestCase method testCreateContainerGateway.
@Test
public void testCreateContainerGateway() throws ContainerBasedGatewayException, ConfigurationException {
APIGatewayPublisherImpl apiGatewayPublisher = new APIGatewayPublisherImpl();
ContainerBasedGatewayGenerator containerBasedGatewayGenerator = Mockito.mock(ContainerBasedGatewayGenerator.class);
apiGatewayPublisher.setContainerBasedGatewayGenerator(containerBasedGatewayGenerator);
API api = SampleTestObjectCreator.createDefaultAPI().build();
apiGatewayPublisher.createContainerBasedGateway("label", api);
Mockito.verify(containerBasedGatewayGenerator, Mockito.times(1)).createContainerGateway("label", api);
}
use of org.wso2.carbon.apimgt.api.model.Label in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testRegisterGatewayLabels.
@Test(description = "Register gateway labels")
public void testRegisterGatewayLabels() throws APIManagementException {
LabelDAO labelDAO = Mockito.mock(LabelDAO.class);
List<Label> labels = new ArrayList<>();
Label label1 = SampleTestObjectCreator.createLabel("testLabel1", SampleTestObjectCreator.LABEL_TYPE_STORE).build();
Label label2 = SampleTestObjectCreator.createLabel("testLabel2", 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);
existingLabels.add(label2);
Mockito.when(labelDAO.getLabelsByName(labelNames)).thenReturn(existingLabels);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(labelDAO);
adminService.registerGatewayLabels(labels, "false");
Mockito.verify(labelDAO, Mockito.times(1)).addLabels(labels);
}
use of org.wso2.carbon.apimgt.api.model.Label in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetAPIsByGatewayLabel.
@Test(description = "Test getting APIs by Gateway label")
public void testGetAPIsByGatewayLabel() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
List<String> gatewayLabels = new ArrayList<>();
gatewayLabels.add("Label1");
List<API> apiListExpected = new ArrayList<>();
API api = SampleTestObjectCreator.createDefaultAPI().labels(new ArrayList<>(gatewayLabels)).build();
apiListExpected.add(api);
Mockito.when(apiDAO.getAPIsByGatewayLabel(gatewayLabels)).thenReturn(apiListExpected);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(apiDAO);
List<API> apiListReturned = adminService.getAPIsByGatewayLabel(gatewayLabels);
Assert.assertEquals(apiListReturned, apiListExpected);
// When gateway labels are null
try {
adminService.getAPIsByGatewayLabel(null);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Gateway labels cannot be null");
}
// Error path
// Error while getting the APIs
Mockito.when(apiDAO.getAPIsByGatewayLabel(gatewayLabels)).thenThrow(APIMgtDAOException.class);
try {
adminService.getAPIsByGatewayLabel(gatewayLabels);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Error occurred while getting the API list in given gateway labels");
}
}
use of org.wso2.carbon.apimgt.api.model.Label in project carbon-apimgt by wso2.
the class KubernetesGatewayImplTestCase method testRemoveContainerBasedGatewayForException.
@Test(expected = ContainerBasedGatewayException.class)
public void testRemoveContainerBasedGatewayForException() throws Exception {
OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
KubernetesGatewayImpl kubernetesGateway = new KubernetesGatewayImpl();
kubernetesGateway.setClient(openShiftClient);
kubernetesGateway.setValues(createImplParametersMap());
Mockito.when(openShiftClient.services().inNamespace(NAMESPACE)).thenThrow(KubernetesClientException.class);
API api = SampleTestObjectCreator.createDefaultAPI().build();
kubernetesGateway.removeContainerBasedGateway("label", api);
}
use of org.wso2.carbon.apimgt.api.model.Label in project carbon-apimgt by wso2.
the class WSDL11ProcessorImplTestCase method testWSDLArchive.
@Test
public void testWSDLArchive() throws Exception {
String extractedLocation = SampleTestObjectCreator.createDefaultWSDL11Archive();
WSDL11ProcessorImpl wsdl11Processor = new WSDL11ProcessorImpl();
wsdl11Processor.initPath(extractedLocation);
Assert.assertTrue(wsdl11Processor.canProcess());
assertDefaultArchivedWSDLContent(wsdl11Processor.getWsdlInfo(), new String[] { SampleTestObjectCreator.ORIGINAL_ENDPOINT_WEATHER, SampleTestObjectCreator.ORIGINAL_ENDPOINT_STOCK_QUOTE }, null);
API api = SampleTestObjectCreator.createDefaultAPI().build();
Label label = SampleTestObjectCreator.createLabel(SAMPLE_LABEL_NAME, SampleTestObjectCreator.LABEL_TYPE_STORE).build();
String updatedPath = wsdl11Processor.getUpdatedWSDLPath(api, label);
WSDL11ProcessorImpl wsdl11Processor2 = new WSDL11ProcessorImpl();
wsdl11Processor2.initPath(updatedPath);
Assert.assertTrue(wsdl11Processor2.canProcess());
assertDefaultArchivedWSDLContent(wsdl11Processor2.getWsdlInfo(), new String[] { UPDATED_ENDPOINT_API_LABEL }, new String[] { SampleTestObjectCreator.ORIGINAL_ENDPOINT_STOCK_QUOTE, SampleTestObjectCreator.ORIGINAL_ENDPOINT_WEATHER });
}
Aggregations