Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package com.facebook.presto.metadata;
 
 
 import java.util.Map;
 
 import static com.facebook.presto.SessionTestUtils.TEST_SESSION;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertTrue;
 
 @Test(singleThreaded = true)
 public class TestJsonTableHandle
 {
     private static final Map<StringObjectSYSTEM_AS_MAP = ImmutableMap.<StringObject>of("type""system",
             "schemaName""system_schema",
             "tableName""system_table");
 
     private static final Map<StringObjectINFORMATION_SCHEMA_AS_MAP = ImmutableMap.<StringObject>of(
             "type""information_schema",
             "session", ImmutableMap.<StringObject>builder()
                     .put("user".getUser())
                     .put("source".getSource())
                     .put("catalog".getCatalog())
                     .put("schema".getSchema())
                     .put("timeZoneKey", (int.getTimeZoneKey().getKey())
                     .put("locale".getLocale().toString())
                     .put("remoteUserAddress".getRemoteUserAddress())
                     .put("userAgent".getUserAgent())
                     .put("startTime".getStartTime())
                     .put("systemProperties", ImmutableMap.of())
                     .put("catalogProperties", ImmutableMap.of())
                     .build(),
             "catalogName""information_schema_catalog",
             "schemaName""information_schema_schema",
             "tableName""information_schema_table"
     );
 
     private ObjectMapper objectMapper;
 
     @BeforeMethod
     public void startUp()
     {
         Injector injector = Guice.createInjector(.,
                 new JsonModule(),
                 new HandleJsonModule(),
                 new Module()
                 {
                     @Override
                     public void configure(Binder binder)
                     {
                         MapBinder<StringConnectorHandleResolverconnectorHandleResolverBinder = MapBinder.newMapBinder(binderString.classConnectorHandleResolver.class);
                         connectorHandleResolverBinder.addBinding("system").to(SystemHandleResolver.class).in(.);
                         connectorHandleResolverBinder.addBinding("information_schema").to(InformationSchemaHandleResolver.class).in(.);
                     }
                 });
 
          = injector.getInstance(ObjectMapper.class);
     }
 
     @Test
     public void testSystemSerialize()
             throws Exception
     {
         SystemTableHandle internalHandle = new SystemTableHandle("system_schema""system_table");
 
        String json = .writeValueAsString(internalHandle);
        testJsonEquals(json);
    }
    @Test
    public void testInformationSchemaSerialize()
            throws Exception
    {
        InformationSchemaTableHandle informationSchemaTableHandle = new InformationSchemaTableHandle(
                ,
                "information_schema_catalog",
                "information_schema_schema",
                "information_schema_table");
        String json = .writeValueAsString(informationSchemaTableHandle);
    }
    @Test
    public void testSystemDeserialize()
            throws Exception
    {
        ConnectorTableHandle tableHandle = .readValue(jsonConnectorTableHandle.class);
        assertEquals(tableHandle.getClass(), SystemTableHandle.class);
        SystemTableHandle systemHandle = (SystemTableHandletableHandle;
        assertEquals(systemHandle.getSchemaTableName(), new SchemaTableName("system_schema""system_table"));
    }
    @Test
    public void testInformationSchemaDeserialize()
            throws Exception
    {
        ConnectorTableHandle tableHandle = .readValue(jsonConnectorTableHandle.class);
        assertEquals(tableHandle.getClass(), InformationSchemaTableHandle.class);
        InformationSchemaTableHandle informationSchemaHandle = (InformationSchemaTableHandletableHandle;
        assertEquals(informationSchemaHandle.getCatalogName(), "information_schema_catalog");
        assertEquals(informationSchemaHandle.getSchemaName(), "information_schema_schema");
        assertEquals(informationSchemaHandle.getTableName(), "information_schema_table");
    }
    private void testJsonEquals(String jsonMap<StringObjectexpectedMap)
            throws Exception
    {
        Map<StringObjectjsonMap = .readValue(jsonnew TypeReference<Map<StringObject>>() {});
        Assertions.assertEqualsIgnoreOrder(jsonMap.entrySet(), expectedMap.entrySet());
    }
New to GrepCode? Check out our FAQ X