1/*
2 * Copyright 2009 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.mockftpserver.stub
17
18import org.mockftpserver.test.AbstractGroovyTest
19import org.apache.commons.net.ftp.FTPClient
20import org.mockftpserver.test.PortTestUtil
21
22/**
23 * Integration tests for restart of an StubFtpServer.
24 *
25 * @version $Revision$ - $Date$
26 *
27 * @author Chris Mair
28 */
29class StubFtpServer_RestartTest extends AbstractGroovyTest {
30    static final SERVER = "localhost"
31    private stubFtpServer
32    private ftpClient
33
34    void testRestart() {
35        stubFtpServer.start()
36        ftpClient.connect(SERVER, PortTestUtil.getFtpServerControlPort())
37        assert ftpClient.changeWorkingDirectory("dir1")
38
39        stubFtpServer.stop()
40        LOG.info("Restarting...")
41
42        stubFtpServer.start()
43        ftpClient.connect(SERVER, PortTestUtil.getFtpServerControlPort())
44        assert ftpClient.changeWorkingDirectory("dir1")
45    }
46
47    void setUp() {
48        super.setUp()
49        stubFtpServer = new StubFtpServer()
50        stubFtpServer.setServerControlPort(PortTestUtil.getFtpServerControlPort())
51        ftpClient = new FTPClient()
52    }
53
54    void tearDown() {
55        super.tearDown()
56        stubFtpServer.stop()
57    }
58}