Java 类com.amazonaws.services.apigateway.model.Resources 实例源码

项目:aws-apigateway-importer    文件:ApiGatewaySdkApiImporter.java   
protected List<Resource> buildResourceList(RestApi api) {
    List<Resource> resourceList = new ArrayList<>();

    Resources resources = api.getResources();
    resourceList.addAll(resources.getItem());

    LOG.debug("Building list of resources. Stack trace: ", new Throwable());

    final RateLimiter rl = RateLimiter.create(2);
    while (resources._isLinkAvailable("next")) {
        rl.acquire();
        resources = resources.getNext();
        resourceList.addAll(resources.getItem());
    }

    return resourceList;
}
项目:aws-api-gateway    文件:ApiGatewaySdkApiImporter.java   
protected List<Resource> buildResourceList(RestApi api) {
    List<Resource> resourceList = new ArrayList<>();

    Resources resources = api.getResources();
    resourceList.addAll(resources.getItem());

    LOG.debug("Building list of resources. Stack trace: ", new Throwable());

    final RateLimiter rl = RateLimiter.create(2);
    while (resources._isLinkAvailable("next")) {
        rl.acquire();
        resources = resources.getNext();
        resourceList.addAll(resources.getItem());
    }

    return resourceList;
}
项目:aws-apigateway-swagger-exporter    文件:APIGExporter.java   
private static Resources safeGetNext(Resources resources) {
    try {
        return resources.getNext();
    } catch (UnsupportedOperationException e) {
        return null;
    }
}
项目:aws-apigateway-swagger-exporter    文件:APIGExporter.java   
private static String getBasePath(RestApi restApi) {
    String[] basePath = null;
    for (Resources resources = restApi.getResources(); resources != null; resources = safeGetNext(resources)) {
        for (Resource resource : resources.getItem()) {
            Map<String, Method> resourceMethods = resource.getResourceMethods();
            if (resourceMethods.isEmpty()) {
                continue;
            }
            String[] resourcePath = resource.getPath().split("/");
            if (basePath == null) {
                basePath = resourcePath;
            } else {
                int i=0;
                for (; i<basePath.length && i<resourcePath.length; i++) {
                    if (!basePath[i].equals(resourcePath[i])) {
                        break;
                    }
                }
                basePath = Arrays.copyOf(basePath, i);
            }
        }
    }
    StringBuilder sb = new StringBuilder();
    for (String s : basePath) {
        if (!s.isEmpty()) {
            sb.append("/");
            sb.append(s);
        }
    }
    return sb.toString();
}
项目:aws-apigateway-importer    文件:ApiGatewaySwaggerFileImporterTest.java   
@Before
public void setUp() throws Exception {
    BasicConfigurator.configure();

    Injector injector = Guice.createInjector(new SwaggerApiImporterTestModule());

    client = injector.getInstance(ApiGateway.class);
    importer = injector.getInstance(SwaggerApiFileImporter.class);

    RestApis mockRestApis = mock(RestApis.class);
    Integration mockIntegration = Mockito.mock(Integration.class);

    Method mockMethod = Mockito.mock(Method.class);
    when(mockMethod.getHttpMethod()).thenReturn("GET");
    when(mockMethod.putIntegration(any())).thenReturn(mockIntegration);

    mockChildResource = Mockito.mock(Resource.class);
    when(mockChildResource.getPath()).thenReturn("/child");
    when(mockChildResource.putMethod(any(), any())).thenReturn(mockMethod);

    mockResource = Mockito.mock(Resource.class);
    when(mockResource.getPath()).thenReturn("/");
    when(mockResource.createResource(any())).thenReturn(mockChildResource);
    when(mockResource.putMethod(any(), any())).thenReturn(mockMethod);

    Resources mockResources = mock(Resources.class);
    when(mockResources.getItem()).thenReturn(Arrays.asList(mockResource));

    Model mockModel = Mockito.mock(Model.class);
    when(mockModel.getName()).thenReturn("test model");

    Models mockModels = mock(Models.class);
    when(mockModels.getItem()).thenReturn(Arrays.asList(mockModel));

    mockRestApi = mock(RestApi.class);
    when(mockRestApi.getResources()).thenReturn(mockResources);
    when(mockRestApi.getModels()).thenReturn(mockModels);
    when(mockRestApi.getResourceById(any())).thenReturn(mockResource);

    when(client.getRestApis()).thenReturn(mockRestApis);
    when(client.createRestApi(any())).thenReturn(mockRestApi);

    importer.importApi(getResourcePath(API_GATEWAY));
}
项目:aws-api-gateway    文件:ApiGatewaySwaggerFileImporterTest.java   
@Before
public void setUp() throws Exception {
    BasicConfigurator.configure();

    Injector injector = Guice.createInjector(new SwaggerApiImporterTestModule());

    client = injector.getInstance(ApiGateway.class);
    importer = injector.getInstance(SwaggerApiFileImporter.class);

    RestApis mockRestApis = mock(RestApis.class);
    Integration mockIntegration = Mockito.mock(Integration.class);

    Method mockMethod = Mockito.mock(Method.class);
    when(mockMethod.getHttpMethod()).thenReturn("GET");
    when(mockMethod.putIntegration(any())).thenReturn(mockIntegration);

    mockChildResource = Mockito.mock(Resource.class);
    when(mockChildResource.getPath()).thenReturn("/child");
    when(mockChildResource.putMethod(any(), any())).thenReturn(mockMethod);

    mockResource = Mockito.mock(Resource.class);
    when(mockResource.getPath()).thenReturn("/");
    when(mockResource.createResource(any())).thenReturn(mockChildResource);
    when(mockResource.putMethod(any(), any())).thenReturn(mockMethod);

    Resources mockResources = mock(Resources.class);
    when(mockResources.getItem()).thenReturn(Arrays.asList(mockResource));

    Model mockModel = Mockito.mock(Model.class);
    when(mockModel.getName()).thenReturn("test model");

    Models mockModels = mock(Models.class);
    when(mockModels.getItem()).thenReturn(Arrays.asList(mockModel));

    mockRestApi = mock(RestApi.class);
    when(mockRestApi.getResources()).thenReturn(mockResources);
    when(mockRestApi.getModels()).thenReturn(mockModels);
    when(mockRestApi.getResourceById(any())).thenReturn(mockResource);

    when(client.getRestApis()).thenReturn(mockRestApis);
    when(client.createRestApi(any())).thenReturn(mockRestApi);

    importer.importApi(getResourcePath(API_GATEWAY));
}