001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.resiliency.spi;
016    
017    import com.liferay.portal.kernel.nio.intraband.RegistrationReference;
018    import com.liferay.portal.kernel.resiliency.mpi.MPI;
019    import com.liferay.portal.kernel.resiliency.spi.agent.SPIAgent;
020    
021    import java.rmi.RemoteException;
022    
023    /**
024     * @author Shuyang Zhou
025     */
026    public class MockSPI implements SPI {
027    
028            @Override
029            public void addServlet(
030                    String contextPath, String docBasePath, String mappingPattern,
031                    String servletClassName) {
032    
033                    throw new UnsupportedOperationException();
034            }
035    
036            @Override
037            public void addWebapp(String contextPath, String docBasePath) {
038                    throw new UnsupportedOperationException();
039            }
040    
041            @Override
042            public void destroy() throws RemoteException {
043                    if (failOnDestroy) {
044                            throw new RemoteException();
045                    }
046    
047                    destroyed = true;
048            }
049    
050            @Override
051            public MPI getMPI() {
052                    return mpi;
053            }
054    
055            @Override
056            public RegistrationReference getRegistrationReference()
057                    throws RemoteException {
058    
059                    if (registrationReference == null) {
060                            throw new RemoteException();
061                    }
062    
063                    return registrationReference;
064            }
065    
066            @Override
067            public SPIAgent getSPIAgent() {
068                    throw new UnsupportedOperationException();
069            }
070    
071            @Override
072            public SPIConfiguration getSPIConfiguration() throws RemoteException {
073                    if (failOnGetConfiguration) {
074                            throw new RemoteException();
075                    }
076    
077                    return spiConfiguration;
078            }
079    
080            @Override
081            public String getSPIProviderName() {
082                    return spiProviderName;
083            }
084    
085            @Override
086            public void init() {
087                    throw new UnsupportedOperationException();
088            }
089    
090            @Override
091            public boolean isAlive() throws RemoteException {
092                    if (failOnIsAlive) {
093                            throw new RemoteException();
094                    }
095    
096                    return true;
097            }
098    
099            @Override
100            public void start() {
101                    throw new UnsupportedOperationException();
102            }
103    
104            @Override
105            public void stop() throws RemoteException {
106                    if (failOnStop) {
107                            throw new RemoteException();
108                    }
109    
110                    stopped = true;
111            }
112    
113            public boolean destroyed;
114            public boolean failOnDestroy;
115            public boolean failOnGetConfiguration;
116            public boolean failOnIsAlive;
117            public boolean failOnStop;
118            public MPI mpi;
119            public RegistrationReference registrationReference;
120            public SPIConfiguration spiConfiguration;
121            public String spiProviderName;
122            public boolean stopped;
123    
124    }