Search in sources :

Example 41 with StringMap

use of com.linkedin.data.template.StringMap in project rest.li by linkedin.

the class TwitterAccountsResource method closeAccounts.

/**
 * This is a sample Javadoc comment for an action. This method below takes in parameters that
 * specify what accounts to close
 *
 * @return
 *
 * a map that contains details about account closures.     This return description here is intentionally
 *  long     and poorly spaced in   between
 *      so that I can       make sure it shows up correctly in the restspec.json
 *
 * @param emailAddresses Array of email addresses
 * @param someFlag flag for some custom behavior
 * @param options a map specifying some custom options
 */
@Action(name = "closeAccounts")
public StringMap closeAccounts(@ActionParam("emailAddresses") StringArray emailAddresses, @ActionParam("someFlag") boolean someFlag, @ActionParam("options") @Optional StringMap options) {
    StringMap res = new StringMap();
    res.put("numClosed", "5");
    res.put("resultCode", "11");
    return new StringMap(res);
}
Also used : StringMap(com.linkedin.data.template.StringMap) Action(com.linkedin.restli.server.annotations.Action)

Example 42 with StringMap

use of com.linkedin.data.template.StringMap in project rest.li by linkedin.

the class TestParameterDefaultValue method testWrappedMap.

@Test
public void testWrappedMap() {
    Object result;
    result = test("{\"key1\": \"Hello\", \"key2\": \"World\"}", StringMap.class);
    final Map<String, String> stringFixture = new HashMap<>();
    stringFixture.put("key1", "Hello");
    stringFixture.put("key2", "World");
    Assert.assertEquals(result, new StringMap(stringFixture));
    Assert.assertSame(result.getClass(), StringMap.class);
    result = test("{\"key1\": true, \"key2\": false}", BooleanMap.class);
    final Map<String, Boolean> booleanFixture = new HashMap<>();
    booleanFixture.put("key1", true);
    booleanFixture.put("key2", false);
    Assert.assertEquals(result, new BooleanMap(booleanFixture));
    Assert.assertSame(result.getClass(), BooleanMap.class);
    result = test("{\"key1\": 1, \"key2\": 2}", IntegerMap.class);
    final Map<String, Integer> integerFixture = new HashMap<>();
    integerFixture.put("key1", 1);
    integerFixture.put("key2", 2);
    Assert.assertEquals(result, new IntegerMap(integerFixture));
    Assert.assertSame(result.getClass(), IntegerMap.class);
    result = test("{\"key1\": 2, \"key2\": 3}", LongMap.class);
    final Map<String, Long> longFixture = new HashMap<>();
    longFixture.put("key1", 2L);
    longFixture.put("key2", 3L);
    Assert.assertEquals(result, new LongMap(longFixture));
    Assert.assertSame(result.getClass(), LongMap.class);
    result = test("{\"key1\": 1.1, \"key2\": 2.2}", FloatMap.class);
    final Map<String, Float> floatFixture = new HashMap<>();
    floatFixture.put("key1", 1.1F);
    floatFixture.put("key2", 2.2F);
    Assert.assertEquals(result, new FloatMap(floatFixture));
    Assert.assertSame(result.getClass(), FloatMap.class);
    result = test("{\"key1\": 2.2, \"key2\": 3.3}", DoubleMap.class);
    final Map<String, Double> doubleFixture = new HashMap<>();
    doubleFixture.put("key1", 2.2D);
    doubleFixture.put("key2", 3.3D);
    Assert.assertEquals(result, new DoubleMap(doubleFixture));
    Assert.assertSame(result.getClass(), DoubleMap.class);
    result = test("{\"key1\": " + _bytes16Quoted + ", \"key2\": " + _bytes16Quoted + "}", BytesMap.class);
    final Map<String, ByteString> bytesFixture = new HashMap<>();
    bytesFixture.put("key1", ByteString.copyAvroString(_bytes16, true));
    bytesFixture.put("key2", ByteString.copyAvroString(_bytes16, true));
    Assert.assertEquals(result, new BytesMap(new DataMap(bytesFixture)));
    Assert.assertSame(result.getClass(), BytesMap.class);
    result = test("{\"key1\": {\"location\": \"Sunnyvale\"}, \"key2\": {\"location\": \"MTV\"}}", RecordBarMap.class);
    final DataMap dataFixture1 = new DataMap();
    final DataMap dataFixture2 = new DataMap();
    dataFixture1.put("location", "Sunnyvale");
    dataFixture2.put("location", "MTV");
    final RecordBar record1 = new RecordBar(dataFixture1);
    final RecordBar record2 = new RecordBar(dataFixture2);
    final Map<String, RecordBar> recordFixture = new HashMap<>();
    recordFixture.put("key1", record1);
    recordFixture.put("key2", record2);
    Assert.assertEquals(result, new RecordBarMap(recordFixture));
    Assert.assertSame(result.getClass(), RecordBarMap.class);
}
Also used : StringMap(com.linkedin.data.template.StringMap) HashMap(java.util.HashMap) ByteString(com.linkedin.data.ByteString) BytesMap(com.linkedin.data.template.BytesMap) RecordBar(com.linkedin.pegasus.generator.test.RecordBar) ByteString(com.linkedin.data.ByteString) CustomString(com.linkedin.restli.server.custom.types.CustomString) DoubleMap(com.linkedin.data.template.DoubleMap) DataMap(com.linkedin.data.DataMap) RecordBarMap(com.linkedin.pegasus.generator.test.RecordBarMap) IntegerMap(com.linkedin.data.template.IntegerMap) LongMap(com.linkedin.data.template.LongMap) FloatMap(com.linkedin.data.template.FloatMap) BooleanMap(com.linkedin.data.template.BooleanMap) CustomLong(com.linkedin.restli.server.custom.types.CustomLong) Test(org.testng.annotations.Test) ArrayTest(com.linkedin.pegasus.generator.test.ArrayTest)

