Package com.alu.e3.data.model

Examples of com.alu.e3.data.model.Api


    Map<String, String> properties = (Map<String,String>) exchange.getProperty(ExchangeConstantKeys.E3_MODEL_PROPERTIES.toString());
    if(properties == null)
      properties = new HashMap<String, String>();

    // First add the TDRs from the API
    Api api = identity.getApi();
    applyHeaderTransforms(api.getHeaderTransformations(), type, properties, exchange);

    // Next add all of the tdr values for the Policies
    Iterator<CallDescriptor> it = identity.getCallDescriptors().iterator();
    while(it.hasNext()){
      CallDescriptor cd = it.next();
View Full Code Here


  @Test
  public void testAddGetRemoveApi() {

    // Add a new API
    Api api = new Api();
    api.setId("id1");
    api.setApiDetail(new ApiDetail());
    api.getApiDetail().setEndpoint("http://www.google.com");
    dataManager.addApi(api);

    // Now, get the "simple" API and check that it's OK
    Api api2 = dataManager.getApiById("id1");
    assertNotNull("API was added/returned", api2);
    assertNull("API details is null", api2.getApiDetail());

    // Now, get the "full" API and check that it's OK
    Api api3 = dataManager.getApiById("id1", true);
    assertNotNull("API was added/returned", api3);
    assertEquals("API values are correct", api.getApiDetail().getEndpoint(), api3.getApiDetail().getEndpoint());

    dataManager.removeApi("id1");

    boolean isInvalidID = false;
View Full Code Here

  @Test
  public void testAddTwiceApi() {

    // Add a new API
    Api api = new Api();
    api.setId("id1");
    api.setApiDetail(new ApiDetail());
    api.getApiDetail().setEndpoint("http://www.google.com");
    dataManager.addApi(api);

    boolean exceptionRaised = false;
    try
    {
      dataManager.addApi(api);
    }
    catch(Exception e)
    {
      exceptionRaised = true;
    }

    assertTrue("Exception raised", exceptionRaised);

    // cleanup
    dataManager.removeApi(api.getId());
  }
View Full Code Here

  }

  @Override
  public void updateApi(Api api) throws InvalidIDException {

    Api oldApi = cachingTableApi.get(api.getId());
    if (oldApi == null)
      throw new InvalidIDException("An API with that ID [" + api.getId() + "] doesn't exist");

    // Remove all contexts and bucket ids
    for (ApiIds apiIds : oldApi.getContextIds()) {
      cachingTableContext.remove(Integer.valueOf(apiIds.getApiContextId()));
      usedBucketIds.remove(Integer.valueOf(apiIds.getApiBucketId()));
      for (IDataManagerUsedBucketIdsListener listner : this.usedBucketIdslisteners)
      {
        listner.usedBucketIdsRemoved(new Integer(apiIds.getApiBucketId()));
      }
    }

    // Remove endpoint from the used endpoints
    ApiDetail oldDetail = cachingTableApiDetails.get(api.getId());
    usedEndpoints.remove(oldDetail.getEndpoint());

    // add updated contexts
    internalSaveApiDetails(api);

    api.setPolicyIds(oldApi.getPolicyIds());

    cachingTableApi.set(api.getId(), api);
    usedEndpoints.add(api.getApiDetail().getEndpoint());
  }
View Full Code Here

  @Test
  public void testGetAllApi() {

    // Add a new API
    Api api = new Api();
    api.setId("id10");
    api.setApiDetail(new ApiDetail());
    api.getApiDetail().setEndpoint("http://www.google.com");
    dataManager.addApi(api);

    // Add a new API
    Api api2 = new Api();
    api2.setId("id2");
    api2.setApiDetail(new ApiDetail());
    api2.getApiDetail().setEndpoint("http://www.yahoo.com");
    dataManager.addApi(api2);

    Set<String> apis = dataManager.getAllApiIds();
    assertNotNull("No apis found", apis);

    List<String> apisList = new ArrayList<String>();

    for (String apiStr : apis) {
      apisList.add(apiStr);
    }

    assertEquals("API count is correct", 2, apisList.size());
    assertTrue("Both APIs are found", (api.getId().equals(apisList.get(0)) || api2.getId().equals(apisList.get(0))) && (api.getId().equals(apisList.get(1))  || api2.getId().equals(apisList.get(1))));

    // cleanup
    dataManager.removeApi(api.getId());
    dataManager.removeApi(api2.getId());
  }
View Full Code Here

    usedEndpoints.add(api.getApiDetail().getEndpoint());
  }

  @Override
  public void removeApi(String id) throws InvalidIDException {
    Api api = cachingTableApi.remove(id);

    ApiDetail detail = cachingTableApiDetails.remove(id);

    if (api == null) {
      throw new InvalidIDException("An API with that ID [" + id + "] doesn't exist");
    }

    // Find the policies associated, and remove this API
    for (String policyId : api.getPolicyIds()) {
      Policy policy = getPolicyById(policyId);
      if (policy != null) {
        policy.getApiIds().remove(api.getId());
        cachingTablePolicy.set(policyId, policy);
      }
    }

    // Remove the contexts
    for (ApiIds apiIds : api.getContextIds()) {
      cachingTableContext.remove(Integer.valueOf(apiIds.getApiContextId()));
      usedBucketIds.remove(new Integer(apiIds.getApiBucketId()));
      for (IDataManagerUsedBucketIdsListener listner : this.usedBucketIdslisteners)
      {
        listner.usedBucketIdsRemoved(new Integer(apiIds.getApiBucketId()));
      }
    }
    // Remove endpoint from the used endpoints
    usedEndpoints.remove(detail.getEndpoint());

    usedBucketIds.remove(api.getApiId());
    for (IDataManagerUsedBucketIdsListener listner : this.usedBucketIdslisteners)
    {
      listner.usedBucketIdsRemoved(new Integer(api.getApiId()));
    }
  }
