Search in sources :

Example 46 with ApplicationDTO

use of org.wso2.micro.gateway.tests.common.model.ApplicationDTO in project product-microgateway by wso2.

the class ResourceLevelEndpointsTestCase method start.

@BeforeClass
public void start() throws Exception {
    String project = "resourceEndpointProject";
    // Define application info
    ApplicationDTO application = new ApplicationDTO();
    application.setName("jwtApp");
    application.setTier("Unlimited");
    application.setId((int) (Math.random() * 1000));
    jwtTokenProd = TokenUtil.getBasicJWT(application, new JSONObject(), TestConstant.KEY_TYPE_PRODUCTION, 3600);
    // generate apis with CLI and start the micro gateway server
    super.init(project, new String[] { "common_api.yaml" });
}
Also used : ApplicationDTO(org.wso2.micro.gateway.tests.common.model.ApplicationDTO) JSONObject(org.json.JSONObject) BeforeClass(org.testng.annotations.BeforeClass)

Example 47 with ApplicationDTO

use of org.wso2.micro.gateway.tests.common.model.ApplicationDTO in project product-microgateway by wso2.

the class BasicGrpcTestCase method start.

@BeforeClass
public void start() throws Exception {
    String project = "GrpcProject";
    // Define application info
    ApplicationDTO application = new ApplicationDTO();
    application.setName("grpcApp");
    application.setTier("Unlimited");
    application.setId((int) (Math.random() * 1000));
    jwtTokenProd = TokenUtil.getBasicJWT(application, new JSONObject(), TestConstant.KEY_TYPE_PRODUCTION, 3600);
    Map<String, String> claimMap = new HashMap<>();
    claimMap.put("scope", "scope_1");
    jwtTokenProdWithValidScopes = TokenUtil.getJwtWithCustomClaims(application, new JSONObject(), TestConstant.KEY_TYPE_PRODUCTION, 3600, claimMap);
    String originalInput = "generalUser1:password";
    basicAuthToken = Base64.getEncoder().encodeToString(originalInput.getBytes());
    // generate apis with CLI and start the micro gateway server
    super.init(project, new String[] { "../protobuf/mgwProto/basicProto.proto" });
    grpcServer = new GrpcServer();
    grpcServer.start();
}
Also used : ApplicationDTO(org.wso2.micro.gateway.tests.common.model.ApplicationDTO) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) BeforeClass(org.testng.annotations.BeforeClass)

Example 48 with ApplicationDTO

use of org.wso2.micro.gateway.tests.common.model.ApplicationDTO in project product-microgateway by wso2.

the class APIInvokeWithOAuthTestCase method start.

@BeforeClass
public void start() throws Exception {
    String label = "apimTestLabel";
    String project = "apimTestProject";
    // get mock APIM Instance
    MockAPIPublisher pub = MockAPIPublisher.getInstance();
    API api = new API();
    api.setName("PizzaShackAPI");
    api.setContext("/pizzashack");
    api.setProdEndpoint(getMockServiceURLHttp("/echo/prod"));
    api.setSandEndpoint(getMockServiceURLHttp("/echo/sand"));
    api.setVersion("1.0.0");
    api.setProvider("admin");
    // Register API with label
    pub.addApi(label, api);
    // Define application info
    ApplicationDTO application = new ApplicationDTO();
    application.setName("jwtApp");
    application.setTier("Unlimited");
    application.setId(2);
    // Register a production token with key validation info
    KeyValidationInfo info = new KeyValidationInfo();
    info.setApi(api);
    info.setApplication(application);
    info.setAuthorized(true);
    info.setKeyType(TestConstant.KEY_TYPE_PRODUCTION);
    info.setSubscriptionTier("Unlimited");
    info.setTokenType(TestConstant.KEY_TYPE_PRODUCTION);
    // Register a production token with key validation info
    prodToken = pub.getAndRegisterAccessToken(info);
    // Register a sandbox token with key validation info
    KeyValidationInfo infoSand = new KeyValidationInfo();
    infoSand.setApi(api);
    infoSand.setApplication(application);
    infoSand.setAuthorized(true);
    infoSand.setKeyType(TestConstant.KEY_TYPE_SANDBOX);
    infoSand.setTokenType(TestConstant.KEY_TYPE_SANDBOX);
    infoSand.setSubscriptionTier("Unlimited");
    sandToken = pub.getAndRegisterAccessToken(infoSand);
    jwtTokenProd = getJWT(api, application, "Unlimited", TestConstant.KEY_TYPE_PRODUCTION, 3600);
    jwtTokenSand = getJWT(api, application, "Unlimited", TestConstant.KEY_TYPE_SANDBOX, 3600);
    expiringJwtTokenProd = getJWT(api, application, "Unlimited", TestConstant.KEY_TYPE_PRODUCTION, 1);
    // generate apis with CLI and start the micro gateway server
    super.init(label, project);
}
Also used : ApplicationDTO(org.wso2.micro.gateway.tests.common.model.ApplicationDTO) API(org.wso2.micro.gateway.tests.common.model.API) MockAPIPublisher(org.wso2.micro.gateway.tests.common.MockAPIPublisher) KeyValidationInfo(org.wso2.micro.gateway.tests.common.KeyValidationInfo) BeforeClass(org.testng.annotations.BeforeClass)

