Package com.alu.e3.prov.restapi.model

Examples of com.alu.e3.prov.restapi.model.Api


  }

  @Test
  public void testCreateSubscriptionApi() {
    Api newApi = newApi();

    String apiID = "Subscription"+(new Random().nextLong());
    newApi.setId(apiID);

    newApi.setNotificationFormat(NotificationFormat.HEADER);

    // Testing we can't have NotificationFormat tag on Non Notification type APIs
    BasicResponse response = given()
        .contentType("application/xml")
        .body(newApi, ObjectMapper.JAXB)
        .expect()
        .statusCode(500)
        //.rootPath("response")
        //.body("status", equalTo("SUCCESS"))
        //.body("id", notNullValue())
        .log().ifError()
        .when()
        .post("")
        .andReturn()
        .as(BasicResponse.class, ObjectMapper.JAXB);

    Assert.assertNotNull("No error message", response.getError());
    Assert.assertNotNull("No error message", response.getError().getErrorText());
    Assert.assertTrue("Wrong errorMsg value", response.getError().getErrorText().contains("can't have NotificationFormat"));

    // Testing Wrong : Subscription + Notification Format
    newApi.setSubscriptionStep(SubscriptionStep.SUBSCRIPTION);
    response = given()
        .contentType("application/xml")
        .body(newApi, ObjectMapper.JAXB)
        .expect()
        .statusCode(500)
        //.rootPath("response")
        //.body("status", equalTo("SUCCESS"))
        //.body("id", notNullValue())
        .log().ifError()
        .when()
        .post("")
        .andReturn()
        .as(BasicResponse.class, ObjectMapper.JAXB);

    Assert.assertNotNull("No error message", response.getError());
    Assert.assertNotNull("No error message", response.getError().getErrorText());
    Assert.assertTrue("Wrong errorMsg value", response.getError().getErrorText().contains("can't have a NotificationFormat in Subscription step mode"));

    // Testing Wrong : Notification + NotificationFormat + Target hosts
    newApi.setSubscriptionStep(SubscriptionStep.NOTIFICATION);

    response = given()
        .contentType("application/xml")
        .body(newApi, ObjectMapper.JAXB)
        .expect()
        .statusCode(500)
        //.rootPath("response")
        //.body("status", equalTo("SUCCESS"))
        //.body("id", notNullValue())
        .log().ifError()
        .when()
        .post("")
        .andReturn()
        .as(BasicResponse.class, ObjectMapper.JAXB);

    Assert.assertNotNull("No error message", response.getError());
    Assert.assertNotNull("No error message", response.getError().getErrorText());
    Assert.assertTrue("Wrong errorMsg value", response.getError().getErrorText().contains("Notification step can't have any target host"));

    // Testing Wrong : Notification - NotificationFormat - TargetHost
    for (ApiContext apiCtx : newApi.getContexts())
      apiCtx.setTargetHosts(null);

    newApi.setNotificationFormat(null);

    response = given()
        .contentType("application/xml")
        .body(newApi, ObjectMapper.JAXB)
        .expect()
        .statusCode(500)
        //.rootPath("response")
        //.body("status", equalTo("SUCCESS"))
        //.body("id", notNullValue())
        .log().ifError()
        .when()
        .post("")
        .andReturn()
        .as(BasicResponse.class, ObjectMapper.JAXB);

    Assert.assertNotNull("No error message", response.getError());
    Assert.assertNotNull("No error message", response.getError().getErrorText());
    Assert.assertTrue("Wrong errorMsg value", response.getError().getErrorText().contains("Notification must have a NotificationFormat"));

    // SUCCESS : Notification + NotificationFormat - TargetHost
    newApi.setNotificationFormat(NotificationFormat.HEADER);
    response = given()
        .contentType("application/xml")
        .body(newApi, ObjectMapper.JAXB)
        .expect()
        .statusCode(200)
        .rootPath("response")
        .body("status", equalTo("SUCCESS"))
        .body("id", notNullValue())
        .body("id", equalTo(newApi.getId()))
        .log().ifError()
        .when()
        .post("")
        .andReturn()
        .as(BasicResponse.class, ObjectMapper.JAXB);
View Full Code Here


    testMessage.assertIsSatisfied();
  }

  private void setupExchange(Exchange exchange, boolean https){
    Api api = new Api();

    api.setType(ApiType.PASS_THROUGH);

    ApiContext env = new ApiContext();
    env.setId("test");

    api.setContexts(Arrays.asList(env));

    List<TargetHost> targetList = new ArrayList<TargetHost>();

    api.setEndpoint("www.yahoo.fr");

    TargetHost to1 = new TargetHost();
    to1.setUrl("http://www.google.com");
    targetList.add(to1);

    TargetHost to2 = new TargetHost();
    to2.setUrl("http://www.google.com?toto=tutu");
    targetList.add(to2);

    TargetHost to3 = new TargetHost();
    to3.setUrl("http://www.google.com?toto=tutu&tata=tete&titi=toto");
    targetList.add(to3);

    env.setTargetHosts(targetList);

    TdrEnabled tdr = new TdrEnabled();
    tdr.setEnabled("true");
    api.setTdrEnabled(tdr);


    exchange.setProperty(ExchangeConstantKeys.E3_REQUEST_PAYLOAD.toString(), api);
    exchange.setProperty(ExchangeConstantKeys.E3_API_ID.toString(), "MyApiID");
    exchange.setProperty(ExchangeConstantKeys.E3_API_ID_ENCODED.toString(), "MonApiIDEncoded");
    exchange.setProperty(ExchangeConstantKeys.E3_PROVISION_ID.toString(), "MyProvId");

    ProvisionAuthentication auth = new ProvisionAuthentication();
    Authkey authKey = new Authkey();
    authKey.setKeyName("MyAuthkeyValue");
    auth.getAuths().add(AuthType.AUTHKEY);
    auth.setAuthKey(authKey);

    HTTPSType httpsType = new HTTPSType();
    httpsType.setEnabled(https);
    httpsType.setTlsMode(TLSMode.ONE_WAY);
    api.setHttps(httpsType);

    TdrData tdrData = new TdrData();

    TdrType tdrType = new TdrType();
    tdrType.getType().add("apiRateLimit");

    DynamicTdr dt = new DynamicTdr();
    dt.setHttpHeaderName("HTTP_HEADER");
    dt.setTdrPropName("propname");
    dt.setTypes(tdrType);

    tdrData.getDynamic().add(dt);

    StaticTdr st = new StaticTdr();
    st.setValue("staticValue");
    st.setTdrPropName("staticName");

    st.setTypes(tdrType);

    tdrData.getStatic().add(st);
    api.setTdr(tdrData);

    api.setAuthentication(auth);

  }
