use of org.wso2.carbon.governance.api.exception.GovernanceException in project carbon-apimgt by wso2.
the class PersistenceHelper method getSampleAPIArtifact.
public static GenericArtifact getSampleAPIArtifact() throws GovernanceException {
GenericArtifact artifact = new GenericArtifactWrapper(new QName("", "PizzaShackAPI", ""), "application/vnd.wso2-api+xml");
artifact.setAttribute("overview_endpointSecured", "false");
artifact.setAttribute("overview_transports", "http,https");
artifact.setAttribute("URITemplate_authType3", "Application & Application User");
artifact.setAttribute("overview_wadl", null);
artifact.setAttribute("URITemplate_authType4", "Application & Application User");
artifact.setAttribute("overview_authorizationHeader", "Authorization");
artifact.setAttribute("URITemplate_authType1", "Application & Application User");
artifact.setAttribute("overview_visibleTenants", null);
artifact.setAttribute("URITemplate_authType2", "Application & Application User");
artifact.setAttribute("overview_wsdl", null);
artifact.setAttribute("overview_apiSecurity", "oauth2,oauth_basic_auth_api_key_mandatory");
artifact.setAttribute("URITemplate_authType0", "Application & Application User");
artifact.setAttribute("overview_keyManagers", "[\"all\"]");
artifact.setAttribute("overview_environments", "Default");
artifact.setAttribute("overview_context", "/pizzashack/1.0.0");
artifact.setAttribute("overview_visibility", "restricted");
artifact.setAttribute("overview_isLatest", "true");
artifact.setAttribute("overview_outSequence", "log_out_message");
artifact.setAttribute("overview_provider", "admin");
artifact.setAttribute("apiCategories_categoryName", "testcategory");
artifact.setAttribute("overview_thumbnail", "/registry/resource/_system/governance/apimgt/applicationdata/provider/admin/PizzaShackAPI/1.0.0/icon");
artifact.setAttribute("overview_contextTemplate", "/pizzashack/{version}");
artifact.setAttribute("overview_description", "This is a simple API for Pizza Shack online pizza delivery store.");
artifact.setAttribute("overview_technicalOwner", "John Doe");
artifact.setAttribute("overview_type", "HTTP");
artifact.setAttribute("overview_technicalOwnerEmail", "architecture@pizzashack.com");
artifact.setAttribute("URITemplate_httpVerb4", "DELETE");
artifact.setAttribute("overview_inSequence", "log_in_message");
artifact.setAttribute("URITemplate_httpVerb2", "GET");
artifact.setAttribute("URITemplate_httpVerb3", "PUT");
artifact.setAttribute("URITemplate_httpVerb0", "POST");
artifact.setAttribute("URITemplate_httpVerb1", "GET");
artifact.setAttribute("labels_labelName", "gwlable");
artifact.setAttribute("overview_businessOwner", "Jane Roe");
artifact.setAttribute("overview_version", "1.0.0");
artifact.setAttribute("overview_endpointConfig", "{\"endpoint_type\":\"http\",\"sandbox_endpoints\":{\"url\":\"https://localhost:9443/am/sample/pizzashack/v1/api/\"}," + "\"endpoint_security\":{\"production\":{\"password\":\"admin\",\"tokenUrl\":null,\"clientId\":null," + "\"clientSecret\":null,\"customParameters\":\"{}\",\"additionalProperties\":{},\"type\":\"BASIC\"," + "\"grantType\":null,\"enabled\":true,\"uniqueIdentifier\":null,\"username\":\"admin\"}," + "\"sandbox\":{\"password\":null,\"tokenUrl\":null,\"clientId\":null,\"clientSecret\":null," + "\"customParameters\":\"{}\",\"additionalProperties\":{},\"type\":null,\"grantType\":null,\"enabled\":false," + "\"uniqueIdentifier\":null,\"username\":null}},\"production_endpoints\":" + "{\"url\":\"https://localhost:9443/am/sample/pizzashack/v1/api/\"}}");
artifact.setAttribute("overview_tier", "Bronze||Silver||Gold||Unlimited");
artifact.setAttribute("overview_sandboxTps", "1000");
artifact.setAttribute("overview_apiOwner", null);
artifact.setAttribute("overview_businessOwnerEmail", "marketing@pizzashack.com");
artifact.setAttribute("isMonetizationEnabled", "false");
artifact.setAttribute("overview_implementation", "ENDPOINT");
artifact.setAttribute("overview_deployments", "null");
artifact.setAttribute("overview_redirectURL", null);
artifact.setAttribute("monetizationProperties", "{}");
artifact.setAttribute("overview_name", "PizzaShackAPI");
artifact.setAttribute("overview_subscriptionAvailability", "current_tenant");
artifact.setAttribute("overview_productionTps", "1000");
artifact.setAttribute("overview_cacheTimeout", "300");
artifact.setAttribute("overview_visibleRoles", "admin,internal/subscriber");
artifact.setAttribute("overview_testKey", null);
artifact.setAttribute("overview_corsConfiguration", "{\"corsConfigurationEnabled\":true,\"accessControlAllowOrigins\":[\"*\"]," + "\"accessControlAllowCredentials\":false,\"accessControlAllowHeaders\":[\"authorization\"," + "\"Access-Control-Allow-Origin\",\"Content-Type\",\"SOAPAction\",\"apikey\",\"testKey\"]," + "\"accessControlAllowMethods\":[\"GET\",\"PUT\",\"POST\",\"DELETE\",\"PATCH\",\"OPTIONS\"]}");
artifact.setAttribute("overview_advertiseOnly", "false");
artifact.setAttribute("overview_versionType", "context");
artifact.setAttribute("overview_status", "PUBLISHED");
artifact.setAttribute("overview_endpointPpassword", null);
artifact.setAttribute("overview_tenants", null);
artifact.setAttribute("overview_endpointAuthDigest", "false");
artifact.setAttribute("overview_faultSequence", "json_fault");
artifact.setAttribute("overview_responseCaching", "Enabled");
artifact.setAttribute("URITemplate_urlPattern4", "/order/{orderId}");
artifact.setAttribute("overview_isDefaultVersion", "true");
artifact.setAttribute("URITemplate_urlPattern2", "/order/{orderId}");
artifact.setAttribute("URITemplate_urlPattern3", "/order/{orderId}");
artifact.setAttribute("URITemplate_urlPattern0", "/order");
artifact.setAttribute("URITemplate_urlPattern1", "/menu");
artifact.setAttribute("overview_enableStore", "true");
artifact.setAttribute("overview_enableSchemaValidation", "true");
artifact.setAttribute("overview_endpointUsername", null);
artifact.setAttribute("overview_status", "PUBLISHED");
artifact.setId("88e758b7-6924-4e9f-8882-431070b6492b");
artifact.setAttribute("overview_audience", "PUBLIC");
return artifact;
}
use of org.wso2.carbon.governance.api.exception.GovernanceException in project carbon-apimgt by wso2.
the class APIProviderImplTest method testChangeLifeCycleStatusAPIMgtException.
@Test(expected = APIManagementException.class)
public void testChangeLifeCycleStatusAPIMgtException() throws RegistryException, UserStoreException, APIManagementException, FaultGatewaysException, WorkflowException, XMLStreamException {
APIIdentifier apiId = new APIIdentifier("admin", "API1", "1.0.0");
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
prepareForChangeLifeCycleStatus(apiProvider, apimgtDAO, apiId, artifact);
GovernanceException exception = new GovernanceException(new APIManagementException("APIManagementException:" + "Error while retrieving Life cycle state"));
Mockito.when(artifact.getLifecycleState()).thenThrow(exception);
apiProvider.changeLifeCycleStatus(apiId, APIConstants.API_LC_ACTION_DEPRECATE, "org1");
}
use of org.wso2.carbon.governance.api.exception.GovernanceException in project carbon-apimgt by wso2.
the class APIProviderImplTest method testChangeAPILCCheckListItems.
@Test
public void testChangeAPILCCheckListItems() throws APIManagementException, GovernanceException {
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
APIIdentifier apiId = new APIIdentifier("admin", "API1", "1.0.1");
GenericArtifact apiArtifact = Mockito.mock(GenericArtifact.class);
Mockito.when(APIUtil.getAPIArtifact(apiId, apiProvider.registry)).thenReturn(apiArtifact);
Mockito.when(apiArtifact.isLCItemChecked(10, "APILifeCycle")).thenThrow(GovernanceException.class).thenReturn(false, true);
String msg = "Error while setting registry lifecycle checklist items for the API: API1";
try {
apiProvider.changeAPILCCheckListItems(apiId, 10, true);
} catch (APIManagementException e) {
Assert.assertEquals(msg, e.getMessage());
}
// status checked
assertTrue(apiProvider.changeAPILCCheckListItems(apiId, 10, true));
// status false
assertTrue(apiProvider.changeAPILCCheckListItems(apiId, 10, true));
}
use of org.wso2.carbon.governance.api.exception.GovernanceException in project carbon-apimgt by wso2.
the class APIProviderImplTest method testGetAllProviders.
@Test
public void testGetAllProviders() throws APIManagementException, GovernanceException {
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
UserRegistry userReg = Mockito.mock(UserRegistry.class);
API api1 = new API(new APIIdentifier("admin", "API1", "1.0.1"));
api1.setContext("api1context");
api1.setStatus(APIConstants.PUBLISHED);
api1.setDescription("API 1 Desciption");
GenericArtifact genericArtifact1 = Mockito.mock(GenericArtifact.class);
GenericArtifact genericArtifact2 = Mockito.mock(GenericArtifact.class);
Mockito.when(genericArtifact1.getAttribute(APIConstants.API_OVERVIEW_NAME)).thenReturn("API1");
Mockito.when(genericArtifact1.getAttribute(APIConstants.API_OVERVIEW_VERSION)).thenReturn("1.0.1");
Mockito.when(genericArtifact1.getAttribute(APIConstants.API_OVERVIEW_CONTEXT)).thenReturn("api1context");
Mockito.when(genericArtifact1.getAttribute(APIConstants.API_OVERVIEW_DESCRIPTION)).thenReturn("API 1 Desciption");
Mockito.when(APIUtil.getAPI(genericArtifact1, apiProvider.registry)).thenReturn(api1);
Mockito.when(APIUtil.getAPI(genericArtifact1)).thenReturn(api1);
GenericArtifact[] genericArtifacts = { genericArtifact1, genericArtifact2 };
Mockito.when(artifactManager.getAllGenericArtifacts()).thenReturn(genericArtifacts);
PowerMockito.when(APIUtil.getArtifactManager(userReg, APIConstants.API_KEY)).thenReturn(artifactManager);
Mockito.when(artifactManager.getAllGenericArtifacts()).thenReturn(genericArtifacts);
Assert.assertNotNull(apiProvider.getAllProviders());
// generic artifact null
Mockito.when(artifactManager.getAllGenericArtifacts()).thenReturn(genericArtifacts);
PowerMockito.when(APIUtil.getArtifactManager(userReg, APIConstants.API_KEY)).thenReturn(artifactManager);
Mockito.when(artifactManager.getAllGenericArtifacts()).thenReturn(null);
Assert.assertNotNull(apiProvider.getAllProviders());
}
use of org.wso2.carbon.governance.api.exception.GovernanceException in project carbon-apimgt by wso2.
the class APIProviderImplTest method testAddAPIVersionWithIllegalCharacters.
@Test
public void testAddAPIVersionWithIllegalCharacters() throws APIManagementException, GovernanceException {
APIIdentifier apiId = new APIIdentifier("admin", "API3", "1.0.2&");
API api = new API(apiId);
api.setContext("/test");
api.setStatus(APIConstants.CREATED);
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
Mockito.when(artifactManager.newGovernanceArtifact(any(QName.class))).thenReturn(artifact);
Mockito.when(APIUtil.createAPIArtifactContent(artifact, api)).thenReturn(artifact);
try {
apiProvider.addAPI(api);
Assert.fail("Exception was expected, but wasn't thrown");
} catch (APIManagementException e) {
Assert.assertTrue(e.getMessage().contains("API Version contains one or more illegal characters"));
}
}
Aggregations