View Full Code Here


  @Override
  public Api getApiById(String id, boolean getFullDetails) throws InvalidIDException {

    Api api = cachingTableApi.get(id);

    if (api == null) {
      throw new InvalidIDException("An API with that ID [" + id + "] doesn't exist");
    }

    if (getFullDetails) {

      ApiDetail details = cachingTableApiDetails.get(id);

      if (details != null) {

        api.setApiDetail(details);
        // It's not because List<Context> is transient on ApiDetail
        // that it isn't stored in hazelcast memory locally.
        // For sure, it will not be replicated
        details.getContexts().clear();
        // We can't be sure here to reuse existing List<APIContext>
        // it may be not up to date.

        for (ApiIds ids : api.getContextIds()) {
          details.getContexts().add(cachingTableContext.get(ids.getApiContextId()).getApiContext());
        }
      }
    }
    else
      api.setApiDetail(null);

    return api;
  }
View Full Code Here

  @Test
  public void testAddPolicyAndUpdateApiAuthThenRemovePolicy() {

    // Add a new API
    Api api = new Api();
    api.setId("id1");
    api.setApiDetail(new ApiDetail());
    dataManager.addApi(api);

    // Add a new Auth
    Auth auth = new Auth();
    auth.setId("id2");
    auth.setStatus(StatusType.ACTIVE);
    auth.setAuthDetail(new AuthDetail());
    auth.getAuthDetail().setType(NBAuthType.AUTHKEY);
    auth.getAuthDetail().setAuthKeyValue("authKey10");
    dataManager.addAuth(auth);

    // Add a new Policy
    Policy policy = new Policy();
    policy.setId("id3");
    policy.getApiIds().add(api.getId());
    dataManager.addPolicy(policy);

    // Create bucket
    QuotaRLBucket authIds = new QuotaRLBucket();
    authIds.setId("id3");
    authIds.getAuthIds().add(auth.getId());
    dataManager.createBucket(policy.getId(), authIds);

    // Now, get the API and check that it's OK
    Api api2 = dataManager.getApiById("id1");
    assertEquals("API has new policy", policy.getId(), api2.getPolicyIds().get(0));

    // Now, get the Auth and check that it's OK
    Auth auth2 = dataManager.getAuthById("id2");
    assertEquals("Auth has new policy", policy.getId(), auth2.getPolicyContexts().get(0).getPolicyId());

    // Check that bucket is added correctly to policy
    policy = dataManager.getPolicyById(policy.getId());
    assertEquals("Correct number of buckets for policy", 1, policy.getAuthIds().size());
    assertEquals("Policy has new bucket", authIds.getId(), policy.getAuthIds().get(0).getId());   

    dataManager.removePolicy(policy.getId());

    // Now, get the API and check that it's OK
    Api api3 = dataManager.getApiById("id1");
    assertEquals("API has no policy", 0, api3.getPolicyIds().size());

    // Now, get the API and check that it's OK
    Auth auth3 = dataManager.getAuthById("id2");
    assertEquals("Auth has no policy", 0, auth3.getPolicyContexts().size());
View Full Code Here

    cachingTablePolicy.set(policy.getId(), policy);

    // Now, iterate through all APIs and Auth in this policy and update them
    for (String apiId : policy.getApiIds()) {
      Api api = getApiById(apiId);
      if (api.getPolicyIds().indexOf(policy.getId()) < 0)
      {
        api.getPolicyIds().add(policy.getId());
        cachingTableApi.set(api.getId(), api);
      }
    }

    for (QuotaRLBucket bucket : policy.getAuthIds()) {
      for(String authId : bucket.getAuthIds()) {
View Full Code Here

    if (policy == null)
      throw new InvalidIDException("A Policy with that ID [" + id + "] doesn't exist");

    // Now, iterate through all APIs and Auth in this policy and update them
    for (String apiId : policy.getApiIds()) {
      Api api = getApiById(apiId);
      if (api != null) {
        api.getPolicyIds().remove(policy.getId());
        cachingTableApi.set(api.getId(), api);
      }
    }

    for (QuotaRLBucket bucket : policy.getAuthIds()) {
      for(String authId : bucket.getAuthIds()) {
View Full Code Here

TOP

Related Classes of com.alu.e3.data.model.Api

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.