Fix the api publisher and store update

4.x.x
geethkokila 7 years ago
parent 3cdd0e5a10
commit 7cb9685bc6

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

@ -50,10 +50,10 @@ public class APIPublisherServiceImpl implements APIPublisherService {
PublisherClient publisherClient = APIPublisherDataHolder.getInstance().getIntegrationClientService() PublisherClient publisherClient = APIPublisherDataHolder.getInstance().getIntegrationClientService()
.getPublisherClient(); .getPublisherClient();
API api = getAPI(apiConfig); 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)) { 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())) { if (CREATED_STATUS.equals(api.getStatus())) {
publisherClient.getApi().apisChangeLifecyclePost(PUBLISH_ACTION, api.getId(), null, null, null); 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.model.OAuthApplication;
import org.wso2.carbon.apimgt.integration.client.publisher.PublisherClient; import org.wso2.carbon.apimgt.integration.client.publisher.PublisherClient;
import org.wso2.carbon.apimgt.integration.client.service.IntegrationClientService; 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.API;
import org.wso2.carbon.apimgt.integration.generated.client.publisher.model.APIInfo; import org.wso2.carbon.apimgt.integration.generated.client.publisher.model.APIInfo;
import org.wso2.carbon.apimgt.integration.generated.client.publisher.model.APIList; 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(). PublisherClient publisherClient = APIPublisherDataHolder.getInstance().getIntegrationClientService().
getPublisherClient(); getPublisherClient();
doReturn(publisherClient).when(integrationClientService).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(); doReturn(apIsApi).when(publisherClient).getApi();
API api = Mockito.mock(API.class, Mockito.CALLS_REAL_METHODS); API api = Mockito.mock(API.class, Mockito.CALLS_REAL_METHODS);
api.setStatus("CREATED"); 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); apiPublisherService.publishAPI(apiConfig);
} }
@ -97,18 +97,18 @@ public class APIPublisherServiceTest extends BaseAPIPublisherTest {
PublisherClient publisherClient = APIPublisherDataHolder.getInstance().getIntegrationClientService(). PublisherClient publisherClient = APIPublisherDataHolder.getInstance().getIntegrationClientService().
getPublisherClient(); getPublisherClient();
doReturn(publisherClient).when(integrationClientService).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(); doReturn(apIsApi).when(publisherClient).getApi();
API api = Mockito.mock(API.class, Mockito.CALLS_REAL_METHODS); API api = Mockito.mock(API.class, Mockito.CALLS_REAL_METHODS);
api.setStatus("CREATED"); 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); APIList apiList = Mockito.mock(APIList.class, Mockito.CALLS_REAL_METHODS);
APIInfo apiInfo = new APIInfo(); APIInfo apiInfo = new APIInfo();
List<APIInfo> apiInfoList = new ArrayList<>(); List<APIInfo> apiInfoList = new ArrayList<>();
apiInfoList.add(apiInfo); apiInfoList.add(apiInfo);
apiList.list(apiInfoList); apiList.list(apiInfoList);
doReturn(apiList).when(apIsApi).apisGet(Mockito.anyInt(), Mockito.anyInt(), // doReturn(apiList).when(apIsApi).apisGet(Mockito.anyInt(), Mockito.anyInt(),
Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); // Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
doReturn(api).when(apIsApi).apisApiIdPut(Mockito.anyString(), Mockito.any(), doReturn(api).when(apIsApi).apisApiIdPut(Mockito.anyString(), Mockito.any(),
Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
apiPublisherService.publishAPI(apiConfig); apiPublisherService.publishAPI(apiConfig);
@ -126,11 +126,11 @@ public class APIPublisherServiceTest extends BaseAPIPublisherTest {
PublisherClient publisherClient = APIPublisherDataHolder.getInstance().getIntegrationClientService(). PublisherClient publisherClient = APIPublisherDataHolder.getInstance().getIntegrationClientService().
getPublisherClient(); getPublisherClient();
doReturn(publisherClient).when(integrationClientService).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(); doReturn(apIsApi).when(publisherClient).getApi();
API api = Mockito.mock(API.class, Mockito.CALLS_REAL_METHODS); API api = Mockito.mock(API.class, Mockito.CALLS_REAL_METHODS);
api.setStatus("CREATED"); 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); APIList apiList = Mockito.mock(APIList.class, Mockito.CALLS_REAL_METHODS);
APIInfo apiInfo = new APIInfo(); APIInfo apiInfo = new APIInfo();
apiInfo.setName("testAPI-3"); apiInfo.setName("testAPI-3");
@ -139,8 +139,8 @@ public class APIPublisherServiceTest extends BaseAPIPublisherTest {
List<APIInfo> apiInfoList = new ArrayList<>(); List<APIInfo> apiInfoList = new ArrayList<>();
apiInfoList.add(apiInfo); apiInfoList.add(apiInfo);
apiList.list(apiInfoList); apiList.list(apiInfoList);
doReturn(apiList).when(apIsApi).apisGet(Mockito.anyInt(), Mockito.anyInt(), // doReturn(apiList).when(apIsApi).apisGet(Mockito.anyInt(), Mockito.anyInt(),
Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); // Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
doReturn(api).when(apIsApi).apisApiIdPut(Mockito.anyString(), Mockito.any(), doReturn(api).when(apIsApi).apisApiIdPut(Mockito.anyString(), Mockito.any(),
Mockito.anyString(), Mockito.anyString(), Mockito.anyString()); Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
apiConfig.setSharedWithAllTenants(false); 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.internal.APIIntegrationClientDataHolder;
import org.wso2.carbon.apimgt.integration.client.publisher.PublisherClient; import org.wso2.carbon.apimgt.integration.client.publisher.PublisherClient;
import org.wso2.carbon.apimgt.integration.client.service.IntegrationClientService; 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.internal.APIPublisherDataHolder;
import org.wso2.carbon.apimgt.webapp.publisher.utils.MockApi; import org.wso2.carbon.apimgt.webapp.publisher.utils.MockApi;
import org.wso2.carbon.base.MultitenantConstants; import org.wso2.carbon.base.MultitenantConstants;
@ -87,7 +87,7 @@ public abstract class BaseAPIPublisherTest {
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(); doReturn(publisherClient).when(integrationClientService).getPublisherClient();
APIsApi api = new MockApi(); APIIndividualApi api = new MockApi();
Field field = PublisherClient.class.getDeclaredField("api"); Field field = PublisherClient.class.getDeclaredField("api");
field.setAccessible(true); field.setAccessible(true);
field.set(publisherClient, api); field.set(publisherClient, api);

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

Loading…
Cancel
Save