Search in sources :

Example 1 with OptionsResponse

use of com.linkedin.restli.common.OptionsResponse in project rest.li by linkedin.

the class TestGreetingsClient method testModelsForOptionsRequest.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "optionsData")
public void testModelsForOptionsRequest(OptionsRequestBuilder request, NamedDataSchema[] schemas) throws RemoteInvocationException, URISyntaxException, IOException {
    Request<OptionsResponse> optionsRequest = request.build();
    OptionsResponse optionsResponse = getClient().sendRequest(optionsRequest).getResponse().getEntity();
    Map<String, DataSchema> rawDataSchemas = optionsResponse.getDataSchemas();
    for (NamedDataSchema dataSchema : schemas) {
        DataSchema optionsDataSchema = rawDataSchemas.get(dataSchema.getFullName());
        Assert.assertEquals(optionsDataSchema, dataSchema);
    }
}
Also used : DataSchema(com.linkedin.data.schema.DataSchema) NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) OptionsResponse(com.linkedin.restli.common.OptionsResponse) Test(org.testng.annotations.Test)

Example 2 with OptionsResponse

use of com.linkedin.restli.common.OptionsResponse in project rest.li by linkedin.

the class OptionsResponseDecoder method wrapResponse.

@Override
public OptionsResponse wrapResponse(DataMap dataMap, Map<String, String> headers, ProtocolVersion version) throws IOException {
    if (dataMap == null) {
        return null;
    }
    DataMap resources = dataMap.getDataMap(RESOURCES);
    if (resources == null)
        resources = new DataMap();
    HashMap<String, ResourceSchema> resourceMap = new HashMap<String, ResourceSchema>(resources.size());
    for (Map.Entry<String, Object> entry : resources.entrySet()) {
        resourceMap.put(entry.getKey(), new ResourceSchema((DataMap) entry.getValue()));
    }
    DataMap schemas = dataMap.getDataMap(MODELS);
    if (schemas == null)
        schemas = new DataMap();
    HashMap<String, DataSchema> dataSchemaMap = new HashMap<String, DataSchema>(schemas.size());
    for (Map.Entry<String, Object> entry : schemas.entrySet()) {
        String schemaText = CODEC.mapToString((DataMap) entry.getValue());
        dataSchemaMap.put(entry.getKey(), DataTemplateUtil.parseSchema(schemaText));
    }
    return new OptionsResponse(resourceMap, dataSchemaMap);
}
Also used : DataSchema(com.linkedin.data.schema.DataSchema) ResourceSchema(com.linkedin.restli.restspec.ResourceSchema) HashMap(java.util.HashMap) DataMap(com.linkedin.data.DataMap) Map(java.util.Map) HashMap(java.util.HashMap) OptionsResponse(com.linkedin.restli.common.OptionsResponse) DataMap(com.linkedin.data.DataMap)

Example 3 with OptionsResponse

use of com.linkedin.restli.common.OptionsResponse in project rest.li by linkedin.

the class TestGreetingsClient method testOptions.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderWithResourceNameDataProvider")
public void testOptions(RootBuilderWrapper<Long, Greeting> builders, String resourceName, ProtocolVersion protocolVersion) throws RemoteInvocationException, URISyntaxException, IOException {
    Request<OptionsResponse> optionsRequest = builders.options().build();
    OptionsResponse optionsResponse = getClient().sendRequest(optionsRequest).getResponse().getEntity();
    Map<String, ResourceSchema> resources = optionsResponse.getResourceSchemas();
    Assert.assertEquals(resources.size(), 1);
    ResourceSchema resourceSchema = resources.get("com.linkedin.restli.examples.greetings.client." + resourceName);
    // sanity check the resource schema
    Assert.assertEquals(resourceSchema.getName(), resourceName);
    Assert.assertTrue(resourceSchema.hasCollection());
}
Also used : ResourceSchema(com.linkedin.restli.restspec.ResourceSchema) OptionsResponse(com.linkedin.restli.common.OptionsResponse) Test(org.testng.annotations.Test)

Aggregations

OptionsResponse (com.linkedin.restli.common.OptionsResponse)3 DataSchema (com.linkedin.data.schema.DataSchema)2 ResourceSchema (com.linkedin.restli.restspec.ResourceSchema)2 Test (org.testng.annotations.Test)2 DataMap (com.linkedin.data.DataMap)1 NamedDataSchema (com.linkedin.data.schema.NamedDataSchema)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1