Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Remove PowerMock
  • Loading branch information
cbeer authored and Andrew Woods committed Sep 24, 2014
1 parent 3bfc11f commit 8c0f022
Show file tree
Hide file tree
Showing 20 changed files with 140 additions and 204 deletions.
5 changes: 5 additions & 0 deletions fcrepo-auth-common/pom.xml
Expand Up @@ -128,6 +128,11 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
4 changes: 4 additions & 0 deletions fcrepo-generator-dc/pom.xml
Expand Up @@ -94,6 +94,10 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
Expand Down
Expand Up @@ -30,24 +30,16 @@
import com.google.common.collect.ImmutableMap;
import org.fcrepo.kernel.identifiers.PidMinter;
import org.fcrepo.kernel.services.NodeService;
import org.fcrepo.kernel.utils.NamespaceTools;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.modeshape.jcr.api.NamespaceRegistry;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

/**
* <p>AbstractResourceTest class.</p>
*
* @author awoods
*/
@RunWith(PowerMockRunner.class)
@PowerMockIgnore({"org.slf4j.*", "javax.xml.parsers.*", "org.apache.xerces.*"})
@PrepareForTest({NamespaceTools.class})
public class AbstractResourceTest {

private AbstractResource testObj;
Expand Down
4 changes: 4 additions & 0 deletions fcrepo-jms/pom.xml
Expand Up @@ -118,6 +118,10 @@
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Expand Up @@ -48,11 +48,16 @@ public class ExternalContentServiceImpl implements ExternalContentService {
@Override
public InputStream retrieveExternalContent(final URI sourceUri) throws IOException {
final HttpGet httpGet = new HttpGet(sourceUri);
final CloseableHttpClient client = HttpClients.createMinimal(connManager);
final CloseableHttpClient client = getCloseableHttpClient();
final HttpResponse response = client.execute(httpGet);
return response.getEntity().getContent();
}

@VisibleForTesting
protected CloseableHttpClient getCloseableHttpClient() {
return HttpClients.createMinimal(connManager);
}

@VisibleForTesting
protected void setConnManager(final HttpClientConnectionManager connManager) {
this.connManager = connManager;
Expand Down
Expand Up @@ -318,8 +318,8 @@ public static NodeTypeManager getNodeTypeManager(final Node node) throws Reposit
public static PropertyDefinition getDefinitionForPropertyName(final Node node,
final String propertyName) throws RepositoryException {

final PropertyDefinition[] propertyDefinitions =
node.getPrimaryNodeType().getPropertyDefinitions();
final NodeType primaryNodeType = node.getPrimaryNodeType();
final PropertyDefinition[] propertyDefinitions = primaryNodeType.getPropertyDefinitions();
LOGGER.debug("Looking for property name: {}", propertyName);
for (final PropertyDefinition p : propertyDefinitions) {
LOGGER.debug("Checking property: {}", p.getName());
Expand Down
Expand Up @@ -29,6 +29,7 @@
import javax.jcr.Session;
import javax.jcr.Value;

import com.google.common.annotations.VisibleForTesting;
import com.hp.hpl.jena.rdf.model.AnonId;
import org.apache.commons.lang.StringUtils;
import org.fcrepo.kernel.RdfLexicon;
Expand Down Expand Up @@ -80,7 +81,25 @@ public class JcrPropertyStatementListener extends StatementListener {
*/
public static JcrPropertyStatementListener getListener(
final IdentifierTranslator subjects, final Session session, final Model problemModel) {
return new JcrPropertyStatementListener(subjects, session, problemModel);
return new JcrPropertyStatementListener(subjects,
session,
problemModel,
JcrRdfTools.withContext(subjects, session));
}

/**
* Return a Listener given the subject factory and JcrSession.
* @param subjects
* @param session
* @param problemModel
* @return JcrPropertyStatementListener for the given subject factory and JcrSession
*/
@VisibleForTesting
public static JcrPropertyStatementListener getListener(final IdentifierTranslator subjects,
final Session session,
final Model problemModel,
final JcrRdfTools tools) {
return new JcrPropertyStatementListener(subjects, session, problemModel, tools);
}

/**
Expand All @@ -90,12 +109,12 @@ public static JcrPropertyStatementListener getListener(
* @param session
*/
private JcrPropertyStatementListener(final IdentifierTranslator subjects,
final Session session, final Model problems) {
final Session session, final Model problems, final JcrRdfTools tools) {
super();
this.session = session;
this.subjects = subjects;
this.problems = problems;
this.jcrRdfTools = JcrRdfTools.withContext(subjects, session);
this.jcrRdfTools = tools;
this.skolemizedBnodeMap = new HashMap<>();
}

Expand Down
Expand Up @@ -33,15 +33,10 @@

import org.fcrepo.jcr.FedoraJcrTypes;
import org.fcrepo.kernel.FedoraObject;
import org.fcrepo.kernel.impl.services.ServiceHelpers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import com.google.common.base.Predicate;

Expand All @@ -50,9 +45,6 @@
*
* @author ksclarke
*/
@RunWith(PowerMockRunner.class)
@PowerMockIgnore({"org.slf4j.*", "javax.xml.parsers.*", "org.apache.xerces.*"})
@PrepareForTest({ServiceHelpers.class})
public class FedoraObjectImplTest implements FedoraJcrTypes {

private static final String testPid = "testObj";
Expand Down
Expand Up @@ -22,7 +22,6 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.powermock.api.mockito.PowerMockito.mockStatic;

import java.io.InputStream;
import java.net.URI;
Expand All @@ -38,31 +37,21 @@
import org.fcrepo.jcr.FedoraJcrTypes;
import org.fcrepo.kernel.FedoraBinary;
import org.fcrepo.kernel.rdf.IdentifierTranslator;
import org.fcrepo.kernel.impl.rdf.JcrRdfTools;
import org.fcrepo.kernel.services.DatastreamService;
import org.fcrepo.kernel.utils.CacheEntry;
import org.fcrepo.kernel.utils.FixityResult;
import org.fcrepo.kernel.impl.utils.impl.CacheEntryFactory;
import org.fcrepo.kernel.utils.iterators.RdfStream;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.modeshape.jcr.api.ValueFactory;
import org.modeshape.jcr.value.binary.StoredBinaryValue;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

/**
* <p>DatastreamServiceImplTest class.</p>
*
* @author ksclarke
*/
@RunWith(PowerMockRunner.class)
@PowerMockIgnore({"org.slf4j.*", "org.apache.xerces.*", "javax.xml.*",
"org.xml.sax.*", "javax.management.*"})
@PrepareForTest({JcrRdfTools.class, CacheEntryFactory.class})
public class DatastreamServiceImplTest implements FedoraJcrTypes {

private static final String MOCK_CONTENT_TYPE = "application/test-data";
Expand Down Expand Up @@ -140,9 +129,6 @@ public void testGetDatastream() throws Exception {

@Test
public void testGetFixityResultsModel() throws Exception {
mockStatic(CacheEntryFactory.class);


final IdentifierTranslator mockSubjects = mock(IdentifierTranslator.class);
when(mockSubjects.getSubject(mockNode.getPath())).thenReturn(createResource("abc"));

Expand All @@ -155,14 +141,12 @@ public void testGetFixityResultsModel() throws Exception {
when(mockNode.getNode(JCR_CONTENT)).thenReturn(mockContent);
when(mockContent.getProperty(JCR_DATA)).thenReturn(mockProperty);
when(mockProperty.getBinary()).thenReturn(mockBinary);
when(mockFedoraBinary.getFixity(mockRepository, "SHA-1")).thenReturn(fixityResults);

when(mockFedoraBinary.getNode()).thenReturn(mockNode);
when(mockFedoraBinary.getContentDigest()).thenReturn(
new URI("urn:sha1:abc"));

when(CacheEntryFactory.forProperty(mockRepository, mockProperty)).thenReturn(mockCacheEntry);

when(mockCacheEntry.checkFixity(any(String.class))).thenReturn(fixityResults);

final RdfStream actual = testObj.getFixityResultsModel(mockSubjects, mockFedoraBinary);

Expand Down
Expand Up @@ -15,12 +15,11 @@
*/
package org.fcrepo.kernel.impl.services;

import static org.apache.http.impl.client.HttpClients.createMinimal;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
import static org.powermock.api.mockito.PowerMockito.when;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -31,22 +30,14 @@
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.HttpClientConnectionManager;
import org.apache.http.impl.client.HttpClients;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;


/**
* @author cabeer
*/
@RunWith(PowerMockRunner.class)
@PowerMockIgnore({"org.slf4j.*", "javax.xml.parsers.*", "org.apache.xerces.*"})
@PrepareForTest({HttpClients.class})
public class ExternalContentServiceImplTest {

private ExternalContentServiceImpl testObj;
Expand All @@ -72,11 +63,10 @@ public class ExternalContentServiceImplTest {
public void setUp() throws URISyntaxException, IOException {
initMocks(this);
sourceUri = new URI("http://localhost:8080/xyz");
testObj = new ExternalContentServiceImpl();
testObj = spy(new ExternalContentServiceImpl());
testObj.setConnManager(mockClientPool);

mockStatic(HttpClients.class);
when(createMinimal(mockClientPool)).thenReturn(mockClient);
when(testObj.getCloseableHttpClient()).thenReturn(mockClient);
when(mockClient.execute(any(HttpGet.class))).thenReturn(mockResponse);
when(mockResponse.getEntity()).thenReturn(mockEntity);
when(mockEntity.getContent()).thenReturn(mockInputStream);
Expand Down
Expand Up @@ -22,16 +22,13 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.modeshape.jcr.api.JcrConstants.JCR_PATH;
import static org.powermock.api.mockito.PowerMockito.mockStatic;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -55,17 +52,11 @@

import org.fcrepo.jcr.FedoraJcrTypes;
import org.fcrepo.kernel.rdf.IdentifierTranslator;
import org.fcrepo.kernel.impl.rdf.JcrRdfTools;
import org.fcrepo.kernel.services.RepositoryService;
import org.fcrepo.kernel.utils.iterators.RdfStream;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.modeshape.jcr.api.NamespaceRegistry;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.rdf.model.Resource;
Expand All @@ -75,11 +66,6 @@
*
* @author ksclarke
*/
@RunWith(PowerMockRunner.class)
// PowerMock needs to ignore some packages to prevent class-cast errors
@PowerMockIgnore({"org.slf4j.*", "org.apache.xerces.*", "javax.xml.*",
"org.xml.sax.*", "javax.management.*"})
@PrepareForTest({JcrRdfTools.class})
public class RepositoryServiceImplTest implements FedoraJcrTypes {

private static final String TESTPID = "testObj";
Expand Down Expand Up @@ -211,9 +197,6 @@ public void testGetRepositoryObjectCount() {
}

private void setupSearchRepository() throws RepositoryException {
mockStatic(JcrRdfTools.class);
final JcrRdfTools mockJcrRdfTools = mock(JcrRdfTools.class);
when(JcrRdfTools.withContext(mockSubjectFactory, mockSession)).thenReturn(mockJcrRdfTools);

subject = createResource(RESTAPI_NAMESPACE + "search/request");

Expand All @@ -227,9 +210,6 @@ private void setupSearchRepository() throws RepositoryException {
when(mockQueryResult.getNodes()).thenReturn(mockNI);
when(mockNI.getSize()).thenReturn(500L);
when(mockNI.next()).thenReturn("");
when(mockJcrRdfTools.getJcrPropertiesModel(
any(org.fcrepo.kernel.utils.iterators.NodeIterator.class),
eq(subject))).thenReturn(new RdfStream());
}

@Test
Expand Down

0 comments on commit 8c0f022

Please sign in to comment.