@Test
  public void testUTF8() throws Exception {
    String classType = random();
    String attrName = random();
    String attrValue = random();

    HierarchicalTypeDefinition<ClassType> classTypeDefinition =
        TypesUtil.createClassTypeDef(
            classType,
            ImmutableList.<String>of(),
            TypesUtil.createUniqueRequiredAttrDef(attrName, DataTypes.STRING_TYPE));
    TypesDef typesDef =
        TypeUtils.getTypesDef(
            ImmutableList.<EnumTypeDefinition>of(),
            ImmutableList.<StructTypeDefinition>of(),
            ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(),
            ImmutableList.of(classTypeDefinition));
    createType(typesDef);

    Referenceable instance = new Referenceable(classType);
    instance.set(attrName, attrValue);
    Id guid = createInstance(instance);

    ClientResponse response = getEntityDefinition(guid._getId());
    String definition = getEntityDefinition(response);
    Referenceable getReferenceable = InstanceSerialization.fromJsonReferenceable(definition, true);
    Assert.assertEquals(getReferenceable.get(attrName), attrValue);
  }
  @Test(dependsOnMethods = "testSubmitEntity")
  public void testAddReferenceProperty() throws Exception {
    // Create new db instance
    Referenceable databaseInstance = new Referenceable(DATABASE_TYPE);
    databaseInstance.set("name", randomString());
    databaseInstance.set("description", "new database");

    Id dbInstance = createInstance(databaseInstance);
    String dbId = dbInstance._getId();

    // Add reference property
    final String guid = tableId._getId();
    ClientResponse clientResponse = addProperty(guid, "db", dbId);
    Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode());
  }
  @Test(dependsOnMethods = "testGetTraitNames")
  public void testAddTrait() throws Exception {
    traitName = "PII_Trait" + randomString();
    HierarchicalTypeDefinition<TraitType> piiTrait =
        TypesUtil.createTraitTypeDef(traitName, ImmutableList.<String>of());
    String traitDefinitionAsJSON = TypesSerialization$.MODULE$.toJson(piiTrait, true);
    LOG.debug("traitDefinitionAsJSON = " + traitDefinitionAsJSON);
    createType(traitDefinitionAsJSON);

    Struct traitInstance = new Struct(traitName);
    String traitInstanceAsJSON = InstanceSerialization.toJson(traitInstance, true);
    LOG.debug("traitInstanceAsJSON = " + traitInstanceAsJSON);

    final String guid = tableId._getId();
    ClientResponse clientResponse =
        service
            .path(ENTITIES)
            .path(guid)
            .path(TRAITS)
            .accept(Servlets.JSON_MEDIA_TYPE)
            .type(Servlets.JSON_MEDIA_TYPE)
            .method(HttpMethod.POST, ClientResponse.class, traitInstanceAsJSON);
    Assert.assertEquals(clientResponse.getStatus(), Response.Status.CREATED.getStatusCode());

    String responseAsString = clientResponse.getEntity(String.class);
    Assert.assertNotNull(responseAsString);

    JSONObject response = new JSONObject(responseAsString);
    Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
    Assert.assertNotNull(response.get(AtlasClient.GUID));
  }
 @Test(dependsOnMethods = "testSubmitEntity", expectedExceptions = IllegalArgumentException.class)
 public void testAddNullPropertyValue() throws Exception {
   final String guid = tableId._getId();
   // add property
   addProperty(guid, "description", null);
   Assert.fail();
 }
  @Test(dependsOnMethods = "testSubmitEntity")
  public void testAddProperty() throws Exception {
    final String guid = tableId._getId();
    // add property
    String description = "bar table - new desc";
    ClientResponse clientResponse = addProperty(guid, "description", description);
    Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode());

    String entityRef = getEntityDefinition(getEntityDefinition(guid));
    Assert.assertNotNull(entityRef);

    tableInstance.set("description", description);

    // invalid property for the type
    clientResponse = addProperty(guid, "invalid_property", "bar table");
    Assert.assertEquals(clientResponse.getStatus(), Response.Status.BAD_REQUEST.getStatusCode());

    // non-string property, update
    String currentTime = String.valueOf(System.currentTimeMillis());
    clientResponse = addProperty(guid, "createTime", currentTime);
    Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode());

    entityRef = getEntityDefinition(getEntityDefinition(guid));
    Assert.assertNotNull(entityRef);

    tableInstance.set("createTime", currentTime);
  }
  @Test
  public void testSubmitEntity() throws Exception {
    tableInstance = createHiveTableInstance(DATABASE_NAME, TABLE_NAME);
    tableId = createInstance(tableInstance);

    final String guid = tableId._getId();
    try {
      Assert.assertNotNull(UUID.fromString(guid));
    } catch (IllegalArgumentException e) {
      Assert.fail("Response is not a guid, " + guid);
    }
  }
  @Test(dependsOnMethods = "testGetTraitNames")
  public void testAddTraitWithAttribute() throws Exception {
    final String traitName = "PII_Trait" + randomString();
    HierarchicalTypeDefinition<TraitType> piiTrait =
        TypesUtil.createTraitTypeDef(
            traitName,
            ImmutableList.<String>of(),
            TypesUtil.createRequiredAttrDef("type", DataTypes.STRING_TYPE));
    String traitDefinitionAsJSON = TypesSerialization$.MODULE$.toJson(piiTrait, true);
    LOG.debug("traitDefinitionAsJSON = " + traitDefinitionAsJSON);
    createType(traitDefinitionAsJSON);

    Struct traitInstance = new Struct(traitName);
    traitInstance.set("type", "SSN");
    String traitInstanceAsJSON = InstanceSerialization.toJson(traitInstance, true);
    LOG.debug("traitInstanceAsJSON = " + traitInstanceAsJSON);

    final String guid = tableId._getId();
    ClientResponse clientResponse =
        service
            .path(ENTITIES)
            .path(guid)
            .path(TRAITS)
            .accept(Servlets.JSON_MEDIA_TYPE)
            .type(Servlets.JSON_MEDIA_TYPE)
            .method(HttpMethod.POST, ClientResponse.class, traitInstanceAsJSON);
    Assert.assertEquals(clientResponse.getStatus(), Response.Status.CREATED.getStatusCode());

    String responseAsString = clientResponse.getEntity(String.class);
    Assert.assertNotNull(responseAsString);

    JSONObject response = new JSONObject(responseAsString);
    Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
    Assert.assertNotNull(response.get(AtlasClient.GUID));

    // verify the response
    clientResponse = getEntityDefinition(guid);
    Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode());
    responseAsString = clientResponse.getEntity(String.class);
    Assert.assertNotNull(responseAsString);
    response = new JSONObject(responseAsString);
    Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));

    final String definition = response.getString(AtlasClient.DEFINITION);
    Assert.assertNotNull(definition);
    Referenceable entityRef = InstanceSerialization.fromJsonReferenceable(definition, true);
    IStruct traitRef = entityRef.getTrait(traitName);
    String type = (String) traitRef.get("type");
    Assert.assertEquals(type, "SSN");
  }
  @Test(dependsOnMethods = "testSubmitEntity")
  public void testGetEntityDefinition() throws Exception {
    final String guid = tableId._getId();
    ClientResponse clientResponse = getEntityDefinition(guid);
    Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode());

    String responseAsString = clientResponse.getEntity(String.class);
    Assert.assertNotNull(responseAsString);

    JSONObject response = new JSONObject(responseAsString);
    Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));

    final String definition = response.getString(AtlasClient.DEFINITION);
    Assert.assertNotNull(definition);
    LOG.debug("tableInstanceAfterGet = " + definition);
    InstanceSerialization.fromJsonReferenceable(definition, true);
  }
  @Test(dependsOnMethods = "testAddTrait")
  public void testAddExistingTrait() throws Exception {
    final String traitName = "PII_Trait" + randomString();

    Struct traitInstance = new Struct(traitName);
    String traitInstanceAsJSON = InstanceSerialization.toJson(traitInstance, true);
    LOG.debug("traitInstanceAsJSON = " + traitInstanceAsJSON);

    final String guid = tableId._getId();
    ClientResponse clientResponse =
        service
            .path(ENTITIES)
            .path(guid)
            .path(TRAITS)
            .accept(Servlets.JSON_MEDIA_TYPE)
            .type(Servlets.JSON_MEDIA_TYPE)
            .method(HttpMethod.POST, ClientResponse.class, traitInstanceAsJSON);
    Assert.assertEquals(clientResponse.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
  }
예제 #10
0
  public Vertex createVertexWithoutIdentity(
      String typeName, Id typedInstanceId, Set<String> superTypeNames) {
    LOG.debug(
        "Creating vertex for type {} id {}",
        typeName,
        typedInstanceId != null ? typedInstanceId._getId() : null);
    final Vertex vertexWithoutIdentity = titanGraph.addVertex(null);

    // add type information
    setProperty(vertexWithoutIdentity, Constants.ENTITY_TYPE_PROPERTY_KEY, typeName);

    // add super types
    for (String superTypeName : superTypeNames) {
      addProperty(vertexWithoutIdentity, Constants.SUPER_TYPES_PROPERTY_KEY, superTypeName);
    }

    // add timestamp information
    setProperty(
        vertexWithoutIdentity, Constants.TIMESTAMP_PROPERTY_KEY, System.currentTimeMillis());

    return vertexWithoutIdentity;
  }
  @Test(dependsOnMethods = "testAddTrait")
  public void testDeleteTrait() throws Exception {
    final String guid = tableId._getId();

    ClientResponse clientResponse =
        service
            .path(ENTITIES)
            .path(guid)
            .path(TRAITS)
            .path(traitName)
            .accept(Servlets.JSON_MEDIA_TYPE)
            .type(Servlets.JSON_MEDIA_TYPE)
            .method(HttpMethod.DELETE, ClientResponse.class);
    Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode());

    String responseAsString = clientResponse.getEntity(String.class);
    Assert.assertNotNull(responseAsString);

    JSONObject response = new JSONObject(responseAsString);
    Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
    Assert.assertNotNull(response.get("GUID"));
    Assert.assertNotNull(response.get("traitName"));
  }
  @Test(dependsOnMethods = "testSubmitEntity")
  public void testGetTraitNames() throws Exception {
    final String guid = tableId._getId();
    ClientResponse clientResponse =
        service
            .path(ENTITIES)
            .path(guid)
            .path(TRAITS)
            .accept(Servlets.JSON_MEDIA_TYPE)
            .type(Servlets.JSON_MEDIA_TYPE)
            .method(HttpMethod.GET, ClientResponse.class);
    Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode());

    String responseAsString = clientResponse.getEntity(String.class);
    Assert.assertNotNull(responseAsString);

    JSONObject response = new JSONObject(responseAsString);
    Assert.assertNotNull(response.get(AtlasClient.REQUEST_ID));
    Assert.assertNotNull(response.get("GUID"));

    final JSONArray list = response.getJSONArray(AtlasClient.RESULTS);
    Assert.assertEquals(list.length(), 7);
  }
 @Test(dependsOnMethods = "testSubmitEntity")
 public void testGetEntityList() throws Exception {
   List<String> entities = serviceClient.listEntities(HIVE_TABLE_TYPE);
   Assert.assertNotNull(entities);
   Assert.assertTrue(entities.contains(tableId._getId()));
 }