You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by ma...@apache.org on 2017/11/05 20:31:36 UTC
[14/40] atlas git commit: ATLAS-2251: Remove TypeSystem and related
implementation, to avoid unncessary duplicate of type details in cache
http://git-wip-us.apache.org/repos/asf/atlas/blob/0877e47c/repository/src/test/java/org/apache/atlas/repository/typestore/GraphBackedTypeStoreTest.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/repository/typestore/GraphBackedTypeStoreTest.java b/repository/src/test/java/org/apache/atlas/repository/typestore/GraphBackedTypeStoreTest.java
deleted file mode 100755
index 6e3dabb..0000000
--- a/repository/src/test/java/org/apache/atlas/repository/typestore/GraphBackedTypeStoreTest.java
+++ /dev/null
@@ -1,256 +0,0 @@
-/**
- * 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.repository.typestore;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import org.apache.atlas.AtlasException;
-import org.apache.atlas.TestModules;
-import org.apache.atlas.TestUtils;
-import org.apache.atlas.repository.RepositoryException;
-import org.apache.atlas.repository.graph.GraphHelper;
-import org.apache.atlas.repository.graphdb.AtlasEdge;
-import org.apache.atlas.repository.graphdb.AtlasEdgeDirection;
-import org.apache.atlas.repository.graphdb.AtlasGraph;
-import org.apache.atlas.repository.graphdb.AtlasVertex;
-import org.apache.atlas.typesystem.TypesDef;
-import org.apache.atlas.typesystem.types.*;
-import org.apache.atlas.typesystem.types.utils.TypesUtil;
-import org.testng.Assert;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Guice;
-import org.testng.annotations.Test;
-
-import javax.inject.Inject;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import static org.apache.atlas.typesystem.types.utils.TypesUtil.createClassTypeDef;
-import static org.apache.atlas.typesystem.types.utils.TypesUtil.createOptionalAttrDef;
-import static org.apache.atlas.typesystem.types.utils.TypesUtil.createRequiredAttrDef;
-import static org.apache.atlas.typesystem.types.utils.TypesUtil.createStructTypeDef;
-
-@Guice(modules = TestModules.TestOnlyModule.class)
-public class GraphBackedTypeStoreTest {
-
- private static final String DESCRIPTION = "_description";
-
- @Inject
- private ITypeStore typeStore;
-
- private TypeSystem ts;
-
- @BeforeClass
- public void setUp() throws Exception {
- ts = TypeSystem.getInstance();
- ts.reset();
- TestUtils.defineDeptEmployeeTypes(ts);
- }
-
- @AfterClass
- public void tearDown() throws Exception {
- ts.reset();
-// AtlasGraphProvider.cleanup();
- }
-
-
- @Test
- public void testStore() throws AtlasException {
- ImmutableList<String> typeNames = ts.getTypeNames();
- typeStore.store(ts, typeNames);
- dumpGraph();
- }
-
- @Test(dependsOnMethods = "testStore")
- public void testRestoreType() throws Exception {
- TypesDef typesDef = typeStore.restoreType("Manager");
- verifyRestoredClassType(typesDef, "Manager");
- }
-
- private void dumpGraph() {
- AtlasGraph<?, ?> graph = TestUtils.getGraph();
- for (AtlasVertex<?,?> v : graph.getVertices()) {
- System.out.println("****v = " + GraphHelper.vertexString(v));
- for (AtlasEdge<?,?> e : v.getEdges(AtlasEdgeDirection.OUT)) {
- System.out.println("****e = " + GraphHelper.edgeString(e));
- }
- }
- }
-
- @Test(dependsOnMethods = "testStore")
- public void testRestore() throws Exception {
- TypesDef types = typeStore.restore();
-
- //validate enum
- List<EnumTypeDefinition> enumTypes = types.enumTypesAsJavaList();
- Assert.assertEquals(1, enumTypes.size());
- EnumTypeDefinition orgLevel = enumTypes.get(0);
- Assert.assertEquals(orgLevel.name, "OrgLevel");
- Assert.assertEquals(orgLevel.description, "OrgLevel"+DESCRIPTION);
- Assert.assertEquals(orgLevel.enumValues.length, 2);
- EnumValue enumValue = orgLevel.enumValues[0];
- Assert.assertEquals(enumValue.value, "L1");
- Assert.assertEquals(enumValue.ordinal, 1);
-
- //validate class
- List<StructTypeDefinition> structTypes = types.structTypesAsJavaList();
- Assert.assertEquals(1, structTypes.size());
-
- verifyRestoredClassType(types, "Manager");
-
- //validate trait
- List<HierarchicalTypeDefinition<TraitType>> traitTypes = types.traitTypesAsJavaList();
- Assert.assertEquals(1, traitTypes.size());
- HierarchicalTypeDefinition<TraitType> trait = traitTypes.get(0);
- Assert.assertEquals("SecurityClearance", trait.typeName);
- Assert.assertEquals(trait.typeName+DESCRIPTION, trait.typeDescription);
- Assert.assertEquals(1, trait.attributeDefinitions.length);
- AttributeDefinition attribute = trait.attributeDefinitions[0];
- Assert.assertEquals("level", attribute.name);
- Assert.assertEquals(DataTypes.INT_TYPE.getName(), attribute.dataTypeName);
-
- //validate the new types
- ts.reset();
- ts.defineTypes(types);
- }
-
- @Test
- public void testTypeWithSpecialChars() throws AtlasException {
- HierarchicalTypeDefinition<ClassType> specialTypeDef1 = createClassTypeDef("SpecialTypeDef1", "Typedef with special character",
- ImmutableSet.<String>of(), createRequiredAttrDef("attribute$", DataTypes.STRING_TYPE));
-
- HierarchicalTypeDefinition<ClassType> specialTypeDef2 = createClassTypeDef("SpecialTypeDef2", "Typedef with special character",
- ImmutableSet.<String>of(), createRequiredAttrDef("attribute%", DataTypes.STRING_TYPE));
-
- HierarchicalTypeDefinition<ClassType> specialTypeDef3 = createClassTypeDef("SpecialTypeDef3", "Typedef with special character",
- ImmutableSet.<String>of(), createRequiredAttrDef("attribute{", DataTypes.STRING_TYPE));
-
- HierarchicalTypeDefinition<ClassType> specialTypeDef4 = createClassTypeDef("SpecialTypeDef4", "Typedef with special character",
- ImmutableSet.<String>of(), createRequiredAttrDef("attribute}", DataTypes.STRING_TYPE));
-
- HierarchicalTypeDefinition<ClassType> specialTypeDef5 = createClassTypeDef("SpecialTypeDef5", "Typedef with special character",
- ImmutableSet.<String>of(), createRequiredAttrDef("attribute$%{}", DataTypes.STRING_TYPE));
-
- TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(),
- ImmutableList.<StructTypeDefinition>of(),
- ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(),
- ImmutableList.of(specialTypeDef1, specialTypeDef2, specialTypeDef3, specialTypeDef4, specialTypeDef5));
-
- Map<String, IDataType> createdTypes = ts.defineTypes(typesDef);
- typeStore.store(ts, ImmutableList.copyOf(createdTypes.keySet()));
-
- //Validate the updated types
- TypesDef types = typeStore.restore();
- ts.reset();
- ts.defineTypes(types);
- }
-
- @Test(dependsOnMethods = "testStore")
- public void testTypeUpdate() throws Exception {
- //Add enum value
- String _description = "_description_updated";
- EnumTypeDefinition orgLevelEnum = new EnumTypeDefinition("OrgLevel", "OrgLevel"+_description, new EnumValue("L1", 1),
- new EnumValue("L2", 2), new EnumValue("L3", 3));
-
- //Add attribute
- StructTypeDefinition addressDetails =
- createStructTypeDef("Address", createRequiredAttrDef("street", DataTypes.STRING_TYPE),
- createRequiredAttrDef("city", DataTypes.STRING_TYPE),
- createOptionalAttrDef("state", DataTypes.STRING_TYPE));
-
- HierarchicalTypeDefinition<ClassType> deptTypeDef = createClassTypeDef("Department", "Department"+_description,
- ImmutableSet.<String>of(), createRequiredAttrDef("name", DataTypes.STRING_TYPE),
- new AttributeDefinition("employees", String.format("array<%s>", "Person"), Multiplicity.OPTIONAL,
- true, "department"),
- new AttributeDefinition("positions", String.format("map<%s,%s>", DataTypes.STRING_TYPE.getName(), "Person"), Multiplicity.OPTIONAL, false, null));
- TypesDef typesDef = TypesUtil.getTypesDef(ImmutableList.of(orgLevelEnum), ImmutableList.of(addressDetails),
- ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(),
- ImmutableList.of(deptTypeDef));
-
- Map<String, IDataType> typesAdded = ts.updateTypes(typesDef);
- typeStore.store(ts, ImmutableList.copyOf(typesAdded.keySet()));
-
- verifyEdges();
-
- //Validate the updated types
- TypesDef types = typeStore.restore();
- ts.reset();
- ts.defineTypes(types);
-
- //Assert new enum value
- EnumType orgLevel = ts.getDataType(EnumType.class, orgLevelEnum.name);
- Assert.assertEquals(orgLevel.name, orgLevelEnum.name);
- Assert.assertEquals(orgLevel.description, orgLevelEnum.description);
- Assert.assertEquals(orgLevel.values().size(), orgLevelEnum.enumValues.length);
- Assert.assertEquals(orgLevel.fromValue("L3").ordinal, 3);
-
- //Assert new attribute
- StructType addressType = ts.getDataType(StructType.class, addressDetails.typeName);
- Assert.assertEquals(addressType.numFields, 3);
- Assert.assertEquals(addressType.fieldMapping.fields.get("state").dataType(), DataTypes.STRING_TYPE);
-
- //Updating the definition again shouldn't add another edge
- typesDef = TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(),
- ImmutableList.<StructTypeDefinition>of(),
- ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(),
- ImmutableList.of(deptTypeDef));
- typesAdded = ts.updateTypes(typesDef);
- typeStore.store(ts, ImmutableList.copyOf(typesAdded.keySet()));
- verifyEdges();
- }
-
- private void verifyEdges() throws RepositoryException {
- // ATLAS-474: verify that type update did not write duplicate edges to the type store.
- if (typeStore instanceof GraphBackedTypeStore) {
- GraphBackedTypeStore gbTypeStore = (GraphBackedTypeStore) typeStore;
- AtlasVertex typeVertex = gbTypeStore.findVertices(Collections.singletonList("Department")).get("Department");
- int edgeCount = countOutgoingEdges(typeVertex, gbTypeStore.getEdgeLabel("Department", "employees"));
- Assert.assertEquals(edgeCount, 1, "Should only be 1 edge for employees attribute on Department type AtlasVertex");
- }
- }
-
- private int countOutgoingEdges(AtlasVertex typeVertex, String edgeLabel) {
-
- Iterator<AtlasEdge> outGoingEdgesByLabel = GraphHelper.getInstance().getOutGoingEdgesByLabel(typeVertex, edgeLabel);
- int edgeCount = 0;
- for (; outGoingEdgesByLabel.hasNext();) {
- outGoingEdgesByLabel.next();
- edgeCount++;
- }
- return edgeCount;
- }
-
- private void verifyRestoredClassType(TypesDef types, String typeName) throws AtlasException {
- boolean clsTypeFound = false;
- List<HierarchicalTypeDefinition<ClassType>> classTypes = types.classTypesAsJavaList();
- for (HierarchicalTypeDefinition<ClassType> classType : classTypes) {
- if (classType.typeName.equals(typeName)) {
- ClassType expectedType = ts.getDataType(ClassType.class, classType.typeName);
- Assert.assertEquals(expectedType.immediateAttrs.size(), classType.attributeDefinitions.length);
- Assert.assertEquals(expectedType.superTypes.size(), classType.superTypes.size());
- Assert.assertEquals(classType.typeDescription, classType.typeName+DESCRIPTION);
- clsTypeFound = true;
- }
- }
- Assert.assertTrue(clsTypeFound, typeName + " type not restored");
- }
-}
http://git-wip-us.apache.org/repos/asf/atlas/blob/0877e47c/repository/src/test/java/org/apache/atlas/repository/typestore/StoreBackedTypeCacheTest.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/repository/typestore/StoreBackedTypeCacheTest.java b/repository/src/test/java/org/apache/atlas/repository/typestore/StoreBackedTypeCacheTest.java
deleted file mode 100644
index 2ea63ff..0000000
--- a/repository/src/test/java/org/apache/atlas/repository/typestore/StoreBackedTypeCacheTest.java
+++ /dev/null
@@ -1,169 +0,0 @@
-/**
- * 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.repository.typestore;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import org.apache.atlas.AtlasException;
-import org.apache.atlas.TestModules;
-import org.apache.atlas.TestUtils;
-import org.apache.atlas.typesystem.types.AttributeInfo;
-import org.apache.atlas.typesystem.types.ClassType;
-import org.apache.atlas.typesystem.types.DataTypes.TypeCategory;
-import org.apache.atlas.typesystem.types.HierarchicalType;
-import org.apache.atlas.typesystem.types.IDataType;
-import org.apache.atlas.typesystem.types.TraitType;
-import org.apache.atlas.typesystem.types.TypeSystem;
-import org.apache.atlas.typesystem.types.TypeUtils;
-import org.testng.Assert;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Guice;
-import org.testng.annotations.Test;
-
-import javax.inject.Inject;
-import java.util.HashMap;
-import java.util.Map;
-
-
-/**
- * Unit test for {@link StoreBackedTypeCache}
- */
-@Guice(modules = TestModules.TestOnlyModule.class)
-public class StoreBackedTypeCacheTest {
-
- @Inject
- private ITypeStore typeStore;
-
- @Inject
- private StoreBackedTypeCache typeCache;
-
- private TypeSystem ts;
-
- private Map<String, ClassType> classTypesToTest = new HashMap<>();
-
- @Inject
- public StoreBackedTypeCacheTest() {
- }
-
- @BeforeClass
- public void setUp() throws Exception {
- //force graph to be initialized up front
- TestUtils.getGraph();
-
- ts = TypeSystem.getInstance();
- ts.reset();
- ts.setTypeCache(typeCache);
-
- // Populate the type store for testing.
- TestUtils.defineDeptEmployeeTypes(ts);
- TestUtils.createHiveTypes(ts);
- ImmutableList<String> typeNames = ts.getTypeNames();
- typeStore.store(ts, typeNames);
-
- ClassType type = ts.getDataType(ClassType.class, "Manager");
- classTypesToTest.put("Manager", type);
- type = ts.getDataType(ClassType.class, TestUtils.TABLE_TYPE);
- classTypesToTest.put(TestUtils.TABLE_TYPE, type);
- }
-
- @AfterClass
- public void tearDown() throws Exception {
- ts.reset();
-// AtlasGraphProvider.cleanup();
- }
-
- @BeforeMethod
- public void setupTestMethod() throws Exception {
- typeCache.clear();
- }
-
- @Test
- public void testGetClassType() throws Exception {
- for (Map.Entry<String, ClassType> typeEntry : classTypesToTest.entrySet()) {
- // Not cached yet
- Assert.assertFalse(typeCache.isCachedInMemory(typeEntry.getKey()));
-
- IDataType dataType = ts.getDataType(IDataType.class, typeEntry.getKey());
- // Verify the type is now cached.
- Assert.assertTrue(typeCache.isCachedInMemory(typeEntry.getKey()));
-
- Assert.assertTrue(dataType instanceof ClassType);
- ClassType cachedType = (ClassType)dataType;
- // Verify that get() also loaded and cached any dependencies of this type from the type store.
- verifyHierarchicalType(cachedType, typeEntry.getValue());
- }
- }
-
- @Test
- public void testGetTraitType() throws Exception {
- ImmutableList<String> traitNames = ts.getTypeNamesByCategory(TypeCategory.TRAIT);
- for (String traitTypeName : traitNames) {
- // Not cached yet
- Assert.assertFalse(typeCache.isCachedInMemory(traitTypeName));
-
- IDataType dataType = typeCache.get(traitTypeName);
- // Verify the type is now cached.
- Assert.assertTrue(typeCache.isCachedInMemory(traitTypeName));
-
- Assert.assertTrue(dataType instanceof TraitType);
- TraitType cachedType = (TraitType)dataType;
- // Verify that get() also loaded and cached any dependencies of this type from the type store.
- verifyHierarchicalType(cachedType, ts.getDataType(TraitType.class, traitTypeName));
- }
- }
-
- private <T extends HierarchicalType> void verifyHierarchicalType(T dataType, T expectedDataType) throws AtlasException {
- Assert.assertEquals(dataType.numFields, expectedDataType.numFields);
- Assert.assertEquals(dataType.immediateAttrs.size(), expectedDataType.immediateAttrs.size());
- Assert.assertEquals(dataType.fieldMapping().fields.size(), expectedDataType.fieldMapping().fields.size());
- ImmutableSet<String> superTypes = dataType.superTypes;
- Assert.assertEquals(superTypes.size(), expectedDataType.superTypes.size());
-
- // Verify that any attribute and super types were also cached.
- for (String superTypeName : superTypes) {
- Assert.assertTrue(typeCache.has(superTypeName));
- }
- for (AttributeInfo attrInfo : dataType.fieldMapping().fields.values()) {
- switch (attrInfo.dataType().getTypeCategory()) {
- case CLASS:
- case STRUCT:
- case ENUM:
- Assert.assertTrue(typeCache.has(attrInfo.dataType().getName()), attrInfo.dataType().getName() + " should be cached");
- break;
- case ARRAY:
- String elementTypeName = TypeUtils.parseAsArrayType(attrInfo.dataType().getName());
- if (!ts.getCoreTypes().contains(elementTypeName)) {
- Assert.assertTrue(typeCache.has(elementTypeName), elementTypeName + " should be cached");
- }
- break;
- case MAP:
- String[] mapTypeNames = TypeUtils.parseAsMapType(attrInfo.dataType().getName());
- for (String typeName : mapTypeNames) {
- if (!ts.getCoreTypes().contains(typeName)) {
- Assert.assertTrue(typeCache.has(typeName), typeName + " should be cached");
- }
- }
- break;
- default:
- break;
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/atlas/blob/0877e47c/repository/src/test/java/org/apache/atlas/repository/userprofile/UserProfileServiceTest.java
----------------------------------------------------------------------
diff --git a/repository/src/test/java/org/apache/atlas/repository/userprofile/UserProfileServiceTest.java b/repository/src/test/java/org/apache/atlas/repository/userprofile/UserProfileServiceTest.java
deleted file mode 100644
index 0532f16..0000000
--- a/repository/src/test/java/org/apache/atlas/repository/userprofile/UserProfileServiceTest.java
+++ /dev/null
@@ -1,280 +0,0 @@
-/**
- * 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.repository.userprofile;
-
-import org.apache.atlas.AtlasErrorCode;
-import org.apache.atlas.TestModules;
-import org.apache.atlas.exception.AtlasBaseException;
-import org.apache.atlas.model.SearchFilter;
-import org.apache.atlas.model.discovery.SearchParameters;
-import org.apache.atlas.model.profile.AtlasUserProfile;
-import org.apache.atlas.model.profile.AtlasUserSavedSearch;
-import org.apache.atlas.model.typedef.AtlasTypesDef;
-import org.apache.atlas.repository.util.FilterUtil;
-import org.apache.atlas.store.AtlasTypeDefStore;
-import org.apache.atlas.type.AtlasType;
-import org.apache.atlas.type.AtlasTypeRegistry;
-import org.testng.annotations.Guice;
-import org.testng.annotations.Test;
-
-import javax.inject.Inject;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.apache.atlas.model.profile.AtlasUserSavedSearch.SavedSearchType.BASIC;
-import static org.apache.atlas.repository.impexp.ZipFileResourceTestUtils.loadModelFromJson;
-import static org.testng.Assert.*;
-
-@Guice(modules = TestModules.TestOnlyModule.class)
-public class UserProfileServiceTest {
- private UserProfileService userProfileService;
- private AtlasTypeDefStore typeDefStore;
- private int max_searches = 4;
-
- @Inject
- public void UserProfileServiceTest(AtlasTypeRegistry typeRegistry,
- AtlasTypeDefStore typeDefStore,
- UserProfileService userProfileService) throws IOException, AtlasBaseException {
- this.typeDefStore = typeDefStore;
- this.userProfileService = userProfileService;
-
- loadModelFromJson("0010-base_model.json", typeDefStore, typeRegistry);
- }
-
- @Test
- public void filterInternalType() throws AtlasBaseException {
- SearchFilter searchFilter = new SearchFilter();
- AtlasTypesDef filteredTypeDefs = typeDefStore.searchTypesDef(searchFilter);
- int maxTypeDefs = filteredTypeDefs.getEntityDefs().size();
-
- FilterUtil.addParamsToHideInternalType(searchFilter);
- filteredTypeDefs = typeDefStore.searchTypesDef(searchFilter);
-
- assertNotNull(filteredTypeDefs);
- assertEquals(filteredTypeDefs.getEntityDefs().size(), maxTypeDefs - 3);
- }
-
- @Test
- public void createsNewProfile() throws AtlasBaseException {
- int i = 0;
- assertSaveLoadUserProfile(i++);
- assertSaveLoadUserProfile(i);
- }
-
- @Test(dependsOnMethods = { "createsNewProfile", "savesQueryForAnNonExistentUser" }, expectedExceptions = AtlasBaseException.class)
- public void atteptsToAddAlreadyExistingQueryForAnExistingUser() throws AtlasBaseException {
- SearchParameters expectedSearchParameter = getActualSearchParameters();
-
- for (int i = 0; i < 2; i++) {
- String userName = getIndexBasedUserName(i);
-
- for (int j = 0; j < max_searches; j++) {
- String queryName = getIndexBasedQueryName(j);
- AtlasUserSavedSearch expected = getDefaultSavedSearch(userName, queryName, expectedSearchParameter);
- AtlasUserSavedSearch actual = userProfileService.addSavedSearch(expected);
-
- assertNotNull(actual);
- assertNotNull(actual.getGuid());
- assertEquals(actual.getOwnerName(), expected.getOwnerName());
- assertEquals(actual.getName(), expected.getName());
- assertEquals(actual.getSearchType(), expected.getSearchType());
- assertEquals(actual.getSearchParameters(), expected.getSearchParameters());
- }
- }
- }
-
- @Test(dependsOnMethods = { "createsNewProfile", "savesQueryForAnNonExistentUser", "atteptsToAddAlreadyExistingQueryForAnExistingUser" })
- public void savesExistingQueryForAnExistingUser() throws AtlasBaseException {
- SearchParameters expectedSearchParameter = getActualSearchParameters();
-
- for (int i = 0; i < 2; i++) {
- String userName = getIndexBasedUserName(i);
-
- for (int j = 4; j < max_searches + 6; j++) {
- String queryName = getIndexBasedQueryName(j);
- AtlasUserSavedSearch actual = userProfileService.addSavedSearch(getDefaultSavedSearch(userName, queryName, expectedSearchParameter));
- assertNotNull(actual);
-
- AtlasUserSavedSearch savedSearch = userProfileService.getSavedSearch(userName, queryName);
- assertNotNull(savedSearch);
- assertEquals(savedSearch.getSearchParameters(), expectedSearchParameter);
- }
- }
- }
-
- private SearchParameters getActualSearchParameters() {
- SearchParameters sp = new SearchParameters();
- sp.setClassification("test-classification");
- sp.setQuery("g.v().has('__guid').__guid.toList()");
- sp.setLimit(10);
- sp.setTypeName("some-type");
-
- return sp;
- }
-
- @Test(dependsOnMethods = "createsNewProfile")
- public void savesQueryForAnNonExistentUser() throws AtlasBaseException {
- String expectedUserName = getIndexBasedUserName(0);
- String expectedQueryName = "testQuery";
- SearchParameters expectedSearchParam = getActualSearchParameters();
- AtlasUserSavedSearch expectedSavedSearch = getDefaultSavedSearch(expectedUserName, expectedQueryName, expectedSearchParam);
-
- AtlasUserSavedSearch actual = userProfileService.addSavedSearch(expectedSavedSearch);
- assertEquals(actual.getOwnerName(), expectedUserName);
- assertEquals(actual.getName(), expectedQueryName);
- }
-
- private AtlasUserSavedSearch getDefaultSavedSearch(String userName, String queryName, SearchParameters expectedSearchParam) {
- return new AtlasUserSavedSearch(userName, queryName,
- BASIC, expectedSearchParam);
- }
-
- @Test(dependsOnMethods = "createsNewProfile")
- public void savesMultipleQueriesForUser() throws AtlasBaseException {
- final String userName = getIndexBasedUserName(0);
- createUserWithSavedQueries(userName);
- }
-
- private void createUserWithSavedQueries(String userName) throws AtlasBaseException {
- SearchParameters actualSearchParameter = getActualSearchParameters();
-
- saveQueries(userName, actualSearchParameter);
- for (int i = 0; i < max_searches; i++) {
- AtlasUserSavedSearch savedSearch = userProfileService.getSavedSearch(userName, getIndexBasedQueryName(i));
- assertEquals(savedSearch.getName(), getIndexBasedQueryName(i));
- assertEquals(savedSearch.getSearchParameters(), actualSearchParameter);
- }
- }
-
- private void saveQueries(String userName, SearchParameters sp) throws AtlasBaseException {
- for (int i = 0; i < max_searches; i++) {
- userProfileService.addSavedSearch(getDefaultSavedSearch(userName, getIndexBasedQueryName(i), sp));
- }
- }
-
- @Test(dependsOnMethods = {"createsNewProfile", "savesMultipleQueriesForUser"})
- public void verifyQueryNameListForUser() throws AtlasBaseException {
- final String userName = getIndexBasedUserName(0);
-
- List<AtlasUserSavedSearch> list = userProfileService.getSavedSearches(userName);
- List<String> names = getIndexBasedQueryNamesList();
- for (int i = 0; i < names.size(); i++) {
- assertTrue(names.contains(list.get(i).getName()), list.get(i).getName() + " failed!");
- }
- }
-
- @Test(dependsOnMethods = {"createsNewProfile", "savesMultipleQueriesForUser"}, enabled = false)
- public void verifyQueryConversionFromJSON() throws AtlasBaseException {
- List<AtlasUserSavedSearch> list = userProfileService.getSavedSearches("first-0");
-
- for (int i = 0; i < max_searches; i++) {
- SearchParameters sp = list.get(i).getSearchParameters();
- String json = AtlasType.toJson(sp);
- assertEquals(AtlasType.toJson(getActualSearchParameters()).replace("\n", "").replace(" ", ""), json);
- }
- }
-
- @Test(dependsOnMethods = {"createsNewProfile", "savesMultipleQueriesForUser"})
- public void updateSearch() throws AtlasBaseException {
- final String queryName = getIndexBasedQueryName(0);
- String userName = getIndexBasedUserName(0);
- AtlasUserSavedSearch expected = userProfileService.getSavedSearch(userName, queryName);
- assertNotNull(expected);
-
- SearchParameters sp = expected.getSearchParameters();
- sp.setClassification("new-classification");
-
- AtlasUserSavedSearch actual = userProfileService.updateSavedSearch(expected);
-
- assertNotNull(actual);
- assertNotNull(actual.getSearchParameters());
- assertEquals(actual.getSearchParameters().getClassification(), expected.getSearchParameters().getClassification());
- }
-
- @Test(dependsOnMethods = {"createsNewProfile", "savesMultipleQueriesForUser", "verifyQueryNameListForUser"}, expectedExceptions = AtlasBaseException.class)
- public void deleteUsingGuid() throws AtlasBaseException {
- final String queryName = getIndexBasedQueryName(1);
- String userName = getIndexBasedUserName(0);
-
- AtlasUserSavedSearch expected = userProfileService.getSavedSearch(userName, queryName);
- assertNotNull(expected);
-
- userProfileService.deleteSavedSearch(expected.getGuid());
- userProfileService.getSavedSearch(userName, queryName);
- }
-
- @Test(dependsOnMethods = {"createsNewProfile", "savesMultipleQueriesForUser", "verifyQueryNameListForUser"})
- public void deleteSavedQuery() throws AtlasBaseException {
- final String userName = getIndexBasedUserName(0);
- AtlasUserProfile expected = userProfileService.getUserProfile(userName);
- assertNotNull(expected);
-
- int new_max_searches = expected.getSavedSearches().size();
- String queryNameToBeDeleted = getIndexBasedQueryName(max_searches - 2);
- userProfileService.deleteSearchBySearchName(userName, queryNameToBeDeleted);
-
- List<AtlasUserSavedSearch> savedSearchList = userProfileService.getSavedSearches(userName);
- assertEquals(savedSearchList.size(), new_max_searches - 1);
- }
-
- @Test(dependsOnMethods = {"createsNewProfile", "savesMultipleQueriesForUser", "verifyQueryNameListForUser"})
- void deleteUser() throws AtlasBaseException {
- String userName = getIndexBasedUserName(1);
-
- userProfileService.deleteUserProfile(userName);
- try {
- userProfileService.getUserProfile(userName);
- }
- catch(AtlasBaseException ex) {
- assertEquals(ex.getAtlasErrorCode().name(), AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND.name());
- }
- }
-
- private void assertSaveLoadUserProfile(int i) throws AtlasBaseException {
- String s = String.valueOf(i);
- AtlasUserProfile expected = getAtlasUserProfile(i);
-
- AtlasUserProfile actual = userProfileService.saveUserProfile(expected);
- assertNotNull(actual);
- assertEquals(expected.getName(), actual.getName());
- assertEquals(expected.getFullName(), actual.getFullName());
- assertNotNull(actual.getGuid());
- }
-
- public static AtlasUserProfile getAtlasUserProfile(Integer s) {
- return new AtlasUserProfile(getIndexBasedUserName(s), String.format("first-%s last-%s", s, s));
- }
-
- private static String getIndexBasedUserName(Integer i) {
- return String.format("first-%s", i.toString());
- }
-
- private static String getIndexBasedQueryName(Integer i) {
- return String.format("testQuery-%s", i.toString());
- }
-
- public List<String> getIndexBasedQueryNamesList() {
- List<String> list = new ArrayList<>();
- for (int i = 0; i < max_searches; i++) {
- list.add(getIndexBasedQueryName(i));
- }
-
- return list;
- }
-}