Search in sources :

Example 1 with CorsInformation

use of com.ibm.cloud.cloudant.v1.model.CorsInformation in project cloudant-java-sdk by IBM.

the class Cloudant method getCorsInformation.

/**
 * Retrieve CORS configuration information.
 *
 * Lists all Cross-origin resource sharing (CORS) configuration. CORS defines a way in which the browser and the
 * server interact to determine whether or not to allow the request.
 *
 * @param getCorsInformationOptions the {@link GetCorsInformationOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link CorsInformation}
 */
public ServiceCall<CorsInformation> getCorsInformation(GetCorsInformationOptions getCorsInformationOptions) {
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_api/v2/user/config/cors"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getCorsInformation");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    ResponseConverter<CorsInformation> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<CorsInformation>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : CorsInformation(com.ibm.cloud.cloudant.v1.model.CorsInformation) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder)

Example 2 with CorsInformation

use of com.ibm.cloud.cloudant.v1.model.CorsInformation in project cloudant-java-sdk by IBM.

the class CorsInformationTest method testCorsInformation.

@Test
public void testCorsInformation() throws Throwable {
    CorsInformation corsInformationModel = new CorsInformation();
    assertNull(corsInformationModel.isAllowCredentials());
    assertNull(corsInformationModel.isEnableCors());
    assertNull(corsInformationModel.getOrigins());
}
Also used : CorsInformation(com.ibm.cloud.cloudant.v1.model.CorsInformation) Test(org.testng.annotations.Test)

Example 3 with CorsInformation

use of com.ibm.cloud.cloudant.v1.model.CorsInformation in project cloudant-java-sdk by IBM.

the class CloudantTest method testGetCorsInformationWOptions.

@Test
public void testGetCorsInformationWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"allow_credentials\": true, \"enable_cors\": true, \"origins\": [\"origins\"]}";
    String getCorsInformationPath = "/_api/v2/user/config/cors";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the GetCorsInformationOptions model
    GetCorsInformationOptions getCorsInformationOptionsModel = new GetCorsInformationOptions();
    // Invoke operation with valid options model (positive test)
    Response<CorsInformation> response = cloudantService.getCorsInformation(getCorsInformationOptionsModel).execute();
    assertNotNull(response);
    CorsInformation responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "GET");
    // Check query
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNull(query);
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, getCorsInformationPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) CorsInformation(com.ibm.cloud.cloudant.v1.model.CorsInformation) GetCorsInformationOptions(com.ibm.cloud.cloudant.v1.model.GetCorsInformationOptions) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

CorsInformation (com.ibm.cloud.cloudant.v1.model.CorsInformation)3 Test (org.testng.annotations.Test)2 GetCorsInformationOptions (com.ibm.cloud.cloudant.v1.model.GetCorsInformationOptions)1 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 MockResponse (okhttp3.mockwebserver.MockResponse)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1