Changeset 705


Ignore:
Timestamp:
May 8, 2012, 2:13:22 PM (5 years ago)
Author:
mark9630@…
Message:

more unit tests for TripleStorageServiceImpl?

Location:
trunk/code/conceptwiki/storage/storage-neo4j/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/code/conceptwiki/storage/storage-neo4j/src/main/java/nl/nbic/conceptwiki/storage/neo4j/impl/TripleStorageServiceImpl.java

    r702 r705  
    1919import org.neo4j.graphdb.index.Index;
    2020
    21 import org.slf4j.Logger; 
     21import org.slf4j.Logger;
    2222import org.slf4j.LoggerFactory;
    2323
  • trunk/code/conceptwiki/storage/storage-neo4j/src/test/java/nl/nbic/conceptwiki/storage/neo4j/impl/TripleStorageServiceImplTest.java

    r703 r705  
    66import static org.junit.Assert.assertNotNull;
    77import static org.junit.Assert.assertNull;
     8
     9import java.util.NoSuchElementException;
     10
     11import javax.inject.Inject;
     12import javax.management.relation.RelationType;
     13import javax.validation.constraints.AssertTrue;
     14
    815import nl.nbic.conceptwiki.common.api.Triple;
     16import nl.nbic.conceptwiki.common.impl.QueryScopeImpl;
     17import nl.nbic.conceptwiki.common.util.CommonTestObjects;
    918import nl.nbic.conceptwiki.storage.neo4j.GraphTemplate;
     19import nl.nbic.conceptwiki.storage.neo4j.NodeTransformer;
    1020import nl.nbic.conceptwiki.storage.neo4j.NodePropertyKeys;
    1121
     
    1626import org.mockito.Mockito;
    1727import org.mockito.runners.MockitoJUnitRunner;
     28import org.neo4j.graphdb.Direction;
    1829import org.neo4j.graphdb.Node;
     30import org.neo4j.graphdb.NotFoundException;
     31import org.neo4j.graphdb.Relationship;
    1932import org.neo4j.graphdb.index.Index;
    2033import org.neo4j.graphdb.index.IndexHits;
     
    3649
    3750    @Mock
     51    private NodeTransformer transformer;
     52   
     53    @Mock
     54    private Relationship relationship;
     55   
     56    @Mock
    3857    private IndexHits<Node> indexHits;
    39 
     58   
    4059    @Mock
    4160    private Node node;
     
    94113    @Test
    95114    public void testGetTriple() {
    96         // Mockito.when(tripleStorageService.getTripleNode()).
     115        final int[] someBranches = {1,3,4};
     116        Mockito.when(tripleIndex.get(Mockito.anyString(), Mockito.anyString())).thenReturn(indexHits);
     117        Mockito.when(indexHits.getSingle()).thenReturn(node);
     118        Mockito.when(node.getProperty(Mockito.anyString())).thenReturn(someBranches);
     119
     120        Mockito.when(node.getSingleRelationship(nl.nbic.conceptwiki.storage.neo4j.RelationType.HAS_SUBJECT, Direction.OUTGOING)).thenReturn(relationship);
     121        Mockito.when(node.getSingleRelationship(nl.nbic.conceptwiki.storage.neo4j.RelationType.HAS_PREDICATE, Direction.OUTGOING)).thenReturn(relationship);
     122        Mockito.when(node.getSingleRelationship(nl.nbic.conceptwiki.storage.neo4j.RelationType.HAS_OBJECT, Direction.OUTGOING)).thenReturn(relationship);
     123        Mockito.when(relationship.getEndNode()).thenReturn(node);
     124        Mockito.when(transformer.toConcept(node, QueryScopeImpl.LITE_SCOPE)).thenReturn(CONCEPT_A).thenReturn(CONCEPT_B).thenReturn(CONCEPT_C);
     125       
     126        Triple result = tripleStorageService.getTriple(CommonTestObjects.NONEXISTENT_UUID, TEST_BRANCH);
     127
     128        assertNotNull(result);
     129        assert(result.getSubject().equals(CONCEPT_A));
     130        assert(result.getPredicate().equals(CONCEPT_C));
     131        assert(result.getObject().equals(CONCEPT_C));
    97132    }
     133   
     134    @Test
     135    public void testGetTripleNotInBranch() {
     136        final int[] someBranches = {1,3,4};
     137        final int WRONG_BRANCH = 2;
     138        Mockito.when(tripleIndex.get(Mockito.anyString(), Mockito.anyString())).thenReturn(indexHits);
     139        Mockito.when(indexHits.getSingle()).thenReturn(node);
     140        Mockito.when(node.getProperty(Mockito.anyString())).thenReturn(someBranches);
     141
     142        Mockito.when(node.getSingleRelationship(nl.nbic.conceptwiki.storage.neo4j.RelationType.HAS_SUBJECT, Direction.OUTGOING)).thenReturn(relationship);
     143        Mockito.when(node.getSingleRelationship(nl.nbic.conceptwiki.storage.neo4j.RelationType.HAS_PREDICATE, Direction.OUTGOING)).thenReturn(relationship);
     144        Mockito.when(node.getSingleRelationship(nl.nbic.conceptwiki.storage.neo4j.RelationType.HAS_OBJECT, Direction.OUTGOING)).thenReturn(relationship);
     145        Mockito.when(relationship.getEndNode()).thenReturn(node);
     146        Mockito.when(transformer.toConcept(node, QueryScopeImpl.LITE_SCOPE)).thenReturn(CONCEPT_A).thenReturn(CONCEPT_B).thenReturn(CONCEPT_C);
     147       
     148        Triple result = tripleStorageService.getTriple(CommonTestObjects.NONEXISTENT_UUID, WRONG_BRANCH);
     149
     150        assertNull(result);
     151    }
     152   
     153    @Test(expected = NoSuchElementException.class)
     154    public void testGetTripleThatDoesntExist() {
     155        Mockito.when(tripleIndex.get(Mockito.anyString(), Mockito.anyString())).thenReturn(indexHits);
     156        Mockito.when(indexHits.getSingle()).thenThrow(new NoSuchElementException());
     157
     158        tripleStorageService.getTriple(CommonTestObjects.NONEXISTENT_UUID, TEST_BRANCH);
     159    }
     160=======
    98161
    99162    @Test
     
    112175        tripleStorageService.deleteTriple(uuid, "Please do try this at home.", TEST_BRANCH);
    113176    }
     177>>>>>>> .r704
    114178}
Note: See TracChangeset for help on using the changeset viewer.