123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- /*
- * SonarQube
- * Copyright (C) 2009-2021 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
- package org.sonar.server.platform;
-
- import java.io.File;
- import java.util.Date;
- import org.junit.Before;
- import org.junit.Test;
- import org.sonar.api.platform.Server;
- import org.sonar.api.platform.ServerStartHandler;
- import org.sonar.api.platform.ServerStopHandler;
-
- import static org.mockito.Mockito.mock;
- import static org.mockito.Mockito.never;
- import static org.mockito.Mockito.verify;
-
- public class ServerLifecycleNotifierTest {
-
- private Server server;
- private ServerStartHandler start1;
- private ServerStartHandler start2;
- private ServerStopHandler stop1;
- private ServerStopHandler stop2;
-
- @Before
- public void before() {
- server = new FakeServer();
- start1 = mock(ServerStartHandler.class);
- start2 = mock(ServerStartHandler.class);
- stop1 = mock(ServerStopHandler.class);
- stop2 = mock(ServerStopHandler.class);
- }
-
- /**
- * see the explanation in the method ServerLifecycleNotifier.start()
- */
- @Test
- public void doNotNotifyWithTheStartMethod() {
- ServerLifecycleNotifier notifier = new ServerLifecycleNotifier(server, new ServerStartHandler[]{start1, start2}, new ServerStopHandler[]{stop2});
- notifier.start();
-
- verify(start1, never()).onServerStart(server);
- verify(start2, never()).onServerStart(server);
- verify(stop1, never()).onServerStop(server);
- }
-
- @Test
- public void notifyOnStart() {
- ServerLifecycleNotifier notifier = new ServerLifecycleNotifier(server, new ServerStartHandler[]{start1, start2}, new ServerStopHandler[]{stop2});
- notifier.notifyStart();
-
- verify(start1).onServerStart(server);
- verify(start2).onServerStart(server);
- verify(stop1, never()).onServerStop(server);
- }
-
-
- @Test
- public void notifyOnStop() {
- ServerLifecycleNotifier notifier = new ServerLifecycleNotifier(server, new ServerStartHandler[]{start1, start2}, new ServerStopHandler[]{stop1, stop2});
- notifier.stop();
-
- verify(start1, never()).onServerStart(server);
- verify(start2, never()).onServerStart(server);
- verify(stop1).onServerStop(server);
- verify(stop2).onServerStop(server);
- }
- }
-
- class FakeServer extends Server {
-
- @Override
- public String getId() {
- return null;
- }
-
- @Override
- public String getVersion() {
- return null;
- }
-
- @Override
- public Date getStartedAt() {
- return null;
- }
-
- @Override
- public String getContextPath() {
- return null;
- }
-
- @Override
- public String getPublicRootUrl() {
- return null;
- }
-
- @Override
- public boolean isSecured() {
- return false;
- }
-
- @Override
- public String getPermanentServerId() {
- return null;
- }
- }
|