TableFieldMappingResource { @GET public Response get(@PathParam("name") final String table) { try { return Response.ok(queryStore.getFieldMappings(table)).build(); } catch (QueryStoreException ex) { logger.error("Unable to fetch Table Metadata " , ex); throw new WebApplicationException(Response.serverError() .entity(Collections.singletonMap("error", "Metadata Fetch Failed")).build()); } } TableFieldMappingResource(QueryStore queryStore); @GET Response get(@PathParam("name") final String table);  }
@Test public void testGet() throws Exception { queryStore.save(TestUtils.TEST_TABLE_NAME, TestUtils.getMappingDocuments(mapper)); Thread.sleep(500); Set<FieldTypeMapping> mappings = new HashSet<FieldTypeMapping>(); mappings.add(new FieldTypeMapping("word", FieldType.STRING)); mappings.add(new FieldTypeMapping("data.data", FieldType.STRING)); mappings.add(new FieldTypeMapping("header.hello", FieldType.STRING)); mappings.add(new FieldTypeMapping("head.hello", FieldType.LONG)); TableFieldMapping tableFieldMapping = new TableFieldMapping(TestUtils.TEST_TABLE_NAME, mappings); String response = client().resource(String.format("/v1/tables/%s/fields", TestUtils.TEST_TABLE_NAME)) .get(String.class); TableFieldMapping mapping = mapper.readValue(response, TableFieldMapping.class); assertEquals(tableFieldMapping.getTable(), mapping.getTable()); assertTrue(tableFieldMapping.getMappings().equals(mapping.getMappings())); }
@Test(expected = UniformInterfaceException.class) public void testGetInvalidTable() throws Exception { client().resource(String.format("/v1/tables/%s/fields", TestUtils.TEST_TABLE_NAME + "-missing")) .get(String.class); }
@Test public void testGetTableWithNoDocument() throws Exception { TableFieldMapping request = new TableFieldMapping(TestUtils.TEST_TABLE_NAME, new HashSet<FieldTypeMapping>()); TableFieldMapping response = client().resource(String.format("/v1/tables/%s/fields", TestUtils.TEST_TABLE_NAME)) .get(TableFieldMapping.class); assertEquals(request.getTable(), response.getTable()); assertTrue(request.getMappings().equals(response.getMappings())); }