use of org.wso2.carbon.apimgt.impl.APIManagerFactory in project carbon-apimgt by wso2.
the class ThreatProtectionPoliciesApiServiceImplTestCase method testThreatProtectionPoliciesGet.
@Test
public void testThreatProtectionPoliciesGet() throws Exception {
PowerMockito.mockStatic(APIManagerFactory.class);
APIManagerFactory apiManagerFactory = Mockito.mock(APIManagerFactory.class);
APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(apiManagerFactory);
Mockito.when(apiManagerFactory.getAPIMgtAdminService()).thenReturn(adminService);
List<ThreatProtectionPolicy> policyList = new ArrayList<>();
policyList.add(createThreatProtectionPolicy());
policyList.add(createThreatProtectionPolicy());
policyList.add(createThreatProtectionPolicy());
Mockito.when(adminService.getThreatProtectionPolicyList()).thenReturn(policyList);
ThreatProtectionPoliciesApiServiceImpl apiService = new ThreatProtectionPoliciesApiServiceImpl();
Response response = apiService.threatProtectionPoliciesGet(getRequest());
Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
// Error path
Mockito.when(adminService.getThreatProtectionPolicyList()).thenThrow(APIManagementException.class);
response = apiService.threatProtectionPoliciesGet(getRequest());
Assert.assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus());
}
use of org.wso2.carbon.apimgt.impl.APIManagerFactory in project carbon-apimgt by wso2.
the class ThreatProtectionPoliciesApiServiceImplTestCase method testThreatProtectionPoliciesThreatProtectionPolicyIdDelete.
@Test
public void testThreatProtectionPoliciesThreatProtectionPolicyIdDelete() throws Exception {
PowerMockito.mockStatic(APIManagerFactory.class);
APIManagerFactory apiManagerFactory = Mockito.mock(APIManagerFactory.class);
APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(apiManagerFactory);
Mockito.when(apiManagerFactory.getAPIMgtAdminService()).thenReturn(adminService);
ThreatProtectionPoliciesApiServiceImpl apiService = new ThreatProtectionPoliciesApiServiceImpl();
Response response = apiService.threatProtectionPoliciesThreatProtectionPolicyIdDelete("ID", getRequest());
Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
// Error path
Mockito.doThrow(APIManagementException.class).when(adminService).deleteThreatProtectionPolicy(Mockito.anyString());
response = apiService.threatProtectionPoliciesThreatProtectionPolicyIdDelete("ID", getRequest());
Assert.assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus());
}
use of org.wso2.carbon.apimgt.impl.APIManagerFactory in project carbon-apimgt by wso2.
the class ThreatProtectionPoliciesApiServiceImplTestCase method testThreatProtectionPoliciesThreatProtectionPolicyIdGet.
@Test
public void testThreatProtectionPoliciesThreatProtectionPolicyIdGet() throws Exception {
PowerMockito.mockStatic(APIManagerFactory.class);
APIManagerFactory apiManagerFactory = Mockito.mock(APIManagerFactory.class);
APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(apiManagerFactory);
Mockito.when(apiManagerFactory.getAPIMgtAdminService()).thenReturn(adminService);
ThreatProtectionPolicy policy = createThreatProtectionPolicy();
Mockito.when(adminService.getThreatProtectionPolicy(policy.getUuid())).thenReturn(policy);
ThreatProtectionPoliciesApiServiceImpl apiService = new ThreatProtectionPoliciesApiServiceImpl();
Response response = apiService.threatProtectionPoliciesThreatProtectionPolicyIdGet(policy.getUuid(), getRequest());
Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
ThreatProtectionPolicyDTO returnedPolicy = (ThreatProtectionPolicyDTO) response.getEntity();
Assert.assertEquals(policy.getUuid(), returnedPolicy.getUuid());
Assert.assertEquals(policy.getName(), returnedPolicy.getName());
Assert.assertEquals(policy.getType(), returnedPolicy.getType());
// Error path
Mockito.when(adminService.getThreatProtectionPolicy(policy.getUuid())).thenThrow(APIManagementException.class);
response = apiService.threatProtectionPoliciesThreatProtectionPolicyIdGet(policy.getUuid(), getRequest());
Assert.assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus());
}
use of org.wso2.carbon.apimgt.impl.APIManagerFactory in project carbon-apimgt by wso2.
the class EndpointsApiServiceImplTestCase method endpointsEndpointIdGatewayConfigGetTest.
@Test
public void endpointsEndpointIdGatewayConfigGetTest() throws Exception {
APIMgtAdminServiceImpl apiMgtAdminService = Mockito.mock(APIMgtAdminServiceImpl.class);
APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
PowerMockito.mockStatic(APIManagerFactory.class);
PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
Mockito.when(instance.getAPIMgtAdminService()).thenReturn(apiMgtAdminService);
EndpointsApiServiceImpl endpointsApiService = new EndpointsApiServiceImpl();
String endpointId = UUID.randomUUID().toString();
String endpointGatewayConfig = "package deployment.org.wso2.apim;\n" + "import ballerina.net.http;\n" + "\n" + "@http:BasePath(\"/aaa1\")\n" + "service aaa1_1489666767745 {\n" + "\n" + " @http:GET\n" + " @http:Path(\"/*\")\n" + " resource get_star_ (message m) {\n" + " http:ClientConnector productionEndpoint = create http:ClientConnector(getUrlFromKey" + "(\"aaa1_1.0.0__ep\"));\n http:ClientConnector sandboxEndpoint = create http:ClientConnector" + "(getUrlFromKey(\"aaa1_1.0.0__ep\"));\n message response;\n string endpointType;\n string " + "productionType;\n \n \n endpointType = \"production\";\n productionType = \"production\";\n" + "\n if (endpointType == productionType) {\n" + " response = http:ClientConnector.execute(productionEndpoint, \"get\", \"\", m);\n" + " } else {\n" + " response = http:ClientConnector.execute(sandboxEndpoint, \"get\", \"\", m);\n" + " }\n" + "\n" + " reply response;\n" + " }\n" + "}";
Mockito.when(apiMgtAdminService.getEndpointGatewayConfig(endpointId)).thenReturn(endpointGatewayConfig);
Response response = endpointsApiService.endpointsEndpointIdGatewayConfigGet(endpointId, null, getRequest());
Assert.assertEquals(response.getStatus(), 200);
}
use of org.wso2.carbon.apimgt.impl.APIManagerFactory in project carbon-apimgt by wso2.
the class EndpointsApiServiceImplTestCase method nullEndpointGatewayConfigTest.
@Test
public void nullEndpointGatewayConfigTest() throws Exception {
APIMgtAdminServiceImpl apiMgtAdminService = Mockito.mock(APIMgtAdminServiceImpl.class);
APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
PowerMockito.mockStatic(APIManagerFactory.class);
PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
Mockito.when(instance.getAPIMgtAdminService()).thenReturn(apiMgtAdminService);
EndpointsApiServiceImpl endpointsApiService = new EndpointsApiServiceImpl();
String endpointId = UUID.randomUUID().toString();
String endpointGatewayConfig = null;
Mockito.when(apiMgtAdminService.getEndpointGatewayConfig(endpointId)).thenReturn(endpointGatewayConfig);
Response response = endpointsApiService.endpointsEndpointIdGatewayConfigGet(endpointId, null, getRequest());
Assert.assertEquals(response.getStatus(), 404);
}
Aggregations