use of org.wso2.carbon.apimgt.core.dao.LabelDAO in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testAddApiSandboxEndpoint.
@Test(description = "Test add api with sandbox endpoint")
public void testAddApiSandboxEndpoint() throws APIManagementException, LifecycleException {
Map<String, Endpoint> endpointMap = new HashMap<>();
Map<String, Endpoint> resourceEndpointMap = new HashMap<>();
Map<String, UriTemplate> uriTemplateMap = new HashMap();
UriTemplate.UriTemplateBuilder uriTemplateBuilder = new UriTemplate.UriTemplateBuilder();
uriTemplateBuilder.endpoint(resourceEndpointMap);
uriTemplateBuilder.templateId("getApisApiIdGet");
uriTemplateBuilder.uriTemplate("/apis/");
uriTemplateBuilder.authType(APIMgtConstants.AUTH_APPLICATION_LEVEL_TOKEN);
uriTemplateBuilder.policy(APIUtils.getDefaultAPIPolicy());
uriTemplateBuilder.httpVerb("GET");
uriTemplateMap.put("getApisApiIdGet", uriTemplateBuilder.build());
API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI().id("").endpoint(endpointMap).uriTemplates(uriTemplateMap);
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
Mockito.when(apiLifecycleManager.addLifecycle(APIMgtConstants.API_LIFECYCLE, USER)).thenReturn(new LifecycleState());
String endpointId = String.valueOf(apiBuilder.getEndpoint().get("sandbox"));
Endpoint endpoint = new Endpoint.Builder().id(endpointId).name("testEndpoint").build();
Mockito.when(apiDAO.getEndpoint(endpointId)).thenReturn(endpoint);
GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
APIGateway gateway = Mockito.mock(APIGateway.class);
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
LabelDAO labelDao = Mockito.mock(LabelDAO.class);
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.api, APIMgtConstants.DEFAULT_API_POLICY)).thenReturn(new APIPolicy(APIMgtConstants.DEFAULT_API_POLICY));
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, GOLD_TIER)).thenReturn(new SubscriptionPolicy(GOLD_TIER));
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, SILVER_TIER)).thenReturn(new SubscriptionPolicy(SILVER_TIER));
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, BRONZE_TIER)).thenReturn(new SubscriptionPolicy(BRONZE_TIER));
APIPublisherImpl apiPublisher = getApiPublisherImpl(null, apiDAO, null, null, policyDAO, apiLifecycleManager, labelDao, null, null, null, gatewaySourceGenerator, gateway);
apiPublisher.addAPI(apiBuilder);
Mockito.verify(apiDAO, Mockito.times(1)).addAPI(apiBuilder.build());
Mockito.verify(apiLifecycleManager, Mockito.times(1)).addLifecycle(APIMgtConstants.API_LIFECYCLE, USER);
}
use of org.wso2.carbon.apimgt.core.dao.LabelDAO in project carbon-apimgt by wso2.
the class LabelDAOImplIT method testDeleteLabel.
@Test
public void testDeleteLabel() throws Exception {
LabelDAO labelDAO = DAOFactory.getLabelDAO();
Label label = SampleTestObjectCreator.createLabel("public", SampleTestObjectCreator.LABEL_TYPE_STORE).build();
LabelDAOImpl.addLabel(label);
labelDAO.deleteLabel(label.getId());
Label labelFromDb = labelDAO.getLabelByID(label.getId());
Assert.assertNull(labelFromDb);
}
use of org.wso2.carbon.apimgt.core.dao.LabelDAO in project carbon-apimgt by wso2.
the class LabelDAOImplIT method testGetLabelById.
@Test
public void testGetLabelById() throws Exception {
LabelDAO labelDAO = DAOFactory.getLabelDAO();
Label label = SampleTestObjectCreator.createLabel("public", SampleTestObjectCreator.LABEL_TYPE_STORE).build();
Label labelAdded = LabelDAOImpl.addLabel(label);
Label labelFromDb = labelDAO.getLabelByID(labelAdded.getId());
Assert.assertNotNull(labelFromDb);
Assert.assertEquals(label.getName(), labelFromDb.getName());
Assert.assertEquals(label.getType(), labelFromDb.getType());
}
use of org.wso2.carbon.apimgt.core.dao.LabelDAO in project carbon-apimgt by wso2.
the class LabelDAOImplIT method testGetLabelNamesByIDs.
@Test
public void testGetLabelNamesByIDs() throws Exception {
LabelDAO labelDAO = DAOFactory.getLabelDAO();
Label label1 = SampleTestObjectCreator.createLabel("public", SampleTestObjectCreator.LABEL_TYPE_STORE).build();
Label label2 = SampleTestObjectCreator.createLabel("private", SampleTestObjectCreator.LABEL_TYPE_STORE).build();
List<Label> labelList = new ArrayList<>();
labelList.add(label1);
labelList.add(label2);
labelDAO.addLabels(labelList);
List<String> labelIds = new ArrayList<>();
labelIds.add("10000000003");
labelIds.add(label2.getId());
List<Label> labelFromDb = new ArrayList<>();
for (String id : labelIds) {
labelFromDb.add(labelDAO.getLabelByID(id));
}
Assert.assertNotNull(labelFromDb);
Assert.assertEquals(labelFromDb.size(), 2);
}
use of org.wso2.carbon.apimgt.core.dao.LabelDAO in project carbon-apimgt by wso2.
the class LabelDAOImplIT method testGetLabelsByIDForIncorrectLabelID.
@Test
public void testGetLabelsByIDForIncorrectLabelID() throws Exception {
LabelDAO labelDAO = DAOFactory.getLabelDAO();
Label labelFromDb = labelDAO.getLabelByID("100000000002");
Assert.assertNull(labelFromDb);
}
Aggregations