Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
atlas
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dataplatform
atlas
Commits
fa502b21
Commit
fa502b21
authored
9 years ago
by
Suma Shivaprasad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removing accidental file commit - GraphBackedMetadataRepositoryDeleteEntitiesTest
parent
ae1d636f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
189 deletions
+0
-189
GraphBackedMetadataRepositoryDeleteEntitiesTest.java
...raph/GraphBackedMetadataRepositoryDeleteEntitiesTest.java
+0
-189
No files found.
repository/src/test/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepositoryDeleteEntitiesTest.java
deleted
100644 → 0
View file @
ae1d636f
/**
* 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
.
graph
;
import
java.util.ArrayList
;
import
java.util.List
;
import
javax.inject.Inject
;
import
org.apache.atlas.RepositoryMetadataModule
;
import
org.apache.atlas.TestUtils
;
import
org.apache.atlas.discovery.graph.GraphBackedDiscoveryService
;
import
org.apache.atlas.repository.Constants
;
import
org.apache.atlas.repository.RepositoryException
;
import
org.apache.atlas.typesystem.ITypedReferenceableInstance
;
import
org.apache.atlas.typesystem.Referenceable
;
import
org.apache.atlas.typesystem.exception.EntityNotFoundException
;
import
org.apache.atlas.typesystem.types.ClassType
;
import
org.apache.atlas.typesystem.types.Multiplicity
;
import
org.apache.atlas.typesystem.types.TypeSystem
;
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
com.thinkaurelius.titan.core.TitanGraph
;
import
com.thinkaurelius.titan.core.util.TitanCleanup
;
import
com.tinkerpop.blueprints.Vertex
;
/**
* Test for GraphBackedMetadataRepository.deleteEntities
*
* Guice loads the dependencies and injects the necessary objects
*
*/
@Guice
(
modules
=
RepositoryMetadataModule
.
class
)
public
class
GraphBackedMetadataRepositoryDeleteEntitiesTest
{
@Inject
private
GraphProvider
<
TitanGraph
>
graphProvider
;
@Inject
private
GraphBackedMetadataRepository
repositoryService
;
@Inject
private
GraphBackedDiscoveryService
discoveryService
;
private
TypeSystem
typeSystem
;
@BeforeClass
public
void
setUp
()
throws
Exception
{
typeSystem
=
TypeSystem
.
getInstance
();
typeSystem
.
reset
();
new
GraphBackedSearchIndexer
(
graphProvider
);
TestUtils
.
defineDeptEmployeeTypes
(
typeSystem
);
TestUtils
.
createHiveTypes
(
typeSystem
);
}
@AfterClass
public
void
tearDown
()
throws
Exception
{
TypeSystem
.
getInstance
().
reset
();
try
{
graphProvider
.
get
().
shutdown
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
try
{
TitanCleanup
.
clear
(
graphProvider
.
get
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
@Test
public
void
testDeleteEntities
()
throws
Exception
{
String
hrDeptGuid
=
createHrDeptGraph
();
ITypedReferenceableInstance
hrDept
=
repositoryService
.
getEntityDefinition
(
hrDeptGuid
);
Object
refValue
=
hrDept
.
get
(
"employees"
);
Assert
.
assertTrue
(
refValue
instanceof
List
);
List
<
Object
>
employees
=
(
List
<
Object
>)
refValue
;
Assert
.
assertEquals
(
employees
.
size
(),
4
);
List
<
String
>
employeeGuids
=
new
ArrayList
<
String
>(
4
);
for
(
Object
listValue
:
employees
)
{
Assert
.
assertTrue
(
listValue
instanceof
ITypedReferenceableInstance
);
ITypedReferenceableInstance
employee
=
(
ITypedReferenceableInstance
)
listValue
;
employeeGuids
.
add
(
employee
.
getId
().
_getId
());
}
// There should be 4 vertices for Address structs (one for each Person.address attribute value).
int
vertexCount
=
countVertices
(
Constants
.
ENTITY_TYPE_PROPERTY_KEY
,
"Address"
);
Assert
.
assertEquals
(
vertexCount
,
4
);
vertexCount
=
countVertices
(
Constants
.
ENTITY_TYPE_PROPERTY_KEY
,
"SecurityClearance"
);
Assert
.
assertEquals
(
vertexCount
,
1
);
List
<
String
>
deletedEntities
=
repositoryService
.
deleteEntities
(
hrDeptGuid
);
Assert
.
assertTrue
(
deletedEntities
.
contains
(
hrDeptGuid
));
// Verify Department entity and its contained Person entities were deleted.
verifyEntityDoesNotExist
(
hrDeptGuid
);
for
(
String
employeeGuid
:
employeeGuids
)
{
verifyEntityDoesNotExist
(
employeeGuid
);
}
// Verify all Person.address struct vertices were removed.
vertexCount
=
countVertices
(
Constants
.
ENTITY_TYPE_PROPERTY_KEY
,
"Address"
);
Assert
.
assertEquals
(
vertexCount
,
0
);
// Verify all SecurityClearance trait vertices were removed.
vertexCount
=
countVertices
(
Constants
.
ENTITY_TYPE_PROPERTY_KEY
,
"SecurityClearance"
);
Assert
.
assertEquals
(
vertexCount
,
0
);
}
@Test
(
dependsOnMethods
=
"testDeleteEntities"
)
public
void
testDeleteContainedEntity
()
throws
Exception
{
String
hrDeptGuid
=
createHrDeptGraph
();
ITypedReferenceableInstance
hrDept
=
repositoryService
.
getEntityDefinition
(
hrDeptGuid
);
Object
refValue
=
hrDept
.
get
(
"employees"
);
Assert
.
assertTrue
(
refValue
instanceof
List
);
List
<
Object
>
employees
=
(
List
<
Object
>)
refValue
;
Assert
.
assertEquals
(
employees
.
size
(),
4
);
Object
listValue
=
employees
.
get
(
2
);
Assert
.
assertTrue
(
listValue
instanceof
ITypedReferenceableInstance
);
ITypedReferenceableInstance
employee
=
(
ITypedReferenceableInstance
)
listValue
;
String
employeeGuid
=
employee
.
getId
().
_getId
();
List
<
String
>
deletedEntities
=
repositoryService
.
deleteEntities
(
employeeGuid
);
Assert
.
assertTrue
(
deletedEntities
.
contains
(
employeeGuid
));
verifyEntityDoesNotExist
(
employeeGuid
);
}
private
String
createHrDeptGraph
()
throws
Exception
{
Referenceable
deptEg1
=
TestUtils
.
createDeptEg1
(
typeSystem
);
ClassType
deptType
=
typeSystem
.
getDataType
(
ClassType
.
class
,
"Department"
);
ITypedReferenceableInstance
hrDept2
=
deptType
.
convert
(
deptEg1
,
Multiplicity
.
REQUIRED
);
List
<
String
>
guids
=
repositoryService
.
createEntities
(
hrDept2
);
Assert
.
assertNotNull
(
guids
);
Assert
.
assertEquals
(
guids
.
size
(),
5
);
List
<
String
>
entityList
=
repositoryService
.
getEntityList
(
"Department"
);
Assert
.
assertNotNull
(
entityList
);
Assert
.
assertEquals
(
entityList
.
size
(),
1
);
String
hrDeptGuid
=
entityList
.
get
(
0
);
return
hrDeptGuid
;
}
private
int
countVertices
(
String
propertyName
,
Object
value
)
{
Iterable
<
Vertex
>
vertices
=
graphProvider
.
get
().
getVertices
(
propertyName
,
value
);
int
vertexCount
=
0
;
for
(
Vertex
vertex
:
vertices
)
{
vertexCount
++;
}
return
vertexCount
;
}
private
void
verifyEntityDoesNotExist
(
String
hrDeptGuid
)
throws
RepositoryException
{
try
{
repositoryService
.
getEntityDefinition
(
hrDeptGuid
);
Assert
.
fail
(
"EntityNotFoundException was expected but none thrown"
);
}
catch
(
EntityNotFoundException
e
)
{
// good
}
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment