AtlasClient extends AtlasBaseClient { protected List<String> createEntity(JSONArray entities) throws AtlasServiceException { LOG.debug("Creating entities: {}", entities); JSONObject response = callAPIWithBody(API.CREATE_ENTITY, entities.toString()); List<String> results = extractEntityResult(response).getCreatedEntities(); LOG.debug("Create entities returned results: {}", results); return results; } AtlasClient(String[] baseUrl, String cookieName, String value, String path, String domain);  AtlasClient(String[] baseUrl, Cookie cookie);  AtlasClient(String[] baseUrl, String[] basicAuthUserNamePassword);  AtlasClient(String... baseUrls);  AtlasClient(UserGroupInformation ugi, String doAsUser, String... baseUrls); private  AtlasClient(UserGroupInformation ugi, String[] baseUrls); protected  AtlasClient(); @VisibleForTesting  AtlasClient(Configuration configuration, String[] baseUrl, String[] basicAuthUserNamePassword); @VisibleForTesting  AtlasClient(Configuration configuration, String... baseUrls); @VisibleForTesting  AtlasClient(WebResource service, Configuration configuration); WebResource getResource(); List<String> createType(String typeAsJson); List<String> createType(TypesDef typeDef); List<String> createTraitType(String traitName, ImmutableSet<String> superTraits, AttributeDefinition... attributeDefinitions); List<String> createTraitType(String traitName); List<String> updateType(String typeAsJson); List<String> updateType(TypesDef typeDef); List<String> listTypes(); List<String> listTypes(final DataTypes.TypeCategory category); List<String> listTypes(final DataTypes.TypeCategory category, final String superType,
                                  final String notSupertype); TypesDef getType(String typeName); List<String> createEntity(String... entitiesAsJson); List<String> createEntity(Referenceable... entities); List<String> createEntity(Collection<Referenceable> entities); EntityResult updateEntities(Referenceable... entities); EntityResult updateEntities(Collection<Referenceable> entities); EntityResult updateEntityAttribute(final String guid, final String attribute, String value); EntityResult updateEntity(String guid, Referenceable entity); void addTrait(String guid, Struct traitDefinition); void deleteTrait(String guid, String traitName); EntityResult updateEntity(final String entityType, final String uniqueAttributeName,
                                     final String uniqueAttributeValue,
                                     Referenceable entity); EntityResult deleteEntities(final String ... guids); EntityResult deleteEntity(String entityType, String uniqueAttributeName, String uniqueAttributeValue); Referenceable getEntity(String guid); static String toString(JSONArray jsonArray); Referenceable getEntity(final String entityType, final String attribute, final String value); List<String> listEntities(final String entityType); List<String> listTraits(final String guid); List<Struct> listTraitDefinitions(final String guid); Struct getTraitDefinition(final String guid, final String traitName); List<EntityAuditEvent> getEntityAuditEvents(String entityId, short numResults); List<EntityAuditEvent> getEntityAuditEvents(String entityId, String startKey, short numResults); JSONArray search(final String searchQuery, final int limit, final int offset); JSONArray searchByDSL(final String query, final int limit, final int offset); JSONObject searchByFullText(final String query, final int limit, final int offset); JSONObject getInputGraph(String datasetName); JSONObject getOutputGraph(String datasetName); JSONObject getInputGraphForEntity(String entityId); JSONObject getOutputGraphForEntity(String datasetId); JSONObject getSchemaForEntity(String datasetId); @VisibleForTesting JSONObject callAPIWithResource(API api, WebResource resource); @VisibleForTesting WebResource getResource(API api, String ... params); @VisibleForTesting JSONObject callAPIWithBody(API api, Object requestObject); @VisibleForTesting JSONObject callAPIWithBodyAndParams(API api, Object requestObject, String ... params); @VisibleForTesting JSONObject callAPIWithQueryParams(API api, MultivaluedMap<String, String> queryParams); static final String TYPE; static final String TYPENAME; static final String GUID; static final String ENTITIES; static final String GUID_ASSIGNMENTS; static final String DEFINITION; static final String ERROR; static final String STACKTRACE; static final String REQUEST_ID; static final String RESULTS; static final String COUNT; static final String ROWS; static final String DATATYPE; static final String STATUS; static final String EVENTS; static final String START_KEY; static final String NUM_RESULTS; static final String URI_ENTITY; static final String URI_ENTITY_AUDIT; static final String URI_SEARCH; static final String URI_NAME_LINEAGE; static final String URI_LINEAGE; static final String URI_TRAITS; static final String TRAITS; static final String TRAIT_DEFINITIONS; static final String QUERY; static final String LIMIT; static final String OFFSET; static final String QUERY_TYPE; static final String ATTRIBUTE_NAME; static final String ATTRIBUTE_VALUE; static final String SUPERTYPE; static final String NOT_SUPERTYPE; static final String ASSET_TYPE; static final String NAME; static final String DESCRIPTION; static final String OWNER; static final String INFRASTRUCTURE_SUPER_TYPE; static final String DATA_SET_SUPER_TYPE; static final String PROCESS_SUPER_TYPE; static final String PROCESS_ATTRIBUTE_INPUTS; static final String PROCESS_ATTRIBUTE_OUTPUTS; static final String REFERENCEABLE_SUPER_TYPE; static final String QUALIFIED_NAME; static final String REFERENCEABLE_ATTRIBUTE_NAME; static final String UNKNOWN_STATUS; }
@Test public void testCreateEntity() throws Exception { setupRetryParams(); AtlasClient atlasClient = new AtlasClient(service, configuration); WebResource.Builder builder = setupBuilder(AtlasClient.API.CREATE_ENTITY, service); ClientResponse response = mock(ClientResponse.class); when(response.getStatus()).thenReturn(Response.Status.CREATED.getStatusCode()); JSONObject jsonResponse = new JSONObject(new EntityResult(Arrays.asList("id"), null, null).toString()); when(response.getEntity(String.class)).thenReturn(jsonResponse.toString()); when(response.getLength()).thenReturn(jsonResponse.length()); String entityJson = InstanceSerialization.toJson(new Referenceable("type"), true); when(builder.method(anyString(), Matchers.<Class>any(), anyString())).thenReturn(response); List<String> ids = atlasClient.createEntity(entityJson); assertEquals(ids.size(), 1); assertEquals(ids.get(0), "id"); }