View Full Code Here

    provisionData.setValidation(fromDataModel(api.getValidation()));
    provisionData.setHeaderTransEnabled(api.getHeaderTransEnabled());
    provisionData.setInternal(api.getInternal());
   
    ApiProxySettings proxySettings = null;
   
    if(api.isUseGlobalProxy()){
      proxySettings = new ApiProxySettings();
      proxySettings.setGlobalProxy(new ApiProxySettings.GlobalProxy());
    }else if(api.getForwardProxy() != null){
      proxySettings = new ApiProxySettings();
      proxySettings.setLocalProxy(fromDataModel(api.getForwardProxy()));
    }
    provisionData.setProxySettings(proxySettings);
   
    return provisionData;
  }
View Full Code Here

        try {
          apiService.create(api);
        } catch (ProvisionException e) {
          throw new WebApplicationException(e);
        }
        return new ApiResponse(ApiResponse.SUCCESS, api.getId());
      }
    };

    return execute(action, (Object) null);
   
View Full Code Here

    Action action = new Action() {
      protected Object doAction(Object... params) {
        try {
          apiService.update(api);
          return new ApiResponse(ApiResponse.SUCCESS, apiId);

        } catch (ProvisionException e) {
          throw new WebApplicationException(e);
        }
      }
View Full Code Here

        try {
          apiService.delete(apiId);
        } catch (ProvisionException e) {
          throw new WebApplicationException(e);
        }
        return new ApiResponse(ApiResponse.SUCCESS, apiId);
      }
    };
    return execute(action, (Object) null);

  }
View Full Code Here

    Action action = new Action() {

      protected Object doAction(Object... params) {
        try {
          Api api = apiService.get(apiId);
          return new ApiResponse(ApiResponse.SUCCESS, api);

        } catch (ProvisionException e) {
          throw new WebApplicationException(e);
        }
      }
View Full Code Here

    Action action = new Action() {

      protected Object doAction(Object... params) {
        try {
          List<String> apiIdsList = apiService.getAll();
          return new ApiResponse(ApiResponse.SUCCESS, apiIdsList);

        } catch (ProvisionException e) {
          throw new WebApplicationException(e);
        }
      }
View Full Code Here

    return new Action() {

      @Override
      protected Object doAction(Object... params) {
        String policyId = (String) params[0];
        AuthIdsNoIdType authIds = (AuthIdsNoIdType) params[1];

        if(authIds.getId() == null || authIds.getId().equals("")) {
          // create the id
          authIds.setId(UUID.randomUUID().toString());
        }

        if(LOG.isDebugEnabled()) {
          LOG.debug("Create bucket:", authIds.getId());
        }

        com.alu.e3.data.model.sub.QuotaRLBucket authIdsDataModel = BeanConverterUtil.toDataModel(authIds);
        dataManager.createBucket(policyId, authIdsDataModel);

        PolicyResponse response = new PolicyResponse(PolicyResponse.SUCCESS);
        response.setId(authIds.getId());

        return response;
      }
    };
  }
View Full Code Here

      @Override
      protected Object doAction(Object... params) {
        String policyId = (String) params[0];
        String bucketId = (String) params[1];
        AuthIdsNoIdType authIds = (AuthIdsNoIdType) params[2];

        if(LOG.isDebugEnabled()) {
          LOG.debug("Add auths to policy:" + policyId + " on bucket:", bucketId);
        }
View Full Code Here

TOP

Related Classes of com.alu.e3.prov.restapi.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.