Example 49 with ApplicationDTO

use of org.wso2.micro.gateway.tests.common.model.ApplicationDTO in project product-microgateway by wso2.

the class DistributedThrottlingTestCase method start.

@BeforeClass
private void start() throws Exception {
    String label = "apimTestLabel";
    project = "apimTestProject";
    // get mock APIM Instance
    MockAPIPublisher pub = MockAPIPublisher.getInstance();
    API api = new API();
    api.setName("PizzaShackAPI");
    api.setContext("/pizzashack");
    api.setProdEndpoint(getMockServiceURLHttp("/echo/prod"));
    api.setSandEndpoint(getMockServiceURLHttp("/echo/sand"));
    api.setVersion("1.0.0");
    api.setProvider("admin");
    // Register API with label
    pub.addApi(label, api);
    // Define application info
    ApplicationDTO application = new ApplicationDTO();
    application.setName("jwtApp");
    application.setTier("Unlimited");
    application.setId((int) (Math.random() * 1000));
    SubscriptionPolicy subscriptionPolicy = new SubscriptionPolicy();
    subscriptionPolicy.setPolicyName("10MinSubPolicy");
    subscriptionPolicy.setRequestCount(10);
    pub.addSubscriptionPolicy(subscriptionPolicy);
    SubscriptionPolicy subPolicyContinueOnLimit = new SubscriptionPolicy();
    subPolicyContinueOnLimit.setPolicyName("allowOnLimitExceed");
    subPolicyContinueOnLimit.setRequestCount(10);
    subPolicyContinueOnLimit.setStopOnQuotaReach(false);
    pub.addSubscriptionPolicy(subPolicyContinueOnLimit);
    ApplicationPolicy applicationPolicy = new ApplicationPolicy();
    applicationPolicy.setPolicyName("10MinAppPolicy");
    applicationPolicy.setRequestCount(10);
    pub.addApplicationPolicy(applicationPolicy);
    ApplicationDTO application2 = new ApplicationDTO();
    application2.setName("jwtApp2");
    application2.setTier(applicationPolicy.getPolicyName());
    application2.setId((int) (Math.random() * 1000));
    ApplicationDTO application3 = new ApplicationDTO();
    application3.setName("jwtApp3");
    application3.setTier("Unlimited");
    application3.setId((int) (Math.random() * 1000));
    // Register a token with key validation info
    jwtToken = getJWT(api, application, subscriptionPolicy.getPolicyName(), TestConstant.KEY_TYPE_PRODUCTION, 3600);
    jwtToken2 = getJWT(api, application2, "Unlimited", TestConstant.KEY_TYPE_PRODUCTION, 3600);
    continueOnQuotaToken = getJWT(api, application3, subPolicyContinueOnLimit.getPolicyName(), TestConstant.KEY_TYPE_PRODUCTION, 3600);
    KeyValidationInfo info = new KeyValidationInfo();
    info.setApi(api);
    info.setApplication(application);
    info.setAuthorized(true);
    info.setKeyType(TestConstant.KEY_TYPE_PRODUCTION);
    info.setSubscriptionTier(subscriptionPolicy.getPolicyName());
    info.setTokenType(TestConstant.TOKEN_TYPE_SUBSCRIPTION_THROTTLING);
    token1 = pub.getAndRegisterAccessToken(info);
    KeyValidationInfo info2 = new KeyValidationInfo();
    info2.setApi(api);
    info2.setApplication(application2);
    info2.setAuthorized(true);
    info2.setKeyType(TestConstant.KEY_TYPE_PRODUCTION);
    info2.setSubscriptionTier("Unlimited");
    info2.setTokenType(TestConstant.TOKEN_TYPE_APPLICATION_THROTTLING);
    token2 = pub.getAndRegisterAccessToken(info2);
    ApplicationDTO appWithNonExistPolicy = new ApplicationDTO();
    appWithNonExistPolicy.setName("appWithNonExistPolicy");
    appWithNonExistPolicy.setTier("AppPolicyNotExist");
    appWithNonExistPolicy.setId((int) (Math.random() * 1000));
    noSubPolicyJWT = getJWT(api, application, "SubPolicyNotExist", TestConstant.KEY_TYPE_PRODUCTION, 3600);
    noAppPolicyJWT = getJWT(api, appWithNonExistPolicy, "Unlimited", TestConstant.KEY_TYPE_PRODUCTION, 3600);
    KeyValidationInfo info3 = new KeyValidationInfo();
    info3.setApi(api);
    info3.setApplication(application);
    info3.setAuthorized(true);
    info3.setKeyType(TestConstant.KEY_TYPE_PRODUCTION);
    info3.setSubscriptionTier("SubPolicyNotExist");
    noSubPolicyToken = pub.getAndRegisterAccessToken(info3);
    info3.setApplication(appWithNonExistPolicy);
    info.setSubscriptionTier(subscriptionPolicy.getPolicyName());
    noAppPolicyToken = pub.getAndRegisterAccessToken(info3);
    binaryTestServer1 = new BinaryTestServer();
    binaryTestServer2 = new BinaryTestServer();
    String streamDefinition = readFromInputStream(getClass().getClassLoader().getResourceAsStream("distributedThrottling/stream-definition.json"));
    binaryTestServer1.addStreamDefinition(streamDefinition);
    binaryTestServer2.addStreamDefinition(streamDefinition);
    binaryTestServer1.startServer(9611, 9711);
    binaryTestServer2.startServer(9612, 9712);
    // generate apis with CLI and start the micro gateway server
    init(label, project);
}
Also used : ApplicationDTO(org.wso2.micro.gateway.tests.common.model.ApplicationDTO) SubscriptionPolicy(org.wso2.micro.gateway.tests.common.model.SubscriptionPolicy) ApplicationPolicy(org.wso2.micro.gateway.tests.common.model.ApplicationPolicy) API(org.wso2.micro.gateway.tests.common.model.API) MockAPIPublisher(org.wso2.micro.gateway.tests.common.MockAPIPublisher) KeyValidationInfo(org.wso2.micro.gateway.tests.common.KeyValidationInfo) BeforeClass(org.testng.annotations.BeforeClass)

