From 98a9d0beabf6ba46b44972830230ef8ee06d460b Mon Sep 17 00:00:00 2001 From: Nirothipan Date: Fri, 29 Sep 2017 23:16:34 +0530 Subject: [PATCH 1/7] unCOmpleted chnages of initial test for apiPblisher --- .../pom.xml | 5 + .../publisher/APIPublisherServiceImpl.java | 7 +- .../publisher/APIPublisherServiceTest.java | 107 +++ .../webapp/publisher/BaseAPIPublisheTest.java | 257 +++++++ .../webapp/publisher/DataSourceConfig.java | 76 ++ .../apimgt/webapp/publisher/utils/Utils.java | 79 +++ .../resources/carbon-home/dbscripts/h2.sql | 429 ++++++++++++ .../repository/conf/apim-integration.xml | 34 + .../carbon-home/repository/conf/carbon.xml | 656 ++++++++++++++++++ .../carbon-home/repository/conf/registry.xml | 50 ++ .../config/datasource/data-source-config.xml | 33 + .../resources/config/operation/cdm-config.xml | 96 +++ .../config/schema/app-mgt-config-schema.xsd | 31 + .../schema/device-mgt-config-schema.xsd | 48 ++ .../src/test/resources/testng.xml | 29 + .../user-test/user-mgt-registry-test.xml | 80 +++ components/test-coverage/pom.xml | 3 + 17 files changed, 2017 insertions(+), 3 deletions(-) create mode 100644 components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceTest.java create mode 100644 components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/BaseAPIPublisheTest.java create mode 100644 components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/DataSourceConfig.java create mode 100644 components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/utils/Utils.java create mode 100644 components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/carbon-home/dbscripts/h2.sql create mode 100644 components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/carbon-home/repository/conf/apim-integration.xml create mode 100644 components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/carbon-home/repository/conf/carbon.xml create mode 100644 components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/carbon-home/repository/conf/registry.xml create mode 100644 components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/config/datasource/data-source-config.xml create mode 100644 components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/config/operation/cdm-config.xml create mode 100644 components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/config/schema/app-mgt-config-schema.xsd create mode 100644 components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/config/schema/device-mgt-config-schema.xsd create mode 100644 components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/testng.xml create mode 100644 components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/user-test/user-mgt-registry-test.xml diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml index 34fef116f5..66db3da85f 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml @@ -107,6 +107,11 @@ org.wso2.carbon.devicemgt org.wso2.carbon.apimgt.integration.client + + com.h2database.wso2 + h2-database-engine + test + diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java index f7914d3d52..2604bfc83e 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java @@ -43,8 +43,8 @@ public class APIPublisherServiceImpl implements APIPublisherService { @Override public void publishAPI(APIConfig apiConfig) throws APIManagerPublisherException { String tenantDomain = MultitenantUtils.getTenantDomain(apiConfig.getOwner()); - PrivilegedCarbonContext.startTenantFlow(); - PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true); +// PrivilegedCarbonContext.startTenantFlow(); +// PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true); PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(apiConfig.getOwner()); try { PublisherClient publisherClient = APIPublisherDataHolder.getInstance().getIntegrationClientService() @@ -74,7 +74,8 @@ public class APIPublisherServiceImpl implements APIPublisherService { } catch (FeignException e) { throw new APIManagerPublisherException(e); } finally { - PrivilegedCarbonContext.endTenantFlow(); + + //PrivilegedCarbonContext.endTenantFlow(); } } diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceTest.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceTest.java new file mode 100644 index 0000000000..835c1df12b --- /dev/null +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceTest.java @@ -0,0 +1,107 @@ +/* +* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 Inc. licenses this file to you 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.carbon.apimgt.webapp.publisher; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.apimgt.integration.client.OAuthRequestInterceptor; +import org.wso2.carbon.apimgt.integration.client.model.OAuthApplication; +import org.wso2.carbon.apimgt.webapp.publisher.dto.ApiScope; +import org.wso2.carbon.apimgt.webapp.publisher.dto.ApiUriTemplate; +import org.wso2.carbon.apimgt.webapp.publisher.exception.APIManagerPublisherException; + +import java.lang.reflect.Field; +import java.util.*; + +public class +APIPublisherServiceTest extends BaseAPIPublisheTest{ + private static final Log log = LogFactory.getLog(APIPublisherServiceTest.class); + + + + @Test + public void publishAPI() throws APIManagerPublisherException, NoSuchFieldException, IllegalAccessException { + APIPublisherServiceImpl apiPublisherService = new APIPublisherServiceImpl(); + + APIConfig apiConfig = new APIConfig(); + + apiConfig.setName("Windows Device Management Administrative Service"); + apiConfig.setContext("/api/device-mgt/windows/v1.0/admin/devices"); + apiConfig.setOwner("admin"); + apiConfig.setEndpoint("https://localhost:9443/api/device-mgt/windows/v1.0/admin/devices"); + apiConfig.setVersion("1.0.0"); + apiConfig.setTransports("http,https"); + apiConfig.setPolicy(null); + apiConfig.setSharedWithAllTenants(true); + apiConfig.setTags(new String[]{"windows", "device_management"}); + apiConfig.setTenantDomain("carbon.super"); + apiConfig.setSecured(false); + + Map apiScopes = new HashMap<>(); + Set scopes = new HashSet<>(apiScopes.values()); + + // apiScopes.put("key","") + + + + + apiConfig.setScopes(scopes); + + + + Set uriTemplates = new LinkedHashSet<>(); + ApiUriTemplate template = new ApiUriTemplate(); + template.setAuthType("Application & Application User"); + template.setHttpVerb("POST"); + template.setResourceURI("https://localhost:9443/api/device-mgt/windows/v1.0/admin/devices/reboot"); + template.setUriTemplate("/reboot"); + ApiScope scope = new ApiScope(); + scope.setKey("perm:windows:reboot"); + scope.setName("Reboot"); + scope.setRoles("/permission/admin/device-mgt/devices/owning-device/operations/windows/reboot"); + scope.setDescription("Lock reset on Windows devices"); + template.setScope(scope); + uriTemplates.add(template); + + apiConfig.setUriTemplates(uriTemplates); + + + + OAuthApplication oAuthApplication = new OAuthApplication(); + + oAuthApplication.setClientName("admin_api_integration_client"); + oAuthApplication.setIsSaasApplication("true"); + oAuthApplication.setClientId("dsnkdsaxakdnfkanfdax="); + oAuthApplication.setClientSecret("safjksajnjnkjcksancka"); + + Field oAuth = OAuthRequestInterceptor.class.getDeclaredField("oAuthApplication"); + oAuth.setAccessible(true); + oAuth.set(null,oAuthApplication); + + + apiPublisherService.publishAPI(apiConfig); + } + + @BeforeClass + @Override + public void init() throws Exception { + // do nothing + } +} diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/BaseAPIPublisheTest.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/BaseAPIPublisheTest.java new file mode 100644 index 0000000000..fcf2129716 --- /dev/null +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/BaseAPIPublisheTest.java @@ -0,0 +1,257 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.carbon.apimgt.webapp.publisher; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.tomcat.jdbc.pool.PoolProperties; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeSuite; +import org.w3c.dom.Document; +import org.wso2.carbon.CarbonConstants; +import org.wso2.carbon.apimgt.integration.client.IntegrationClientServiceImpl; +import org.wso2.carbon.apimgt.integration.client.internal.APIIntegrationClientDataHolder; +import org.wso2.carbon.apimgt.webapp.publisher.internal.APIPublisherDataHolder; +import org.wso2.carbon.apimgt.webapp.publisher.utils.Utils; +import org.wso2.carbon.base.MultitenantConstants; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.context.RegistryType; +import org.wso2.carbon.context.internal.OSGiDataHolder; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.governance.api.util.GovernanceArtifactConfiguration; +import org.wso2.carbon.governance.api.util.GovernanceUtils; +import org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerServiceImpl; +import org.wso2.carbon.registry.core.Registry; +import org.wso2.carbon.registry.core.config.RegistryContext; +import org.wso2.carbon.registry.core.exceptions.RegistryException; +import org.wso2.carbon.registry.core.internal.RegistryDataHolder; +import org.wso2.carbon.registry.core.jdbc.realm.InMemoryRealmService; +import org.wso2.carbon.registry.core.service.RegistryService; +import org.wso2.carbon.registry.core.session.UserRegistry; +import org.wso2.carbon.user.api.TenantManager; +import org.wso2.carbon.user.api.UserStoreException; +import org.wso2.carbon.user.core.service.RealmService; +import org.wso2.carbon.user.core.tenant.JDBCTenantManager; +import org.wso2.carbon.utils.FileUtil; + +import javax.sql.DataSource; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +import static org.wso2.carbon.governance.api.util.GovernanceUtils.getGovernanceArtifactConfiguration; + +public abstract class BaseAPIPublisheTest { + + private DataSource dataSource; + private static final Log log = LogFactory.getLog(BaseAPIPublisheTest.class); + + @BeforeSuite + public void iniTwo() throws RegistryException, IOException, org.wso2.carbon.user.api.UserStoreException { + ClassLoader classLoader = getClass().getClassLoader(); + URL resourceUrl = classLoader.getResource("license.rxt"); + String rxt = null; + File carbonHome; + if (resourceUrl != null) { + rxt = FileUtil.readFileToString(resourceUrl.getFile()); + } + resourceUrl = classLoader.getResource("carbon-home"); + + if (resourceUrl != null) { + carbonHome = new File(resourceUrl.getFile()); + System.setProperty("carbon.home", carbonHome.getAbsolutePath()); + } + + PrivilegedCarbonContext.getThreadLocalCarbonContext() + .setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID); + RegistryService registryService = this.getRegistryService(); + OSGiDataHolder.getInstance().setRegistryService(registryService); + UserRegistry systemRegistry = + registryService.getRegistry(CarbonConstants.REGISTRY_SYSTEM_USERNAME); + + GovernanceArtifactConfiguration configuration = getGovernanceArtifactConfiguration(rxt); + List configurations = new ArrayList<>(); + configurations.add(configuration); + GovernanceUtils.loadGovernanceArtifacts(systemRegistry, configurations); + Registry governanceSystemRegistry = registryService.getConfigSystemRegistry(); + // DeviceTypeExtensionDataHolder.getInstance().setRegistryService(registryService); + PrivilegedCarbonContext.getThreadLocalCarbonContext() + .setRegistry(RegistryType.SYSTEM_CONFIGURATION, governanceSystemRegistry); + } + + @BeforeSuite + public void setupDataSource() throws Exception { + this.initDataSource(); + // this.initSQLScript(); + this.initializeCarbonContext(); + this.initServices(); + } + + protected void initDataSource() throws Exception { + this.dataSource = this.getDataSource(this.readDataSourceConfig()); + } + + private void initServices() throws DeviceManagementException, RegistryException { + APIPublisherDataHolder.getInstance().setIntegrationClientService(IntegrationClientServiceImpl.getInstance()); + APIIntegrationClientDataHolder.getInstance().setJwtClientManagerService(new JWTClientManagerServiceImpl()); + + +// DeviceConfigurationManager.getInstance().initConfig(); +// DeviceManagementProviderService deviceMgtService = new DeviceManagementProviderServiceImpl(); +// DeviceManagementServiceComponent.notifyStartupListeners(); +// DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceMgtService); +// DeviceManagementDataHolder.getInstance().setRegistryService(getRegistryService()); +// DeviceManagementDataHolder.getInstance().setDeviceAccessAuthorizationService(new DeviceAccessAuthorizationServiceImpl()); +// DeviceManagementDataHolder.getInstance().setGroupManagementProviderService(new GroupManagementProviderServiceImpl()); +// DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(null); + } + + private RegistryService getRegistryService() throws RegistryException, UserStoreException { + RealmService realmService = new InMemoryRealmService(); + TenantManager tenantManager = new JDBCTenantManager(dataSource, + org.wso2.carbon.utils.multitenancy.MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); + realmService.setTenantManager(tenantManager); + APIPublisherDataHolder.getInstance().setRealmService(realmService); + RegistryDataHolder.getInstance().setRealmService(realmService); + + //DeviceManagementDataHolder.getInstance().setRealmService(realmService); + InputStream is = this.getClass().getClassLoader().getResourceAsStream("carbon-home/repository/conf/registry.xml"); + RegistryContext context = RegistryContext.getBaseInstance(is, realmService); + context.setSetup(true); + return context.getEmbeddedRegistryService(); + } + + @BeforeClass + public abstract void init() throws Exception; + + private DataSource getDataSource(DataSourceConfig config) { + int id =0; + PoolProperties properties = new PoolProperties(); + properties.setUrl(config.getUrl()); + properties.setDriverClassName(config.getDriverClassName()); + properties.setUsername(config.getUser()); + properties.setPassword(config.getPassword()); + return new org.apache.tomcat.jdbc.pool.DataSource(properties); + } + + private void initializeCarbonContext() { + + if (System.getProperty("carbon.home") == null) { + int noweowe = 89; + File file = new File("src/test/resources/carbon-home"); + if (file.exists()) { + System.setProperty("carbon.home", file.getAbsolutePath()); + } + file = new File("../resources/carbon-home"); + if (file.exists()) { + System.setProperty("carbon.home", file.getAbsolutePath()); + } + file = new File("../../resources/carbon-home"); + if (file.exists()) { + System.setProperty("carbon.home", file.getAbsolutePath()); + } + file = new File("../../../resources/carbon-home"); + if (file.exists()) { + System.setProperty("carbon.home", file.getAbsolutePath()); + } + } + + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants + .SUPER_TENANT_DOMAIN_NAME); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID); + } + + private DataSourceConfig readDataSourceConfig() throws DeviceManagementException { + try { + File file = new File("src/test/resources/config/datasource/data-source-config.xml"); + Document doc = Utils.convertToDocument(file); + JAXBContext testDBContext = JAXBContext.newInstance(DataSourceConfig.class); + Unmarshaller unmarshaller = testDBContext.createUnmarshaller(); + return (DataSourceConfig) unmarshaller.unmarshal(doc); + } catch (JAXBException e) { + throw new DeviceManagementException("Error occurred while reading data source configuration", e); + } + } + +/* + private void initSQLScript() throws Exception { + Connection conn = null; + Statement stmt = null; + try { + conn = this.getDataSource().getConnection(); + stmt = conn.createStatement(); + stmt.executeUpdate("RUNSCRIPT FROM './src/test/resources/sql/h2.sql'"); + } finally { + TestUtils.cleanupResources(conn, stmt, null); + } + }*/ + + /* public void deleteData() { + Connection conn = null; + try { + conn = getDataSource().getConnection(); + conn.setAutoCommit(false); + String[] cleanupTables = new String[]{"DM_NOTIFICATION","DM_DEVICE_OPERATION_RESPONSE","DM_ENROLMENT_OP_MAPPING", "DM_CONFIG_OPERATION", + "DM_POLICY_OPERATION", "DM_COMMAND_OPERATION", "DM_PROFILE_OPERATION", "DM_DEVICE_GROUP_MAP", + "DM_GROUP", "DM_ENROLMENT", "DM_DEVICE_APPLICATION_MAPPING", + "DM_APPLICATION", "DM_DEVICE", "DM_DEVICE_TYPE"}; + for (String table : cleanupTables) { + this.cleanData(conn, table); + } + conn.commit(); + } catch (SQLException e) { + try { + if (conn != null) { + conn.rollback(); + } + } catch (SQLException e1) { + log.error("Error occurred while roll-backing the transaction", e); + } + String msg = "Error occurred while cleaning up temporary data generated during test execution"; + log.error(msg, e); + Assert.fail(msg, e); + } finally { + if (conn != null) { + try { + conn.close(); + } catch (SQLException e) { + log.warn("Error occurred while closing the connection", e); + } + } + } + }*/ + + /*private void cleanData(Connection conn, String tableName) throws SQLException { + try (PreparedStatement stmt = conn.prepareStatement("DELETE FROM " + tableName)) { + stmt.execute(); + } + } + + protected DataSource getDataSource() { + return dataSource; + }*/ + +} diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/DataSourceConfig.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/DataSourceConfig.java new file mode 100644 index 0000000000..f3e31968fe --- /dev/null +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/DataSourceConfig.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.carbon.apimgt.webapp.publisher; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "DataSourceConfig") +public class DataSourceConfig { + + private String url; + private String driverClassName; + private String user; + private String password; + + @Override public String toString() { + return "DataSourceConfig[" + + " Url ='" + url + '\'' + + ", DriverClassName ='" + driverClassName + '\'' + + ", UserName ='" + user + '\'' + + ", Password ='" + password + '\'' + + "]"; + } + + @XmlElement(name = "Url", nillable = false) + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + @XmlElement(name = "DriverClassName", nillable = false) + public String getDriverClassName() { + return driverClassName; + } + + public void setDriverClassName(String driverClassName) { + this.driverClassName = driverClassName; + } + + @XmlElement(name = "User", nillable = false) + public String getUser() { + return user; + } + + public void setUser(String user) { + this.user = user; + } + + @XmlElement(name = "Password", nillable = false) + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + +} diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/utils/Utils.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/utils/Utils.java new file mode 100644 index 0000000000..33b095d670 --- /dev/null +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/utils/Utils.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.carbon.apimgt.webapp.publisher.utils; + +import org.w3c.dom.Document; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.registry.core.exceptions.RegistryException; + +import javax.xml.XMLConstants; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import java.io.File; + +/** + * This class handles the test utility tasks. + */ +public class Utils { + + public static Document convertToDocument(File file) throws DeviceManagementException { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + try { + int rwew = 222; + DocumentBuilder docBuilder = factory.newDocumentBuilder(); + factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); + return docBuilder.parse(file); + } catch (Exception e) { + throw new DeviceManagementException("Error occurred while parsing file, while converting " + + "to a org.w3c.dom.Document", e); + } + } + + /* *//** + * To get the registry service. + * @return RegistryService + * @throws RegistryException Registry Exception + *//* + public static RegistryService getRegistryService() throws RegistryException, org.wso2.carbon.user.api.UserStoreException { + RealmService realmService = new InMemoryRealmService(); + + + PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername("admin"); + + BasicDataSource dataSource = new BasicDataSource(); + String connectionUrl = "jdbc:h2:./target/database-test/CARBON_TEST"; + dataSource.setUrl(connectionUrl); + dataSource.setDriverClassName("org.h2.Driver"); + TenantManager jdbcTenantManager = new JDBCTenantManager(dataSource, + MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); + + realmService.setTenantManager(jdbcTenantManager); + RegistryDataHolder.getInstance().setRealmService(realmService); + APIPublisherDataHolder.getInstance().setRealmService(realmService); + //APIApplicationManagerExtensionDataHolder.getInstance().setRealmService(realmService); + //DeviceManagementDataHolder.getInstance().setRealmService(realmService); + InputStream is = Utils.class.getClassLoader().getResourceAsStream("carbon-home/repository/" + + "conf/registry.xml"); + RegistryContext context = RegistryContext.getBaseInstance(is, realmService); + context.setSetup(true); + return context.getEmbeddedRegistryService(); + }*/ +} diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/carbon-home/dbscripts/h2.sql b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/carbon-home/dbscripts/h2.sql new file mode 100644 index 0000000000..f6b31c78d9 --- /dev/null +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/carbon-home/dbscripts/h2.sql @@ -0,0 +1,429 @@ +CREATE TABLE IF NOT EXISTS REG_CLUSTER_LOCK ( + REG_LOCK_NAME VARCHAR (20), + REG_LOCK_STATUS VARCHAR (20), + REG_LOCKED_TIME TIMESTAMP, + REG_TENANT_ID INTEGER DEFAULT 0, + PRIMARY KEY (REG_LOCK_NAME) +); + +CREATE TABLE IF NOT EXISTS REG_LOG ( + REG_LOG_ID INTEGER AUTO_INCREMENT, + REG_PATH VARCHAR (2000), + REG_USER_ID VARCHAR (31) NOT NULL, + REG_LOGGED_TIME TIMESTAMP NOT NULL, + REG_ACTION INTEGER NOT NULL, + REG_ACTION_DATA VARCHAR (500), + REG_TENANT_ID INTEGER DEFAULT 0, + PRIMARY KEY (REG_LOG_ID, REG_TENANT_ID) +); + +CREATE INDEX IF NOT EXISTS REG_LOG_IND_BY_REG_LOGTIME ON REG_LOG(REG_LOGGED_TIME, REG_TENANT_ID); + +CREATE TABLE IF NOT EXISTS REG_PATH( + REG_PATH_ID INTEGER NOT NULL AUTO_INCREMENT, + REG_PATH_VALUE VARCHAR(2000) NOT NULL, + REG_PATH_PARENT_ID INT, + REG_TENANT_ID INTEGER DEFAULT 0, + CONSTRAINT PK_REG_PATH PRIMARY KEY(REG_PATH_ID, REG_TENANT_ID) +); +CREATE INDEX IF NOT EXISTS REG_PATH_IND_BY_NAME ON REG_PATH(REG_PATH_VALUE, REG_TENANT_ID); +CREATE INDEX IF NOT EXISTS REG_PATH_IND_BY_PARENT_ID ON REG_PATH(REG_PATH_PARENT_ID, REG_TENANT_ID); + + +CREATE TABLE IF NOT EXISTS REG_CONTENT ( + REG_CONTENT_ID INTEGER NOT NULL AUTO_INCREMENT, + REG_CONTENT_DATA LONGBLOB, + REG_TENANT_ID INTEGER DEFAULT 0, + CONSTRAINT PK_REG_CONTENT PRIMARY KEY(REG_CONTENT_ID, REG_TENANT_ID) +); + +CREATE TABLE IF NOT EXISTS REG_CONTENT_HISTORY ( + REG_CONTENT_ID INTEGER NOT NULL, + REG_CONTENT_DATA LONGBLOB, + REG_DELETED SMALLINT, + REG_TENANT_ID INTEGER DEFAULT 0, + CONSTRAINT PK_REG_CONTENT_HISTORY PRIMARY KEY(REG_CONTENT_ID, REG_TENANT_ID) +); + +CREATE TABLE IF NOT EXISTS REG_RESOURCE ( + REG_PATH_ID INTEGER NOT NULL, + REG_NAME VARCHAR(256), + REG_VERSION INTEGER NOT NULL AUTO_INCREMENT, + REG_MEDIA_TYPE VARCHAR(500), + REG_CREATOR VARCHAR(31) NOT NULL, + REG_CREATED_TIME TIMESTAMP NOT NULL, + REG_LAST_UPDATOR VARCHAR(31), + REG_LAST_UPDATED_TIME TIMESTAMP NOT NULL, + REG_DESCRIPTION VARCHAR(1000), + REG_CONTENT_ID INTEGER, + REG_TENANT_ID INTEGER DEFAULT 0, + REG_UUID VARCHAR(100) NOT NULL, + CONSTRAINT PK_REG_RESOURCE PRIMARY KEY(REG_VERSION, REG_TENANT_ID) +); + +ALTER TABLE REG_RESOURCE ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_FK_BY_PATH_ID FOREIGN KEY (REG_PATH_ID, REG_TENANT_ID) REFERENCES REG_PATH (REG_PATH_ID, REG_TENANT_ID); +ALTER TABLE REG_RESOURCE ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_FK_BY_CONTENT_ID FOREIGN KEY (REG_CONTENT_ID, REG_TENANT_ID) REFERENCES REG_CONTENT (REG_CONTENT_ID, REG_TENANT_ID); +CREATE INDEX IF NOT EXISTS REG_RESOURCE_IND_BY_NAME ON REG_RESOURCE(REG_NAME, REG_TENANT_ID); +CREATE INDEX IF NOT EXISTS REG_RESOURCE_IND_BY_PATH_ID_NAME ON REG_RESOURCE(REG_PATH_ID, REG_NAME, REG_TENANT_ID); +CREATE INDEX IF NOT EXISTS REG_RESOURCE_IND_BY_UUID ON REG_RESOURCE(REG_UUID); +CREATE INDEX IF NOT EXISTS REG_RESOURCE_IND_BY_TENANT ON REG_RESOURCE(REG_TENANT_ID, REG_UUID); +CREATE INDEX IF NOT EXISTS REG_RESOURCE_IND_BY_TYPE ON REG_RESOURCE(REG_TENANT_ID, REG_MEDIA_TYPE); + +CREATE TABLE IF NOT EXISTS REG_RESOURCE_HISTORY ( + REG_PATH_ID INTEGER NOT NULL, + REG_NAME VARCHAR(256), + REG_VERSION INTEGER NOT NULL, + REG_MEDIA_TYPE VARCHAR(500), + REG_CREATOR VARCHAR(31) NOT NULL, + REG_CREATED_TIME TIMESTAMP NOT NULL, + REG_LAST_UPDATOR VARCHAR(31), + REG_LAST_UPDATED_TIME TIMESTAMP NOT NULL, + REG_DESCRIPTION VARCHAR(1000), + REG_CONTENT_ID INTEGER, + REG_DELETED SMALLINT, + REG_TENANT_ID INTEGER DEFAULT 0, + REG_UUID VARCHAR(100) NOT NULL, + CONSTRAINT PK_REG_RESOURCE_HISTORY PRIMARY KEY(REG_VERSION, REG_TENANT_ID) +); + +ALTER TABLE REG_RESOURCE_HISTORY ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_HIST_FK_BY_PATHID FOREIGN KEY (REG_PATH_ID, REG_TENANT_ID) REFERENCES REG_PATH (REG_PATH_ID, REG_TENANT_ID); +ALTER TABLE REG_RESOURCE_HISTORY ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_HIST_FK_BY_CONTENT_ID FOREIGN KEY (REG_CONTENT_ID, REG_TENANT_ID) REFERENCES REG_CONTENT_HISTORY (REG_CONTENT_ID, REG_TENANT_ID); +CREATE INDEX IF NOT EXISTS REG_RESOURCE_HISTORY_IND_BY_NAME ON REG_RESOURCE_HISTORY(REG_NAME, REG_TENANT_ID); +CREATE INDEX IF NOT EXISTS REG_RESOURCE_HISTORY_IND_BY_PATH_ID_NAME ON REG_RESOURCE(REG_PATH_ID, REG_NAME, REG_TENANT_ID); + +CREATE TABLE IF NOT EXISTS REG_COMMENT ( + REG_ID INTEGER NOT NULL AUTO_INCREMENT, + REG_COMMENT_TEXT VARCHAR(500) NOT NULL, + REG_USER_ID VARCHAR(31) NOT NULL, + REG_COMMENTED_TIME TIMESTAMP NOT NULL, + REG_TENANT_ID INTEGER DEFAULT 0, + CONSTRAINT PK_REG_COMMENT PRIMARY KEY(REG_ID, REG_TENANT_ID) +); + +CREATE TABLE IF NOT EXISTS REG_RESOURCE_COMMENT ( + REG_COMMENT_ID INTEGER NOT NULL, + REG_VERSION INTEGER, + REG_PATH_ID INTEGER, + REG_RESOURCE_NAME VARCHAR(256), + REG_TENANT_ID INTEGER DEFAULT 0 +); + +ALTER TABLE REG_RESOURCE_COMMENT ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_COMMENT_FK_BY_PATH_ID FOREIGN KEY (REG_PATH_ID, REG_TENANT_ID) REFERENCES REG_PATH (REG_PATH_ID, REG_TENANT_ID); +ALTER TABLE REG_RESOURCE_COMMENT ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_COMMENT_FK_BY_COMMENT_ID FOREIGN KEY (REG_COMMENT_ID, REG_TENANT_ID) REFERENCES REG_COMMENT (REG_ID, REG_TENANT_ID); +CREATE INDEX IF NOT EXISTS REG_RESOURCE_COMMENT_IND_BY_PATH_ID_AND_RESOURCE_NAME ON REG_RESOURCE_COMMENT(REG_PATH_ID, REG_RESOURCE_NAME, REG_TENANT_ID); +CREATE INDEX IF NOT EXISTS REG_RESOURCE_COMMENT_IND_BY_VERSION ON REG_RESOURCE_COMMENT(REG_VERSION, REG_TENANT_ID); + +CREATE TABLE IF NOT EXISTS REG_RATING ( + REG_ID INTEGER NOT NULL AUTO_INCREMENT, + REG_RATING INTEGER NOT NULL, + REG_USER_ID VARCHAR(31) NOT NULL, + REG_RATED_TIME TIMESTAMP NOT NULL, + REG_TENANT_ID INTEGER DEFAULT 0, + CONSTRAINT PK_REG_RATING PRIMARY KEY(REG_ID, REG_TENANT_ID) +); + +CREATE TABLE IF NOT EXISTS REG_RESOURCE_RATING ( + REG_RATING_ID INTEGER NOT NULL, + REG_VERSION INTEGER, + REG_PATH_ID INTEGER, + REG_RESOURCE_NAME VARCHAR(256), + REG_TENANT_ID INTEGER DEFAULT 0 +); + +ALTER TABLE REG_RESOURCE_RATING ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_RATING_FK_BY_PATH_ID FOREIGN KEY (REG_PATH_ID, REG_TENANT_ID) REFERENCES REG_PATH (REG_PATH_ID, REG_TENANT_ID); +ALTER TABLE REG_RESOURCE_RATING ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_RATING_FK_BY_RATING_ID FOREIGN KEY (REG_RATING_ID, REG_TENANT_ID) REFERENCES REG_RATING (REG_ID, REG_TENANT_ID); +CREATE INDEX IF NOT EXISTS REG_RESOURCE_RATING_IND_BY_PATH_ID_AND_RESOURCE_NAME ON REG_RESOURCE_RATING(REG_PATH_ID, REG_RESOURCE_NAME, REG_TENANT_ID); +CREATE INDEX IF NOT EXISTS REG_RESOURCE_RATING_IND_BY_VERSION ON REG_RESOURCE_RATING(REG_VERSION, REG_TENANT_ID); + + +CREATE TABLE IF NOT EXISTS REG_TAG ( + REG_ID INTEGER NOT NULL AUTO_INCREMENT, + REG_TAG_NAME VARCHAR(500) NOT NULL, + REG_USER_ID VARCHAR(31) NOT NULL, + REG_TAGGED_TIME TIMESTAMP NOT NULL, + REG_TENANT_ID INTEGER DEFAULT 0, + CONSTRAINT PK_REG_TAG PRIMARY KEY(REG_ID, REG_TENANT_ID) +); + +CREATE TABLE IF NOT EXISTS REG_RESOURCE_TAG ( + REG_TAG_ID INTEGER NOT NULL, + REG_VERSION INTEGER, + REG_PATH_ID INTEGER, + REG_RESOURCE_NAME VARCHAR(256), + REG_TENANT_ID INTEGER DEFAULT 0 +); + +ALTER TABLE REG_RESOURCE_TAG ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_TAG_FK_BY_PATH_ID FOREIGN KEY (REG_PATH_ID, REG_TENANT_ID) REFERENCES REG_PATH (REG_PATH_ID, REG_TENANT_ID); +ALTER TABLE REG_RESOURCE_TAG ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_TAG_FK_BY_TAG_ID FOREIGN KEY (REG_TAG_ID, REG_TENANT_ID) REFERENCES REG_TAG (REG_ID, REG_TENANT_ID); +CREATE INDEX IF NOT EXISTS REG_RESOURCE_TAG_IND_BY_PATH_ID_AND_RESOURCE_NAME ON REG_RESOURCE_TAG(REG_PATH_ID, REG_RESOURCE_NAME, REG_TENANT_ID); +CREATE INDEX IF NOT EXISTS REG_RESOURCE_TAG_IND_BY_VERSION ON REG_RESOURCE_TAG(REG_VERSION, REG_TENANT_ID); + +CREATE TABLE IF NOT EXISTS REG_PROPERTY ( + REG_ID INTEGER NOT NULL AUTO_INCREMENT, + REG_NAME VARCHAR(100) NOT NULL, + REG_VALUE VARCHAR(1000), + REG_TENANT_ID INTEGER DEFAULT 0, + CONSTRAINT PK_REG_PROPERTY PRIMARY KEY(REG_ID, REG_TENANT_ID) +); + +CREATE TABLE IF NOT EXISTS REG_RESOURCE_PROPERTY ( + REG_PROPERTY_ID INTEGER NOT NULL, + REG_VERSION INTEGER, + REG_PATH_ID INTEGER, + REG_RESOURCE_NAME VARCHAR(256), + REG_TENANT_ID INTEGER DEFAULT 0 +); + +ALTER TABLE REG_RESOURCE_PROPERTY ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_PROPERTY_FK_BY_PATH_ID FOREIGN KEY (REG_PATH_ID, REG_TENANT_ID) REFERENCES REG_PATH (REG_PATH_ID, REG_TENANT_ID); +ALTER TABLE REG_RESOURCE_PROPERTY ADD CONSTRAINT IF NOT EXISTS REG_RESOURCE_PROPERTY_FK_BY_TAG_ID FOREIGN KEY (REG_PROPERTY_ID, REG_TENANT_ID) REFERENCES REG_PROPERTY (REG_ID, REG_TENANT_ID); +CREATE INDEX IF NOT EXISTS REG_RESOURCE_PROPERTY_IND_BY_PATH_ID_AND_RESOURCE_NAME ON REG_RESOURCE_PROPERTY(REG_PATH_ID, REG_RESOURCE_NAME, REG_TENANT_ID); +CREATE INDEX IF NOT EXISTS REG_RESOURCE_PROPERTY_IND_BY_VERSION ON REG_RESOURCE_PROPERTY(REG_VERSION, REG_TENANT_ID); + +CREATE TABLE IF NOT EXISTS REG_ASSOCIATION ( + REG_ASSOCIATION_ID INTEGER AUTO_INCREMENT, + REG_SOURCEPATH VARCHAR (2000) NOT NULL, + REG_TARGETPATH VARCHAR (2000) NOT NULL, + REG_ASSOCIATION_TYPE VARCHAR (2000) NOT NULL, + REG_TENANT_ID INTEGER DEFAULT 0, + PRIMARY KEY (REG_ASSOCIATION_ID, REG_TENANT_ID) +); + +CREATE TABLE IF NOT EXISTS REG_SNAPSHOT ( + REG_SNAPSHOT_ID INTEGER NOT NULL AUTO_INCREMENT, + REG_PATH_ID INTEGER NOT NULL, + REG_RESOURCE_NAME VARCHAR (256), + REG_RESOURCE_VIDS LONGBLOB NOT NULL, + REG_TENANT_ID INTEGER DEFAULT 0, + CONSTRAINT PK_REG_SNAPSHOT PRIMARY KEY(REG_SNAPSHOT_ID, REG_TENANT_ID) +); + +ALTER TABLE REG_SNAPSHOT ADD CONSTRAINT IF NOT EXISTS REG_SNAPSHOT_FK_BY_PATH_ID FOREIGN KEY (REG_PATH_ID, REG_TENANT_ID) REFERENCES REG_PATH (REG_PATH_ID, REG_TENANT_ID); +CREATE INDEX IF NOT EXISTS REG_SNAPSHOT_IND_BY_PATH_ID_AND_RESOURCE_NAME ON REG_SNAPSHOT(REG_PATH_ID, REG_RESOURCE_NAME, REG_TENANT_ID); + +-- ################################ +-- USER MANAGER TABLES +-- ################################ + +CREATE TABLE IF NOT EXISTS UM_TENANT ( + UM_ID INTEGER NOT NULL AUTO_INCREMENT, + UM_DOMAIN_NAME VARCHAR(255) NOT NULL, + UM_EMAIL VARCHAR(255), + UM_ACTIVE BOOLEAN DEFAULT FALSE, + UM_CREATED_DATE TIMESTAMP NOT NULL, + UM_USER_CONFIG LONGBLOB NOT NULL, + PRIMARY KEY (UM_ID), + UNIQUE(UM_DOMAIN_NAME)); + +CREATE TABLE IF NOT EXISTS UM_DOMAIN( + UM_DOMAIN_ID INTEGER NOT NULL AUTO_INCREMENT, + UM_DOMAIN_NAME VARCHAR(255), + UM_TENANT_ID INTEGER DEFAULT 0, + PRIMARY KEY (UM_DOMAIN_ID, UM_TENANT_ID) +); + +CREATE INDEX IF NOT EXISTS INDEX_UM_TENANT_UM_DOMAIN_NAME ON UM_TENANT (UM_DOMAIN_NAME); + +CREATE TABLE IF NOT EXISTS UM_USER ( + UM_ID INTEGER NOT NULL AUTO_INCREMENT, + UM_USER_NAME VARCHAR(255) NOT NULL, + UM_USER_PASSWORD VARCHAR(255) NOT NULL, + UM_SALT_VALUE VARCHAR(31), + UM_REQUIRE_CHANGE BOOLEAN DEFAULT FALSE, + UM_CHANGED_TIME TIMESTAMP NOT NULL, + UM_TENANT_ID INTEGER DEFAULT 0, + PRIMARY KEY (UM_ID, UM_TENANT_ID), + UNIQUE(UM_USER_NAME, UM_TENANT_ID)); + +CREATE TABLE IF NOT EXISTS UM_SYSTEM_USER ( + UM_ID INTEGER NOT NULL AUTO_INCREMENT, + UM_USER_NAME VARCHAR(255) NOT NULL, + UM_USER_PASSWORD VARCHAR(255) NOT NULL, + UM_SALT_VALUE VARCHAR(31), + UM_REQUIRE_CHANGE BOOLEAN DEFAULT FALSE, + UM_CHANGED_TIME TIMESTAMP NOT NULL, + UM_TENANT_ID INTEGER DEFAULT 0, + PRIMARY KEY (UM_ID, UM_TENANT_ID), + UNIQUE(UM_USER_NAME, UM_TENANT_ID)); + +CREATE TABLE IF NOT EXISTS UM_USER_ATTRIBUTE ( + UM_ID INTEGER NOT NULL AUTO_INCREMENT, + UM_ATTR_NAME VARCHAR(255) NOT NULL, + UM_ATTR_VALUE VARCHAR(1024), + UM_PROFILE_ID VARCHAR(255), + UM_USER_ID INTEGER, + UM_TENANT_ID INTEGER DEFAULT 0, + PRIMARY KEY (UM_ID, UM_TENANT_ID), + FOREIGN KEY (UM_USER_ID, UM_TENANT_ID) REFERENCES UM_USER(UM_ID, UM_TENANT_ID)); + +CREATE INDEX IF NOT EXISTS UM_USER_ID_INDEX ON UM_USER_ATTRIBUTE(UM_USER_ID); + +CREATE TABLE IF NOT EXISTS UM_ROLE ( + UM_ID INTEGER NOT NULL AUTO_INCREMENT, + UM_ROLE_NAME VARCHAR(255) NOT NULL, + UM_TENANT_ID INTEGER DEFAULT 0, + UM_SHARED_ROLE BOOLEAN DEFAULT FALSE, + PRIMARY KEY (UM_ID, UM_TENANT_ID), + UNIQUE(UM_ROLE_NAME, UM_TENANT_ID)); + +CREATE TABLE IF NOT EXISTS UM_MODULE( + UM_ID INTEGER NOT NULL AUTO_INCREMENT, + UM_MODULE_NAME VARCHAR(100), + UNIQUE(UM_MODULE_NAME), + PRIMARY KEY(UM_ID) +); + +CREATE TABLE IF NOT EXISTS UM_MODULE_ACTIONS( + UM_ACTION VARCHAR(255) NOT NULL, + UM_MODULE_ID INTEGER NOT NULL, + PRIMARY KEY(UM_ACTION, UM_MODULE_ID), + FOREIGN KEY (UM_MODULE_ID) REFERENCES UM_MODULE(UM_ID) ON DELETE CASCADE +); + +CREATE TABLE IF NOT EXISTS UM_PERMISSION ( + UM_ID INTEGER NOT NULL AUTO_INCREMENT, + UM_RESOURCE_ID VARCHAR(255) NOT NULL, + UM_ACTION VARCHAR(255) NOT NULL, + UM_TENANT_ID INTEGER DEFAULT 0, + UM_MODULE_ID INTEGER DEFAULT 0, + UNIQUE(UM_RESOURCE_ID,UM_ACTION, UM_TENANT_ID), + PRIMARY KEY (UM_ID, UM_TENANT_ID)); + +CREATE INDEX IF NOT EXISTS INDEX_UM_PERMISSION_UM_RESOURCE_ID_UM_ACTION ON UM_PERMISSION (UM_RESOURCE_ID, UM_ACTION, UM_TENANT_ID); + +CREATE TABLE IF NOT EXISTS UM_ROLE_PERMISSION ( + UM_ID INTEGER NOT NULL AUTO_INCREMENT, + UM_PERMISSION_ID INTEGER NOT NULL, + UM_ROLE_NAME VARCHAR(255) NOT NULL, + UM_IS_ALLOWED SMALLINT NOT NULL, + UM_TENANT_ID INTEGER DEFAULT 0, + UM_DOMAIN_ID INTEGER, + FOREIGN KEY (UM_PERMISSION_ID, UM_TENANT_ID) REFERENCES UM_PERMISSION(UM_ID, UM_TENANT_ID) ON DELETE CASCADE, + FOREIGN KEY (UM_DOMAIN_ID, UM_TENANT_ID) REFERENCES UM_DOMAIN(UM_DOMAIN_ID, UM_TENANT_ID) ON DELETE CASCADE, + PRIMARY KEY (UM_ID, UM_TENANT_ID)); + +CREATE TABLE IF NOT EXISTS UM_USER_PERMISSION ( + UM_ID INTEGER NOT NULL AUTO_INCREMENT, + UM_PERMISSION_ID INTEGER NOT NULL, + UM_USER_NAME VARCHAR(255) NOT NULL, + UM_IS_ALLOWED SMALLINT NOT NULL, + UNIQUE (UM_PERMISSION_ID, UM_USER_NAME, UM_TENANT_ID), + UM_TENANT_ID INTEGER DEFAULT 0, + FOREIGN KEY (UM_PERMISSION_ID, UM_TENANT_ID) REFERENCES UM_PERMISSION(UM_ID, UM_TENANT_ID) ON DELETE CASCADE, + PRIMARY KEY (UM_ID, UM_TENANT_ID)); + +CREATE TABLE IF NOT EXISTS UM_USER_ROLE ( + UM_ID INTEGER NOT NULL AUTO_INCREMENT, + UM_ROLE_ID INTEGER NOT NULL, + UM_USER_ID INTEGER NOT NULL, + UM_TENANT_ID INTEGER DEFAULT 0, + UNIQUE (UM_USER_ID, UM_ROLE_ID, UM_TENANT_ID), + FOREIGN KEY (UM_ROLE_ID, UM_TENANT_ID) REFERENCES UM_ROLE(UM_ID, UM_TENANT_ID), + FOREIGN KEY (UM_USER_ID, UM_TENANT_ID) REFERENCES UM_USER(UM_ID, UM_TENANT_ID), + PRIMARY KEY (UM_ID, UM_TENANT_ID)); + + +CREATE TABLE IF NOT EXISTS UM_SHARED_USER_ROLE( + UM_ROLE_ID INTEGER NOT NULL, + UM_USER_ID INTEGER NOT NULL, + UM_USER_TENANT_ID INTEGER NOT NULL, + UM_ROLE_TENANT_ID INTEGER NOT NULL, + UNIQUE(UM_USER_ID,UM_ROLE_ID,UM_USER_TENANT_ID, UM_ROLE_TENANT_ID), + FOREIGN KEY(UM_ROLE_ID,UM_ROLE_TENANT_ID) REFERENCES UM_ROLE(UM_ID,UM_TENANT_ID) ON DELETE CASCADE , + FOREIGN KEY(UM_USER_ID,UM_USER_TENANT_ID) REFERENCES UM_USER(UM_ID,UM_TENANT_ID) ON DELETE CASCADE +); + +CREATE TABLE IF NOT EXISTS UM_ACCOUNT_MAPPING( + UM_ID INTEGER NOT NULL AUTO_INCREMENT, + UM_USER_NAME VARCHAR(255) NOT NULL, + UM_TENANT_ID INTEGER NOT NULL, + UM_USER_STORE_DOMAIN VARCHAR(100), + UM_ACC_LINK_ID INTEGER NOT NULL, + UNIQUE(UM_USER_NAME, UM_TENANT_ID, UM_USER_STORE_DOMAIN, UM_ACC_LINK_ID), + FOREIGN KEY (UM_TENANT_ID) REFERENCES UM_TENANT(UM_ID) ON DELETE CASCADE, + PRIMARY KEY (UM_ID) +); + + +CREATE TABLE IF NOT EXISTS UM_DIALECT( + UM_ID INTEGER NOT NULL AUTO_INCREMENT, + UM_DIALECT_URI VARCHAR(255) NOT NULL, + UM_TENANT_ID INTEGER DEFAULT 0, + UNIQUE(UM_DIALECT_URI, UM_TENANT_ID), + PRIMARY KEY (UM_ID, UM_TENANT_ID) +); + + +CREATE TABLE IF NOT EXISTS UM_CLAIM( + UM_ID INTEGER NOT NULL AUTO_INCREMENT, + UM_DIALECT_ID INTEGER NOT NULL, + UM_CLAIM_URI VARCHAR(255) NOT NULL, + UM_DISPLAY_TAG VARCHAR(255), + UM_DESCRIPTION VARCHAR(255), + UM_MAPPED_ATTRIBUTE_DOMAIN VARCHAR(255), + UM_MAPPED_ATTRIBUTE VARCHAR(255), + UM_REG_EX VARCHAR(255), + UM_SUPPORTED SMALLINT, + UM_REQUIRED SMALLINT, + UM_DISPLAY_ORDER INTEGER, + UM_CHECKED_ATTRIBUTE SMALLINT, + UM_READ_ONLY SMALLINT, + UM_TENANT_ID INTEGER DEFAULT 0, + UNIQUE(UM_DIALECT_ID, UM_CLAIM_URI,UM_MAPPED_ATTRIBUTE_DOMAIN, UM_TENANT_ID), + FOREIGN KEY(UM_DIALECT_ID, UM_TENANT_ID) REFERENCES UM_DIALECT(UM_ID, UM_TENANT_ID), + PRIMARY KEY (UM_ID, UM_TENANT_ID) +); + +CREATE TABLE IF NOT EXISTS UM_PROFILE_CONFIG( + UM_ID INTEGER NOT NULL AUTO_INCREMENT, + UM_DIALECT_ID INTEGER, + UM_PROFILE_NAME VARCHAR(255), + UM_TENANT_ID INTEGER DEFAULT 0, + FOREIGN KEY(UM_DIALECT_ID, UM_TENANT_ID) REFERENCES UM_DIALECT(UM_ID, UM_TENANT_ID), + PRIMARY KEY (UM_ID, UM_TENANT_ID) +); + + +CREATE TABLE IF NOT EXISTS UM_HYBRID_ROLE( + UM_ID INTEGER NOT NULL AUTO_INCREMENT, + UM_ROLE_NAME VARCHAR(255), + UM_TENANT_ID INTEGER DEFAULT 0, + PRIMARY KEY (UM_ID, UM_TENANT_ID) +); + +CREATE TABLE IF NOT EXISTS UM_HYBRID_USER_ROLE( + UM_ID INTEGER NOT NULL AUTO_INCREMENT, + UM_USER_NAME VARCHAR(255), + UM_ROLE_ID INTEGER NOT NULL, + UM_TENANT_ID INTEGER DEFAULT 0, + UM_DOMAIN_ID INTEGER, + UNIQUE (UM_USER_NAME, UM_ROLE_ID, UM_TENANT_ID,UM_DOMAIN_ID), + FOREIGN KEY (UM_ROLE_ID, UM_TENANT_ID) REFERENCES UM_HYBRID_ROLE(UM_ID, UM_TENANT_ID) ON DELETE CASCADE, + FOREIGN KEY (UM_DOMAIN_ID, UM_TENANT_ID) REFERENCES UM_DOMAIN(UM_DOMAIN_ID, UM_TENANT_ID) ON DELETE CASCADE, + PRIMARY KEY (UM_ID, UM_TENANT_ID) +); + +CREATE TABLE IF NOT EXISTS UM_HYBRID_REMEMBER_ME ( + UM_ID INTEGER NOT NULL AUTO_INCREMENT, + UM_USER_NAME VARCHAR(255) NOT NULL, + UM_COOKIE_VALUE VARCHAR(1024), + UM_CREATED_TIME TIMESTAMP, + UM_TENANT_ID INTEGER DEFAULT 0, + PRIMARY KEY (UM_ID, UM_TENANT_ID) +); + +CREATE TABLE IF NOT EXISTS UM_SYSTEM_ROLE( + UM_ID INTEGER NOT NULL AUTO_INCREMENT, + UM_ROLE_NAME VARCHAR(255), + UM_TENANT_ID INTEGER DEFAULT 0, + PRIMARY KEY (UM_ID, UM_TENANT_ID) +); + +CREATE TABLE IF NOT EXISTS UM_SYSTEM_USER_ROLE( + UM_ID INTEGER NOT NULL AUTO_INCREMENT, + UM_USER_NAME VARCHAR(255), + UM_ROLE_ID INTEGER NOT NULL, + UM_TENANT_ID INTEGER DEFAULT 0, + UNIQUE (UM_USER_NAME, UM_ROLE_ID, UM_TENANT_ID), + FOREIGN KEY (UM_ROLE_ID, UM_TENANT_ID) REFERENCES UM_SYSTEM_ROLE(UM_ID, UM_TENANT_ID), + PRIMARY KEY (UM_ID, UM_TENANT_ID) +); diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/carbon-home/repository/conf/apim-integration.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/carbon-home/repository/conf/apim-integration.xml new file mode 100644 index 0000000000..74b178f165 --- /dev/null +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/carbon-home/repository/conf/apim-integration.xml @@ -0,0 +1,34 @@ + + + + https://${iot.keymanager.host}:${iot.keymanager.https.port}/client-registration/v0.11/register + https://${iot.gateway.host}:${iot.gateway.https.port}/token + https://${iot.apimpublisher.host}:${iot.apimpublisher.https.port}/api/am/publisher/v0.11 + https://${iot.apimstore.host}:${iot.apimstore.https.port}/api/am/store/v0.11 + + https://localhost:9443/client-registration/v0.11/register + https://localhost:9443/token + https://${iot.apimpublisher.host}:${iot.apimpublisher.https.port}/api/am/publisher/v0.11 + https://${iot.apimstore.host}:${iot.apimstore.https.port}/api/am/store/v0.11 + + admin + admin + diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/carbon-home/repository/conf/carbon.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/carbon-home/repository/conf/carbon.xml new file mode 100644 index 0000000000..31752cf9b4 --- /dev/null +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/carbon-home/repository/conf/carbon.xml @@ -0,0 +1,656 @@ + + + + + + + + + ${product.name} + + + ${product.key} + + + ${product.version} + + + + + + + + + local:/${carbon.context}/services/ + + + + + + + ${default.server.role} + + + + + + + org.wso2.carbon + + + / + + + + + + + + + 15 + + + + + + + + + 0 + + + + + 9999 + + 11111 + + + + + + 10389 + + 8000 + + + + + + 10500 + + + + + + + org.wso2.carbon.tomcat.jndi.CarbonJavaURLContextFactory + + + + + + + + + java + + + + + + + + + + false + + + false + + + 600 + + + + false + + + + + + + + 30 + + + + + + + + + 15 + + + + + + ${carbon.home}/repository/deployment/server/ + + + 15 + + + ${carbon.home}/repository/conf/axis2/axis2.xml + + + 30000 + + + ${carbon.home}/repository/deployment/client/ + + ${carbon.home}/repository/conf/axis2/axis2_client.xml + + true + + + + + + + + + + admin + Default Administrator Role + + + user + Default User Role + + + + + + + + + + + + ${carbon.home}/repository/resources/security/wso2carbon.jks + + JKS + + wso2carbon + + wso2carbon + + wso2carbon + + + + + + ${carbon.home}/repository/resources/security/client-truststore.jks + + JKS + + wso2carbon + + + + + + + + + + + + + + + + + + + UserManager + + + false + + + + + + + ${carbon.home}/tmp/work + + + + + + true + + + 10 + + + 30 + + + + + + 100 + + + + keystore + certificate + * + + org.wso2.carbon.ui.transports.fileupload.AnyFileUploadExecutor + + + + + jarZip + + org.wso2.carbon.ui.transports.fileupload.JarZipUploadExecutor + + + + dbs + + org.wso2.carbon.ui.transports.fileupload.DBSFileUploadExecutor + + + + tools + + org.wso2.carbon.ui.transports.fileupload.ToolsFileUploadExecutor + + + + toolsAny + + org.wso2.carbon.ui.transports.fileupload.ToolsAnyFileUploadExecutor + + + + + + + info + org.wso2.carbon.core.transports.util.InfoProcessor + + + wsdl + org.wso2.carbon.core.transports.util.Wsdl11Processor + + + wsdl2 + org.wso2.carbon.core.transports.util.Wsdl20Processor + + + xsd + org.wso2.carbon.core.transports.util.XsdProcessor + + + + + + false + false + true + svn + http://svnrepo.example.com/repos/ + username + password + true + + + + + + + + + + + + + + + ${require.carbon.servlet} + + + + + true + + + + + + + default repository + ${p2.repo.url} + + + + + + + + true + + + + + + true + + diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/carbon-home/repository/conf/registry.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/carbon-home/repository/conf/registry.xml new file mode 100644 index 0000000000..0bb97a7dc9 --- /dev/null +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/carbon-home/repository/conf/registry.xml @@ -0,0 +1,50 @@ + + + + + + + + wso2registry + false + true + / + + + jdbc:h2:./target/databasetest/CARBON_TEST + + org.h2.Driver + 80 + 60000 + 5 + + + false + + + + true + true + true + true + + diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/config/datasource/data-source-config.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/config/datasource/data-source-config.xml new file mode 100644 index 0000000000..d9be5b3ac0 --- /dev/null +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/config/datasource/data-source-config.xml @@ -0,0 +1,33 @@ + + + + + jdbc:h2:mem:cdm-test-db;DB_CLOSE_ON_EXIT=FALSE;MVCC=true + org.h2.Driver + wso2carbon + wso2carbon + + + + + + + + + diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/config/operation/cdm-config.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/config/operation/cdm-config.xml new file mode 100644 index 0000000000..d4e1acb139 --- /dev/null +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/config/operation/cdm-config.xml @@ -0,0 +1,96 @@ + + + + + + + + jdbc/DM_DS + + + + + 2 + 2000 + 2000 + true + + org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.FCMBasedPushNotificationProvider + + org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.MQTTBasedPushNotificationProvider + org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.HTTPBasedPushNotificationProvider + org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.XMPPBasedPushNotificationProvider + + + + false + + + https://localhost:9443 + admin + admin + + + org.wso2.carbon.policy.mgt + true + 60000 + 5 + 8 + 20 + + + + Simple + + + + 20 + 20 + 20 + 20 + 20 + 20 + + + + true + + + + false + 600 + + 10000 + + + false + 86400 + + + false + false + + BYOD,COPE + + diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/config/schema/app-mgt-config-schema.xsd b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/config/schema/app-mgt-config-schema.xsd new file mode 100644 index 0000000000..b2fc9d553e --- /dev/null +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/config/schema/app-mgt-config-schema.xsd @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/config/schema/device-mgt-config-schema.xsd b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/config/schema/device-mgt-config-schema.xsd new file mode 100644 index 0000000000..420980b470 --- /dev/null +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/config/schema/device-mgt-config-schema.xsd @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/testng.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/testng.xml new file mode 100644 index 0000000000..7dfa0ef71a --- /dev/null +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/testng.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/user-test/user-mgt-registry-test.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/user-test/user-mgt-registry-test.xml new file mode 100644 index 0000000000..bac4fc7667 --- /dev/null +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/user-test/user-mgt-registry-test.xml @@ -0,0 +1,80 @@ + + + + + true + admin + + admin + admin + + everyone + false + 500 + jdbc:h2:target/databasetest/CARBON_TEST + org.h2.Driver + 50 + 60000 + 5 + + + org.wso2.carbon.user.core.tenant.JDBCTenantManager + false + 100 + false + default + SHA-256 + true + true + true + false + ^[\S]{5,30}$ + Password length should be between 5 to 30 characters + + ^[\S]{5,30}$ + [a-zA-Z0-9._-|//]{3,30}$ + ^[\S]{3,30}$ + ^[^~!#$;%^*+={}\\|\\\\<>,\'\"]{3,30}$ + ^[\S]{3,30}$ + true + 100 + 100 + false + false + true + , + true + + + true + + + + login + manage-configuration + manage-security + upload-services + manage-services + manage-lc-configuration + manage-mediation + monitor-system + delegate-identity + + diff --git a/components/test-coverage/pom.xml b/components/test-coverage/pom.xml index d5b06418e6..c440e67ceb 100644 --- a/components/test-coverage/pom.xml +++ b/components/test-coverage/pom.xml @@ -183,6 +183,9 @@ + + + From 4824ca1d402ac5f515d9a70e912a05c5383af22c Mon Sep 17 00:00:00 2001 From: Nirothipan Date: Wed, 11 Oct 2017 16:46:32 +0530 Subject: [PATCH 2/7] initial commit --- .../pom.xml | 5 + .../publisher/APIPublisherServiceImpl.java | 7 +- .../publisher/APIPublisherServiceTest.java | 40 +-- .../webapp/publisher/BaseAPIPublisheTest.java | 257 ------------------ .../publisher/BaseAPIPublisherTest.java | 199 ++++++++++++++ .../apimgt/webapp/publisher/utils/Utils.java | 31 --- .../repository/conf/apim-integration.xml | 6 +- .../src/test/resources/jwt.properties | 57 ++++ .../sample-default-platform-configuration.xml | 0 .../repository/conf/etc/jwt.properties | 57 ++++ .../test/resources/jwt-config/jwt.properties | 57 ++++ 11 files changed, 403 insertions(+), 313 deletions(-) delete mode 100644 components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/BaseAPIPublisheTest.java create mode 100644 components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/BaseAPIPublisherTest.java create mode 100644 components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/jwt.properties rename components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/repository/conf/etc/device-mgt-plugin-configs/{mobile => }/sample-default-platform-configuration.xml (100%) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/repository/conf/etc/jwt.properties create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/jwt-config/jwt.properties diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml index 66db3da85f..f27a796a9c 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml @@ -35,6 +35,11 @@ http://wso2.org + + org.powermock + powermock-api-mockito + test + org.eclipse.osgi org.eclipse.osgi diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java index 2604bfc83e..f7914d3d52 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java @@ -43,8 +43,8 @@ public class APIPublisherServiceImpl implements APIPublisherService { @Override public void publishAPI(APIConfig apiConfig) throws APIManagerPublisherException { String tenantDomain = MultitenantUtils.getTenantDomain(apiConfig.getOwner()); -// PrivilegedCarbonContext.startTenantFlow(); -// PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true); + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true); PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(apiConfig.getOwner()); try { PublisherClient publisherClient = APIPublisherDataHolder.getInstance().getIntegrationClientService() @@ -74,8 +74,7 @@ public class APIPublisherServiceImpl implements APIPublisherService { } catch (FeignException e) { throw new APIManagerPublisherException(e); } finally { - - //PrivilegedCarbonContext.endTenantFlow(); + PrivilegedCarbonContext.endTenantFlow(); } } diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceTest.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceTest.java index 835c1df12b..e70437eef9 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceTest.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceTest.java @@ -20,6 +20,7 @@ package org.wso2.carbon.apimgt.webapp.publisher; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import org.wso2.carbon.apimgt.integration.client.OAuthRequestInterceptor; import org.wso2.carbon.apimgt.integration.client.model.OAuthApplication; @@ -31,9 +32,14 @@ import java.lang.reflect.Field; import java.util.*; public class -APIPublisherServiceTest extends BaseAPIPublisheTest{ +APIPublisherServiceTest extends BaseAPIPublisherTest { private static final Log log = LogFactory.getLog(APIPublisherServiceTest.class); + @BeforeTest + public void initialConfigs() throws Exception { + + + } @Test @@ -57,9 +63,9 @@ APIPublisherServiceTest extends BaseAPIPublisheTest{ Map apiScopes = new HashMap<>(); Set scopes = new HashSet<>(apiScopes.values()); - // apiScopes.put("key","") - - + String REQUIRED_SCOPE = + "apim:api_create apim:api_view apim:api_publish apim:subscribe apim:tier_view apim:tier_manage " + + "apim:subscription_view apim:subscription_block"; apiConfig.setScopes(scopes); @@ -71,30 +77,28 @@ APIPublisherServiceTest extends BaseAPIPublisheTest{ template.setAuthType("Application & Application User"); template.setHttpVerb("POST"); template.setResourceURI("https://localhost:9443/api/device-mgt/windows/v1.0/admin/devices/reboot"); - template.setUriTemplate("/reboot"); - ApiScope scope = new ApiScope(); - scope.setKey("perm:windows:reboot"); - scope.setName("Reboot"); - scope.setRoles("/permission/admin/device-mgt/devices/owning-device/operations/windows/reboot"); - scope.setDescription("Lock reset on Windows devices"); - template.setScope(scope); + template.setUriTemplate("/reboot"); + ApiScope scope = new ApiScope(); + scope.setKey("perm:windows:reboot"); + scope.setName("Reboot"); + scope.setRoles("/permission/admin/device-mgt/devices/owning-device/operations/windows/reboot"); + scope.setDescription("Lock reset on Windows devices"); + template.setScope(scope); uriTemplates.add(template); apiConfig.setUriTemplates(uriTemplates); - OAuthApplication oAuthApplication = new OAuthApplication(); oAuthApplication.setClientName("admin_api_integration_client"); oAuthApplication.setIsSaasApplication("true"); - oAuthApplication.setClientId("dsnkdsaxakdnfkanfdax="); - oAuthApplication.setClientSecret("safjksajnjnkjcksancka"); - - Field oAuth = OAuthRequestInterceptor.class.getDeclaredField("oAuthApplication"); - oAuth.setAccessible(true); - oAuth.set(null,oAuthApplication); + oAuthApplication.setClientId("random"); + oAuthApplication.setClientSecret("random="); + Field oAuth = OAuthRequestInterceptor.class.getDeclaredField("oAuthApplication"); + oAuth.setAccessible(true); + oAuth.set(null, oAuthApplication); apiPublisherService.publishAPI(apiConfig); } diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/BaseAPIPublisheTest.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/BaseAPIPublisheTest.java deleted file mode 100644 index fcf2129716..0000000000 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/BaseAPIPublisheTest.java +++ /dev/null @@ -1,257 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you 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.carbon.apimgt.webapp.publisher; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.tomcat.jdbc.pool.PoolProperties; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.BeforeSuite; -import org.w3c.dom.Document; -import org.wso2.carbon.CarbonConstants; -import org.wso2.carbon.apimgt.integration.client.IntegrationClientServiceImpl; -import org.wso2.carbon.apimgt.integration.client.internal.APIIntegrationClientDataHolder; -import org.wso2.carbon.apimgt.webapp.publisher.internal.APIPublisherDataHolder; -import org.wso2.carbon.apimgt.webapp.publisher.utils.Utils; -import org.wso2.carbon.base.MultitenantConstants; -import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.context.RegistryType; -import org.wso2.carbon.context.internal.OSGiDataHolder; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.governance.api.util.GovernanceArtifactConfiguration; -import org.wso2.carbon.governance.api.util.GovernanceUtils; -import org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerServiceImpl; -import org.wso2.carbon.registry.core.Registry; -import org.wso2.carbon.registry.core.config.RegistryContext; -import org.wso2.carbon.registry.core.exceptions.RegistryException; -import org.wso2.carbon.registry.core.internal.RegistryDataHolder; -import org.wso2.carbon.registry.core.jdbc.realm.InMemoryRealmService; -import org.wso2.carbon.registry.core.service.RegistryService; -import org.wso2.carbon.registry.core.session.UserRegistry; -import org.wso2.carbon.user.api.TenantManager; -import org.wso2.carbon.user.api.UserStoreException; -import org.wso2.carbon.user.core.service.RealmService; -import org.wso2.carbon.user.core.tenant.JDBCTenantManager; -import org.wso2.carbon.utils.FileUtil; - -import javax.sql.DataSource; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Unmarshaller; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; - -import static org.wso2.carbon.governance.api.util.GovernanceUtils.getGovernanceArtifactConfiguration; - -public abstract class BaseAPIPublisheTest { - - private DataSource dataSource; - private static final Log log = LogFactory.getLog(BaseAPIPublisheTest.class); - - @BeforeSuite - public void iniTwo() throws RegistryException, IOException, org.wso2.carbon.user.api.UserStoreException { - ClassLoader classLoader = getClass().getClassLoader(); - URL resourceUrl = classLoader.getResource("license.rxt"); - String rxt = null; - File carbonHome; - if (resourceUrl != null) { - rxt = FileUtil.readFileToString(resourceUrl.getFile()); - } - resourceUrl = classLoader.getResource("carbon-home"); - - if (resourceUrl != null) { - carbonHome = new File(resourceUrl.getFile()); - System.setProperty("carbon.home", carbonHome.getAbsolutePath()); - } - - PrivilegedCarbonContext.getThreadLocalCarbonContext() - .setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); - PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID); - RegistryService registryService = this.getRegistryService(); - OSGiDataHolder.getInstance().setRegistryService(registryService); - UserRegistry systemRegistry = - registryService.getRegistry(CarbonConstants.REGISTRY_SYSTEM_USERNAME); - - GovernanceArtifactConfiguration configuration = getGovernanceArtifactConfiguration(rxt); - List configurations = new ArrayList<>(); - configurations.add(configuration); - GovernanceUtils.loadGovernanceArtifacts(systemRegistry, configurations); - Registry governanceSystemRegistry = registryService.getConfigSystemRegistry(); - // DeviceTypeExtensionDataHolder.getInstance().setRegistryService(registryService); - PrivilegedCarbonContext.getThreadLocalCarbonContext() - .setRegistry(RegistryType.SYSTEM_CONFIGURATION, governanceSystemRegistry); - } - - @BeforeSuite - public void setupDataSource() throws Exception { - this.initDataSource(); - // this.initSQLScript(); - this.initializeCarbonContext(); - this.initServices(); - } - - protected void initDataSource() throws Exception { - this.dataSource = this.getDataSource(this.readDataSourceConfig()); - } - - private void initServices() throws DeviceManagementException, RegistryException { - APIPublisherDataHolder.getInstance().setIntegrationClientService(IntegrationClientServiceImpl.getInstance()); - APIIntegrationClientDataHolder.getInstance().setJwtClientManagerService(new JWTClientManagerServiceImpl()); - - -// DeviceConfigurationManager.getInstance().initConfig(); -// DeviceManagementProviderService deviceMgtService = new DeviceManagementProviderServiceImpl(); -// DeviceManagementServiceComponent.notifyStartupListeners(); -// DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceMgtService); -// DeviceManagementDataHolder.getInstance().setRegistryService(getRegistryService()); -// DeviceManagementDataHolder.getInstance().setDeviceAccessAuthorizationService(new DeviceAccessAuthorizationServiceImpl()); -// DeviceManagementDataHolder.getInstance().setGroupManagementProviderService(new GroupManagementProviderServiceImpl()); -// DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(null); - } - - private RegistryService getRegistryService() throws RegistryException, UserStoreException { - RealmService realmService = new InMemoryRealmService(); - TenantManager tenantManager = new JDBCTenantManager(dataSource, - org.wso2.carbon.utils.multitenancy.MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); - realmService.setTenantManager(tenantManager); - APIPublisherDataHolder.getInstance().setRealmService(realmService); - RegistryDataHolder.getInstance().setRealmService(realmService); - - //DeviceManagementDataHolder.getInstance().setRealmService(realmService); - InputStream is = this.getClass().getClassLoader().getResourceAsStream("carbon-home/repository/conf/registry.xml"); - RegistryContext context = RegistryContext.getBaseInstance(is, realmService); - context.setSetup(true); - return context.getEmbeddedRegistryService(); - } - - @BeforeClass - public abstract void init() throws Exception; - - private DataSource getDataSource(DataSourceConfig config) { - int id =0; - PoolProperties properties = new PoolProperties(); - properties.setUrl(config.getUrl()); - properties.setDriverClassName(config.getDriverClassName()); - properties.setUsername(config.getUser()); - properties.setPassword(config.getPassword()); - return new org.apache.tomcat.jdbc.pool.DataSource(properties); - } - - private void initializeCarbonContext() { - - if (System.getProperty("carbon.home") == null) { - int noweowe = 89; - File file = new File("src/test/resources/carbon-home"); - if (file.exists()) { - System.setProperty("carbon.home", file.getAbsolutePath()); - } - file = new File("../resources/carbon-home"); - if (file.exists()) { - System.setProperty("carbon.home", file.getAbsolutePath()); - } - file = new File("../../resources/carbon-home"); - if (file.exists()) { - System.setProperty("carbon.home", file.getAbsolutePath()); - } - file = new File("../../../resources/carbon-home"); - if (file.exists()) { - System.setProperty("carbon.home", file.getAbsolutePath()); - } - } - - PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants - .SUPER_TENANT_DOMAIN_NAME); - PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID); - } - - private DataSourceConfig readDataSourceConfig() throws DeviceManagementException { - try { - File file = new File("src/test/resources/config/datasource/data-source-config.xml"); - Document doc = Utils.convertToDocument(file); - JAXBContext testDBContext = JAXBContext.newInstance(DataSourceConfig.class); - Unmarshaller unmarshaller = testDBContext.createUnmarshaller(); - return (DataSourceConfig) unmarshaller.unmarshal(doc); - } catch (JAXBException e) { - throw new DeviceManagementException("Error occurred while reading data source configuration", e); - } - } - -/* - private void initSQLScript() throws Exception { - Connection conn = null; - Statement stmt = null; - try { - conn = this.getDataSource().getConnection(); - stmt = conn.createStatement(); - stmt.executeUpdate("RUNSCRIPT FROM './src/test/resources/sql/h2.sql'"); - } finally { - TestUtils.cleanupResources(conn, stmt, null); - } - }*/ - - /* public void deleteData() { - Connection conn = null; - try { - conn = getDataSource().getConnection(); - conn.setAutoCommit(false); - String[] cleanupTables = new String[]{"DM_NOTIFICATION","DM_DEVICE_OPERATION_RESPONSE","DM_ENROLMENT_OP_MAPPING", "DM_CONFIG_OPERATION", - "DM_POLICY_OPERATION", "DM_COMMAND_OPERATION", "DM_PROFILE_OPERATION", "DM_DEVICE_GROUP_MAP", - "DM_GROUP", "DM_ENROLMENT", "DM_DEVICE_APPLICATION_MAPPING", - "DM_APPLICATION", "DM_DEVICE", "DM_DEVICE_TYPE"}; - for (String table : cleanupTables) { - this.cleanData(conn, table); - } - conn.commit(); - } catch (SQLException e) { - try { - if (conn != null) { - conn.rollback(); - } - } catch (SQLException e1) { - log.error("Error occurred while roll-backing the transaction", e); - } - String msg = "Error occurred while cleaning up temporary data generated during test execution"; - log.error(msg, e); - Assert.fail(msg, e); - } finally { - if (conn != null) { - try { - conn.close(); - } catch (SQLException e) { - log.warn("Error occurred while closing the connection", e); - } - } - } - }*/ - - /*private void cleanData(Connection conn, String tableName) throws SQLException { - try (PreparedStatement stmt = conn.prepareStatement("DELETE FROM " + tableName)) { - stmt.execute(); - } - } - - protected DataSource getDataSource() { - return dataSource; - }*/ - -} diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/BaseAPIPublisherTest.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/BaseAPIPublisherTest.java new file mode 100644 index 0000000000..c8cf587722 --- /dev/null +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/BaseAPIPublisherTest.java @@ -0,0 +1,199 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you 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.carbon.apimgt.webapp.publisher; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.mockito.Mockito; +import org.testng.annotations.BeforeSuite; +import org.wso2.carbon.apimgt.integration.client.IntegrationClientServiceImpl; +import org.wso2.carbon.apimgt.integration.client.internal.APIIntegrationClientDataHolder; +import org.wso2.carbon.apimgt.integration.client.publisher.PublisherClient; +import org.wso2.carbon.apimgt.integration.client.service.IntegrationClientService; +import org.wso2.carbon.apimgt.integration.generated.client.publisher.api.APIsApi; +import org.wso2.carbon.apimgt.integration.generated.client.publisher.model.API; +import org.wso2.carbon.apimgt.integration.generated.client.publisher.model.APIList; +import org.wso2.carbon.apimgt.integration.generated.client.publisher.model.FileInfo; +import org.wso2.carbon.apimgt.webapp.publisher.internal.APIPublisherDataHolder; +import org.wso2.carbon.base.MultitenantConstants; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.context.internal.OSGiDataHolder; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.identity.jwt.client.extension.JWTClient; +import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo; +import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientConfigurationException; +import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException; +import org.wso2.carbon.identity.jwt.client.extension.internal.JWTClientExtensionDataHolder; +import org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService; +import org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerServiceImpl; +import org.wso2.carbon.registry.core.config.RegistryContext; +import org.wso2.carbon.registry.core.exceptions.RegistryException; +import org.wso2.carbon.registry.core.internal.RegistryDataHolder; +import org.wso2.carbon.registry.core.jdbc.realm.InMemoryRealmService; +import org.wso2.carbon.registry.core.service.RegistryService; +import org.wso2.carbon.user.api.TenantManager; +import org.wso2.carbon.user.api.UserStoreException; +import org.wso2.carbon.user.core.service.RealmService; +import org.wso2.carbon.user.core.tenant.JDBCTenantManager; + +import javax.sql.DataSource; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Field; +import java.net.URL; + +import static org.mockito.Mockito.doReturn; + +public abstract class BaseAPIPublisherTest { + + private static final Log log = LogFactory.getLog(BaseAPIPublisherTest.class); + + + + @BeforeSuite + public void initialise() throws Exception { + this.initializeCarbonContext(); + this.initServices(); + } + + + private void initServices() throws DeviceManagementException, RegistryException, IOException, JWTClientConfigurationException, NoSuchFieldException, JWTClientException, IllegalAccessException { + IntegrationClientService integrationClientService = Mockito.mock(IntegrationClientServiceImpl.class,Mockito.CALLS_REAL_METHODS); + APIPublisherDataHolder.getInstance().setIntegrationClientService(integrationClientService); + + PublisherClient publisherClient = Mockito.mock(PublisherClient.class,Mockito.CALLS_REAL_METHODS); + doReturn(publisherClient).when(integrationClientService).getPublisherClient(); + + APIsApi api = new APIsApi() { + @Override + public void apisApiIdDelete(String apiId, String ifMatch, String ifUnmodifiedSince) { + + } + + @Override + public API apisApiIdGet(String apiId, String accept, String ifNoneMatch, String ifModifiedSince) { + return null; + } + + @Override + public API apisApiIdPut(String apiId, API body, String contentType, String ifMatch, String ifUnmodifiedSince) { + return null; + } + + @Override + public void apisApiIdSwaggerGet(String apiId, String accept, String ifNoneMatch, String ifModifiedSince) { + + } + + @Override + public void apisApiIdSwaggerPut(String apiId, String apiDefinition, String contentType, String ifMatch, String ifUnmodifiedSince) { + + } + + @Override + public void apisApiIdThumbnailGet(String apiId, String accept, String ifNoneMatch, String ifModifiedSince) { + + } + + @Override + public FileInfo apisApiIdThumbnailPost(String apiId, File file, String contentType, String ifMatch, String ifUnmodifiedSince) { + return null; + } + + @Override + public void apisChangeLifecyclePost(String action, String apiId, String lifecycleChecklist, String ifMatch, String ifUnmodifiedSince) { + + } + + @Override + public void apisCopyApiPost(String newVersion, String apiId) { + + } + + @Override + public APIList apisGet(Integer limit, Integer offset, String query, String accept, String ifNoneMatch) { + return null; + } + + @Override + public API apisPost(API body, String contentType) { + return new API(); + } + }; + + Field field = PublisherClient.class.getDeclaredField("api"); + field.setAccessible(true); + field.set(publisherClient,api); + + AccessTokenInfo accessTokenInfo = new AccessTokenInfo(); + accessTokenInfo.setTokenType("type"); + String REQUIRED_SCOPE = + "apim:api_create apim:api_view apim:api_publish apim:subscribe apim:tier_view apim:tier_manage " + + "apim:subscription_view apim:subscription_block"; + accessTokenInfo.setScopes(REQUIRED_SCOPE); + + JWTClientManagerService jwtClientManagerService = Mockito.mock(JWTClientManagerServiceImpl.class, Mockito.CALLS_REAL_METHODS); + JWTClient jwtClient = Mockito.mock(JWTClient.class, Mockito.CALLS_REAL_METHODS); + doReturn(accessTokenInfo).when(jwtClient).getAccessToken(Mockito.anyString(), Mockito.anyString(), + Mockito.anyString(), Mockito.anyString()); + doReturn(jwtClient).when(jwtClientManagerService).getJWTClient(); + APIIntegrationClientDataHolder.getInstance().setJwtClientManagerService(jwtClientManagerService); + } + + private RegistryService getRegistryService() throws RegistryException, UserStoreException { + RealmService realmService = new InMemoryRealmService(); +// TenantManager tenantManager = new JDBCTenantManager(dataSource, +// org.wso2.carbon.utils.multitenancy.MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); + // realmService.setTenantManager(tenantManager); + APIPublisherDataHolder.getInstance().setRealmService(realmService); + RegistryDataHolder.getInstance().setRealmService(realmService); + JWTClientExtensionDataHolder.getInstance().setRealmService(realmService); + + InputStream is = this.getClass().getClassLoader().getResourceAsStream("carbon-home/repository/conf/registry.xml"); + RegistryContext context = RegistryContext.getBaseInstance(is, realmService); + context.setSetup(true); + return context.getEmbeddedRegistryService(); + } + + + + private void initializeCarbonContext() throws UserStoreException, RegistryException { + + ClassLoader classLoader = getClass().getClassLoader(); + URL resourceUrl = classLoader.getResource("carbon-home"); + + if (resourceUrl != null) { + File carbonHome = new File(resourceUrl.getFile()); + System.setProperty("carbon.home", carbonHome.getAbsolutePath()); + } + + PrivilegedCarbonContext.getThreadLocalCarbonContext() + .setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID); + RegistryService registryService = this.getRegistryService(); + OSGiDataHolder.getInstance().setRegistryService(registryService); + JWTClientExtensionDataHolder.getInstance().setRegistryService(registryService); + + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants + .SUPER_TENANT_DOMAIN_NAME); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID); + } + +} diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/utils/Utils.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/utils/Utils.java index 33b095d670..21d6a7007a 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/utils/Utils.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/utils/Utils.java @@ -21,7 +21,6 @@ package org.wso2.carbon.apimgt.webapp.publisher.utils; import org.w3c.dom.Document; import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.registry.core.exceptions.RegistryException; import javax.xml.XMLConstants; import javax.xml.parsers.DocumentBuilder; @@ -46,34 +45,4 @@ public class Utils { "to a org.w3c.dom.Document", e); } } - - /* *//** - * To get the registry service. - * @return RegistryService - * @throws RegistryException Registry Exception - *//* - public static RegistryService getRegistryService() throws RegistryException, org.wso2.carbon.user.api.UserStoreException { - RealmService realmService = new InMemoryRealmService(); - - - PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername("admin"); - - BasicDataSource dataSource = new BasicDataSource(); - String connectionUrl = "jdbc:h2:./target/database-test/CARBON_TEST"; - dataSource.setUrl(connectionUrl); - dataSource.setDriverClassName("org.h2.Driver"); - TenantManager jdbcTenantManager = new JDBCTenantManager(dataSource, - MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); - - realmService.setTenantManager(jdbcTenantManager); - RegistryDataHolder.getInstance().setRealmService(realmService); - APIPublisherDataHolder.getInstance().setRealmService(realmService); - //APIApplicationManagerExtensionDataHolder.getInstance().setRealmService(realmService); - //DeviceManagementDataHolder.getInstance().setRealmService(realmService); - InputStream is = Utils.class.getClassLoader().getResourceAsStream("carbon-home/repository/" + - "conf/registry.xml"); - RegistryContext context = RegistryContext.getBaseInstance(is, realmService); - context.setSetup(true); - return context.getEmbeddedRegistryService(); - }*/ } diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/carbon-home/repository/conf/apim-integration.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/carbon-home/repository/conf/apim-integration.xml index 74b178f165..400b7a06b6 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/carbon-home/repository/conf/apim-integration.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/carbon-home/repository/conf/apim-integration.xml @@ -21,13 +21,13 @@ https://${iot.keymanager.host}:${iot.keymanager.https.port}/client-registration/v0.11/register https://${iot.gateway.host}:${iot.gateway.https.port}/token - https://${iot.apimpublisher.host}:${iot.apimpublisher.https.port}/api/am/publisher/v0.11 + https://localhost:9445/api/am/publisher/v0.11 https://${iot.apimstore.host}:${iot.apimstore.https.port}/api/am/store/v0.11 https://localhost:9443/client-registration/v0.11/register https://localhost:9443/token - https://${iot.apimpublisher.host}:${iot.apimpublisher.https.port}/api/am/publisher/v0.11 - https://${iot.apimstore.host}:${iot.apimstore.https.port}/api/am/store/v0.11 + https://localhost:9445/api/am/publisher/v0.11 + https://localhost:9445/api/am/store/v0.11 admin admin diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/jwt.properties b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/jwt.properties new file mode 100644 index 0000000000..0c9641fa2d --- /dev/null +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/jwt.properties @@ -0,0 +1,57 @@ +# +# Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +# +# WSO2 Inc. licenses this file to you 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. +# + +#issuer of the JWT +iss=wso2.org/products/iot + +TokenEndpoint=https://${iot.gateway.host}:${iot.gateway.https.port}/token?tenantDomain=carbon.super + +#audience of JWT claim +#comma seperated values +aud=devicemgt + +#expiration time of JWT (number of minutes from the current time) +exp=1000 + +#issued at time of JWT (number of minutes from the current time) +iat=0 + +#nbf time of JWT (number of minutes from current time) +nbf=0 + +#skew between IDP and issuer(seconds) +skew=0 + +# JWT Id +#jti=token123 + +#KeyStore to cryptographic credentials +#KeyStore=repository/resources/security/wso2carbon.jks + +#Password of the KeyStore +#KeyStorePassword=wso2carbon + +#Alias of the SP's private key +#PrivateKeyAlias=wso2carbon + +#Private key password to retrieve the private key used to sign +#AuthnRequest and LogoutRequest messages +#PrivateKeyPassword=wso2carbon + +#this will be used as the default IDP config if there isn't any config available for tenants. +default-jwt-client=true diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/repository/conf/etc/device-mgt-plugin-configs/mobile/sample-default-platform-configuration.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/repository/conf/etc/device-mgt-plugin-configs/sample-default-platform-configuration.xml similarity index 100% rename from components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/repository/conf/etc/device-mgt-plugin-configs/mobile/sample-default-platform-configuration.xml rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/repository/conf/etc/device-mgt-plugin-configs/sample-default-platform-configuration.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/repository/conf/etc/jwt.properties b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/repository/conf/etc/jwt.properties new file mode 100644 index 0000000000..0c9641fa2d --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/repository/conf/etc/jwt.properties @@ -0,0 +1,57 @@ +# +# Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +# +# WSO2 Inc. licenses this file to you 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. +# + +#issuer of the JWT +iss=wso2.org/products/iot + +TokenEndpoint=https://${iot.gateway.host}:${iot.gateway.https.port}/token?tenantDomain=carbon.super + +#audience of JWT claim +#comma seperated values +aud=devicemgt + +#expiration time of JWT (number of minutes from the current time) +exp=1000 + +#issued at time of JWT (number of minutes from the current time) +iat=0 + +#nbf time of JWT (number of minutes from current time) +nbf=0 + +#skew between IDP and issuer(seconds) +skew=0 + +# JWT Id +#jti=token123 + +#KeyStore to cryptographic credentials +#KeyStore=repository/resources/security/wso2carbon.jks + +#Password of the KeyStore +#KeyStorePassword=wso2carbon + +#Alias of the SP's private key +#PrivateKeyAlias=wso2carbon + +#Private key password to retrieve the private key used to sign +#AuthnRequest and LogoutRequest messages +#PrivateKeyPassword=wso2carbon + +#this will be used as the default IDP config if there isn't any config available for tenants. +default-jwt-client=true diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/jwt-config/jwt.properties b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/jwt-config/jwt.properties new file mode 100644 index 0000000000..0c9641fa2d --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/jwt-config/jwt.properties @@ -0,0 +1,57 @@ +# +# Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +# +# WSO2 Inc. licenses this file to you 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. +# + +#issuer of the JWT +iss=wso2.org/products/iot + +TokenEndpoint=https://${iot.gateway.host}:${iot.gateway.https.port}/token?tenantDomain=carbon.super + +#audience of JWT claim +#comma seperated values +aud=devicemgt + +#expiration time of JWT (number of minutes from the current time) +exp=1000 + +#issued at time of JWT (number of minutes from the current time) +iat=0 + +#nbf time of JWT (number of minutes from current time) +nbf=0 + +#skew between IDP and issuer(seconds) +skew=0 + +# JWT Id +#jti=token123 + +#KeyStore to cryptographic credentials +#KeyStore=repository/resources/security/wso2carbon.jks + +#Password of the KeyStore +#KeyStorePassword=wso2carbon + +#Alias of the SP's private key +#PrivateKeyAlias=wso2carbon + +#Private key password to retrieve the private key used to sign +#AuthnRequest and LogoutRequest messages +#PrivateKeyPassword=wso2carbon + +#this will be used as the default IDP config if there isn't any config available for tenants. +default-jwt-client=true From 39d0cf2f95c0a61b3d323692fc31db43555f5515 Mon Sep 17 00:00:00 2001 From: Nirothipan Date: Wed, 11 Oct 2017 18:10:08 +0530 Subject: [PATCH 3/7] code formatting --- .../publisher/APIPublisherServiceTest.java | 47 +- .../publisher/BaseAPIPublisherTest.java | 136 +--- .../webapp/publisher/DataSourceConfig.java | 76 -- .../apimgt/webapp/publisher/utils/Api.java | 86 +++ .../apimgt/webapp/publisher/utils/Utils.java | 48 -- .../repository/conf/apim-integration.xml | 34 - .../carbon-home/repository/conf/carbon.xml | 656 ------------------ .../config/datasource/data-source-config.xml | 33 - .../resources/config/operation/cdm-config.xml | 96 --- .../config/schema/app-mgt-config-schema.xsd | 31 - .../schema/device-mgt-config-schema.xsd | 48 -- .../src/test/resources/jwt.properties | 57 -- 12 files changed, 133 insertions(+), 1215 deletions(-) delete mode 100644 components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/DataSourceConfig.java create mode 100644 components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/utils/Api.java delete mode 100644 components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/utils/Utils.java delete mode 100644 components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/carbon-home/repository/conf/apim-integration.xml delete mode 100644 components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/carbon-home/repository/conf/carbon.xml delete mode 100644 components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/config/datasource/data-source-config.xml delete mode 100644 components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/config/operation/cdm-config.xml delete mode 100644 components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/config/schema/app-mgt-config-schema.xsd delete mode 100644 components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/config/schema/device-mgt-config-schema.xsd delete mode 100644 components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/jwt.properties diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceTest.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceTest.java index e70437eef9..74481ff712 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceTest.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceTest.java @@ -19,7 +19,6 @@ package org.wso2.carbon.apimgt.webapp.publisher; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import org.wso2.carbon.apimgt.integration.client.OAuthRequestInterceptor; @@ -31,23 +30,28 @@ import org.wso2.carbon.apimgt.webapp.publisher.exception.APIManagerPublisherExce import java.lang.reflect.Field; import java.util.*; +/** + * This is the test class for {@link APIPublisherServiceImpl} + */ public class APIPublisherServiceTest extends BaseAPIPublisherTest { private static final Log log = LogFactory.getLog(APIPublisherServiceTest.class); + private APIPublisherServiceImpl apiPublisherService = new APIPublisherServiceImpl(); + private APIConfig apiConfig = new APIConfig(); @BeforeTest public void initialConfigs() throws Exception { - - + setApiConfigs(apiConfig); + initialise0OAuthApplication(); } + @Test(description = "Publishes an API | will fail if there are any exceptions") + public void publishAPI() throws NoSuchFieldException, IllegalAccessException, + APIManagerPublisherException { + apiPublisherService.publishAPI(apiConfig); + } - @Test - public void publishAPI() throws APIManagerPublisherException, NoSuchFieldException, IllegalAccessException { - APIPublisherServiceImpl apiPublisherService = new APIPublisherServiceImpl(); - - APIConfig apiConfig = new APIConfig(); - + private void setApiConfigs(APIConfig apiConfig) { apiConfig.setName("Windows Device Management Administrative Service"); apiConfig.setContext("/api/device-mgt/windows/v1.0/admin/devices"); apiConfig.setOwner("admin"); @@ -59,19 +63,13 @@ APIPublisherServiceTest extends BaseAPIPublisherTest { apiConfig.setTags(new String[]{"windows", "device_management"}); apiConfig.setTenantDomain("carbon.super"); apiConfig.setSecured(false); - Map apiScopes = new HashMap<>(); Set scopes = new HashSet<>(apiScopes.values()); - - String REQUIRED_SCOPE = - "apim:api_create apim:api_view apim:api_publish apim:subscribe apim:tier_view apim:tier_manage " + - "apim:subscription_view apim:subscription_block"; - - apiConfig.setScopes(scopes); + setAPIUrITemplates(apiConfig); + } - - + private void setAPIUrITemplates(APIConfig apiConfig) { Set uriTemplates = new LinkedHashSet<>(); ApiUriTemplate template = new ApiUriTemplate(); template.setAuthType("Application & Application User"); @@ -85,27 +83,18 @@ APIPublisherServiceTest extends BaseAPIPublisherTest { scope.setDescription("Lock reset on Windows devices"); template.setScope(scope); uriTemplates.add(template); - apiConfig.setUriTemplates(uriTemplates); + } - + private void initialise0OAuthApplication() throws NoSuchFieldException, IllegalAccessException { OAuthApplication oAuthApplication = new OAuthApplication(); - oAuthApplication.setClientName("admin_api_integration_client"); oAuthApplication.setIsSaasApplication("true"); oAuthApplication.setClientId("random"); oAuthApplication.setClientSecret("random="); - Field oAuth = OAuthRequestInterceptor.class.getDeclaredField("oAuthApplication"); oAuth.setAccessible(true); oAuth.set(null, oAuthApplication); - - apiPublisherService.publishAPI(apiConfig); } - @BeforeClass - @Override - public void init() throws Exception { - // do nothing - } } diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/BaseAPIPublisherTest.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/BaseAPIPublisherTest.java index c8cf587722..a8332c70c5 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/BaseAPIPublisherTest.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/BaseAPIPublisherTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * * WSO2 Inc. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except @@ -27,17 +27,13 @@ import org.wso2.carbon.apimgt.integration.client.internal.APIIntegrationClientDa import org.wso2.carbon.apimgt.integration.client.publisher.PublisherClient; import org.wso2.carbon.apimgt.integration.client.service.IntegrationClientService; import org.wso2.carbon.apimgt.integration.generated.client.publisher.api.APIsApi; -import org.wso2.carbon.apimgt.integration.generated.client.publisher.model.API; -import org.wso2.carbon.apimgt.integration.generated.client.publisher.model.APIList; -import org.wso2.carbon.apimgt.integration.generated.client.publisher.model.FileInfo; import org.wso2.carbon.apimgt.webapp.publisher.internal.APIPublisherDataHolder; +import org.wso2.carbon.apimgt.webapp.publisher.utils.Api; import org.wso2.carbon.base.MultitenantConstants; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.internal.OSGiDataHolder; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.identity.jwt.client.extension.JWTClient; import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo; -import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientConfigurationException; import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException; import org.wso2.carbon.identity.jwt.client.extension.internal.JWTClientExtensionDataHolder; import org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService; @@ -47,153 +43,79 @@ import org.wso2.carbon.registry.core.exceptions.RegistryException; import org.wso2.carbon.registry.core.internal.RegistryDataHolder; import org.wso2.carbon.registry.core.jdbc.realm.InMemoryRealmService; import org.wso2.carbon.registry.core.service.RegistryService; -import org.wso2.carbon.user.api.TenantManager; import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.core.service.RealmService; -import org.wso2.carbon.user.core.tenant.JDBCTenantManager; -import javax.sql.DataSource; import java.io.File; -import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Field; import java.net.URL; import static org.mockito.Mockito.doReturn; +/** + * Base class which initializes carbonContext and needed services. + */ public abstract class BaseAPIPublisherTest { private static final Log log = LogFactory.getLog(BaseAPIPublisherTest.class); - - @BeforeSuite public void initialise() throws Exception { this.initializeCarbonContext(); this.initServices(); } + private void initializeCarbonContext() throws RegistryException { + ClassLoader classLoader = getClass().getClassLoader(); + URL resourceUrl = classLoader.getResource("carbon-home"); + if (resourceUrl != null) { + File carbonHome = new File(resourceUrl.getFile()); + System.setProperty("carbon.home", carbonHome.getAbsolutePath()); + } + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID); + } + + private void initServices() throws NoSuchFieldException, IllegalAccessException, JWTClientException, UserStoreException, RegistryException { - private void initServices() throws DeviceManagementException, RegistryException, IOException, JWTClientConfigurationException, NoSuchFieldException, JWTClientException, IllegalAccessException { - IntegrationClientService integrationClientService = Mockito.mock(IntegrationClientServiceImpl.class,Mockito.CALLS_REAL_METHODS); + IntegrationClientService integrationClientService = Mockito.mock(IntegrationClientServiceImpl.class, Mockito.CALLS_REAL_METHODS); APIPublisherDataHolder.getInstance().setIntegrationClientService(integrationClientService); - - PublisherClient publisherClient = Mockito.mock(PublisherClient.class,Mockito.CALLS_REAL_METHODS); + PublisherClient publisherClient = Mockito.mock(PublisherClient.class, Mockito.CALLS_REAL_METHODS); doReturn(publisherClient).when(integrationClientService).getPublisherClient(); - APIsApi api = new APIsApi() { - @Override - public void apisApiIdDelete(String apiId, String ifMatch, String ifUnmodifiedSince) { - - } - - @Override - public API apisApiIdGet(String apiId, String accept, String ifNoneMatch, String ifModifiedSince) { - return null; - } - - @Override - public API apisApiIdPut(String apiId, API body, String contentType, String ifMatch, String ifUnmodifiedSince) { - return null; - } - - @Override - public void apisApiIdSwaggerGet(String apiId, String accept, String ifNoneMatch, String ifModifiedSince) { - - } - - @Override - public void apisApiIdSwaggerPut(String apiId, String apiDefinition, String contentType, String ifMatch, String ifUnmodifiedSince) { - - } - - @Override - public void apisApiIdThumbnailGet(String apiId, String accept, String ifNoneMatch, String ifModifiedSince) { - - } - - @Override - public FileInfo apisApiIdThumbnailPost(String apiId, File file, String contentType, String ifMatch, String ifUnmodifiedSince) { - return null; - } - - @Override - public void apisChangeLifecyclePost(String action, String apiId, String lifecycleChecklist, String ifMatch, String ifUnmodifiedSince) { - - } - - @Override - public void apisCopyApiPost(String newVersion, String apiId) { - - } - - @Override - public APIList apisGet(Integer limit, Integer offset, String query, String accept, String ifNoneMatch) { - return null; - } - - @Override - public API apisPost(API body, String contentType) { - return new API(); - } - }; - + APIsApi api = new Api(); Field field = PublisherClient.class.getDeclaredField("api"); field.setAccessible(true); - field.set(publisherClient,api); + field.set(publisherClient, api); AccessTokenInfo accessTokenInfo = new AccessTokenInfo(); - accessTokenInfo.setTokenType("type"); - String REQUIRED_SCOPE = + final String REQUIRED_SCOPE = "apim:api_create apim:api_view apim:api_publish apim:subscribe apim:tier_view apim:tier_manage " + "apim:subscription_view apim:subscription_block"; - accessTokenInfo.setScopes(REQUIRED_SCOPE); + accessTokenInfo.setScopes(REQUIRED_SCOPE); JWTClientManagerService jwtClientManagerService = Mockito.mock(JWTClientManagerServiceImpl.class, Mockito.CALLS_REAL_METHODS); JWTClient jwtClient = Mockito.mock(JWTClient.class, Mockito.CALLS_REAL_METHODS); doReturn(accessTokenInfo).when(jwtClient).getAccessToken(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); doReturn(jwtClient).when(jwtClientManagerService).getJWTClient(); - APIIntegrationClientDataHolder.getInstance().setJwtClientManagerService(jwtClientManagerService); - } + + APIIntegrationClientDataHolder.getInstance().setJwtClientManagerService(jwtClientManagerService); + RegistryService registryService = this.getRegistryService(); + OSGiDataHolder.getInstance().setRegistryService(registryService); + JWTClientExtensionDataHolder.getInstance().setRegistryService(registryService); + } private RegistryService getRegistryService() throws RegistryException, UserStoreException { RealmService realmService = new InMemoryRealmService(); -// TenantManager tenantManager = new JDBCTenantManager(dataSource, -// org.wso2.carbon.utils.multitenancy.MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); - // realmService.setTenantManager(tenantManager); APIPublisherDataHolder.getInstance().setRealmService(realmService); RegistryDataHolder.getInstance().setRealmService(realmService); JWTClientExtensionDataHolder.getInstance().setRealmService(realmService); - InputStream is = this.getClass().getClassLoader().getResourceAsStream("carbon-home/repository/conf/registry.xml"); RegistryContext context = RegistryContext.getBaseInstance(is, realmService); context.setSetup(true); return context.getEmbeddedRegistryService(); } - - - private void initializeCarbonContext() throws UserStoreException, RegistryException { - - ClassLoader classLoader = getClass().getClassLoader(); - URL resourceUrl = classLoader.getResource("carbon-home"); - - if (resourceUrl != null) { - File carbonHome = new File(resourceUrl.getFile()); - System.setProperty("carbon.home", carbonHome.getAbsolutePath()); - } - - PrivilegedCarbonContext.getThreadLocalCarbonContext() - .setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); - PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID); - RegistryService registryService = this.getRegistryService(); - OSGiDataHolder.getInstance().setRegistryService(registryService); - JWTClientExtensionDataHolder.getInstance().setRegistryService(registryService); - - PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants - .SUPER_TENANT_DOMAIN_NAME); - PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID); - } - } diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/DataSourceConfig.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/DataSourceConfig.java deleted file mode 100644 index f3e31968fe..0000000000 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/DataSourceConfig.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you 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.carbon.apimgt.webapp.publisher; - -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; - -@XmlRootElement(name = "DataSourceConfig") -public class DataSourceConfig { - - private String url; - private String driverClassName; - private String user; - private String password; - - @Override public String toString() { - return "DataSourceConfig[" + - " Url ='" + url + '\'' + - ", DriverClassName ='" + driverClassName + '\'' + - ", UserName ='" + user + '\'' + - ", Password ='" + password + '\'' + - "]"; - } - - @XmlElement(name = "Url", nillable = false) - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - @XmlElement(name = "DriverClassName", nillable = false) - public String getDriverClassName() { - return driverClassName; - } - - public void setDriverClassName(String driverClassName) { - this.driverClassName = driverClassName; - } - - @XmlElement(name = "User", nillable = false) - public String getUser() { - return user; - } - - public void setUser(String user) { - this.user = user; - } - - @XmlElement(name = "Password", nillable = false) - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - -} diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/utils/Api.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/utils/Api.java new file mode 100644 index 0000000000..820da060a9 --- /dev/null +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/utils/Api.java @@ -0,0 +1,86 @@ +/* +* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 Inc. licenses this file to you 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.carbon.apimgt.webapp.publisher.utils; + +import org.wso2.carbon.apimgt.integration.generated.client.publisher.api.APIsApi; +import org.wso2.carbon.apimgt.integration.generated.client.publisher.model.API; +import org.wso2.carbon.apimgt.integration.generated.client.publisher.model.APIList; +import org.wso2.carbon.apimgt.integration.generated.client.publisher.model.FileInfo; + +import java.io.File; + +/** + * Class to create Api for testing. + */ +public class Api implements APIsApi { + + @Override + public void apisApiIdDelete(String apiId, String ifMatch, String ifUnmodifiedSince) { + + } + + @Override + public API apisApiIdGet(String apiId, String accept, String ifNoneMatch, String ifModifiedSince) { + return null; + } + + @Override + public API apisApiIdPut(String apiId, API body, String contentType, String ifMatch, String ifUnmodifiedSince) { + return null; + } + + @Override + public void apisApiIdSwaggerGet(String apiId, String accept, String ifNoneMatch, String ifModifiedSince) { + + } + + @Override + public void apisApiIdSwaggerPut(String apiId, String apiDefinition, String contentType, String ifMatch, String ifUnmodifiedSince) { + + } + + @Override + public void apisApiIdThumbnailGet(String apiId, String accept, String ifNoneMatch, String ifModifiedSince) { + + } + + @Override + public FileInfo apisApiIdThumbnailPost(String apiId, File file, String contentType, String ifMatch, String ifUnmodifiedSince) { + return null; + } + + @Override + public void apisChangeLifecyclePost(String action, String apiId, String lifecycleChecklist, String ifMatch, String ifUnmodifiedSince) { + + } + + @Override + public void apisCopyApiPost(String newVersion, String apiId) { + + } + + @Override + public APIList apisGet(Integer limit, Integer offset, String query, String accept, String ifNoneMatch) { + return null; + } + + @Override + public API apisPost(API body, String contentType) { + return new API(); + } +} diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/utils/Utils.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/utils/Utils.java deleted file mode 100644 index 21d6a7007a..0000000000 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/utils/Utils.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you 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.carbon.apimgt.webapp.publisher.utils; - -import org.w3c.dom.Document; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; - -import javax.xml.XMLConstants; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import java.io.File; - -/** - * This class handles the test utility tasks. - */ -public class Utils { - - public static Document convertToDocument(File file) throws DeviceManagementException { - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); - try { - int rwew = 222; - DocumentBuilder docBuilder = factory.newDocumentBuilder(); - factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); - return docBuilder.parse(file); - } catch (Exception e) { - throw new DeviceManagementException("Error occurred while parsing file, while converting " + - "to a org.w3c.dom.Document", e); - } - } -} diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/carbon-home/repository/conf/apim-integration.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/carbon-home/repository/conf/apim-integration.xml deleted file mode 100644 index 400b7a06b6..0000000000 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/carbon-home/repository/conf/apim-integration.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - https://${iot.keymanager.host}:${iot.keymanager.https.port}/client-registration/v0.11/register - https://${iot.gateway.host}:${iot.gateway.https.port}/token - https://localhost:9445/api/am/publisher/v0.11 - https://${iot.apimstore.host}:${iot.apimstore.https.port}/api/am/store/v0.11 - - https://localhost:9443/client-registration/v0.11/register - https://localhost:9443/token - https://localhost:9445/api/am/publisher/v0.11 - https://localhost:9445/api/am/store/v0.11 - - admin - admin - diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/carbon-home/repository/conf/carbon.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/carbon-home/repository/conf/carbon.xml deleted file mode 100644 index 31752cf9b4..0000000000 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/carbon-home/repository/conf/carbon.xml +++ /dev/null @@ -1,656 +0,0 @@ - - - - - - - - - ${product.name} - - - ${product.key} - - - ${product.version} - - - - - - - - - local:/${carbon.context}/services/ - - - - - - - ${default.server.role} - - - - - - - org.wso2.carbon - - - / - - - - - - - - - 15 - - - - - - - - - 0 - - - - - 9999 - - 11111 - - - - - - 10389 - - 8000 - - - - - - 10500 - - - - - - - org.wso2.carbon.tomcat.jndi.CarbonJavaURLContextFactory - - - - - - - - - java - - - - - - - - - - false - - - false - - - 600 - - - - false - - - - - - - - 30 - - - - - - - - - 15 - - - - - - ${carbon.home}/repository/deployment/server/ - - - 15 - - - ${carbon.home}/repository/conf/axis2/axis2.xml - - - 30000 - - - ${carbon.home}/repository/deployment/client/ - - ${carbon.home}/repository/conf/axis2/axis2_client.xml - - true - - - - - - - - - - admin - Default Administrator Role - - - user - Default User Role - - - - - - - - - - - - ${carbon.home}/repository/resources/security/wso2carbon.jks - - JKS - - wso2carbon - - wso2carbon - - wso2carbon - - - - - - ${carbon.home}/repository/resources/security/client-truststore.jks - - JKS - - wso2carbon - - - - - - - - - - - - - - - - - - - UserManager - - - false - - - - - - - ${carbon.home}/tmp/work - - - - - - true - - - 10 - - - 30 - - - - - - 100 - - - - keystore - certificate - * - - org.wso2.carbon.ui.transports.fileupload.AnyFileUploadExecutor - - - - - jarZip - - org.wso2.carbon.ui.transports.fileupload.JarZipUploadExecutor - - - - dbs - - org.wso2.carbon.ui.transports.fileupload.DBSFileUploadExecutor - - - - tools - - org.wso2.carbon.ui.transports.fileupload.ToolsFileUploadExecutor - - - - toolsAny - - org.wso2.carbon.ui.transports.fileupload.ToolsAnyFileUploadExecutor - - - - - - - info - org.wso2.carbon.core.transports.util.InfoProcessor - - - wsdl - org.wso2.carbon.core.transports.util.Wsdl11Processor - - - wsdl2 - org.wso2.carbon.core.transports.util.Wsdl20Processor - - - xsd - org.wso2.carbon.core.transports.util.XsdProcessor - - - - - - false - false - true - svn - http://svnrepo.example.com/repos/ - username - password - true - - - - - - - - - - - - - - - ${require.carbon.servlet} - - - - - true - - - - - - - default repository - ${p2.repo.url} - - - - - - - - true - - - - - - true - - diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/config/datasource/data-source-config.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/config/datasource/data-source-config.xml deleted file mode 100644 index d9be5b3ac0..0000000000 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/config/datasource/data-source-config.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - jdbc:h2:mem:cdm-test-db;DB_CLOSE_ON_EXIT=FALSE;MVCC=true - org.h2.Driver - wso2carbon - wso2carbon - - - - - - - - - diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/config/operation/cdm-config.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/config/operation/cdm-config.xml deleted file mode 100644 index d4e1acb139..0000000000 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/config/operation/cdm-config.xml +++ /dev/null @@ -1,96 +0,0 @@ - - - - - - - - jdbc/DM_DS - - - - - 2 - 2000 - 2000 - true - - org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.FCMBasedPushNotificationProvider - - org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.MQTTBasedPushNotificationProvider - org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.HTTPBasedPushNotificationProvider - org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.XMPPBasedPushNotificationProvider - - - - false - - - https://localhost:9443 - admin - admin - - - org.wso2.carbon.policy.mgt - true - 60000 - 5 - 8 - 20 - - - - Simple - - - - 20 - 20 - 20 - 20 - 20 - 20 - - - - true - - - - false - 600 - - 10000 - - - false - 86400 - - - false - false - - BYOD,COPE - - diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/config/schema/app-mgt-config-schema.xsd b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/config/schema/app-mgt-config-schema.xsd deleted file mode 100644 index b2fc9d553e..0000000000 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/config/schema/app-mgt-config-schema.xsd +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/config/schema/device-mgt-config-schema.xsd b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/config/schema/device-mgt-config-schema.xsd deleted file mode 100644 index 420980b470..0000000000 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/config/schema/device-mgt-config-schema.xsd +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/jwt.properties b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/jwt.properties deleted file mode 100644 index 0c9641fa2d..0000000000 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/resources/jwt.properties +++ /dev/null @@ -1,57 +0,0 @@ -# -# Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -# -# WSO2 Inc. licenses this file to you 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. -# - -#issuer of the JWT -iss=wso2.org/products/iot - -TokenEndpoint=https://${iot.gateway.host}:${iot.gateway.https.port}/token?tenantDomain=carbon.super - -#audience of JWT claim -#comma seperated values -aud=devicemgt - -#expiration time of JWT (number of minutes from the current time) -exp=1000 - -#issued at time of JWT (number of minutes from the current time) -iat=0 - -#nbf time of JWT (number of minutes from current time) -nbf=0 - -#skew between IDP and issuer(seconds) -skew=0 - -# JWT Id -#jti=token123 - -#KeyStore to cryptographic credentials -#KeyStore=repository/resources/security/wso2carbon.jks - -#Password of the KeyStore -#KeyStorePassword=wso2carbon - -#Alias of the SP's private key -#PrivateKeyAlias=wso2carbon - -#Private key password to retrieve the private key used to sign -#AuthnRequest and LogoutRequest messages -#PrivateKeyPassword=wso2carbon - -#this will be used as the default IDP config if there isn't any config available for tenants. -default-jwt-client=true From 1e6a769130a6b3d4e3724144bb6e83387cfd6ce4 Mon Sep 17 00:00:00 2001 From: Nirothipan Date: Thu, 12 Oct 2017 09:31:25 +0530 Subject: [PATCH 4/7] making required changes --- .../pom.xml | 40 ++++++------- .../publisher/APIPublisherServiceTest.java | 8 +-- .../publisher/BaseAPIPublisherTest.java | 18 +++--- .../repository/conf/etc/jwt.properties | 57 ------------------- .../test/resources/jwt-config/jwt.properties | 57 ------------------- 5 files changed, 35 insertions(+), 145 deletions(-) delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/repository/conf/etc/jwt.properties delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/jwt-config/jwt.properties diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml index 2e139f028b..e678e4927f 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml @@ -17,7 +17,8 @@ ~ under the License. --> - + apimgt-extensions @@ -108,10 +109,10 @@ org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.common - - org.wso2.carbon.devicemgt - org.wso2.carbon.apimgt.integration.client - + + org.wso2.carbon.devicemgt + org.wso2.carbon.apimgt.integration.client + com.h2database.wso2 h2-database-engine @@ -160,25 +161,25 @@ org.wso2.carbon.apimgt.annotations.*, org.wso2.carbon.governance.lcm.util.*, org.wso2.carbon.registry.core.*, - io.swagger.annotations, - javax.net.ssl, - org.scannotation, - org.scannotation.archiveiterator, - org.w3c.dom, - org.wso2.carbon.apimgt.integration.client.*, - org.wso2.carbon.context, - org.wso2.carbon.core.util, - org.wso2.carbon.user.api, - org.wso2.carbon.user.core.*, - org.wso2.carbon.utils.multitenancy, - org.wso2.carbon.apimgt.integration.generated.client.publisher.api, - org.wso2.carbon.apimgt.integration.generated.client.publisher.model + io.swagger.annotations, + javax.net.ssl, + org.scannotation, + org.scannotation.archiveiterator, + org.w3c.dom, + org.wso2.carbon.apimgt.integration.client.*, + org.wso2.carbon.context, + org.wso2.carbon.core.util, + org.wso2.carbon.user.api, + org.wso2.carbon.user.core.*, + org.wso2.carbon.utils.multitenancy, + org.wso2.carbon.apimgt.integration.generated.client.publisher.api, + org.wso2.carbon.apimgt.integration.generated.client.publisher.model javax.ws.rs-api, scribe;scope=compile|runtime;inline=false; - * + * @@ -210,5 +211,4 @@ - diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceTest.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceTest.java index 74481ff712..cf313fca21 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceTest.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceTest.java @@ -42,7 +42,7 @@ APIPublisherServiceTest extends BaseAPIPublisherTest { @BeforeTest public void initialConfigs() throws Exception { setApiConfigs(apiConfig); - initialise0OAuthApplication(); + initializeOAuthApplication(); } @Test(description = "Publishes an API | will fail if there are any exceptions") @@ -66,10 +66,10 @@ APIPublisherServiceTest extends BaseAPIPublisherTest { Map apiScopes = new HashMap<>(); Set scopes = new HashSet<>(apiScopes.values()); apiConfig.setScopes(scopes); - setAPIUrITemplates(apiConfig); + setAPIURITemplates(apiConfig); } - private void setAPIUrITemplates(APIConfig apiConfig) { + private void setAPIURITemplates(APIConfig apiConfig) { Set uriTemplates = new LinkedHashSet<>(); ApiUriTemplate template = new ApiUriTemplate(); template.setAuthType("Application & Application User"); @@ -86,7 +86,7 @@ APIPublisherServiceTest extends BaseAPIPublisherTest { apiConfig.setUriTemplates(uriTemplates); } - private void initialise0OAuthApplication() throws NoSuchFieldException, IllegalAccessException { + private void initializeOAuthApplication() throws NoSuchFieldException, IllegalAccessException { OAuthApplication oAuthApplication = new OAuthApplication(); oAuthApplication.setClientName("admin_api_integration_client"); oAuthApplication.setIsSaasApplication("true"); diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/BaseAPIPublisherTest.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/BaseAPIPublisherTest.java index a8332c70c5..e935b98e2a 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/BaseAPIPublisherTest.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/test/java/org/wso2/carbon/apimgt/webapp/publisher/BaseAPIPublisherTest.java @@ -61,7 +61,7 @@ public abstract class BaseAPIPublisherTest { private static final Log log = LogFactory.getLog(BaseAPIPublisherTest.class); @BeforeSuite - public void initialise() throws Exception { + public void initialize() throws Exception { this.initializeCarbonContext(); this.initServices(); } @@ -73,13 +73,16 @@ public abstract class BaseAPIPublisherTest { File carbonHome = new File(resourceUrl.getFile()); System.setProperty("carbon.home", carbonHome.getAbsolutePath()); } - PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants. + SUPER_TENANT_DOMAIN_NAME); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID); } - private void initServices() throws NoSuchFieldException, IllegalAccessException, JWTClientException, UserStoreException, RegistryException { + private void initServices() throws NoSuchFieldException, IllegalAccessException, + JWTClientException, UserStoreException, RegistryException { - IntegrationClientService integrationClientService = Mockito.mock(IntegrationClientServiceImpl.class, Mockito.CALLS_REAL_METHODS); + IntegrationClientService integrationClientService = Mockito.mock(IntegrationClientServiceImpl.class, + Mockito.CALLS_REAL_METHODS); APIPublisherDataHolder.getInstance().setIntegrationClientService(integrationClientService); PublisherClient publisherClient = Mockito.mock(PublisherClient.class, Mockito.CALLS_REAL_METHODS); doReturn(publisherClient).when(integrationClientService).getPublisherClient(); @@ -95,7 +98,8 @@ public abstract class BaseAPIPublisherTest { "apim:subscription_view apim:subscription_block"; accessTokenInfo.setScopes(REQUIRED_SCOPE); - JWTClientManagerService jwtClientManagerService = Mockito.mock(JWTClientManagerServiceImpl.class, Mockito.CALLS_REAL_METHODS); + JWTClientManagerService jwtClientManagerService = Mockito.mock(JWTClientManagerServiceImpl.class, + Mockito.CALLS_REAL_METHODS); JWTClient jwtClient = Mockito.mock(JWTClient.class, Mockito.CALLS_REAL_METHODS); doReturn(accessTokenInfo).when(jwtClient).getAccessToken(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); @@ -112,10 +116,10 @@ public abstract class BaseAPIPublisherTest { APIPublisherDataHolder.getInstance().setRealmService(realmService); RegistryDataHolder.getInstance().setRealmService(realmService); JWTClientExtensionDataHolder.getInstance().setRealmService(realmService); - InputStream is = this.getClass().getClassLoader().getResourceAsStream("carbon-home/repository/conf/registry.xml"); + InputStream is = this.getClass().getClassLoader().getResourceAsStream("carbon-home/repository/" + + "conf/registry.xml"); RegistryContext context = RegistryContext.getBaseInstance(is, realmService); context.setSetup(true); return context.getEmbeddedRegistryService(); } - } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/repository/conf/etc/jwt.properties b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/repository/conf/etc/jwt.properties deleted file mode 100644 index 0c9641fa2d..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/repository/conf/etc/jwt.properties +++ /dev/null @@ -1,57 +0,0 @@ -# -# Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -# -# WSO2 Inc. licenses this file to you 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. -# - -#issuer of the JWT -iss=wso2.org/products/iot - -TokenEndpoint=https://${iot.gateway.host}:${iot.gateway.https.port}/token?tenantDomain=carbon.super - -#audience of JWT claim -#comma seperated values -aud=devicemgt - -#expiration time of JWT (number of minutes from the current time) -exp=1000 - -#issued at time of JWT (number of minutes from the current time) -iat=0 - -#nbf time of JWT (number of minutes from current time) -nbf=0 - -#skew between IDP and issuer(seconds) -skew=0 - -# JWT Id -#jti=token123 - -#KeyStore to cryptographic credentials -#KeyStore=repository/resources/security/wso2carbon.jks - -#Password of the KeyStore -#KeyStorePassword=wso2carbon - -#Alias of the SP's private key -#PrivateKeyAlias=wso2carbon - -#Private key password to retrieve the private key used to sign -#AuthnRequest and LogoutRequest messages -#PrivateKeyPassword=wso2carbon - -#this will be used as the default IDP config if there isn't any config available for tenants. -default-jwt-client=true diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/jwt-config/jwt.properties b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/jwt-config/jwt.properties deleted file mode 100644 index 0c9641fa2d..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/jwt-config/jwt.properties +++ /dev/null @@ -1,57 +0,0 @@ -# -# Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -# -# WSO2 Inc. licenses this file to you 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. -# - -#issuer of the JWT -iss=wso2.org/products/iot - -TokenEndpoint=https://${iot.gateway.host}:${iot.gateway.https.port}/token?tenantDomain=carbon.super - -#audience of JWT claim -#comma seperated values -aud=devicemgt - -#expiration time of JWT (number of minutes from the current time) -exp=1000 - -#issued at time of JWT (number of minutes from the current time) -iat=0 - -#nbf time of JWT (number of minutes from current time) -nbf=0 - -#skew between IDP and issuer(seconds) -skew=0 - -# JWT Id -#jti=token123 - -#KeyStore to cryptographic credentials -#KeyStore=repository/resources/security/wso2carbon.jks - -#Password of the KeyStore -#KeyStorePassword=wso2carbon - -#Alias of the SP's private key -#PrivateKeyAlias=wso2carbon - -#Private key password to retrieve the private key used to sign -#AuthnRequest and LogoutRequest messages -#PrivateKeyPassword=wso2carbon - -#this will be used as the default IDP config if there isn't any config available for tenants. -default-jwt-client=true From d8c40c97f04cf3013f3fdec38ff07ffdf91cfeac Mon Sep 17 00:00:00 2001 From: Nirothipan Date: Thu, 12 Oct 2017 10:08:08 +0530 Subject: [PATCH 5/7] fixing --- .../{ => mobile}/sample-default-platform-configuration.xml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/repository/conf/etc/device-mgt-plugin-configs/{ => mobile}/sample-default-platform-configuration.xml (100%) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/repository/conf/etc/device-mgt-plugin-configs/sample-default-platform-configuration.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/repository/conf/etc/device-mgt-plugin-configs/mobile/sample-default-platform-configuration.xml similarity index 100% rename from components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/repository/conf/etc/device-mgt-plugin-configs/sample-default-platform-configuration.xml rename to components/device-mgt/org.wso2.carbon.device.mgt.extensions/src/test/resources/carbon-home/repository/conf/etc/device-mgt-plugin-configs/mobile/sample-default-platform-configuration.xml From 14f3ecc2ee414c14aa76730935e9572aaee1dbe7 Mon Sep 17 00:00:00 2001 From: Nirothipan Date: Thu, 12 Oct 2017 10:15:46 +0530 Subject: [PATCH 6/7] adding scope as test --- .../org.wso2.carbon.apimgt.webapp.publisher/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml index c0b6703aca..8eaee02d53 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml @@ -112,6 +112,7 @@ org.wso2.carbon.devicemgt org.wso2.carbon.apimgt.integration.client + test com.h2database.wso2 From 2b99cd0a456e4101cd28200dab643135d33c1ee7 Mon Sep 17 00:00:00 2001 From: Nirothipan Date: Thu, 12 Oct 2017 10:19:46 +0530 Subject: [PATCH 7/7] removing scope --- .../org.wso2.carbon.apimgt.webapp.publisher/pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml index 8eaee02d53..c0b6703aca 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml @@ -112,7 +112,6 @@ org.wso2.carbon.devicemgt org.wso2.carbon.apimgt.integration.client - test com.h2database.wso2