Example 43 with StringMap

use of com.linkedin.data.template.StringMap in project rest.li by linkedin.

the class TestMultiplexedRequestHandlerImpl method fakeIndRequest.

private static IndividualRequest fakeIndRequest(String url, Map<String, String> headers, Map<String, IndividualRequest> dependentRequests) {
    IndividualRequest individualRequest = new IndividualRequest();
    individualRequest.setMethod(HttpMethod.GET.name());
    individualRequest.setRelativeUrl(url);
    if (headers != null && headers.size() > 0) {
        individualRequest.setHeaders(new StringMap(headers));
    }
    individualRequest.setDependentRequests(new IndividualRequestMap(dependentRequests));
    return individualRequest;
}
Also used : IndividualRequest(com.linkedin.restli.common.multiplexer.IndividualRequest) IndividualRequestMap(com.linkedin.restli.common.multiplexer.IndividualRequestMap) StringMap(com.linkedin.data.template.StringMap)

Example 44 with StringMap

use of com.linkedin.data.template.StringMap in project rest.li by linkedin.

the class TestMultiplexedRequestHandlerImpl method fakeIndResponse.

private static IndividualResponse fakeIndResponse(IndividualBody entity) {
    IndividualResponse individualResponse = new IndividualResponse();
    individualResponse.setStatus(HttpStatus.S_200_OK.getCode());
    individualResponse.setHeaders(new StringMap());
    individualResponse.setBody(entity);
    return individualResponse;
}
Also used : StringMap(com.linkedin.data.template.StringMap) IndividualResponse(com.linkedin.restli.common.multiplexer.IndividualResponse)

Example 45 with StringMap

use of com.linkedin.data.template.StringMap in project rest.li by linkedin.

the class TestRecord method testRecordTest.

@Test
public void testRecordTest() throws IOException {
    Object[][] inputs = { { "intField", 8 }, { "intOptionalField", 9 }, { "intDefaultField", 10 }, { "intDefaultOptionalField", 11 }, { "longField", 12L }, { "floatField", 13.0f }, { "doubleField", 14.0 }, { "booleanField", true }, { "stringField", "abc" }, { "bytesField", ByteString.copyAvroString("abcdef", true) }, { "enumField", EnumFruits.BANANA }, { "fixedField", new FixedMD5("0123456789abcdef") }, { "recordField", new RecordBar().setLocation("far") }, { "arrayField", new IntegerArray(Arrays.asList(1, 2, 3, 4, 5)) }, { "mapField", new StringMap(TestUtil.asMap("k1", "v1", "k2", "v2", "k3", "v3")) }, { "unionField", new RecordTest.UnionField(TestUtil.dataMapFromString("{ \"int\" : 3 }")) } };
    RecordTest record = new RecordTest();
    testRecord(record.getClass());
    for (Object[] row : inputs) {
        String fieldName = (String) row[0];
        Object value = row[1];
        testField(record, fieldName, value);
    }
}
Also used : StringMap(com.linkedin.data.template.StringMap) ByteString(com.linkedin.data.ByteString) IntegerArray(com.linkedin.data.template.IntegerArray) Test(org.testng.annotations.Test)

Aggregations

StringMap (com.linkedin.data.template.StringMap)47 Test (org.testng.annotations.Test)26 RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)9 FlowConfig (org.apache.gobblin.service.FlowConfig)9 FlowId (org.apache.gobblin.service.FlowId)9 Schedule (org.apache.gobblin.service.Schedule)9 Map (java.util.Map)8 IndividualRequest (com.linkedin.restli.common.multiplexer.IndividualRequest)6 IndividualRequestMap (com.linkedin.restli.common.multiplexer.IndividualRequestMap)5 TaskExecutionInfo (org.apache.gobblin.rest.TaskExecutionInfo)5 ByteString (com.linkedin.data.ByteString)4 DataMap (com.linkedin.data.DataMap)4 Meter (com.codahale.metrics.Meter)3 RestRequest (com.linkedin.r2.message.rest.RestRequest)3 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)3 PreparedStatement (java.sql.PreparedStatement)3 AbstractMap (java.util.AbstractMap)3 JobExecutionInfo (org.apache.gobblin.rest.JobExecutionInfo)3 Metric (org.apache.gobblin.rest.Metric)3 MetricArray (org.apache.gobblin.rest.MetricArray)3