ATLAS-3875: added missing APIs in AtlasClient
Signed-off-by: Madhan Neethiraj <madhan@apache.org>
This commit is contained in:
parent
a42f0c1cba
commit
8827bfb4da
File diff suppressed because it is too large
Load Diff
|
|
@ -37,10 +37,10 @@ import com.sun.jersey.multipart.MultiPart;
|
|||
import com.sun.jersey.multipart.file.FileDataBodyPart;
|
||||
import com.sun.jersey.multipart.file.StreamDataBodyPart;
|
||||
import com.sun.jersey.multipart.impl.MultiPartWriter;
|
||||
import org.apache.atlas.model.impexp.AtlasServer;
|
||||
import org.apache.atlas.model.impexp.AtlasExportRequest;
|
||||
import org.apache.atlas.model.impexp.AtlasImportRequest;
|
||||
import org.apache.atlas.model.impexp.AtlasImportResult;
|
||||
import org.apache.atlas.model.impexp.AtlasServer;
|
||||
import org.apache.atlas.model.metrics.AtlasMetrics;
|
||||
import org.apache.atlas.security.SecureClientUtils;
|
||||
import org.apache.atlas.type.AtlasType;
|
||||
|
|
@ -66,7 +66,6 @@ import java.io.InputStream;
|
|||
import java.io.OutputStream;
|
||||
import java.net.ConnectException;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
|
|||
|
|
@ -741,6 +741,7 @@
|
|||
<resource>
|
||||
<directory>${basedir}/../addons/models/</directory>
|
||||
<includes>
|
||||
<include>0000-Area0/0011-glossary_model.json</include>
|
||||
<include>0000-Area0/0010-base_model.json</include>
|
||||
<include>1000-Hadoop/**</include>
|
||||
</includes>
|
||||
|
|
|
|||
|
|
@ -56,4 +56,7 @@ public class TestUtils {
|
|||
return System.getProperty("projectBaseDir") + "/webapp/target" ;
|
||||
}
|
||||
|
||||
public static String getGlossaryType(){
|
||||
return System.getProperty("projectBaseDir") + "/webapp/target/models/0000-Area0/0011-glossary_model.json";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ import org.apache.atlas.ApplicationProperties;
|
|||
import org.apache.atlas.AtlasClient;
|
||||
import org.apache.atlas.AtlasClientV2;
|
||||
import org.apache.atlas.AtlasServiceException;
|
||||
import org.apache.atlas.kafka.AtlasKafkaMessage;
|
||||
import org.apache.atlas.kafka.KafkaNotification;
|
||||
import org.apache.atlas.model.instance.AtlasClassification;
|
||||
import org.apache.atlas.model.instance.AtlasEntity;
|
||||
import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo;
|
||||
|
|
@ -31,24 +33,36 @@ import org.apache.atlas.model.instance.AtlasEntityHeader;
|
|||
import org.apache.atlas.model.instance.AtlasStruct;
|
||||
import org.apache.atlas.model.instance.EntityMutationResponse;
|
||||
import org.apache.atlas.model.instance.EntityMutations;
|
||||
import org.apache.atlas.model.typedef.*;
|
||||
import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
|
||||
import org.apache.atlas.model.typedef.AtlasBusinessMetadataDef;
|
||||
import org.apache.atlas.model.typedef.AtlasClassificationDef;
|
||||
import org.apache.atlas.model.typedef.AtlasEntityDef;
|
||||
import org.apache.atlas.model.typedef.AtlasEnumDef;
|
||||
import org.apache.atlas.model.typedef.AtlasRelationshipDef;
|
||||
import org.apache.atlas.model.typedef.AtlasStructDef;
|
||||
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
|
||||
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef.Cardinality;
|
||||
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef;
|
||||
import org.apache.atlas.model.typedef.AtlasTypesDef;
|
||||
import org.apache.atlas.notification.NotificationConsumer;
|
||||
import org.apache.atlas.notification.NotificationInterface;
|
||||
import org.apache.atlas.type.AtlasType;
|
||||
import org.apache.atlas.type.AtlasTypeUtil;
|
||||
import org.apache.atlas.utils.AuthenticationUtil;
|
||||
import org.apache.atlas.utils.ParamChecker;
|
||||
import org.apache.atlas.v1.model.instance.Id;
|
||||
import org.apache.atlas.v1.model.instance.Referenceable;
|
||||
import org.apache.atlas.v1.model.instance.Struct;
|
||||
import org.apache.atlas.v1.model.typedef.*;
|
||||
import org.apache.atlas.v1.model.typedef.EnumTypeDefinition.EnumValue;
|
||||
import org.apache.atlas.notification.NotificationConsumer;
|
||||
import org.apache.atlas.kafka.*;
|
||||
import org.apache.atlas.v1.model.notification.EntityNotificationV1;
|
||||
import org.apache.atlas.type.AtlasType;
|
||||
import org.apache.atlas.type.AtlasTypeUtil;
|
||||
import org.apache.atlas.v1.model.typedef.AttributeDefinition;
|
||||
import org.apache.atlas.v1.model.typedef.ClassTypeDefinition;
|
||||
import org.apache.atlas.v1.model.typedef.EnumTypeDefinition;
|
||||
import org.apache.atlas.v1.model.typedef.EnumTypeDefinition.EnumValue;
|
||||
import org.apache.atlas.v1.model.typedef.Multiplicity;
|
||||
import org.apache.atlas.v1.model.typedef.StructTypeDefinition;
|
||||
import org.apache.atlas.v1.model.typedef.TraitTypeDefinition;
|
||||
import org.apache.atlas.v1.model.typedef.TypesDef;
|
||||
import org.apache.atlas.v1.typesystem.types.utils.TypesUtil;
|
||||
import org.apache.atlas.utils.AuthenticationUtil;
|
||||
import org.apache.atlas.utils.ParamChecker;
|
||||
import org.apache.commons.configuration.Configuration;
|
||||
import org.apache.commons.lang.RandomStringUtils;
|
||||
import org.slf4j.Logger;
|
||||
|
|
@ -66,6 +80,8 @@ import java.util.Map;
|
|||
import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE;
|
||||
import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF;
|
||||
import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_TYPE_OWNED_REF;
|
||||
import static org.apache.atlas.type.AtlasTypeUtil.createBusinessMetadataDef;
|
||||
import static org.apache.atlas.type.AtlasTypeUtil.createOptionalAttrDef;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
|
|
@ -160,6 +176,22 @@ public abstract class BaseResourceIT {
|
|||
}
|
||||
}
|
||||
|
||||
for (AtlasRelationshipDef relationshipDef : typesDef.getRelationshipDefs()) {
|
||||
if (atlasClientV2.typeWithNameExists(relationshipDef.getName())) {
|
||||
LOG.warn("Type with name {} already exists. Skipping", relationshipDef.getName());
|
||||
} else {
|
||||
toCreate.getRelationshipDefs().add(relationshipDef);
|
||||
}
|
||||
}
|
||||
|
||||
for (AtlasBusinessMetadataDef businessMetadataDef : typesDef.getBusinessMetadataDefs()) {
|
||||
if (atlasClientV2.typeWithNameExists(businessMetadataDef.getName())) {
|
||||
LOG.warn("Type with name {} already exists. Skipping", businessMetadataDef.getName());
|
||||
} else {
|
||||
toCreate.getBusinessMetadataDefs().add(businessMetadataDef);
|
||||
}
|
||||
}
|
||||
|
||||
atlasClientV2.createAtlasTypeDefs(toCreate);
|
||||
}
|
||||
|
||||
|
|
@ -440,11 +472,33 @@ public abstract class BaseResourceIT {
|
|||
AtlasClassificationDef secTrait = AtlasTypeUtil.createTraitTypeDef(SEC_TAG, Collections.<String>emptySet());
|
||||
AtlasClassificationDef financeTrait = AtlasTypeUtil.createTraitTypeDef(FINANCE_TAG, Collections.<String>emptySet());
|
||||
|
||||
//bussinessmetadata
|
||||
String _description = "_description";
|
||||
Map<String, String> options = new HashMap<>();
|
||||
options.put("maxStrLength", "20");
|
||||
AtlasBusinessMetadataDef bmNoApplicableTypes = createBusinessMetadataDef("bmNoApplicableTypes", _description, "1.0",
|
||||
createOptionalAttrDef("attr0", "string", options, _description));
|
||||
|
||||
|
||||
AtlasBusinessMetadataDef bmNoAttributes = createBusinessMetadataDef("bmNoAttributes", _description, "1.0", null);
|
||||
|
||||
options.put("applicableEntityTypes", "[\"" + DATABASE_TYPE_V2 + "\",\"" + HIVE_TABLE_TYPE_V2 + "\"]");
|
||||
|
||||
AtlasBusinessMetadataDef bmWithAllTypes = createBusinessMetadataDef("bmWithAllTypes", _description, "1.0",
|
||||
createOptionalAttrDef("attr1", AtlasBusinessMetadataDef.ATLAS_TYPE_BOOLEAN, options, _description),
|
||||
createOptionalAttrDef("attr2", AtlasBusinessMetadataDef.ATLAS_TYPE_BYTE, options, _description),
|
||||
createOptionalAttrDef("attr8", AtlasBusinessMetadataDef.ATLAS_TYPE_STRING, options, _description));
|
||||
|
||||
AtlasBusinessMetadataDef bmWithAllTypesMV = createBusinessMetadataDef("bmWithAllTypesMV", _description, "1.0",
|
||||
createOptionalAttrDef("attr11", "array<boolean>", options, _description),
|
||||
createOptionalAttrDef("attr18", "array<string>", options, _description));
|
||||
|
||||
AtlasTypesDef typesDef = new AtlasTypesDef(Collections.singletonList(enumDef),
|
||||
Collections.singletonList(structTypeDef),
|
||||
Arrays.asList(classificationTrait, piiTrait, phiTrait, pciTrait, soxTrait, secTrait, financeTrait),
|
||||
Arrays.asList(dbClsTypeDef, columnClsDef, tblClsDef, loadProcessClsDef));
|
||||
|
||||
Arrays.asList(dbClsTypeDef, columnClsDef, tblClsDef, loadProcessClsDef),
|
||||
new ArrayList<>(),
|
||||
Arrays.asList(bmNoApplicableTypes, bmNoAttributes, bmWithAllTypes, bmWithAllTypesMV));
|
||||
batchCreateTypes(typesDef);
|
||||
}
|
||||
|
||||
|
|
@ -549,6 +603,7 @@ public abstract class BaseResourceIT {
|
|||
|
||||
return tableInstance;
|
||||
}
|
||||
|
||||
protected Referenceable createHiveDBInstanceBuiltIn(String dbName) {
|
||||
Referenceable databaseInstance = new Referenceable(DATABASE_TYPE_BUILTIN);
|
||||
|
||||
|
|
@ -560,7 +615,6 @@ public abstract class BaseResourceIT {
|
|||
return databaseInstance;
|
||||
}
|
||||
|
||||
|
||||
protected Referenceable createHiveDBInstanceV1(String dbName) {
|
||||
Referenceable databaseInstance = new Referenceable(DATABASE_TYPE);
|
||||
|
||||
|
|
@ -584,7 +638,6 @@ public abstract class BaseResourceIT {
|
|||
return atlasEntity;
|
||||
}
|
||||
|
||||
|
||||
public interface Predicate {
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -23,12 +23,16 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
|||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
|
||||
import org.apache.atlas.AtlasServiceException;
|
||||
import org.apache.atlas.model.discovery.AtlasQuickSearchResult;
|
||||
import org.apache.atlas.model.discovery.AtlasSearchResult;
|
||||
import org.apache.atlas.model.discovery.QuickSearchParameters;
|
||||
import org.apache.atlas.model.discovery.SearchParameters;
|
||||
import org.apache.atlas.model.impexp.AtlasImportRequest;
|
||||
import org.apache.atlas.model.instance.AtlasClassification;
|
||||
import org.apache.atlas.model.instance.AtlasEntity;
|
||||
import org.apache.atlas.model.instance.AtlasEntityHeader;
|
||||
import org.apache.atlas.model.instance.EntityMutationResponse;
|
||||
import org.apache.atlas.model.profile.AtlasUserSavedSearch;
|
||||
import org.apache.atlas.model.typedef.AtlasClassificationDef;
|
||||
import org.apache.atlas.model.typedef.AtlasTypesDef;
|
||||
import org.apache.atlas.type.AtlasTypeUtil;
|
||||
|
|
@ -42,15 +46,18 @@ import java.net.URLEncoder;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE;
|
||||
import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertNull;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
public class BasicSearchIT extends BaseResourceIT {
|
||||
private AtlasUserSavedSearch userSavedSearch;
|
||||
|
||||
@BeforeClass
|
||||
@Override
|
||||
|
|
@ -113,6 +120,13 @@ public class BasicSearchIT extends BaseResourceIT {
|
|||
};
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] attributeSearchJSONNames() {
|
||||
return new String[][]{
|
||||
{"search-parameters/attribute-filters"}
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dataProvider = "basicSearchJSONNames")
|
||||
public void testDiscoveryWithSearchParameters(String jsonFile) {
|
||||
try {
|
||||
|
|
@ -141,6 +155,137 @@ public class BasicSearchIT extends BaseResourceIT {
|
|||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider = "attributeSearchJSONNames")
|
||||
public void testAttributeSearch(String jsonFile) {
|
||||
try {
|
||||
BasicSearchParametersWithExpectation[] testExpectations =
|
||||
TestResourceFileUtils.readObjectFromJson(jsonFile, BasicSearchParametersWithExpectation[].class);
|
||||
assertNotNull(testExpectations);
|
||||
|
||||
for (BasicSearchParametersWithExpectation testExpectation : testExpectations) {
|
||||
LOG.info("TestDescription :{}", testExpectation.testDescription);
|
||||
LOG.info("SearchParameters :{}", testExpectation.searchParameters);
|
||||
SearchParameters parameters = testExpectation.getSearchParameters();
|
||||
|
||||
if (parameters.getEntityFilters() == null || parameters.getEntityFilters().getAttributeName() == null) {
|
||||
continue;
|
||||
}
|
||||
SearchParameters.FilterCriteria filterCriteria = parameters.getEntityFilters();
|
||||
AtlasSearchResult searchResult = atlasClientV2.attributeSearch(parameters.getTypeName(), filterCriteria.getAttributeName(), filterCriteria.getAttributeValue(), parameters.getLimit(), parameters.getOffset());
|
||||
if (testExpectation.expectedCount > 0) {
|
||||
assertNotNull(searchResult.getEntities());
|
||||
assertEquals(searchResult.getEntities().size(), testExpectation.expectedCount);
|
||||
}
|
||||
|
||||
if (testExpectation.searchParameters.getSortBy() != null && !testExpectation.searchParameters.getSortBy().isEmpty()) {
|
||||
assertNotNull(searchResult.getEntities());
|
||||
assertEquals(searchResult.getEntities().get(0).getAttribute("name"),
|
||||
"testtable_1");
|
||||
}
|
||||
}
|
||||
} catch (IOException | AtlasServiceException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider = "attributeSearchJSONNames")
|
||||
public void testSavedSearch(String jsonFile) {
|
||||
try {
|
||||
BasicSearchParametersWithExpectation[] testExpectations =
|
||||
TestResourceFileUtils.readObjectFromJson(jsonFile, BasicSearchParametersWithExpectation[].class);
|
||||
assertNotNull(testExpectations);
|
||||
|
||||
for (BasicSearchParametersWithExpectation testExpectation : testExpectations) {
|
||||
LOG.info("TestDescription :{}", testExpectation.testDescription);
|
||||
LOG.info("SearchParameters :{}", testExpectation.searchParameters);
|
||||
SearchParameters parameters = testExpectation.getSearchParameters();
|
||||
|
||||
AtlasUserSavedSearch savedSearch = new AtlasUserSavedSearch();
|
||||
savedSearch.setSearchType(AtlasUserSavedSearch.SavedSearchType.BASIC);
|
||||
savedSearch.setName("basic_test");
|
||||
savedSearch.setGuid("");
|
||||
savedSearch.setSearchParameters(parameters);
|
||||
savedSearch.setOwnerName("admin");
|
||||
|
||||
userSavedSearch = atlasClientV2.addSavedSearch(savedSearch);
|
||||
assertNotNull(userSavedSearch);
|
||||
List<AtlasUserSavedSearch> list = atlasClientV2.getSavedSearches("admin");
|
||||
assertNotNull(list);
|
||||
}
|
||||
} catch (IOException | AtlasServiceException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testSavedSearch")
|
||||
public void testExecuteSavedSearchByName() {
|
||||
try {
|
||||
AtlasSearchResult searchResult = atlasClientV2.executeSavedSearch("admin", "basic_test");
|
||||
assertNotNull(searchResult);
|
||||
} catch (AtlasServiceException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testSavedSearch")
|
||||
public void tesUpdateSavedSearch() {
|
||||
try {
|
||||
userSavedSearch.setSearchType(AtlasUserSavedSearch.SavedSearchType.ADVANCED);
|
||||
userSavedSearch = atlasClientV2.updateSavedSearch(userSavedSearch);
|
||||
assertNotNull(userSavedSearch);
|
||||
assertEquals(userSavedSearch.getSearchType(), AtlasUserSavedSearch.SavedSearchType.ADVANCED);
|
||||
} catch (AtlasServiceException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "tesUpdateSavedSearch")
|
||||
public void testExecuteSavedSearchByGuid() {
|
||||
try {
|
||||
AtlasSearchResult searchResult = atlasClientV2.executeSavedSearch(userSavedSearch.getGuid());
|
||||
assertNotNull(searchResult);
|
||||
} catch (AtlasServiceException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testExecuteSavedSearchByGuid")
|
||||
public void testDeleteSavedSearch() {
|
||||
AtlasUserSavedSearch searchAfterDelete = null;
|
||||
try {
|
||||
atlasClientV2.deleteSavedSearch(userSavedSearch.getGuid());
|
||||
searchAfterDelete = atlasClientV2.getSavedSearch("admin", "basic_test");
|
||||
} catch (AtlasServiceException e) {
|
||||
assertNull(searchAfterDelete);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetQuickSearch() {
|
||||
try {
|
||||
AtlasQuickSearchResult result = atlasClientV2.quickSearch("test", "hdfs_path", false, 2, 0);
|
||||
assertNotNull(result);
|
||||
List<AtlasEntityHeader> list = result.getSearchResults().getEntities();
|
||||
assertEquals(list.size(), 1);
|
||||
} catch (AtlasServiceException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPostQuickSearch() {
|
||||
try {
|
||||
QuickSearchParameters quickSearchParameters = new QuickSearchParameters();
|
||||
quickSearchParameters.setQuery("test");
|
||||
quickSearchParameters.setTypeName("hdfs_path");
|
||||
AtlasQuickSearchResult result = atlasClientV2.quickSearch(quickSearchParameters);
|
||||
List<AtlasEntityHeader> list = result.getSearchResults().getEntities();
|
||||
assertEquals(list.size(), 1);
|
||||
} catch (AtlasServiceException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@JsonAutoDetect(getterVisibility = PUBLIC_ONLY, setterVisibility = PUBLIC_ONLY, fieldVisibility = NONE)
|
||||
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
|
|
@ -182,4 +327,4 @@ public class BasicSearchIT extends BaseResourceIT {
|
|||
this.testDescription = testDescription;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -18,6 +18,8 @@
|
|||
|
||||
package org.apache.atlas.web.integration;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
|
|
@ -25,18 +27,27 @@ import org.apache.atlas.ApplicationProperties;
|
|||
import org.apache.atlas.AtlasClient;
|
||||
import org.apache.atlas.AtlasServiceException;
|
||||
import org.apache.atlas.EntityAuditEvent;
|
||||
import org.apache.atlas.bulkimport.BulkImportResponse;
|
||||
import org.apache.atlas.model.TimeBoundary;
|
||||
import org.apache.atlas.model.audit.AtlasAuditEntry;
|
||||
import org.apache.atlas.model.audit.AuditSearchParameters;
|
||||
import org.apache.atlas.model.instance.*;
|
||||
import org.apache.atlas.model.audit.EntityAuditEventV2;
|
||||
import org.apache.atlas.model.instance.AtlasClassification;
|
||||
import org.apache.atlas.model.instance.AtlasClassification.AtlasClassifications;
|
||||
import org.apache.atlas.model.instance.AtlasEntity;
|
||||
import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo;
|
||||
import org.apache.atlas.model.instance.AtlasEntityHeader;
|
||||
import org.apache.atlas.model.instance.AtlasObjectId;
|
||||
import org.apache.atlas.model.instance.ClassificationAssociateRequest;
|
||||
import org.apache.atlas.model.instance.EntityMutationResponse;
|
||||
import org.apache.atlas.model.instance.EntityMutations;
|
||||
import org.apache.atlas.model.typedef.AtlasClassificationDef;
|
||||
import org.apache.atlas.model.typedef.AtlasEntityDef;
|
||||
import org.apache.atlas.model.typedef.AtlasTypesDef;
|
||||
import org.apache.atlas.type.AtlasTypeUtil;
|
||||
import org.apache.atlas.utils.TestResourceFileUtils;
|
||||
import org.apache.atlas.v1.typesystem.types.utils.TypesUtil;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang.RandomStringUtils;
|
||||
import org.apache.hadoop.util.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
|
|
@ -45,13 +56,29 @@ import org.testng.Assert;
|
|||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertNotEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
/**
|
||||
* Integration tests for Entity Jersey Resource.
|
||||
|
|
@ -65,9 +92,12 @@ public class EntityV2JerseyResourceIT extends BaseResourceIT {
|
|||
private final String DATABASE_NAME = "db" + randomString();
|
||||
private final String TABLE_NAME = "table" + randomString();
|
||||
private String traitName;
|
||||
private String createdDBName;
|
||||
private String createdTableQualifiedName;
|
||||
|
||||
private AtlasEntity dbEntity;
|
||||
private AtlasEntity tableEntity;
|
||||
private AtlasClassificationDef piiTrait;
|
||||
|
||||
@BeforeClass
|
||||
public void setUp() throws Exception {
|
||||
|
|
@ -83,6 +113,8 @@ public class EntityV2JerseyResourceIT extends BaseResourceIT {
|
|||
assertNotNull(dbAndTable);
|
||||
assertNotNull(dbAndTable.left);
|
||||
assertNotNull(dbAndTable.right);
|
||||
// Writing created table data to a file for import test.
|
||||
createImportFile();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -172,17 +204,6 @@ public class EntityV2JerseyResourceIT extends BaseResourceIT {
|
|||
assertEquals(results.size(), 1);
|
||||
}
|
||||
|
||||
private void assertEntityAudit(String dbid, EntityAuditEvent.EntityAuditAction auditAction)
|
||||
throws Exception {
|
||||
List<EntityAuditEvent> events = atlasClientV1.getEntityAuditEvents(dbid, (short) 100);
|
||||
for (EntityAuditEvent event : events) {
|
||||
if (event.getAction() == auditAction) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
fail("Expected audit event with action = " + auditAction);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEntityDefinitionAcrossTypeUpdate() throws Exception {
|
||||
//create type
|
||||
|
|
@ -267,6 +288,24 @@ public class EntityV2JerseyResourceIT extends BaseResourceIT {
|
|||
assertEquals(byAttribute.getAttribute(NAME), qualifiedName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetEntitiesByAttribute() throws Exception {
|
||||
AtlasEntity hiveDB1 = createHiveDB();
|
||||
AtlasEntity hiveDB2 = createHiveDB();
|
||||
|
||||
String qualifiedNameDB1 = (String) hiveDB1.getAttribute(NAME);
|
||||
String qualifiedNameDB2 = (String) hiveDB2.getAttribute(NAME);
|
||||
List<Map<String, String>> list = new ArrayList<>();
|
||||
list.add(toMap(NAME, qualifiedNameDB1));
|
||||
list.add(toMap(NAME, qualifiedNameDB2));
|
||||
|
||||
AtlasEntity.AtlasEntitiesWithExtInfo info = atlasClientV2.getEntitiesByAttribute(DATABASE_TYPE_V2, list);
|
||||
List<AtlasEntity> entityList = info.getEntities();
|
||||
assertEquals(entityList.size(), 2);
|
||||
assertEquals(entityList.get(0).getTypeName(), DATABASE_TYPE_V2);
|
||||
assertEquals(entityList.get(1).getTypeName(), DATABASE_TYPE_V2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubmitEntityWithBadDateFormat() throws Exception {
|
||||
AtlasEntity hiveDBEntity = createHiveDBInstanceV2("db" + randomString());
|
||||
|
|
@ -376,7 +415,7 @@ public class EntityV2JerseyResourceIT extends BaseResourceIT {
|
|||
AtlasClassifications classifications = atlasClientV2.getClassifications(createHiveTable().getGuid());
|
||||
assertNotNull(classifications);
|
||||
assertTrue(classifications.getList().size() > 0);
|
||||
assertEquals(classifications.getList().size(), 8);
|
||||
assertEquals(classifications.getList().size(), 9);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testSubmitEntity")
|
||||
|
|
@ -390,55 +429,6 @@ public class EntityV2JerseyResourceIT extends BaseResourceIT {
|
|||
Assert.assertNotNull(entity.getUpdateTime());
|
||||
}
|
||||
|
||||
private void addProperty(String guid, String property, Object value) throws AtlasServiceException {
|
||||
|
||||
AtlasEntity entityByGuid = getEntityByGuid(guid);
|
||||
entityByGuid.setAttribute(property, value);
|
||||
EntityMutationResponse response = atlasClientV2.updateEntity(new AtlasEntityWithExtInfo(entityByGuid));
|
||||
assertNotNull(response);
|
||||
assertNotNull(response.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE));
|
||||
}
|
||||
|
||||
private AtlasEntity createHiveDB() {
|
||||
if (dbEntity == null) {
|
||||
dbEntity = createHiveDB(DATABASE_NAME);
|
||||
}
|
||||
return dbEntity;
|
||||
}
|
||||
|
||||
private AtlasEntity createHiveDB(String dbName) {
|
||||
AtlasEntity hiveDBInstanceV2 = createHiveDBInstanceV2(dbName);
|
||||
AtlasEntityHeader entityHeader = createEntity(hiveDBInstanceV2);
|
||||
assertNotNull(entityHeader);
|
||||
assertNotNull(entityHeader.getGuid());
|
||||
hiveDBInstanceV2.setGuid(entityHeader.getGuid());
|
||||
return hiveDBInstanceV2;
|
||||
}
|
||||
|
||||
private TypesUtil.Pair<AtlasEntity, AtlasEntity> createDBAndTable() throws Exception {
|
||||
AtlasEntity dbInstanceV2 = createHiveDB();
|
||||
AtlasEntity hiveTableInstanceV2 = createHiveTable();
|
||||
return TypesUtil.Pair.of(dbInstanceV2, hiveTableInstanceV2);
|
||||
}
|
||||
|
||||
private AtlasEntity createHiveTable() throws Exception {
|
||||
if (tableEntity == null) {
|
||||
tableEntity = createHiveTable(createHiveDB(), TABLE_NAME);
|
||||
}
|
||||
return tableEntity;
|
||||
|
||||
}
|
||||
|
||||
private AtlasEntity createHiveTable(AtlasEntity dbInstanceV2, String tableName) throws Exception {
|
||||
AtlasEntity hiveTableInstanceV2 = createHiveTableInstanceV2(dbInstanceV2, tableName);
|
||||
AtlasEntityHeader createdHeader = createEntity(hiveTableInstanceV2);
|
||||
assertNotNull(createdHeader);
|
||||
assertNotNull(createdHeader.getGuid());
|
||||
hiveTableInstanceV2.setGuid(createdHeader.getGuid());
|
||||
tableEntity = hiveTableInstanceV2;
|
||||
return hiveTableInstanceV2;
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testGetTraitNames")
|
||||
public void testAddTrait() throws Exception {
|
||||
traitName = "PII_Trait" + randomString();
|
||||
|
|
@ -451,6 +441,41 @@ public class EntityV2JerseyResourceIT extends BaseResourceIT {
|
|||
atlasClientV2.addClassifications(createHiveTable().getGuid(), Collections.singletonList(new AtlasClassification(piiTrait.getName())));
|
||||
|
||||
assertEntityAudit(createHiveTable().getGuid(), EntityAuditEvent.EntityAuditAction.TAG_ADD);
|
||||
AtlasClassifications classifications = atlasClientV2.getEntityClassifications(createHiveTable().getGuid(), piiTrait.getName());
|
||||
assertNotNull(classifications);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testAddTrait")
|
||||
public void testAddLabels() throws Exception {
|
||||
Set<String> set = new HashSet<>();
|
||||
set.add("lable");
|
||||
atlasClientV2.addLabels(createHiveTable().getGuid(), set);
|
||||
AtlasEntityWithExtInfo info = atlasClientV2.getEntityByGuid(createHiveTable().getGuid(), false, true);
|
||||
assertNotNull(info);
|
||||
assertNotNull(info.getEntity().getLabels());
|
||||
assertEquals(info.getEntity().getLabels().size(), 1);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testAddLabels")
|
||||
public void testSetLabels() throws Exception {
|
||||
Set<String> setNet = new HashSet<>();
|
||||
setNet.add("labelNext");
|
||||
atlasClientV2.setLabels(createHiveTable().getGuid(), setNet);
|
||||
AtlasEntityWithExtInfo infoForSet = atlasClientV2.getEntityByGuid(createHiveTable().getGuid(), false, true);
|
||||
assertNotNull(infoForSet);
|
||||
assertNotNull(infoForSet.getEntity().getLabels());
|
||||
assertEquals(infoForSet.getEntity().getLabels().size(), 1);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testSetLabels")
|
||||
public void testDeleteLabels() throws Exception {
|
||||
Set<String> set = new HashSet<>();
|
||||
set.add("testNext");
|
||||
atlasClientV2.removeLabels(createHiveTable().getGuid(), set);
|
||||
AtlasEntityWithExtInfo info = atlasClientV2.getEntityByGuid(createHiveTable().getGuid(), false, true);
|
||||
assertNotNull(info);
|
||||
assertNotNull(info.getEntity().getLabels());
|
||||
assertEquals(info.getEntity().getLabels().size(), 1);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testGetTraitNames")
|
||||
|
|
@ -521,10 +546,9 @@ public class EntityV2JerseyResourceIT extends BaseResourceIT {
|
|||
AtlasClassifications classifications = atlasClientV2.getClassifications(hiveTable.getGuid());
|
||||
assertNotNull(classifications);
|
||||
assertTrue(classifications.getList().size() > 0);
|
||||
assertEquals(classifications.getList().size(), 8);
|
||||
assertEquals(classifications.getList().size(), 9);
|
||||
}
|
||||
|
||||
|
||||
@Test(dependsOnMethods = "testGetTraitNames")
|
||||
public void testAddTraitWithAttribute() throws Exception {
|
||||
final String traitName = "PII_Trait" + randomString();
|
||||
|
|
@ -615,18 +639,21 @@ public class EntityV2JerseyResourceIT extends BaseResourceIT {
|
|||
}
|
||||
}
|
||||
|
||||
private String random() {
|
||||
return RandomStringUtils.random(10);
|
||||
@Test(dependsOnMethods = "testSubmitEntity")
|
||||
public void testGetEntityHeaderByGuid() throws Exception {
|
||||
AtlasEntityHeader header = atlasClientV2.getEntityHeaderByGuid(createHiveTable().getGuid());
|
||||
assertNotNull(header);
|
||||
assertEquals(header.getGuid(), createHiveTable().getGuid());
|
||||
}
|
||||
|
||||
private String randomUTF8() throws Exception {
|
||||
String ret = random();
|
||||
|
||||
if (!StandardCharsets.UTF_8.equals(Charset.defaultCharset())) {
|
||||
ret = new String(ret.getBytes(), StandardCharsets.UTF_8.name());
|
||||
}
|
||||
|
||||
return ret;
|
||||
@Test(dependsOnMethods = "testSubmitEntity")
|
||||
public void testGetEntityHeaderByAttribute() throws Exception {
|
||||
AtlasEntity hiveDB = createHiveDB();
|
||||
String qualifiedName = (String) hiveDB.getAttribute(NAME);
|
||||
AtlasEntityHeader header = atlasClientV2.getEntityHeaderByAttribute(DATABASE_TYPE_V2, toMap(NAME, qualifiedName));
|
||||
assertNotNull(header);
|
||||
assertEquals(header.getTypeName(), DATABASE_TYPE_V2);
|
||||
assertEquals(header.getAttribute(NAME), qualifiedName);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -837,6 +864,312 @@ public class EntityV2JerseyResourceIT extends BaseResourceIT {
|
|||
// Verify entities were deleted from the repository.
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPartialUpdateEntityByGuid() throws Exception {
|
||||
EntityMutationResponse updateResponse = atlasClientV2.partialUpdateEntityByGuid(createHiveTable().getGuid(), Collections.singletonMap("key1", "value1"), "description");
|
||||
assertNotNull(updateResponse);
|
||||
assertNotNull(updateResponse.getEntitiesByOperation(EntityMutations.EntityOperation.PARTIAL_UPDATE));
|
||||
assertTrue(updateResponse.getEntitiesByOperation(EntityMutations.EntityOperation.PARTIAL_UPDATE).size() > 0);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testGetTraitNames")
|
||||
public void testAddClassificationsByUniqueAttribute() throws Exception {
|
||||
traitName = "PII_Trait" + randomString();
|
||||
piiTrait =
|
||||
AtlasTypeUtil.createTraitTypeDef(traitName, Collections.<String>emptySet());
|
||||
AtlasTypesDef typesDef = new AtlasTypesDef();
|
||||
typesDef.getClassificationDefs().add(piiTrait);
|
||||
createType(typesDef);
|
||||
|
||||
createdTableQualifiedName = (String) createHiveTable().getAttribute(QUALIFIED_NAME);
|
||||
atlasClientV2.addClassifications(createHiveTable().getTypeName(), toMap(QUALIFIED_NAME, createdTableQualifiedName), Collections.singletonList(new AtlasClassification(piiTrait.getName())));
|
||||
assertEntityAudit(createHiveTable().getGuid(), EntityAuditEvent.EntityAuditAction.TAG_ADD);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testAddClassificationsByUniqueAttribute")
|
||||
public void testUpdateClassifications() throws Exception {
|
||||
atlasClientV2.updateClassifications(createHiveTable().getGuid(), Collections.singletonList(new AtlasClassification(piiTrait.getName())));
|
||||
assertEntityAudit(createHiveTable().getGuid(), EntityAuditEvent.EntityAuditAction.TAG_UPDATE);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testUpdateClassifications")
|
||||
public void testUpdateClassificationsByUniqueAttribute() throws Exception {
|
||||
createdTableQualifiedName = (String) createHiveTable().getAttribute(QUALIFIED_NAME);
|
||||
atlasClientV2.updateClassifications(createHiveTable().getTypeName(), toMap(QUALIFIED_NAME, createdTableQualifiedName), Collections.singletonList(new AtlasClassification(piiTrait.getName())));
|
||||
assertEntityAudit(createHiveTable().getGuid(), EntityAuditEvent.EntityAuditAction.TAG_ADD);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testUpdateClassificationsByUniqueAttribute")
|
||||
public void testRemoveEntityClassification() throws Exception {
|
||||
createdTableQualifiedName = (String) createHiveTable().getAttribute(QUALIFIED_NAME);
|
||||
atlasClientV2.removeClassification(createHiveTable().getTypeName(), toMap(QUALIFIED_NAME, createdTableQualifiedName), piiTrait.getName());
|
||||
assertEntityAuditV2(createHiveTable().getGuid(), EntityAuditEventV2.EntityAuditActionV2.CLASSIFICATION_DELETE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddOrUpdateBusinessAttributes() throws Exception {
|
||||
Map<String, Map<String, Object>> businessAttributesMap = new HashMap<>();
|
||||
Map<String, Object> bmAttrMapReq = new HashMap<>();
|
||||
bmAttrMapReq.put("attr8", "01234567890123456789");
|
||||
businessAttributesMap.put("bmWithAllTypes", bmAttrMapReq);
|
||||
atlasClientV2.addOrUpdateBusinessAttributes(createHiveTable().getGuid(), false, businessAttributesMap);
|
||||
AtlasEntity.AtlasEntityWithExtInfo info = atlasClientV2.getEntityByGuid(createHiveTable().getGuid());
|
||||
assertNotNull(info);
|
||||
Map<String, Map<String, Object>> outputMap = info.getEntity().getBusinessAttributes();
|
||||
assertNotNull(outputMap);
|
||||
assertEquals(outputMap.get("bmWithAllTypes").size(), 1);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testAddOrUpdateBusinessAttributes")
|
||||
public void testRemoveBusinessAttributes() throws Exception {
|
||||
Map<String, Map<String, Object>> businessAttributesMap = new HashMap<>();
|
||||
Map<String, Object> bmAttrMapReq = new HashMap<>();
|
||||
bmAttrMapReq.put("attr8", "01234567890123456789");
|
||||
businessAttributesMap.put("bmWithAllTypes", bmAttrMapReq);
|
||||
atlasClientV2.removeBusinessAttributes(createHiveTable().getGuid(), businessAttributesMap);
|
||||
AtlasEntity.AtlasEntityWithExtInfo info = atlasClientV2.getEntityByGuid(createHiveTable().getGuid());
|
||||
assertNotNull(info);
|
||||
Map<String, Map<String, Object>> outputMap = info.getEntity().getBusinessAttributes();
|
||||
assertNull(outputMap);
|
||||
}
|
||||
|
||||
// TODO Enable this test case after fixing addOrUpdateBusinessAttributesByBName API.
|
||||
@Test(enabled = false)
|
||||
public void testAddOrUpdateBusinessAttributesByBName() throws Exception {
|
||||
Map<String, Map<String, Object>> businessAttributesMap = new HashMap<>();
|
||||
Map<String, Object> bmAttrMapReq = new HashMap<>();
|
||||
bmAttrMapReq.put("attr8", "01234567890123456789");
|
||||
businessAttributesMap.put("bmWithAllTypes", bmAttrMapReq);
|
||||
atlasClientV2.addOrUpdateBusinessAttributes(createHiveTable().getGuid(), "bmWithAllTypes", businessAttributesMap);
|
||||
AtlasEntity.AtlasEntityWithExtInfo info = atlasClientV2.getEntityByGuid(createHiveTable().getGuid());
|
||||
assertNotNull(info);
|
||||
Map<String, Map<String, Object>> outputMap = info.getEntity().getBusinessAttributes();
|
||||
assertNotNull(outputMap);
|
||||
assertEquals(outputMap.get("bmWithAllTypes").size(), 1);
|
||||
}
|
||||
|
||||
// TODO Enable this test case after fixing addOrUpdateBusinessAttributesByBName API.
|
||||
@Test(enabled = false, dependsOnMethods = "testAddOrUpdateBusinessAttributesByBName")
|
||||
public void testRemoveBusinessAttributesByBName() throws Exception {
|
||||
Map<String, Map<String, Object>> businessAttributesMap = new HashMap<>();
|
||||
Map<String, Object> bmAttrMapReq = new HashMap<>();
|
||||
bmAttrMapReq.put("attr8", "01234567890123456789");
|
||||
businessAttributesMap.put("bmWithAllTypes", bmAttrMapReq);
|
||||
atlasClientV2.removeBusinessAttributes(createHiveTable().getGuid(), "bmWithAllTypes", businessAttributesMap);
|
||||
AtlasEntity.AtlasEntityWithExtInfo info = atlasClientV2.getEntityByGuid(createHiveTable().getGuid());
|
||||
assertNotNull(info);
|
||||
Map<String, Map<String, Object>> outputMap = info.getEntity().getBusinessAttributes();
|
||||
assertNull(outputMap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddLabelsByTypeName() throws Exception {
|
||||
createdDBName = (String) createHiveDB().getAttribute(NAME);
|
||||
Set<String> labels = new HashSet<>();
|
||||
labels.add("labelByTypeName");
|
||||
atlasClientV2.addLabels(createHiveDB().getTypeName(), toMap(NAME, createdDBName), labels);
|
||||
AtlasEntityWithExtInfo info = atlasClientV2.getEntityByGuid(createHiveDB().getGuid(), false, true);
|
||||
assertNotNull(info);
|
||||
assertNotNull(info.getEntity().getLabels());
|
||||
assertEquals(info.getEntity().getLabels().size(), 1);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testAddLabelsByTypeName")
|
||||
public void testSetLabelsByTypeName() throws Exception {
|
||||
createdDBName = (String) createHiveDB().getAttribute(NAME);
|
||||
Set<String> labels = new HashSet<>();
|
||||
labels.add("labelByTypeNameNext");
|
||||
atlasClientV2.setLabels(createHiveDB().getTypeName(), toMap(NAME, createdDBName), labels);
|
||||
AtlasEntityWithExtInfo infoForSet = atlasClientV2.getEntityByGuid(createHiveDB().getGuid(), false, true);
|
||||
assertNotNull(infoForSet);
|
||||
assertNotNull(infoForSet.getEntity().getLabels());
|
||||
assertEquals(infoForSet.getEntity().getLabels().size(), 2);
|
||||
}
|
||||
|
||||
|
||||
@Test(dependsOnMethods = "testSetLabelsByTypeName")
|
||||
public void testDeleteLabelsByTypeName() throws Exception {
|
||||
Set<String> labels = new HashSet<>();
|
||||
labels.add("labelByTypeNameNext");
|
||||
createdDBName = (String) createHiveDB().getAttribute(NAME);
|
||||
atlasClientV2.removeLabels(createHiveDB().getTypeName(), toMap(NAME, createdDBName), labels);
|
||||
AtlasEntityWithExtInfo info = atlasClientV2.getEntityByGuid(createHiveDB().getGuid(), false, true);
|
||||
assertNotNull(info);
|
||||
assertNotNull(info.getEntity().getLabels());
|
||||
assertEquals(info.getEntity().getLabels().size(), 1);
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void testAddClassification() throws Exception {
|
||||
traitName = "PII_Trait" + randomString();
|
||||
AtlasClassificationDef piiTrait =
|
||||
AtlasTypeUtil.createTraitTypeDef(traitName, Collections.<String>emptySet());
|
||||
AtlasTypesDef typesDef = new AtlasTypesDef();
|
||||
typesDef.getClassificationDefs().add(piiTrait);
|
||||
createType(typesDef);
|
||||
ClassificationAssociateRequest request = new ClassificationAssociateRequest();
|
||||
request.setEntityGuids(Arrays.asList(createHiveTable().getGuid(), createHiveDB().getGuid()));
|
||||
request.setClassification(new AtlasClassification(piiTrait.getName()));
|
||||
|
||||
atlasClientV2.addClassification(request);
|
||||
|
||||
assertEntityAuditV2(createHiveTable().getGuid(), EntityAuditEventV2.EntityAuditActionV2.CLASSIFICATION_ADD);
|
||||
assertEntityAuditV2(createHiveDB().getGuid(), EntityAuditEventV2.EntityAuditActionV2.CLASSIFICATION_ADD);
|
||||
AtlasClassifications classificationsTable = atlasClientV2.getEntityClassifications(createHiveTable().getGuid(), piiTrait.getName());
|
||||
assertNotNull(classificationsTable);
|
||||
AtlasClassifications classificationsDB = atlasClientV2.getEntityClassifications(createHiveDB().getGuid(), piiTrait.getName());
|
||||
assertNotNull(classificationsDB);
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void testDeleteClassifications() throws Exception {
|
||||
final String guid = createHiveTable().getGuid();
|
||||
try {
|
||||
atlasClientV2.deleteClassifications(guid, Arrays.asList(new AtlasClassification(getAndAddClassification().getName()), new AtlasClassification(getAndAddClassification().getName())));
|
||||
} catch (AtlasServiceException ex) {
|
||||
fail("Deletion should've succeeded");
|
||||
}
|
||||
assertEntityAudit(guid, EntityAuditEvent.EntityAuditAction.TAG_DELETE);
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void testRemoveEntityClassificationByGuid() throws Exception {
|
||||
final String guid = createHiveTable().getGuid();
|
||||
try {
|
||||
String name = getAndAddClassification().getName();
|
||||
atlasClientV2.removeClassification(guid, name, guid);
|
||||
} catch (AtlasServiceException ex) {
|
||||
fail("Deletion should've succeeded");
|
||||
}
|
||||
assertEntityAudit(guid, EntityAuditEvent.EntityAuditAction.TAG_DELETE);
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void testProduceTemplate() {
|
||||
try {
|
||||
String template = atlasClientV2.getTemplateForBulkUpdateBusinessAttributes();
|
||||
assertNotNull(template);
|
||||
} catch (AtlasServiceException ex) {
|
||||
fail("Deletion should've succeeded");
|
||||
}
|
||||
}
|
||||
|
||||
//TODO Enable this test after fixing the BulkImportResponse Deserialization issue.
|
||||
@Test(dependsOnMethods = "testSubmitEntity", enabled = false)
|
||||
public void testImportBMAttributes() throws AtlasServiceException {
|
||||
BulkImportResponse response = atlasClientV2.bulkUpdateBusinessAttributes(TestResourceFileUtils.getTestFilePath("template_metadata.csv"));
|
||||
assertNotNull(response);
|
||||
}
|
||||
|
||||
private void createImportFile() throws Exception {
|
||||
try {
|
||||
String filePath = TestResourceFileUtils.getTestFilePath("template_metadata.csv");
|
||||
String dbName = (String) createHiveTable().getAttribute("name");
|
||||
String header = "TypeName,UniqueAttributeValue,BusinessAttributeName,BusinessAttributeValue,UniqueAttributeName[optional]";
|
||||
String values = "hive_table_v2," + dbName + ",bmWithAllTypes.attr8,\"Awesome Attribute 1\",qualifiedName";
|
||||
File tempFile = new File(filePath);
|
||||
FileUtils.writeLines(tempFile, Arrays.asList(header, values));
|
||||
} catch (IOException e) {
|
||||
fail("Should have created file");
|
||||
throw new AtlasServiceException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void assertEntityAudit(String dbid, EntityAuditEvent.EntityAuditAction auditAction)
|
||||
throws Exception {
|
||||
List<EntityAuditEvent> events = atlasClientV1.getEntityAuditEvents(dbid, (short) 100);
|
||||
for (EntityAuditEvent event : events) {
|
||||
if (event.getAction() == auditAction) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
fail("Expected audit event with action = " + auditAction);
|
||||
}
|
||||
|
||||
private void assertEntityAuditV2(String guid, EntityAuditEventV2.EntityAuditActionV2 auditAction)
|
||||
throws Exception {
|
||||
// Passing auditAction as "null" as this feature is not added for InMemoryEntityRepository for IT testing.
|
||||
List<EntityAuditEventV2> events = atlasClientV2.getAuditEvents(guid, "", null, (short) 100);
|
||||
assertNotNull(events);
|
||||
assertNotEquals(events.size(), 0);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
List<EntityAuditEventV2> auditEventV2s = mapper.convertValue(
|
||||
events,
|
||||
new TypeReference<List<EntityAuditEventV2>>() {
|
||||
});
|
||||
for (EntityAuditEventV2 event : auditEventV2s) {
|
||||
if (event.getAction() == auditAction) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
fail("Expected audit event with action = " + auditAction);
|
||||
}
|
||||
|
||||
private void addProperty(String guid, String property, Object value) throws AtlasServiceException {
|
||||
|
||||
AtlasEntity entityByGuid = getEntityByGuid(guid);
|
||||
entityByGuid.setAttribute(property, value);
|
||||
EntityMutationResponse response = atlasClientV2.updateEntity(new AtlasEntityWithExtInfo(entityByGuid));
|
||||
assertNotNull(response);
|
||||
assertNotNull(response.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE));
|
||||
}
|
||||
|
||||
private AtlasEntity createHiveDB() {
|
||||
if (dbEntity == null) {
|
||||
dbEntity = createHiveDB(DATABASE_NAME);
|
||||
}
|
||||
return dbEntity;
|
||||
}
|
||||
|
||||
private AtlasEntity createHiveDB(String dbName) {
|
||||
AtlasEntity hiveDBInstanceV2 = createHiveDBInstanceV2(dbName);
|
||||
AtlasEntityHeader entityHeader = createEntity(hiveDBInstanceV2);
|
||||
assertNotNull(entityHeader);
|
||||
assertNotNull(entityHeader.getGuid());
|
||||
hiveDBInstanceV2.setGuid(entityHeader.getGuid());
|
||||
return hiveDBInstanceV2;
|
||||
}
|
||||
|
||||
private TypesUtil.Pair<AtlasEntity, AtlasEntity> createDBAndTable() throws Exception {
|
||||
AtlasEntity dbInstanceV2 = createHiveDB();
|
||||
AtlasEntity hiveTableInstanceV2 = createHiveTable();
|
||||
return TypesUtil.Pair.of(dbInstanceV2, hiveTableInstanceV2);
|
||||
}
|
||||
|
||||
private AtlasEntity createHiveTable() throws Exception {
|
||||
if (tableEntity == null) {
|
||||
tableEntity = createHiveTable(createHiveDB(), TABLE_NAME);
|
||||
}
|
||||
return tableEntity;
|
||||
}
|
||||
|
||||
private AtlasEntity createHiveTable(AtlasEntity dbInstanceV2, String tableName) throws Exception {
|
||||
AtlasEntity hiveTableInstanceV2 = createHiveTableInstanceV2(dbInstanceV2, tableName);
|
||||
AtlasEntityHeader createdHeader = createEntity(hiveTableInstanceV2);
|
||||
assertNotNull(createdHeader);
|
||||
assertNotNull(createdHeader.getGuid());
|
||||
hiveTableInstanceV2.setGuid(createdHeader.getGuid());
|
||||
tableEntity = hiveTableInstanceV2;
|
||||
return hiveTableInstanceV2;
|
||||
}
|
||||
|
||||
private AtlasClassificationDef getAndAddClassification() throws Exception {
|
||||
String traitNameNext = "PII_Trait" + randomString();
|
||||
AtlasClassificationDef piiTrait =
|
||||
AtlasTypeUtil.createTraitTypeDef(traitNameNext, Collections.<String>emptySet());
|
||||
AtlasTypesDef typesDef = new AtlasTypesDef();
|
||||
typesDef.getClassificationDefs().add(piiTrait);
|
||||
createType(typesDef);
|
||||
|
||||
atlasClientV2.addClassifications(createHiveTable().getGuid(), Collections.singletonList(new AtlasClassification(piiTrait.getName())));
|
||||
|
||||
assertEntityAudit(createHiveTable().getGuid(), EntityAuditEvent.EntityAuditAction.TAG_ADD);
|
||||
AtlasClassifications classifications = atlasClientV2.getEntityClassifications(createHiveTable().getGuid(), piiTrait.getName());
|
||||
assertNotNull(classifications);
|
||||
return piiTrait;
|
||||
}
|
||||
|
||||
private Map<String, String> toMap(final String name, final String value) {
|
||||
return new HashMap<String, String>() {{
|
||||
put(name, value);
|
||||
|
|
@ -852,4 +1185,18 @@ public class EntityV2JerseyResourceIT extends BaseResourceIT {
|
|||
db.setAttribute("description", randomString());
|
||||
return createEntity(db);
|
||||
}
|
||||
|
||||
private String random() {
|
||||
return RandomStringUtils.random(10);
|
||||
}
|
||||
|
||||
private String randomUTF8() throws Exception {
|
||||
String ret = random();
|
||||
|
||||
if (!StandardCharsets.UTF_8.equals(Charset.defaultCharset())) {
|
||||
ret = new String(ret.getBytes(), StandardCharsets.UTF_8.name());
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,482 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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
|
||||
* <p/>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p/>
|
||||
* 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 org.apache.atlas.web.integration;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import org.apache.atlas.AtlasClientV2;
|
||||
import org.apache.atlas.AtlasServiceException;
|
||||
import org.apache.atlas.model.glossary.AtlasGlossary;
|
||||
import org.apache.atlas.model.glossary.AtlasGlossaryCategory;
|
||||
import org.apache.atlas.model.glossary.AtlasGlossaryTerm;
|
||||
import org.apache.atlas.model.glossary.enums.AtlasTermRelationshipStatus;
|
||||
import org.apache.atlas.model.glossary.relations.AtlasGlossaryHeader;
|
||||
import org.apache.atlas.model.glossary.relations.AtlasRelatedCategoryHeader;
|
||||
import org.apache.atlas.model.glossary.relations.AtlasRelatedTermHeader;
|
||||
import org.apache.atlas.model.instance.AtlasEntity;
|
||||
import org.apache.atlas.model.instance.AtlasEntityHeader;
|
||||
import org.apache.atlas.model.instance.AtlasRelatedObjectId;
|
||||
import org.apache.atlas.model.typedef.AtlasTypesDef;
|
||||
import org.apache.atlas.type.AtlasType;
|
||||
import org.apache.atlas.utils.AuthenticationUtil;
|
||||
import org.apache.atlas.utils.TestResourceFileUtils;
|
||||
import org.apache.atlas.web.TestUtils;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang.RandomStringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertNull;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
public class GlossaryClientV2IT extends BaseResourceIT {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(GlossaryClientV2IT.class);
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
private AtlasTypesDef typeDefinitions;
|
||||
private AtlasClientV2 clientV2;
|
||||
private AtlasGlossary educationGlossary, healthCareGlossary;
|
||||
private AtlasGlossaryTerm educationTerm, schoolEducationTerm;
|
||||
private AtlasGlossaryCategory educationCategory;
|
||||
private List<AtlasRelatedObjectId> relatedObjectIds;
|
||||
private AtlasEntityHeader entityHeader;
|
||||
|
||||
@BeforeClass
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
typeDefinitions = setForGlossary();
|
||||
createType(typeDefinitions);
|
||||
|
||||
if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) {
|
||||
clientV2 = new AtlasClientV2(atlasUrls, new String[]{"admin", "admin"});
|
||||
} else {
|
||||
clientV2 = new AtlasClientV2(atlasUrls);
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public void tearDown() throws Exception {
|
||||
emptyTypeDefs(typeDefinitions);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateGlossary() throws Exception {
|
||||
educationGlossary = createAndGetGlossary("Education");
|
||||
assertNotNull(educationGlossary);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateGlossary")
|
||||
public void testGetGlossaryByGuid() throws Exception {
|
||||
healthCareGlossary = createAndGetGlossary("HealthCare");
|
||||
AtlasGlossary atlasGlossaryByGuid = atlasClientV2.getGlossaryByGuid(healthCareGlossary.getGuid());
|
||||
assertNotNull(atlasGlossaryByGuid);
|
||||
assertEquals(healthCareGlossary.getGuid(), atlasGlossaryByGuid.getGuid());
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateGlossary")
|
||||
public void testGetDetailGlossary() throws Exception {
|
||||
AtlasGlossary.AtlasGlossaryExtInfo extInfo = atlasClientV2.getGlossaryExtInfo(educationGlossary.getGuid());
|
||||
assertNotNull(extInfo);
|
||||
assertEquals(educationGlossary.getGuid(), extInfo.getGuid());
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testGetGlossaryByGuid")
|
||||
public void getAllGlossary() throws Exception {
|
||||
List<AtlasGlossary> list = atlasClientV2.getAllGlossaries("ASC", 5, 0);
|
||||
assertNotNull(list);
|
||||
assertEquals(list.size(), 2);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateGlossary")
|
||||
public void updateGlossaryByGuid() throws Exception {
|
||||
AtlasGlossary newGlossary = new AtlasGlossary();
|
||||
newGlossary.setLanguage("English");
|
||||
newGlossary.setName("updateGlossary");
|
||||
AtlasGlossary updated = atlasClientV2.updateGlossaryByGuid(educationGlossary.getGuid(), newGlossary);
|
||||
assertNotNull(updated);
|
||||
assertEquals(updated.getGuid(), educationGlossary.getGuid());
|
||||
assertEquals(updated.getLanguage(), newGlossary.getLanguage());
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateGlossary")
|
||||
public void testCreateTerm() throws Exception {
|
||||
AtlasGlossaryTerm term = new AtlasGlossaryTerm();
|
||||
AtlasGlossaryHeader header = new AtlasGlossaryHeader();
|
||||
header.setGlossaryGuid(educationGlossary.getGuid());
|
||||
header.setDisplayText(educationGlossary.getName());
|
||||
term.setAnchor(header);
|
||||
term.setName("termForEducation");
|
||||
educationTerm = atlasClientV2.createGlossaryTerm(term);
|
||||
assertNotNull(educationTerm);
|
||||
assertNotNull(educationTerm.getGuid());
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateTerm")
|
||||
public void testGetGlossaryTerm() throws Exception {
|
||||
AtlasGlossaryTerm term = atlasClientV2.getGlossaryTerm(educationTerm.getGuid());
|
||||
assertNotNull(term);
|
||||
assertEquals(term.getGuid(), educationTerm.getGuid());
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateTerm")
|
||||
public void testGetGlossaryTerms() throws Exception {
|
||||
AtlasRelatedTermHeader relatedTermHeader = new AtlasRelatedTermHeader();
|
||||
relatedTermHeader.setTermGuid(educationTerm.getGuid());
|
||||
relatedTermHeader.setDescription("test description");
|
||||
relatedTermHeader.setExpression("test expression");
|
||||
relatedTermHeader.setSource("School");
|
||||
relatedTermHeader.setSteward("School");
|
||||
relatedTermHeader.setStatus(AtlasTermRelationshipStatus.ACTIVE);
|
||||
schoolEducationTerm = new AtlasGlossaryTerm();
|
||||
AtlasGlossaryHeader header = new AtlasGlossaryHeader();
|
||||
header.setGlossaryGuid(educationGlossary.getGuid());
|
||||
header.setDisplayText(educationGlossary.getName());
|
||||
schoolEducationTerm.setAnchor(header);
|
||||
schoolEducationTerm.setName("termForSchool");
|
||||
schoolEducationTerm.setSeeAlso(Collections.singleton(relatedTermHeader));
|
||||
|
||||
schoolEducationTerm = clientV2.createGlossaryTerm(schoolEducationTerm);
|
||||
assertNotNull(schoolEducationTerm);
|
||||
assertNotNull(schoolEducationTerm.getGuid());
|
||||
|
||||
//Getting multiple terms
|
||||
List<AtlasGlossaryTerm> terms = atlasClientV2.getGlossaryTerms(educationGlossary.getGuid(), "ASC", 2, 0);
|
||||
assertNotNull(terms);
|
||||
assertEquals(terms.size(), 2);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateGlossary")
|
||||
public void testCreateGlossaryCategory() throws Exception {
|
||||
AtlasGlossaryCategory category = new AtlasGlossaryCategory();
|
||||
AtlasGlossaryHeader header = new AtlasGlossaryHeader();
|
||||
header.setGlossaryGuid(educationGlossary.getGuid());
|
||||
header.setDisplayText(educationGlossary.getName());
|
||||
category.setAnchor(header);
|
||||
category.setName("categoryForEducation");
|
||||
educationCategory = atlasClientV2.createGlossaryCategory(category);
|
||||
assertNotNull(educationCategory);
|
||||
assertNotNull(educationCategory.getGuid());
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateGlossaryCategory")
|
||||
public void testCreateGlossaryCategories() throws Exception {
|
||||
List<AtlasGlossaryCategory> glossaryCategories = new ArrayList<>();
|
||||
|
||||
AtlasGlossaryCategory category1 = new AtlasGlossaryCategory();
|
||||
AtlasGlossaryHeader header1 = new AtlasGlossaryHeader();
|
||||
header1.setGlossaryGuid(healthCareGlossary.getGuid());
|
||||
header1.setDisplayText(healthCareGlossary.getName());
|
||||
category1.setAnchor(header1);
|
||||
category1.setName("category1ForEducation");
|
||||
glossaryCategories.add(category1);
|
||||
//Setting different category
|
||||
AtlasGlossaryCategory category2 = new AtlasGlossaryCategory();
|
||||
category2.setAnchor(header1);
|
||||
category2.setName("category2ForEducation");
|
||||
glossaryCategories.add(category2);
|
||||
|
||||
List<AtlasGlossaryCategory> list = atlasClientV2.createGlossaryCategories(glossaryCategories);
|
||||
assertNotNull(list);
|
||||
assertEquals(list.size(), 2);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateGlossaryCategory")
|
||||
public void testGetGlossaryByCategory() throws Exception {
|
||||
AtlasGlossaryCategory atlasGlossaryCategory = atlasClientV2.getGlossaryCategory(educationCategory.getGuid());
|
||||
assertNotNull(atlasGlossaryCategory);
|
||||
assertEquals(atlasGlossaryCategory.getGuid(), educationCategory.getGuid());
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testGetGlossaryByGuid")
|
||||
public void testCreateGlossaryTerms() throws Exception {
|
||||
List<AtlasGlossaryTerm> list = new ArrayList<>();
|
||||
int index = 0;
|
||||
List<AtlasGlossary> glossaries = atlasClientV2.getAllGlossaries("ASC", 5, 0);
|
||||
List<AtlasGlossary> glossaryList = mapper.convertValue(
|
||||
glossaries,
|
||||
new TypeReference<List<AtlasGlossary>>() {
|
||||
});
|
||||
|
||||
for (AtlasGlossary glossary : glossaryList) {
|
||||
AtlasGlossaryTerm term = new AtlasGlossaryTerm();
|
||||
AtlasGlossaryHeader header = new AtlasGlossaryHeader();
|
||||
header.setGlossaryGuid(glossary.getGuid());
|
||||
header.setDisplayText(glossary.getName());
|
||||
term.setAnchor(header);
|
||||
term.setName("termName" + index);
|
||||
list.add(term);
|
||||
index++;
|
||||
}
|
||||
List<AtlasGlossaryTerm> termList = atlasClientV2.createGlossaryTerms(list);
|
||||
assertNotNull(termList);
|
||||
assertEquals(termList.size(), 2);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateGlossary")
|
||||
public void testPartialUpdateGlossaryByGuid() throws Exception {
|
||||
Map<String, String> partialUpdates = new HashMap<>();
|
||||
partialUpdates.put("shortDescription", "shortDescription");
|
||||
partialUpdates.put("longDescription", "longDescription");
|
||||
AtlasGlossary atlasGlossary = atlasClientV2.partialUpdateGlossaryByGuid(educationGlossary.getGuid(), partialUpdates);
|
||||
assertNotNull(atlasGlossary);
|
||||
assertEquals(atlasGlossary.getShortDescription(), "shortDescription");
|
||||
assertEquals(atlasGlossary.getLongDescription(), "longDescription");
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateGlossary")
|
||||
public void testUpdateGlossaryTermByGuid() throws Exception {
|
||||
AtlasGlossaryTerm term = new AtlasGlossaryTerm(educationTerm);
|
||||
term.setAbbreviation("trm");
|
||||
AtlasGlossaryTerm responseTerm = atlasClientV2.updateGlossaryTermByGuid(educationTerm.getGuid(), term);
|
||||
assertNotNull(responseTerm);
|
||||
assertEquals(responseTerm.getAbbreviation(), term.getAbbreviation());
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateGlossary")
|
||||
public void testUpdateGlossaryCategoryByGuid() throws Exception {
|
||||
AtlasGlossaryCategory category = new AtlasGlossaryCategory(educationCategory);
|
||||
category.setLongDescription("this is about category");
|
||||
AtlasGlossaryCategory responseCategory = atlasClientV2.updateGlossaryCategoryByGuid(educationCategory.getGuid(), category);
|
||||
assertNotNull(responseCategory);
|
||||
assertEquals(responseCategory.getLongDescription(), category.getLongDescription());
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateGlossary")
|
||||
public void testPartialUpdateTermByGuid() throws Exception {
|
||||
Map<String, String> partialUpdates = new HashMap<>();
|
||||
partialUpdates.put("shortDescription", "shortDescriptionTerm");
|
||||
partialUpdates.put("longDescription", "longDescriptionTerm");
|
||||
|
||||
AtlasGlossaryTerm term = atlasClientV2.partialUpdateTermByGuid(educationTerm.getGuid(), partialUpdates);
|
||||
assertNotNull(term);
|
||||
assertEquals(term.getShortDescription(), "shortDescriptionTerm");
|
||||
assertEquals(term.getLongDescription(), "longDescriptionTerm");
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateGlossary")
|
||||
public void testPartialUpdateCategoryByGuid() throws Exception {
|
||||
Map<String, String> partialUpdates = new HashMap<>();
|
||||
partialUpdates.put("shortDescription", "shortDescriptionCategory");
|
||||
partialUpdates.put("longDescription", "longDescriptionCategory");
|
||||
|
||||
AtlasGlossaryCategory category = atlasClientV2.partialUpdateCategoryByGuid(educationCategory.getGuid(), partialUpdates);
|
||||
assertNotNull(category);
|
||||
assertEquals(category.getShortDescription(), "shortDescriptionCategory");
|
||||
assertEquals(category.getLongDescription(), "longDescriptionCategory");
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateGlossary")
|
||||
public void testGetGlossaryTermHeadersByGuid() throws Exception {
|
||||
List<AtlasRelatedTermHeader> list = atlasClientV2.getGlossaryTermHeaders(educationGlossary.getGuid(), "ASC", 2, 0);
|
||||
assertNotNull(list);
|
||||
assertEquals(list.size(), 1);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateGlossaryCategories")
|
||||
public void testGetGlossaryCategoriesByGuid() throws Exception {
|
||||
List<AtlasGlossaryCategory> list = atlasClientV2.getGlossaryCategories(healthCareGlossary.getGuid(), "ASC", 2, 0);
|
||||
assertNotNull(list);
|
||||
assertEquals(list.size(), 2);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateGlossaryCategories")
|
||||
public void testGetGlossaryCategoryHeaders() throws Exception {
|
||||
List<AtlasRelatedCategoryHeader> list = atlasClientV2.getGlossaryCategoryHeaders(healthCareGlossary.getGuid(), "ASC", 2, 0);
|
||||
assertNotNull(list);
|
||||
assertEquals(list.size(), 2);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateGlossary")
|
||||
public void testGetCategoryTerms() throws Exception {
|
||||
List<AtlasRelatedTermHeader> list = atlasClientV2.getCategoryTerms(educationCategory.getGuid(), "ASC", 2, 0);
|
||||
assertNotNull(list);
|
||||
assertEquals(list.size(), 0);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateGlossary")
|
||||
public void testGetAllRelatedTerms() throws Exception {
|
||||
Map<AtlasGlossaryTerm.Relation, Set<AtlasRelatedTermHeader>> map = atlasClientV2.getRelatedTerms(educationTerm.getGuid(), "ASC", 2, 0);
|
||||
assertNotNull(map);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateTerm")
|
||||
public void testAssignTermToEntities() throws Exception {
|
||||
try {
|
||||
AtlasEntity entity = new AtlasEntity("Asset");
|
||||
entity.setAttribute("qualifiedName", "testAsset");
|
||||
entity.setAttribute("name", "testAsset");
|
||||
if (entityHeader == null) {
|
||||
entityHeader = createEntity(entity);
|
||||
}
|
||||
AtlasRelatedObjectId relatedObjectId = new AtlasRelatedObjectId();
|
||||
relatedObjectId.setGuid(entityHeader.getGuid());
|
||||
relatedObjectId.setTypeName(entityHeader.getTypeName());
|
||||
assertNotNull(relatedObjectId);
|
||||
relatedObjectIds = new ArrayList<>();
|
||||
relatedObjectIds.add(relatedObjectId);
|
||||
|
||||
atlasClientV2.assignTermToEntities(educationTerm.getGuid(), relatedObjectIds);
|
||||
List<AtlasRelatedObjectId> assignedEntities = atlasClientV2.getEntitiesAssignedWithTerm(educationTerm.getGuid(), "ASC", 2, 0);
|
||||
assertNotNull(assignedEntities);
|
||||
assertEquals(assignedEntities.size(), 1);
|
||||
List<AtlasRelatedObjectId> entityList = mapper.convertValue(
|
||||
assignedEntities,
|
||||
new TypeReference<List<AtlasRelatedObjectId>>() {
|
||||
});
|
||||
String relationshipGuid = entityList.get(0).getRelationshipGuid();
|
||||
assertNotNull(relationshipGuid);
|
||||
relatedObjectId.setRelationshipGuid(relationshipGuid);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testAssignTermToEntities")
|
||||
public void testDisassociateTermAssignmentFromEntities() throws Exception {
|
||||
atlasClientV2.disassociateTermFromEntities(educationTerm.getGuid(), relatedObjectIds);
|
||||
AtlasGlossaryTerm term = atlasClientV2.getGlossaryTerm(educationTerm.getGuid());
|
||||
atlasClientV2.deleteEntityByGuid(entityHeader.getGuid());
|
||||
assertNotNull(term);
|
||||
assertNull(term.getAssignedEntities());
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateGlossaryCategory")
|
||||
public void testGetRelatedCategories() throws Exception {
|
||||
Map<String, List<AtlasRelatedCategoryHeader>> map = atlasClientV2.getRelatedCategories(educationCategory.getGuid(), "ASC", 1, 0);
|
||||
assertEquals(map.size(), 0);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testDeleteGlossaryTerm")
|
||||
public void testDeleteGlossary() throws Exception {
|
||||
emptyTypeDefs(typeDefinitions);
|
||||
atlasClientV2.deleteGlossaryByGuid(educationGlossary.getGuid());
|
||||
atlasClientV2.deleteGlossaryByGuid(healthCareGlossary.getGuid());
|
||||
try {
|
||||
atlasClientV2.getGlossaryByGuid(healthCareGlossary.getGuid());
|
||||
} catch (AtlasServiceException ex) {
|
||||
assertNotNull(ex.getStatus());
|
||||
assertEquals(ex.getStatus(), ClientResponse.Status.NOT_FOUND);
|
||||
}
|
||||
try {
|
||||
atlasClientV2.getGlossaryByGuid(educationGlossary.getGuid());
|
||||
} catch (AtlasServiceException ex) {
|
||||
assertNotNull(ex.getStatus());
|
||||
assertEquals(ex.getStatus(), ClientResponse.Status.NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testDisassociateTermAssignmentFromEntities")
|
||||
public void testDeleteGlossaryTerm() throws Exception {
|
||||
atlasClientV2.deleteGlossaryTermByGuid(educationTerm.getGuid());
|
||||
try {
|
||||
atlasClientV2.getGlossaryTerm(educationTerm.getGuid());
|
||||
} catch (AtlasServiceException ex) {
|
||||
assertNotNull(ex.getStatus());
|
||||
assertEquals(ex.getStatus(), ClientResponse.Status.NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testGetRelatedCategories")
|
||||
public void testDeleteGlossaryCategory() throws Exception {
|
||||
atlasClientV2.deleteGlossaryCategoryByGuid(educationCategory.getGuid());
|
||||
try {
|
||||
atlasClientV2.getGlossaryCategory(educationCategory.getGuid());
|
||||
} catch (AtlasServiceException ex) {
|
||||
assertNotNull(ex.getStatus());
|
||||
assertEquals(ex.getStatus(), ClientResponse.Status.NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void testProduceTemplate() {
|
||||
try {
|
||||
String template = atlasClientV2.getGlossaryImportTemplate();
|
||||
|
||||
assertNotNull(template);
|
||||
} catch (AtlasServiceException ex) {
|
||||
fail("Deletion should've succeeded");
|
||||
}
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void testImportGlossaryData() {
|
||||
try {
|
||||
String filePath = TestResourceFileUtils.getTestFilePath("template.csv");
|
||||
List<AtlasGlossaryTerm> terms = atlasClientV2.importGlossary(filePath);
|
||||
|
||||
assertNotNull(terms);
|
||||
|
||||
List<AtlasGlossaryTerm> termList = mapper.convertValue(terms, new TypeReference<List<AtlasGlossaryTerm>>() { });
|
||||
|
||||
assertEquals(terms.size(), 1);
|
||||
|
||||
AtlasGlossaryTerm createdTerm = termList.get(0);
|
||||
|
||||
String glossaryGuid = createdTerm.getAnchor().getGlossaryGuid();
|
||||
|
||||
atlasClientV2.deleteGlossaryByGuid(glossaryGuid);
|
||||
} catch (AtlasServiceException ex) {
|
||||
fail("Import GlossaryData should've succeeded");
|
||||
}
|
||||
}
|
||||
|
||||
private AtlasGlossary createAndGetGlossary(String name) throws Exception {
|
||||
AtlasGlossary atlasGlossary = new AtlasGlossary();
|
||||
atlasGlossary.setName(name);
|
||||
return atlasClientV2.createGlossary(atlasGlossary);
|
||||
}
|
||||
|
||||
private void emptyTypeDefs(AtlasTypesDef def) {
|
||||
def.getEnumDefs().clear();
|
||||
def.getStructDefs().clear();
|
||||
def.getClassificationDefs().clear();
|
||||
def.getEntityDefs().clear();
|
||||
def.getRelationshipDefs().clear();
|
||||
def.getBusinessMetadataDefs().clear();
|
||||
}
|
||||
|
||||
private AtlasTypesDef setForGlossary() throws IOException {
|
||||
String filePath = TestUtils.getGlossaryType();
|
||||
String json = FileUtils.readFileToString(new File(filePath));
|
||||
return AtlasType.fromJson(json, AtlasTypesDef.class);
|
||||
}
|
||||
|
||||
protected String randomString() {
|
||||
//names cannot start with a digit
|
||||
return RandomStringUtils.randomAlphabetic(1) + RandomStringUtils.randomAlphanumeric(9);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,133 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.apache.atlas.web.integration;
|
||||
|
||||
import org.apache.atlas.model.instance.AtlasEntityHeader;
|
||||
import org.apache.atlas.model.lineage.AtlasLineageInfo;
|
||||
import org.apache.atlas.v1.model.instance.Id;
|
||||
import org.apache.atlas.v1.model.instance.Referenceable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.apache.atlas.AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME;
|
||||
|
||||
/**
|
||||
* Entity Lineage v2 Integration Tests.
|
||||
*/
|
||||
public class LineageClientV2IT extends DataSetLineageJerseyResourceIT {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(LineageClientV2IT.class);
|
||||
private String salesFactTable;
|
||||
private String salesMonthlyTable;
|
||||
private String salesDBName;
|
||||
|
||||
@BeforeClass
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
createTypeDefinitionsV1();
|
||||
setupInstances();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLineageInfo() throws Exception {
|
||||
String tableId = atlasClientV1.getEntity(HIVE_TABLE_TYPE,
|
||||
REFERENCEABLE_ATTRIBUTE_NAME, salesMonthlyTable).getId()._getId();
|
||||
|
||||
AtlasLineageInfo inputLineageInfo = atlasClientV2.getLineageInfo(tableId, AtlasLineageInfo.LineageDirection.INPUT, 5);
|
||||
Assert.assertNotNull(inputLineageInfo);
|
||||
Map<String, AtlasEntityHeader> entities = inputLineageInfo.getGuidEntityMap();
|
||||
Assert.assertNotNull(entities);
|
||||
|
||||
Set<AtlasLineageInfo.LineageRelation> relations = inputLineageInfo.getRelations();
|
||||
Assert.assertNotNull(relations);
|
||||
|
||||
Assert.assertEquals(entities.size(), 6);
|
||||
Assert.assertEquals(relations.size(), 5);
|
||||
Assert.assertEquals(inputLineageInfo.getLineageDirection(), AtlasLineageInfo.LineageDirection.INPUT);
|
||||
Assert.assertEquals(inputLineageInfo.getLineageDepth(), 5);
|
||||
Assert.assertEquals(inputLineageInfo.getBaseEntityGuid(), tableId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLineageInfoByAttribute() throws Exception {
|
||||
Map<String, String> attributeMap = new HashMap<>();
|
||||
attributeMap.put("qualifiedName", salesMonthlyTable);
|
||||
|
||||
AtlasLineageInfo bothLineageInfo = atlasClientV2.getLineageInfo(HIVE_TABLE_TYPE, attributeMap, AtlasLineageInfo.LineageDirection.BOTH, 5);
|
||||
Assert.assertNotNull(bothLineageInfo);
|
||||
Map<String, AtlasEntityHeader> entities = bothLineageInfo.getGuidEntityMap();
|
||||
Assert.assertNotNull(entities);
|
||||
|
||||
Set<AtlasLineageInfo.LineageRelation> relations = bothLineageInfo.getRelations();
|
||||
Assert.assertNotNull(relations);
|
||||
|
||||
Assert.assertEquals(entities.size(), 6);
|
||||
Assert.assertEquals(relations.size(), 5);
|
||||
Assert.assertEquals(bothLineageInfo.getLineageDirection(), AtlasLineageInfo.LineageDirection.BOTH);
|
||||
Assert.assertEquals(bothLineageInfo.getLineageDepth(), 5);
|
||||
}
|
||||
|
||||
private void setupInstances() throws Exception {
|
||||
salesDBName = "Sales" + randomString();
|
||||
Id salesDB = database(salesDBName, "Sales Database", "John ETL", "hdfs://host:8000/apps/warehouse/sales");
|
||||
|
||||
List<Referenceable> salesFactColumns = Arrays.asList(column("time_id", "int", "time id"), column("product_id", "int", "product id"),
|
||||
column("customer_id", "int", "customer id"),
|
||||
column("sales", "double", "product id"));
|
||||
|
||||
salesFactTable = "sales_fact" + randomString();
|
||||
Id salesFact = table(salesFactTable, "sales fact table", salesDB, "Joe", "MANAGED", salesFactColumns);
|
||||
|
||||
List<Referenceable> timeDimColumns = Arrays.asList(column("time_id", "int", "time id"), column("dayOfYear", "int", "day Of Year"),
|
||||
column("weekDay", "int", "week Day"));
|
||||
|
||||
Id timeDim =
|
||||
table("time_dim" + randomString(), "time dimension table", salesDB, "John Doe", "EXTERNAL",
|
||||
timeDimColumns);
|
||||
|
||||
Id reportingDB =
|
||||
database("Reporting" + randomString(), "reporting database", "Jane BI",
|
||||
"hdfs://host:8000/apps/warehouse/reporting");
|
||||
|
||||
Id salesFactDaily =
|
||||
table("sales_fact_daily_mv" + randomString(), "sales fact daily materialized view", reportingDB,
|
||||
"Joe BI", "MANAGED", salesFactColumns);
|
||||
|
||||
loadProcess("loadSalesDaily" + randomString(), "John ETL", Arrays.asList(salesFact, timeDim),
|
||||
Collections.singletonList(salesFactDaily), "create table as select ", "plan", "id", "graph");
|
||||
|
||||
salesMonthlyTable = "sales_fact_monthly_mv" + randomString();
|
||||
Id salesFactMonthly =
|
||||
table(salesMonthlyTable, "sales fact monthly materialized view", reportingDB, "Jane BI",
|
||||
"MANAGED", salesFactColumns);
|
||||
|
||||
loadProcess("loadSalesMonthly" + randomString(), "John ETL", Collections.singletonList(salesFactDaily),
|
||||
Collections.singletonList(salesFactMonthly), "create table as select ", "plan", "id", "graph");
|
||||
}
|
||||
}
|
||||
|
|
@ -20,18 +20,20 @@ package org.apache.atlas.web.integration;
|
|||
|
||||
import com.sun.jersey.core.util.MultivaluedMapImpl;
|
||||
import org.apache.atlas.AtlasClientV2;
|
||||
import org.apache.atlas.AtlasErrorCode;
|
||||
import org.apache.atlas.AtlasServiceException;
|
||||
import org.apache.atlas.exception.AtlasBaseException;
|
||||
import org.apache.atlas.model.SearchFilter;
|
||||
import org.apache.atlas.model.TypeCategory;
|
||||
import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
|
||||
import org.apache.atlas.model.typedef.AtlasBusinessMetadataDef;
|
||||
import org.apache.atlas.model.typedef.AtlasClassificationDef;
|
||||
import org.apache.atlas.model.typedef.AtlasEntityDef;
|
||||
import org.apache.atlas.model.typedef.AtlasEnumDef;
|
||||
import org.apache.atlas.model.typedef.AtlasRelationshipDef;
|
||||
import org.apache.atlas.model.typedef.AtlasStructDef;
|
||||
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
|
||||
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef;
|
||||
import org.apache.atlas.model.typedef.AtlasTypeDefHeader;
|
||||
import org.apache.atlas.model.typedef.AtlasTypesDef;
|
||||
import org.apache.atlas.type.AtlasTypeUtil;
|
||||
import org.apache.atlas.utils.AuthenticationUtil;
|
||||
|
|
@ -46,6 +48,7 @@ import javax.ws.rs.core.Response;
|
|||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import static org.apache.atlas.AtlasErrorCode.TYPE_NAME_NOT_FOUND;
|
||||
import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef.Cardinality;
|
||||
|
|
@ -102,6 +105,33 @@ public class TypedefsJerseyResourceIT extends BaseResourceIT {
|
|||
for (AtlasEntityDef entityDef : typeDefinitions.getEntityDefs()) {
|
||||
checkIfTypeExists(entityDef.getName());
|
||||
}
|
||||
|
||||
for (AtlasRelationshipDef relationshipDef : typeDefinitions.getRelationshipDefs()) {
|
||||
checkIfTypeExists(relationshipDef.getName());
|
||||
}
|
||||
|
||||
for (AtlasBusinessMetadataDef businessMetadataDef : typeDefinitions.getBusinessMetadataDefs()) {
|
||||
checkIfTypeExists(businessMetadataDef.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetHeaders() throws Exception {
|
||||
MultivaluedMap<String, String> filterParams = new MultivaluedMapImpl();
|
||||
filterParams.add(SearchFilter.PARAM_TYPE, "ENTITY");
|
||||
List<AtlasTypeDefHeader> headers = clientV2.getAllTypeDefHeaders(new SearchFilter(filterParams));
|
||||
assertNotNull(headers);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testGetDefinition")
|
||||
public void testDeleteAtlasTypeByName() throws Exception {
|
||||
String typeName = "table";
|
||||
boolean typeExists = atlasClientV2.typeWithNameExists(typeName);
|
||||
if (typeExists) {
|
||||
clientV2.deleteTypeByName(typeName);
|
||||
boolean afterDelete = atlasClientV2.typeWithNameExists(typeName);
|
||||
assertEquals(afterDelete, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -191,9 +221,21 @@ public class TypedefsJerseyResourceIT extends BaseResourceIT {
|
|||
verifyByNameAndGUID(entityDef);
|
||||
}
|
||||
}
|
||||
|
||||
if (CollectionUtils.isNotEmpty(typeDefinitions.getRelationshipDefs())) {
|
||||
for (AtlasRelationshipDef relationshipDef : typeDefinitions.getRelationshipDefs()) {
|
||||
verifyByNameAndGUID(relationshipDef);
|
||||
}
|
||||
}
|
||||
|
||||
if (CollectionUtils.isNotEmpty(typeDefinitions.getBusinessMetadataDefs())) {
|
||||
for (AtlasBusinessMetadataDef businessMetadataDef : typeDefinitions.getBusinessMetadataDefs()) {
|
||||
verifyByNameAndGUID(businessMetadataDef);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test()
|
||||
public void testInvalidGets() throws Exception {
|
||||
try {
|
||||
AtlasEnumDef byName = clientV2.getEnumDefByName("blah");
|
||||
|
|
@ -259,6 +301,37 @@ public class TypedefsJerseyResourceIT extends BaseResourceIT {
|
|||
"Should've returned a 404");
|
||||
}
|
||||
|
||||
try {
|
||||
AtlasRelationshipDef byName = clientV2.getRelationshipDefByName("blah");
|
||||
fail("Get for invalid name should have reported a failure");
|
||||
} catch (AtlasServiceException e) {
|
||||
assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(),
|
||||
"Should've returned a 404");
|
||||
}
|
||||
|
||||
try {
|
||||
AtlasRelationshipDef byGuid = clientV2.getRelationshipDefByGuid("blah");
|
||||
fail("Get for invalid name should have reported a failure");
|
||||
} catch (AtlasServiceException e) {
|
||||
assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(),
|
||||
"Should've returned a 404");
|
||||
}
|
||||
|
||||
try {
|
||||
AtlasBusinessMetadataDef byName = clientV2.getBusinessMetadataDefByName("blah");
|
||||
fail("Get for invalid name should have reported a failure");
|
||||
} catch (AtlasServiceException e) {
|
||||
assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(),
|
||||
"Should've returned a 404");
|
||||
}
|
||||
|
||||
try {
|
||||
AtlasBusinessMetadataDef byGuid = clientV2.getBusinessMetadataDefGuid("blah");
|
||||
fail("Get for invalid name should have reported a failure");
|
||||
} catch (AtlasServiceException e) {
|
||||
assertEquals(e.getStatus().getStatusCode(), Response.Status.NOT_FOUND.getStatusCode(),
|
||||
"Should've returned a 404");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -339,6 +412,10 @@ public class TypedefsJerseyResourceIT extends BaseResourceIT {
|
|||
byName = clientV2.getClassificationDefByName(typeDef.getName());
|
||||
} else if (typeDef.getCategory() == TypeCategory.STRUCT) {
|
||||
byName = clientV2.getStructDefByName(typeDef.getName());
|
||||
} else if (typeDef.getCategory() == TypeCategory.RELATIONSHIP) {
|
||||
byName = clientV2.getRelationshipDefByName(typeDef.getName());
|
||||
} else if (typeDef.getCategory() == TypeCategory.BUSINESS_METADATA) {
|
||||
byName = clientV2.getBusinessMetadataDefByName(typeDef.getName());
|
||||
}
|
||||
assertNotNull(byName);
|
||||
} catch (AtlasServiceException e) {
|
||||
|
|
@ -355,6 +432,10 @@ public class TypedefsJerseyResourceIT extends BaseResourceIT {
|
|||
byGuid = clientV2.getClassificationDefByGuid(typeDef.getGuid());
|
||||
} else if (typeDef.getCategory() == TypeCategory.STRUCT) {
|
||||
byGuid = clientV2.getStructDefByGuid(typeDef.getGuid());
|
||||
} else if (typeDef.getCategory() == TypeCategory.RELATIONSHIP) {
|
||||
byGuid = clientV2.getRelationshipDefByGuid(typeDef.getGuid());
|
||||
} else if (typeDef.getCategory() == TypeCategory.BUSINESS_METADATA) {
|
||||
byGuid = clientV2.getBusinessMetadataDefGuid(typeDef.getGuid());
|
||||
}
|
||||
assertNotNull(byGuid);
|
||||
} catch (AtlasServiceException e) {
|
||||
|
|
@ -368,6 +449,8 @@ public class TypedefsJerseyResourceIT extends BaseResourceIT {
|
|||
def.getStructDefs().clear();
|
||||
def.getClassificationDefs().clear();
|
||||
def.getEntityDefs().clear();
|
||||
def.getRelationshipDefs().clear();
|
||||
def.getBusinessMetadataDefs().clear();
|
||||
}
|
||||
|
||||
private void checkIfTypeExists(String typeName) throws Exception {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
[ {
|
||||
"testDescription": "hive_table contains testtable or retentionSize != 0",
|
||||
"searchParameters": {
|
||||
"typeName": "hive_table",
|
||||
"excludeDeletedEntities": true,
|
||||
"classification": "",
|
||||
"query": "",
|
||||
"limit": 25,
|
||||
"offset": 0,
|
||||
"entityFilters": {
|
||||
"attributeName": "name",
|
||||
"attributeValue": "testtable",
|
||||
"condition" : "OR",
|
||||
"criterion" : [
|
||||
{
|
||||
"attributeName": "name",
|
||||
"operator": "contains",
|
||||
"attributeValue": "testtable"
|
||||
},
|
||||
{
|
||||
"attributeName": "retention",
|
||||
"operator": "neq",
|
||||
"attributeValue": "0"
|
||||
}
|
||||
]
|
||||
|
||||
},
|
||||
"tagFilters": null,
|
||||
"attributes": [
|
||||
""
|
||||
]
|
||||
},
|
||||
"expectedCount": 3
|
||||
}]
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
GlossaryName, TermName, ShortDescription, LongDescription, Examples, Abbreviation, Usage, AdditionalAttributes, TranslationTerms, ValidValuesFor, Synonyms, ReplacedBy, ValidValues, ReplacementTerms, SeeAlso, TranslatedTerms, IsA, Antonyms, Classifies, PreferredToTerms, PreferredTerms
|
||||
testBankingGlossary,BankBranch,SD4,LD4,"EXAMPLE","ABBREVIATION","USAGE",,,,,,,,,,,,,,
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
TypeName,UniqueAttributeValue,BusinessAttributeName,BusinessAttributeValue,UniqueAttributeName[optional]
|
||||
hive_table_v2,tableqZPo3C488c,bmWithAllTypes.attr8,"Awesome Attribute 1",qualifiedName
|
||||
|
Loading…
Reference in New Issue