Skip to content

Commit

Permalink
start moving Function unit tests out
Browse files Browse the repository at this point in the history
  • Loading branch information
barmintor committed Apr 3, 2013
1 parent 115fb79 commit d4a6902
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 17 deletions.
Expand Up @@ -4,9 +4,7 @@
import static org.modeshape.jcr.api.JcrConstants.JCR_DATA;

import javax.jcr.Node;
import javax.jcr.PathNotFoundException;
import javax.jcr.RepositoryException;
import javax.jcr.ValueFormatException;

import org.modeshape.jcr.value.BinaryKey;
import org.modeshape.jcr.value.BinaryValue;
Expand Down
Expand Up @@ -113,21 +113,6 @@ public void testGetBinaryBlobs() throws RepositoryException {
assertEquals("foo", actual.iterator().next().getExternalIdentifier());
}

@Test
public void testGetBinaryStore() throws LoginException, RepositoryException {
//TODO Now that this has been refactored into a Function, break the test case out
JcrRepository mockRepo = mock(JcrRepository.class);
JcrSession mockSession = mock(JcrSession.class);
RepositoryConfiguration mockConfig = mock(RepositoryConfiguration.class);
BinaryStorage mockBinStorage = mock(BinaryStorage.class);
when(mockConfig.getBinaryStorage()).thenReturn(mockBinStorage);
when(mockRepo.getConfiguration()).thenReturn(mockConfig);
when(mockSession.getRepository()).thenReturn(mockRepo);
when(mockRepo.login()).thenReturn(mockSession);
GetBinaryStore testObj = new GetBinaryStore();
testObj.apply(mockRepo);
}

@Test
public void testGetSession() throws LoginException, RepositoryException {
Repository mockRepo = mock(Repository.class);
Expand Down
@@ -0,0 +1,31 @@
package org.fcrepo.services.functions;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.modeshape.jcr.api.JcrConstants.JCR_CONTENT;
import static org.modeshape.jcr.api.JcrConstants.JCR_DATA;

import javax.jcr.LoginException;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;

import org.junit.Test;
import org.modeshape.jcr.value.BinaryValue;

public class GetBinaryKeyTest {

@Test
public void testApply() throws LoginException, RepositoryException {
Node mockNode = mock(Node.class);
Node mockContent = mock(Node.class);
Property mockProp = mock(Property.class);
BinaryValue mockBin = mock(BinaryValue.class);
when(mockProp.getBinary()).thenReturn(mockBin);
when(mockContent.getProperty(JCR_DATA)).thenReturn(mockProp);
when(mockNode.getNode(JCR_CONTENT)).thenReturn(mockContent);
GetBinaryKey testObj = new GetBinaryKey();
testObj.apply(mockNode);
}

}
@@ -0,0 +1,31 @@
package org.fcrepo.services.functions;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import javax.jcr.LoginException;
import javax.jcr.RepositoryException;

import org.junit.Test;
import org.modeshape.jcr.JcrRepository;
import org.modeshape.jcr.JcrSession;
import org.modeshape.jcr.RepositoryConfiguration;
import org.modeshape.jcr.RepositoryConfiguration.BinaryStorage;

public class GetBinaryStoreTest {

@Test
public void testApply() throws LoginException, RepositoryException {
JcrRepository mockRepo = mock(JcrRepository.class);
JcrSession mockSession = mock(JcrSession.class);
RepositoryConfiguration mockConfig = mock(RepositoryConfiguration.class);
BinaryStorage mockBinStorage = mock(BinaryStorage.class);
when(mockConfig.getBinaryStorage()).thenReturn(mockBinStorage);
when(mockRepo.getConfiguration()).thenReturn(mockConfig);
when(mockSession.getRepository()).thenReturn(mockRepo);
when(mockRepo.login()).thenReturn(mockSession);
GetBinaryStore testObj = new GetBinaryStore();
testObj.apply(mockRepo);
}

}
@@ -0,0 +1,42 @@
package org.fcrepo.services.functions;

import static org.mockito.Mockito.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import javax.jcr.LoginException;
import javax.jcr.RepositoryException;

import org.infinispan.AdvancedCache;
import org.infinispan.Cache;
import org.infinispan.factories.ComponentRegistry;
import org.infinispan.factories.GlobalComponentRegistry;
import org.infinispan.factories.components.ComponentMetadata;
import org.infinispan.factories.components.ComponentMetadataRepo;
import org.infinispan.loaders.CacheLoaderManager;
import org.infinispan.loaders.CacheStore;
import org.junit.Test;

public class GetCacheStoreTest {

@Test
public void testApply() throws LoginException, RepositoryException {
Cache<?, ?> mockCache = mock(Cache.class);
AdvancedCache mockAC = mock(AdvancedCache.class);
GlobalComponentRegistry mockG = mock(GlobalComponentRegistry.class);
ComponentMetadataRepo mockCMR = mock(ComponentMetadataRepo.class);
when(mockG.getComponentMetadataRepo()).thenReturn(mockCMR);
ComponentRegistry mockCR = null; //new ComponentRegistry("foo", null, mockAC, mockG, getClass().getClassLoader());
ComponentMetadata mockMD = mock(ComponentMetadata.class);
when(mockCMR.findComponentMetadata(any(Class.class))).thenReturn(mockMD);
CacheLoaderManager mockCLM = mock(CacheLoaderManager.class);
CacheStore mockStore = mock(CacheStore.class);
when(mockCLM.getCacheStore()).thenReturn(mockStore);
//when(mockCR.getComponent(CacheLoaderManager.class)).thenReturn(mockCLM);
when(mockAC.getComponentRegistry()).thenReturn(mockCR);
when(mockCache.getAdvancedCache()).thenReturn(mockAC);
GetCacheStore testObj = new GetCacheStore();
//testObj.apply(mockCache);
}

}

0 comments on commit d4a6902

Please sign in to comment.