Search in sources :

Example 36 with Label

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

the class AbstractAPIManagerTestCase method testGetLabelByID.

@Test(description = "Get Label by ID")
public void testGetLabelByID() throws APIManagementException {
    LabelDAO labelDAO = mock(LabelDAO.class);
    Label label = SampleTestObjectCreator.createLabel(LABEL_NAME, SampleTestObjectCreator.LABEL_TYPE_STORE).build();
    AbstractAPIManager apiManager = getApiPublisherImpl(labelDAO);
    when(labelDAO.getLabelByID(label.getId())).thenReturn(label);
    apiManager.getLabelByID(label.getId());
    verify(labelDAO, times(1)).getLabelByID(label.getId());
}
Also used : Label(org.wso2.carbon.apimgt.core.models.Label) LabelDAO(org.wso2.carbon.apimgt.core.dao.LabelDAO) Test(org.testng.annotations.Test)

Example 37 with Label

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

the class APIStoreImplTestCase method testGetAPIWSDL.

@Test(description = "Retrieve a WSDL of an API")
public void testGetAPIWSDL() throws APIManagementException, IOException {
    final String labelName = "SampleLabel";
    Label label = SampleTestObjectCreator.createLabel(labelName, SampleTestObjectCreator.LABEL_TYPE_STORE).build();
    List<String> labels = new ArrayList<>();
    labels.add(label.getName());
    API api = SampleTestObjectCreator.createDefaultAPI().labels(labels).build();
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    LabelDAO labelDAO = Mockito.mock(LabelDAO.class);
    APIStore apiStore = getApiStoreImpl(apiDAO, labelDAO);
    Mockito.when(apiDAO.getAPI(api.getId())).thenReturn(api);
    Mockito.when(labelDAO.getLabelByName(labelName)).thenReturn(label);
    Mockito.when(apiDAO.getWSDL(api.getId())).thenReturn(new String(SampleTestObjectCreator.createDefaultWSDL11Content()));
    String expectedEndpoint = SampleTestObjectCreator.ACCESS_URL + labelName + (api.getContext().startsWith("/") ? api.getContext() : "/" + api.getContext());
    String updatedWSDL = apiStore.getAPIWSDL(api.getId(), label.getName());
    Assert.assertTrue(updatedWSDL.contains(expectedEndpoint));
}
Also used : Label(org.wso2.carbon.apimgt.core.models.Label) ArrayList(java.util.ArrayList) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) LabelDAO(org.wso2.carbon.apimgt.core.dao.LabelDAO) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 38 with Label

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

the class LabelsApiServiceImplTestCase method testLabelsGet.

@Test
public void testLabelsGet() throws APIManagementException, NotFoundException {
    TestUtil.printTestMethodName();
    LabelsApiServiceImpl labelsApiService = new LabelsApiServiceImpl();
    APIStore apiStore = Mockito.mock(APIStoreImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
    Request request = TestUtil.getRequest();
    PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
    List<String> labelNames = new ArrayList<>();
    List<Label> labelList = new ArrayList<>();
    Label label = new Label.Builder().id(UUID.randomUUID().toString()).name("store1").type("STORE").accessUrls(new ArrayList<>()).build();
    labelList.add(label);
    Mockito.when(apiStore.getAllLabels()).thenReturn(labelList);
    Response response = labelsApiService.labelsGet("STORE", null, null, null, request);
    Assert.assertEquals(200, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) Request(org.wso2.msf4j.Request) ArrayList(java.util.ArrayList) Label(org.wso2.carbon.apimgt.core.models.Label) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 39 with Label

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

the class APIGatewayPublisherImplTestCase method testDeleteAPIWhenLabelsAreNull.

@Test
public void testDeleteAPIWhenLabelsAreNull() 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);
    API api = SampleTestObjectCreator.createDefaultAPI().lifeCycleStatus(APIStatus.PUBLISHED.getStatus()).hasOwnGateway(true).labels(null).build();
    apiGatewayPublisher.deleteAPI(api);
    Mockito.verify(containerBasedGatewayGenerator, Mockito.times(0)).removeContainerBasedGateway("label", api);
}
Also used : Broker(org.wso2.carbon.apimgt.core.api.Broker) API(org.wso2.carbon.apimgt.core.models.API) Test(org.junit.Test)

Example 40 with Label

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

the class APIGatewayPublisherImplTestCase method testDeleteAPIWhenAPIDoesNotHaveOwnGateway.

@Test
public void testDeleteAPIWhenAPIDoesNotHaveOwnGateway() 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(false).labels(labels).build();
    apiGatewayPublisher.deleteAPI(api);
    Mockito.verify(containerBasedGatewayGenerator, Mockito.times(0)).removeContainerBasedGateway("label", 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)

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