Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve: Scope Update Test #13189

Merged
merged 7 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/*
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.wso2.am.integration.tests.other;

import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Factory;
import org.testng.annotations.Test;
import org.wso2.am.integration.clients.publisher.api.v1.dto.ScopeDTO;
import org.wso2.am.integration.test.utils.base.APIMIntegrationConstants;
import org.wso2.am.integration.tests.api.lifecycle.APIManagerLifecycleBaseTest;
import org.wso2.carbon.automation.engine.context.AutomationContext;
import org.wso2.carbon.automation.engine.context.TestUserMode;
import org.wso2.carbon.integration.common.utils.mgt.ServerConfigurationManager;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class SharedScopeTestWithRestart extends APIManagerLifecycleBaseTest {

private String sharedScopeName = "TestSharedScopeWithRestart";
private String sharedScopeDisplayName = "Test Shared Scope with Restart";
private String description = "This is a test shared scope with Restart";
private String updatedDescription = "This is a updated test shared scope with Restart";
private String updatedDescription1 = "This is a updated test shared scope with Restart(2)";
private String updatedDescription2 = "This is a updated test shared scope with Restart(3)";
private List<String> roles = new ArrayList<>();
private String sharedScopeId;
private ServerConfigurationManager serverConfigurationManager;

@Factory(dataProvider = "userModeDataProvider")
public SharedScopeTestWithRestart(TestUserMode userMode) {
this.userMode = userMode;
}

@DataProvider
public static Object[][] userModeDataProvider() {
return new Object[][] { new Object[] { TestUserMode.SUPER_TENANT_ADMIN }};
}

@BeforeClass(alwaysRun = true)
public void setEnvironment() throws Exception {
super.init(userMode);
superTenantKeyManagerContext = new AutomationContext(APIMIntegrationConstants.AM_PRODUCT_GROUP_NAME,
APIMIntegrationConstants.AM_KEY_MANAGER_INSTANCE,
TestUserMode.SUPER_TENANT_ADMIN);
serverConfigurationManager = new ServerConfigurationManager(superTenantKeyManagerContext);
serverConfigurationManager.applyConfiguration(new File(
getAMResourceLocation() + File.separator + "scopes"
+ File.separator + "deployment.toml"));
}

@Test(groups = { "wso2.am" }, description = "Test add shared scope")
public void testAddSharedScope() throws Exception {
ScopeDTO scopeDTO = new ScopeDTO();
scopeDTO.setName(sharedScopeName);
scopeDTO.setDisplayName(sharedScopeDisplayName);
scopeDTO.setDescription(description);

roles.add("Internal/publisher");
roles.add("admin");
scopeDTO.setBindings(roles);

ScopeDTO addedScopeDTO = restAPIPublisher.addSharedScope(scopeDTO);
sharedScopeId = addedScopeDTO.getId();
Assert.assertNotNull(sharedScopeId, "The scope ID cannot be null or empty");
}

@Test(groups = { "wso2.am" }, description = "Test get and update shared scope",
dependsOnMethods = "testAddSharedScope")
public void testGetAndUpdateSharedScope() throws Exception {
ScopeDTO sharedScopeDTO = restAPIPublisher.getSharedScopeById(sharedScopeId);
Assert.assertEquals(sharedScopeDTO.getName(), sharedScopeName,
"Shared scope name does not match with the expected name");
Assert.assertEquals(sharedScopeDTO.getDisplayName(), sharedScopeDisplayName,
"Shared scope display name does not match with the expected display name");
Assert.assertTrue(sharedScopeDTO.getBindings().contains("admin"),
"Shared scope does not include the expected role");

sharedScopeDTO.setDescription(updatedDescription);
ScopeDTO updateScopeDTO = restAPIPublisher.updateSharedScope(sharedScopeId, sharedScopeDTO);
Assert.assertEquals(updateScopeDTO.getDescription(), updatedDescription,
"Shared scope description does not match with the expected description");

sharedScopeDTO.setDescription(updatedDescription1);
updateScopeDTO = restAPIPublisher.updateSharedScope(sharedScopeId, sharedScopeDTO);
Assert.assertEquals(updateScopeDTO.getDescription(), updatedDescription1,
"Shared scope description does not match with the expected description");

sharedScopeDTO.setDescription(updatedDescription2);
updateScopeDTO = restAPIPublisher.updateSharedScope(sharedScopeId, sharedScopeDTO);
Assert.assertEquals(updateScopeDTO.getDescription(), updatedDescription2,
"Shared scope description does not match with the expected description");
}

@Test(groups = { "wso2.am" }, description = "Test delete shared scope",
dependsOnMethods = "testGetAndUpdateSharedScope")
public void testDeleteSharedScope() throws Exception {
restAPIPublisher.deleteSharedScope(sharedScopeId);
}

@AfterClass(alwaysRun = true)
public void destroy() throws Exception {
super.cleanUp();
serverConfigurationManager.restoreToLastConfiguration();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
[server]
hostname = "localhost"
#offset=0
base_path = "${carbon.protocol}://${carbon.host}:${carbon.management.port}"
server_role = "default"
enable_shutdown_from_api = true
enable_restart_from_api = true

[super_admin]
username = "admin"
password = "admin"
create_admin_account = true

[user_store]
type = "database_unique_id"

[database.apim_db]
driver = "$env{API_MANAGER_DATABASE_DRIVER}"
url = "$env{API_MANAGER_DATABASE_URL}"
username = "$env{API_MANAGER_DATABASE_USERNAME}"
password = "$env{API_MANAGER_DATABASE_PASSWORD}"
validationQuery = "$env{API_MANAGER_DATABASE_VALIDATION_QUERY}"

[database.shared_db]
driver = "$env{SHARED_DATABASE_DRIVER}"
url = "$env{SHARED_DATABASE_URL}"
username = "$env{SHARED_DATABASE_USERNAME}"
password = "$env{SHARED_DATABASE_PASSWORD}"
validationQuery = "$env{SHARED_DATABASE_VALIDATION_QUERY}"

[keystore.tls]
file_name = "wso2carbon.jks"
type = "JKS"
password = "wso2carbon"
alias = "wso2carbon"
key_password = "wso2carbon"

[[apim.gateway.environment]]
name = "Default"
type = "hybrid"
provider = "wso2"
display_in_api_console = true
description = "This is a hybrid gateway that handles both production and sandbox token traffic."
show_as_token_endpoint_url = true
service_url = "https://localhost:${mgt.transport.https.port}/services/"
username = "admin"
password = "admin"
ws_endpoint = "ws://localhost:9099"
http_endpoint = "http://localhost:${http.nio.port}"
https_endpoint = "https://localhost:${https.nio.port}"

[[apim.gateway.environment]]
name = "devportalEnv"
display_name = "Developer portal Test Environment"
type = "hybrid"
display_in_api_console = false
description = "development api gateway broker"
provider = "solace"
service_url = "http://localhost:9960"
username = "testUser"
ws_endpoint = "ws://localhost:9960/"
wss_endpoint = "wss://localhost:9960/"
http_endpoint = "http://localhost:9960"
https_endpoint = "https://localhost:9960/"
password = "testPassword"
show_as_token_endpoint_url = false

[apim.gateway.environment.properties]
Organization = "TestWSO2"
DisplayName = "Developer portal Test Environment"
DevAccountName = "devPortTestEnv"

[apim.cors]
allow_origins = "*"
allow_methods = ["GET","PUT","POST","DELETE","PATCH","OPTIONS"]
allow_headers = ["authorization","Access-Control-Allow-Origin","Content-Type","SOAPAction"]
allow_credentials = false

[[event_handler]]
name="userPostSelfRegistration"
subscriptions=["POST_ADD_USER"]

[transport]
passthru_https.listener.ssl_profile_interval = 6000
passthru_https.sender.ssl_profile.interval = 6000

[security_audit]
api_token="b57973cf-b74c-4ade-921d-ece83251eceb"
collection_id="f73b8171-4f71-499b-891a-d34aa71f2d45"
base_url="https://localhost:9943/am-auditApi-sample/api/auditapi"
global=true

[apim.certificate_reloader]
period = "1m"

[database.local]
url = "jdbc:h2:./repository/database/WSO2CARBON_DB;DB_CLOSE_ON_EXIT=FALSE"

[[event_listener]]
id = "token_revocation"
type = "org.wso2.carbon.identity.core.handler.AbstractIdentityHandler"
name = "org.wso2.is.notification.ApimOauthEventInterceptor"
order = 1
[event_listener.properties]
notification_endpoint = "https://localhost:${mgt.transport.https.port}/internal/data/v1/notify"
username = "${admin.username}"
password = "${admin.password}"
'header.X-WSO2-KEY-MANAGER' = "default"

[apim.sync_runtime_artifacts.gateway.skip_list]
apis = ["admin--git2231head_v1.0.0.xml","admin--PizzaShackAPI_v1.0.0.xml","admin--ScriptMediatorAPI_v1.0.xml",
"APIThrottleBackendAPI.xml","BackEndSecurity.xml","DigestAuth_API.xml","git2231.xml","HttpPATCHSupport_API.xml","JWKS-Backend.xml","JWTBackendAPI.xml","multiVSR_v1.0.0.xml","Response_API_1.xml","Response_API_2.xml","Response_Custom_API.xml","Response_Error_API.xml","Response_Loc_API.xml","SpecialCRN_v1.0.0.xml","status_code_204_API.xml","stockquote.xml","XML_API.xml","Version1.xml","Version2.xml","schemaValidationAPI.xml"]

[apim.http_client]
max_total= "200"
default_max_per_route= "2"
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@
</classes>
</test>

<test name="apim-integration-tests-shared-scope-with-restart" preserve-order="true" parallel="false" group-by-instances="true">
<parameter name="group" value="group1"/>
<classes>
<class name="org.wso2.am.integration.tests.other.SharedScopeTestWithRestart"/>
</classes>
</test>

<test name="apim-publisher-tests" preserve-order="true" parallel="false" group-by-instances="true">
<parameter name="group" value="group1"/>
<classes>
Expand Down
Loading