org.miniclient.mock.MockApiUserClient Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of miniclient-core-mock Show documentation
Show all versions of miniclient-core-mock Show documentation
Universal REST API client library in Java. Core-Mock Module
package org.miniclient.mock;
import java.io.IOException;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.miniclient.ApiServiceClient;
import org.miniclient.ApiUserClient;
import org.miniclient.RestApiException;
import org.miniclient.credential.UserCredential;
import org.miniclient.impl.AbstractApiUserClient;
import org.miniclient.maker.ApiUserClientMaker;
import org.miniclient.maker.mock.MockApiUserClientMaker;
import org.miniclient.proxy.DecoratedApiUserClient;
// "Mock" object
// We have a very strange "dual" implementation.
// We use either inheritance or decoration, based on how the object is constructed.
public class MockApiUserClient extends AbstractApiUserClient implements DecoratedApiUserClient, Serializable
{
private static final Logger log = Logger.getLogger(MockApiUserClient.class.getName());
private static final long serialVersionUID = 1L;
private final ApiUserClient decoratedClient;
// Based on the use of a particular ctor,
// we use either inheritance or decoration.
public MockApiUserClient(String resourceBaseUrl)
{
this(resourceBaseUrl, null);
}
public MockApiUserClient(String resourceBaseUrl, UserCredential userCredential)
{
super(resourceBaseUrl, userCredential);
this.decoratedClient = null;
}
public MockApiUserClient(ApiServiceClient apiServiceClient)
{
this(apiServiceClient, null);
}
public MockApiUserClient(ApiServiceClient apiServiceClient,
UserCredential userCredential)
{
super(apiServiceClient, userCredential);
this.decoratedClient = null;
}
public MockApiUserClient(ApiUserClient decoratedClient)
{
super((String) null);
this.decoratedClient = decoratedClient;
}
// Factory methods
@Override
protected ApiUserClientMaker makeApiUserClientMaker()
{
return MockApiUserClientMaker.getInstance();
}
// Override methods.
// Note the unusual "dual" delegation.
@Override
public Object get(String id) throws RestApiException, IOException
{
if(log.isLoggable(Level.FINE)) log.fine("MockApiUserClient.get(): id = " + id);
if(decoratedClient != null) {
return decoratedClient.get(id);
} else {
return super.get(id);
}
}
@Override
public List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy