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