1dfb59d50631968ab1a13002ea5421ece93169851chrismair/*
2dfb59d50631968ab1a13002ea5421ece93169851chrismair * Copyright 2010 the original author or authors.
3dfb59d50631968ab1a13002ea5421ece93169851chrismair *
4dfb59d50631968ab1a13002ea5421ece93169851chrismair * Licensed under the Apache License, Version 2.0 (the "License");
5dfb59d50631968ab1a13002ea5421ece93169851chrismair * you may not use this file except in compliance with the License.
6dfb59d50631968ab1a13002ea5421ece93169851chrismair * You may obtain a copy of the License at
7dfb59d50631968ab1a13002ea5421ece93169851chrismair *
8dfb59d50631968ab1a13002ea5421ece93169851chrismair *      http://www.apache.org/licenses/LICENSE-2.0
9dfb59d50631968ab1a13002ea5421ece93169851chrismair *
10dfb59d50631968ab1a13002ea5421ece93169851chrismair * Unless required by applicable law or agreed to in writing, software
11dfb59d50631968ab1a13002ea5421ece93169851chrismair * distributed under the License is distributed on an "AS IS" BASIS,
12dfb59d50631968ab1a13002ea5421ece93169851chrismair * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13dfb59d50631968ab1a13002ea5421ece93169851chrismair * See the License for the specific language governing permissions and
14dfb59d50631968ab1a13002ea5421ece93169851chrismair * limitations under the License.
15dfb59d50631968ab1a13002ea5421ece93169851chrismair */
16dfb59d50631968ab1a13002ea5421ece93169851chrismairpackage org.mockftpserver.fake
17dfb59d50631968ab1a13002ea5421ece93169851chrismair
18dfb59d50631968ab1a13002ea5421ece93169851chrismairimport org.mockftpserver.test.AbstractGroovyTestCase
19dfb59d50631968ab1a13002ea5421ece93169851chrismairimport org.mockftpserver.test.PortTestUtil
20dfb59d50631968ab1a13002ea5421ece93169851chrismair
21dfb59d50631968ab1a13002ea5421ece93169851chrismairclass FakeFtpServer_AlreadyStartedTest extends AbstractGroovyTestCase {
22dfb59d50631968ab1a13002ea5421ece93169851chrismair    private FakeFtpServer ftpServer1 = new FakeFtpServer()
23dfb59d50631968ab1a13002ea5421ece93169851chrismair    private FakeFtpServer ftpServer2 = new FakeFtpServer()
24dfb59d50631968ab1a13002ea5421ece93169851chrismair
25dfb59d50631968ab1a13002ea5421ece93169851chrismair    void testStartServer_WhenAlreadyStarted() {
26dfb59d50631968ab1a13002ea5421ece93169851chrismair        ftpServer1.setServerControlPort(PortTestUtil.getFtpServerControlPort())
27dfb59d50631968ab1a13002ea5421ece93169851chrismair        ftpServer1.start();
28dfb59d50631968ab1a13002ea5421ece93169851chrismair        Thread.sleep(200L);     // give it some time to get started
29dfb59d50631968ab1a13002ea5421ece93169851chrismair        assertEquals("started - after start()", true, ftpServer1.isStarted());
30dfb59d50631968ab1a13002ea5421ece93169851chrismair
31dfb59d50631968ab1a13002ea5421ece93169851chrismair        ftpServer2.setServerControlPort(PortTestUtil.getFtpServerControlPort())
32dfb59d50631968ab1a13002ea5421ece93169851chrismair        ftpServer2.start();
33dfb59d50631968ab1a13002ea5421ece93169851chrismair        log("started ftpServer2")
34dfb59d50631968ab1a13002ea5421ece93169851chrismair        sleep(200L)      // give it a chance to start and terminate
35dfb59d50631968ab1a13002ea5421ece93169851chrismair        assert !ftpServer2.isStarted()
36dfb59d50631968ab1a13002ea5421ece93169851chrismair    }
37dfb59d50631968ab1a13002ea5421ece93169851chrismair
38dfb59d50631968ab1a13002ea5421ece93169851chrismair    void tearDown() {
39dfb59d50631968ab1a13002ea5421ece93169851chrismair        super.tearDown()
40dfb59d50631968ab1a13002ea5421ece93169851chrismair        ftpServer1.stop();
41dfb59d50631968ab1a13002ea5421ece93169851chrismair        ftpServer2.stop();
42dfb59d50631968ab1a13002ea5421ece93169851chrismair    }
43dfb59d50631968ab1a13002ea5421ece93169851chrismair}
44