Example 50 with ApplicationDTO

use of org.wso2.micro.gateway.tests.common.model.ApplicationDTO in project product-microgateway by wso2.

the class ThrottlingTestCase method start.

@BeforeClass
public void start() throws Exception {
    String label = "apimTestLabel";
    String project = "ThrottlingProject";
    // get mock APIM Instance
    MockAPIPublisher pub = MockAPIPublisher.getInstance();
    API api = new API();
    api.setName("PizzaShackAPI");
    api.setContext("/pizzashack");
    api.setEndpoint(getMockServiceURLHttp("/echo"));
    api.setVersion("1.0.0");
    api.setProvider("admin");
    // Register API with label
    pub.addApi(label, api);
    // Define application(Unlimited) info
    ApplicationDTO application = new ApplicationDTO();
    application.setName("jwtApp");
    application.setTier("Unlimited");
    application.setId((int) (Math.random() * 1000));
    ApplicationPolicy applicationPolicy = new ApplicationPolicy();
    applicationPolicy.setPolicyName("5MinAppPolicy");
    applicationPolicy.setRequestCount(5);
    pub.addApplicationPolicy(applicationPolicy);
    // Define 10req application
    ApplicationDTO application2 = new ApplicationDTO();
    application2.setName("jwtApp2");
    application2.setTier(applicationPolicy.getPolicyName());
    application2.setId((int) (Math.random() * 1000));
    SubscriptionPolicy subscriptionPolicy = new SubscriptionPolicy();
    subscriptionPolicy.setPolicyName("5MinSubPolicy");
    subscriptionPolicy.setRequestCount(5);
    pub.addSubscriptionPolicy(subscriptionPolicy);
    SubscriptionPolicy subPolicyContinueOnLimit = new SubscriptionPolicy();
    subPolicyContinueOnLimit.setPolicyName("allowOnLimitExceed");
    subPolicyContinueOnLimit.setRequestCount(10);
    subPolicyContinueOnLimit.setStopOnQuotaReach(false);
    pub.addSubscriptionPolicy(subPolicyContinueOnLimit);
    ApplicationDTO application3 = new ApplicationDTO();
    application3.setName("jwtApp3");
    application3.setTier("Unlimited");
    application3.setId((int) (Math.random() * 1000));
    // Register a token with key validation info
    jwtToken = getJWT(api, application, subscriptionPolicy.getPolicyName(), TestConstant.KEY_TYPE_PRODUCTION, 3600);
    jwtToken2 = getJWT(api, application2, "Unlimited", TestConstant.KEY_TYPE_PRODUCTION, 3600);
    continueOnQuotaToken = getJWT(api, application3, subPolicyContinueOnLimit.getPolicyName(), TestConstant.KEY_TYPE_PRODUCTION, 3600);
    KeyValidationInfo info = new KeyValidationInfo();
    info.setApi(api);
    info.setApplication(application);
    info.setAuthorized(true);
    info.setKeyType(TestConstant.KEY_TYPE_PRODUCTION);
    info.setTokenType(TestConstant.TOKEN_TYPE_5_MIN_SUB);
    info.setSubscriptionTier(subscriptionPolicy.getPolicyName());
    token1 = pub.getAndRegisterAccessToken(info);
    KeyValidationInfo info2 = new KeyValidationInfo();
    info2.setApi(api);
    info2.setApplication(application2);
    info2.setAuthorized(true);
    info2.setKeyType(TestConstant.KEY_TYPE_PRODUCTION);
    info2.setTokenType(TestConstant.TOKEN_TYPE_5_MIN_APP);
    info2.setSubscriptionTier("Unlimited");
    token2 = pub.getAndRegisterAccessToken(info2);
    ApplicationDTO appWithNonExistPolicy = new ApplicationDTO();
    appWithNonExistPolicy.setName("appWithNonExistPolicy");
    appWithNonExistPolicy.setTier("AppPolicyNotExist");
    appWithNonExistPolicy.setId((int) (Math.random() * 1000));
    noSubPolicyJWT = getJWT(api, application, "SubPolicyNotExist", TestConstant.KEY_TYPE_PRODUCTION, 3600);
    noAppPolicyJWT = getJWT(api, appWithNonExistPolicy, "Unlimited", TestConstant.KEY_TYPE_PRODUCTION, 3600);
    KeyValidationInfo info3 = new KeyValidationInfo();
    info3.setApi(api);
    info3.setApplication(application);
    info3.setAuthorized(true);
    info3.setKeyType(TestConstant.KEY_TYPE_PRODUCTION);
    info3.setSubscriptionTier("SubPolicyNotExist");
    info3.setTokenType(TestConstant.TOKEN_TYPE_INVALID_SUB_POLICY);
    noSubPolicyToken = pub.getAndRegisterAccessToken(info3);
    info3.setApplication(appWithNonExistPolicy);
    info3.setSubscriptionTier(subscriptionPolicy.getPolicyName());
    info3.setTokenType(TestConstant.TOKEN_TYPE_INVALID_APP_POLICY);
    noAppPolicyToken = pub.getAndRegisterAccessToken(info3);
    // generate apis with CLI and start the micro gateway server
    super.init(label, project);
}
Also used : ApplicationDTO(org.wso2.micro.gateway.tests.common.model.ApplicationDTO) SubscriptionPolicy(org.wso2.micro.gateway.tests.common.model.SubscriptionPolicy) ApplicationPolicy(org.wso2.micro.gateway.tests.common.model.ApplicationPolicy) API(org.wso2.micro.gateway.tests.common.model.API) MockAPIPublisher(org.wso2.micro.gateway.tests.common.MockAPIPublisher) KeyValidationInfo(org.wso2.micro.gateway.tests.common.KeyValidationInfo) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

