Ruwan Yatawara 7 years ago
commit 91093cbc64

@ -35,12 +35,13 @@ import org.wso2.carbon.core.util.Utils;
public class PublisherClient {
private static final Log log = LogFactory.getLog(PublisherClient.class);
private APIsApi api = null;
private APIDocumentApi document = null;
private ApplicationsApi application = null;
private EnvironmentsApi environments = null;
private SubscriptionsApi subscriptions = null;
private TiersApi tiers = null;
private APIIndividualApi api = null;
private APICollectionApi apis = null;
private DocumentIndividualApi document = null;
private ApplicationIndividualApi application = null;
private EnvironmentCollectionApi environments = null;
private SubscriptionCollectionApi subscriptions = null;
private ThrottlingTierCollectionApi tiers = null;
/**
@ -54,35 +55,40 @@ public class PublisherClient {
.requestInterceptor(requestInterceptor).encoder(new GsonEncoder()).decoder(new GsonDecoder());
String basePath = Utils.replaceSystemProperty(APIMConfigReader.getInstance().getConfig().getPublisherEndpoint());
api = builder.target(APIsApi.class, basePath);
document = builder.target(APIDocumentApi.class, basePath);
application = builder.target(ApplicationsApi.class, basePath);
environments = builder.target(EnvironmentsApi.class, basePath);
subscriptions = builder.target(SubscriptionsApi.class, basePath);
tiers = builder.target(TiersApi.class, basePath);
api = builder.target(APIIndividualApi.class, basePath);
apis = builder.target(APICollectionApi.class, basePath);
document = builder.target(DocumentIndividualApi.class, basePath);
application = builder.target(ApplicationIndividualApi.class, basePath);
environments = builder.target(EnvironmentCollectionApi.class, basePath);
subscriptions = builder.target(SubscriptionCollectionApi.class, basePath);
tiers = builder.target(ThrottlingTierCollectionApi.class, basePath);
}
public APIsApi getApi() {
public APIIndividualApi getApi() {
return api;
}
public APIDocumentApi getDocument() {
public APICollectionApi getApis() {
return apis;
}
public DocumentIndividualApi getDocument() {
return document;
}
public ApplicationsApi getApplication() {
public ApplicationIndividualApi getApplication() {
return application;
}
public EnvironmentsApi getEnvironments() {
public EnvironmentCollectionApi getEnvironments() {
return environments;
}
public SubscriptionsApi getSubscriptions() {
public SubscriptionCollectionApi getSubscriptions() {
return subscriptions;
}
public TiersApi getTiers() {
public ThrottlingTierCollectionApi getTiers() {
return tiers;
}
}

@ -50,10 +50,10 @@ public class APIPublisherServiceImpl implements APIPublisherService {
PublisherClient publisherClient = APIPublisherDataHolder.getInstance().getIntegrationClientService()
.getPublisherClient();
API api = getAPI(apiConfig);
APIList apiList = publisherClient.getApi().apisGet(100, 0, "name:" + api.getName(), CONTENT_TYPE, null);
APIList apiList = publisherClient.getApis().apisGet(100, 0, "name:" + api.getName(), CONTENT_TYPE, null);
if (!isExist(api, apiList)) {
api = publisherClient.getApi().apisPost(api, CONTENT_TYPE);
api = publisherClient.getApi().apisPost(api, CONTENT_TYPE, null);
if (CREATED_STATUS.equals(api.getStatus())) {
publisherClient.getApi().apisChangeLifecyclePost(PUBLISH_ACTION, api.getId(), null, null, null);
}

@ -27,7 +27,7 @@ import org.wso2.carbon.apimgt.integration.client.OAuthRequestInterceptor;
import org.wso2.carbon.apimgt.integration.client.model.OAuthApplication;
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.api.APIIndividualApi;
import org.wso2.carbon.apimgt.integration.generated.client.publisher.model.API;
import org.wso2.carbon.apimgt.integration.generated.client.publisher.model.APIInfo;
import org.wso2.carbon.apimgt.integration.generated.client.publisher.model.APIList;
@ -77,11 +77,11 @@ public class APIPublisherServiceTest extends BaseAPIPublisherTest {
PublisherClient publisherClient = APIPublisherDataHolder.getInstance().getIntegrationClientService().
getPublisherClient();
doReturn(publisherClient).when(integrationClientService).getPublisherClient();
APIsApi apIsApi = Mockito.mock(MockApi.class, Mockito.CALLS_REAL_METHODS);
APIIndividualApi apIsApi = Mockito.mock(MockApi.class, Mockito.CALLS_REAL_METHODS);
doReturn(apIsApi).when(publisherClient).getApi();
API api = Mockito.mock(API.class, Mockito.CALLS_REAL_METHODS);
api.setStatus("CREATED");
doReturn(api).when(apIsApi).apisPost(Mockito.any(), Mockito.anyString());
doReturn(api).when(apIsApi).apisPost(Mockito.any(), Mockito.anyString(), Mockito.anyString());
apiPublisherService.publishAPI(apiConfig);
}
@ -97,18 +97,18 @@ public class APIPublisherServiceTest extends BaseAPIPublisherTest {
PublisherClient publisherClient = APIPublisherDataHolder.getInstance().getIntegrationClientService().
getPublisherClient();
doReturn(publisherClient).when(integrationClientService).getPublisherClient();
APIsApi apIsApi = Mockito.mock(MockApi.class, Mockito.CALLS_REAL_METHODS);
APIIndividualApi apIsApi = Mockito.mock(MockApi.class, Mockito.CALLS_REAL_METHODS);
doReturn(apIsApi).when(publisherClient).getApi();
API api = Mockito.mock(API.class, Mockito.CALLS_REAL_METHODS);
api.setStatus("CREATED");
doReturn(api).when(apIsApi).apisPost(Mockito.any(), Mockito.anyString());
doReturn(api).when(apIsApi).apisPost(Mockito.any(), Mockito.anyString(), Mockito.anyString());
APIList apiList = Mockito.mock(APIList.class, Mockito.CALLS_REAL_METHODS);
APIInfo apiInfo = new APIInfo();
List<APIInfo> apiInfoList = new ArrayList<>();
apiInfoList.add(apiInfo);
apiList.list(apiInfoList);
doReturn(apiList).when(apIsApi).apisGet(Mockito.anyInt(), Mockito.anyInt(),
Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
// doReturn(apiList).when(apIsApi).apisGet(Mockito.anyInt(), Mockito.anyInt(),
// Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
doReturn(api).when(apIsApi).apisApiIdPut(Mockito.anyString(), Mockito.any(),
Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
apiPublisherService.publishAPI(apiConfig);
@ -126,11 +126,11 @@ public class APIPublisherServiceTest extends BaseAPIPublisherTest {
PublisherClient publisherClient = APIPublisherDataHolder.getInstance().getIntegrationClientService().
getPublisherClient();
doReturn(publisherClient).when(integrationClientService).getPublisherClient();
APIsApi apIsApi = Mockito.mock(MockApi.class, Mockito.CALLS_REAL_METHODS);
APIIndividualApi apIsApi = Mockito.mock(MockApi.class, Mockito.CALLS_REAL_METHODS);
doReturn(apIsApi).when(publisherClient).getApi();
API api = Mockito.mock(API.class, Mockito.CALLS_REAL_METHODS);
api.setStatus("CREATED");
doReturn(api).when(apIsApi).apisPost(Mockito.any(), Mockito.anyString());
doReturn(api).when(apIsApi).apisPost(Mockito.any(), Mockito.anyString(), Mockito.anyString());
APIList apiList = Mockito.mock(APIList.class, Mockito.CALLS_REAL_METHODS);
APIInfo apiInfo = new APIInfo();
apiInfo.setName("testAPI-3");
@ -139,8 +139,8 @@ public class APIPublisherServiceTest extends BaseAPIPublisherTest {
List<APIInfo> apiInfoList = new ArrayList<>();
apiInfoList.add(apiInfo);
apiList.list(apiInfoList);
doReturn(apiList).when(apIsApi).apisGet(Mockito.anyInt(), Mockito.anyInt(),
Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
// doReturn(apiList).when(apIsApi).apisGet(Mockito.anyInt(), Mockito.anyInt(),
// Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
doReturn(api).when(apIsApi).apisApiIdPut(Mockito.anyString(), Mockito.any(),
Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
apiConfig.setSharedWithAllTenants(false);

@ -26,7 +26,7 @@ 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.api.APIIndividualApi;
import org.wso2.carbon.apimgt.webapp.publisher.internal.APIPublisherDataHolder;
import org.wso2.carbon.apimgt.webapp.publisher.utils.MockApi;
import org.wso2.carbon.base.MultitenantConstants;
@ -87,7 +87,7 @@ public abstract class BaseAPIPublisherTest {
PublisherClient publisherClient = Mockito.mock(PublisherClient.class, Mockito.CALLS_REAL_METHODS);
doReturn(publisherClient).when(integrationClientService).getPublisherClient();
APIsApi api = new MockApi();
APIIndividualApi api = new MockApi();
Field field = PublisherClient.class.getDeclaredField("api");
field.setAccessible(true);
field.set(publisherClient, api);

@ -17,9 +17,9 @@
*/
package org.wso2.carbon.apimgt.webapp.publisher.utils;
import org.wso2.carbon.apimgt.integration.generated.client.publisher.api.APIsApi;
import feign.Param;
import org.wso2.carbon.apimgt.integration.generated.client.publisher.api.APIIndividualApi;
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;
@ -27,7 +27,7 @@ import java.io.File;
/**
* Class to create MockApi for testing.
*/
public class MockApi implements APIsApi {
public class MockApi implements APIIndividualApi {
@Override
public void apisApiIdDelete(String apiId, String ifMatch, String ifUnmodifiedSince) {
@ -75,12 +75,17 @@ public class MockApi implements APIsApi {
}
@Override
public APIList apisGet(Integer limit, Integer offset, String query, String accept, String ifNoneMatch) {
public API apisPost(API body, @Param("contentType") String contentType, @Param("authorization") String authorization) {
return null;
}
@Override
public API apisPost(API body, String contentType) {
return new API();
}
// @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();
// }
}

Loading…
Cancel
Save