Search in sources :

Example 41 with Label

use of org.wso2.carbon.apimgt.core.models.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);
}
Also used : API(org.wso2.carbon.apimgt.core.models.API) Test(org.junit.Test)

Example 42 with Label

use of org.wso2.carbon.apimgt.core.models.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);
}
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 43 with Label

use of org.wso2.carbon.apimgt.core.models.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");
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ArrayList(java.util.ArrayList) API(org.wso2.carbon.apimgt.core.models.API) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 44 with Label

use of org.wso2.carbon.apimgt.core.models.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);
}
Also used : OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) API(org.wso2.carbon.apimgt.core.models.API) Test(org.junit.Test)

Example 45 with Label

use of org.wso2.carbon.apimgt.core.models.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 });
}
Also used : Label(org.wso2.carbon.apimgt.core.models.Label) API(org.wso2.carbon.apimgt.core.models.API) 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