BeforeClass (org.testng.annotations.BeforeClass)17 ApplicationDTO (org.wso2.micro.gateway.tests.common.model.ApplicationDTO)17 Application (org.wso2.carbon.apimgt.core.models.Application)11 ApplicationDTO (org.wso2.carbon.apimgt.rest.api.store.dto.ApplicationDTO)11 ArrayList (java.util.ArrayList)10 JSONObject (org.json.JSONObject)10 HashMap (java.util.HashMap)9 Application (org.wso2.carbon.apimgt.api.model.Application)8 API (org.wso2.micro.gateway.tests.common.model.API)8 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)7 ExportedApplication (org.wso2.carbon.apimgt.rest.api.store.v1.models.ExportedApplication)7 KeyValidationInfo (org.wso2.micro.gateway.tests.common.KeyValidationInfo)7 MockAPIPublisher (org.wso2.micro.gateway.tests.common.MockAPIPublisher)7 Test (org.junit.Test)6 APIConsumer (org.wso2.carbon.apimgt.api.APIConsumer)6 ApplicationKeysDTO (org.wso2.carbon.apimgt.rest.api.store.dto.ApplicationKeysDTO)6 ApplicationDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.ApplicationDTO)6 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)5 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)5 ApplicationCreationResponse (org.wso2.carbon.apimgt.core.workflow.ApplicationCreationResponse)5