use of org.apache.synapse.rest.API in project wso2-synapse by wso2.
the class SynapseXMLConfigurationSerializerTest method testSerializeConfiguration11.
/**
* Test serializeConfigurationMethod with API added for SynapseConfiguration and assert OMElement returned
*/
@Test
public void testSerializeConfiguration11() {
SynapseXMLConfigurationSerializer serializer = new SynapseXMLConfigurationSerializer();
SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
API api = new API("testAPI", "/");
synapseConfiguration.addAPI(api.getName(), api);
OMElement element = serializer.serializeConfiguration(synapseConfiguration);
Assert.assertNotNull("OMElement is not returned", element);
Assert.assertEquals("definitions", element.getLocalName());
Assert.assertTrue("testAPI added is not serialized.", element.getChildren().next().toString().contains("name=\"testAPI\""));
}
use of org.apache.synapse.rest.API in project wso2-synapse by wso2.
the class SynapseConfigurationTest method testAPITableOrderWithAddAPIwithoutReOrder.
public void testAPITableOrderWithAddAPIwithoutReOrder() {
SynapseConfiguration config = new SynapseConfiguration();
API api1 = new API("API1", "/context/test");
API api2 = new API("API2", "/context");
API api3 = new API("API3", "/context/test/ctx");
config.addAPI("API1", api1, false);
config.addAPI("API2", api2, false);
config.addAPI("API3", api3, false);
// this should get the api table as it is.
Collection<API> apis = config.getAPIs();
API[] apisArray = apis.toArray(new API[apis.size()]);
// api1 with context /context/test/ctx should be first in the list
assertEquals("Order is not correct before sorting", api1, apisArray[0]);
// calling explicitly to order the apitable
config.reconstructAPITable();
apis = config.getAPIs();
API[] apisArray2 = apis.toArray(new API[apis.size()]);
// api3 with context /context/test/ctx should be first in the list
assertEquals("Order is not correct", api3, apisArray2[0]);
}
use of org.apache.synapse.rest.API in project wso2-synapse by wso2.
the class StatisticSynapseConfigurationObserverTest method testApiUpdated.
/**
* Test apiUpdated method by hash generation.
*/
@Test
public void testApiUpdated() {
final String apiName = "testName";
final String apiContext = "/testContext";
API api = new API(apiName, apiContext);
observer.apiUpdated(api);
Assert.assertNotNull("New hash must be set by the method", api.getAspectConfiguration().getHashCode());
}
use of org.apache.synapse.rest.API in project wso2-synapse by wso2.
the class SynapseConfiguration method updateAPI.
public synchronized void updateAPI(String name, API api) {
if (!apiTable.containsKey(name)) {
handleException("No API exists by the name: " + name);
} else {
for (API existingAPI : apiTable.values()) {
if (!api.getName().equals(existingAPI.getName()) && api.getVersion().equals(existingAPI.getVersion()) && existingAPI.getContext().equals(api.getContext())) {
handleException("URL context: " + api.getContext() + " is already registered" + " with the API: " + existingAPI.getName());
}
}
apiTable.put(name, api);
reconstructAPITable();
for (SynapseObserver o : observers) {
o.apiUpdated(api);
}
}
}
use of org.apache.synapse.rest.API in project wso2-synapse by wso2.
the class SynapseConfiguration method reconstructAPITable.
/**
* This method reconstructs the apiTable in descending order of context
*/
public synchronized void reconstructAPITable() {
if (log.isDebugEnabled()) {
log.debug("Start re-constructing the API Table...");
}
Map<String, API> duplicateAPITable = new LinkedHashMap<String, API>();
String[] contextValues = new String[apiTable.size()];
int i = 0;
for (API api : apiTable.values()) {
contextValues[i] = api.getContext();
i++;
}
Arrays.sort(contextValues, new java.util.Comparator<String>() {
public int compare(String context1, String context2) {
return context1.length() - context2.length();
}
});
ArrayUtils.reverse(contextValues);
for (String context : contextValues) {
for (String mapKeys : apiTable.keySet()) {
if (context.equals(apiTable.get(mapKeys).getContext())) {
duplicateAPITable.put(mapKeys, apiTable.get(mapKeys));
break;
}
}
}
apiTable = duplicateAPITable;
}
Aggregations