View Javadoc

1   // Copyright (C) 2005 - 2009 Philip Aston
2   // All rights reserved.
3   //
4   // This file is part of The Grinder software distribution. Refer to
5   // the file LICENSE which is part of The Grinder distribution for
6   // licensing details. The Grinder distribution is available on the
7   // Internet at http://grinder.sourceforge.net/
8   //
9   // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
10  // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
11  // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
12  // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
13  // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
14  // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
15  // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
16  // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
17  // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
18  // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
19  // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
20  // OF THE POSSIBILITY OF SUCH DAMAGE.
21  
22  package net.grinder.engine.agent;
23  
24  import net.grinder.common.processidentity.AgentIdentity;
25  import net.grinder.common.processidentity.WorkerIdentity;
26  import net.grinder.testutility.Serializer;
27  import junit.framework.TestCase;
28  
29  /**
30   * TestAgentIdentityImplementation.
31   *
32   * @author Philip Aston
33   */
34  public class TestAgentIdentityImplementation extends TestCase {
35  
36    public void testAgentIdentityImplementation() throws Exception {
37  
38      final AgentIdentityImplementation a1 =
39        new AgentIdentityImplementation("foo");
40      final AgentIdentity a2 =new AgentIdentityImplementation("foo");
41  
42      assertEquals(a1, a1);
43      assertTrue(!a1.equals(null));
44      assertTrue(!a1.equals(this));
45      assertTrue(!a1.equals(a2));
46  
47      final AgentIdentity a1Copy = Serializer.serialize(a1);
48  
49      assertEquals("foo", a1.getName());
50      a1.setName("bah");
51      assertEquals("bah", a1.getName());
52      assertEquals(a1, a1Copy);
53      assertTrue(!a1Copy.getName().equals(a1.getName()));
54  
55      assertTrue(!a1Copy.toString().equals(a1.toString()));
56      assertTrue(!a1Copy.toString().equals(a2.toString()));
57  
58      a1.setNumber(10);
59      assertEquals(10, a1.getNumber());
60      assertEquals(-1, a1Copy.getNumber());
61      assertEquals(a1, a1Copy);
62  
63      final WorkerIdentity w1 = a1.createWorkerIdentity();
64      final WorkerIdentity w2 = a1.createWorkerIdentity();
65  
66      assertEquals(w1, w1);
67      assertTrue(!w1.equals(null));
68      assertTrue(!w1.equals(a1));
69      assertTrue(!w1.equals(w2));
70  
71      assertTrue(!w1.getName().equals(w2.getName()));
72  
73      final WorkerIdentity w1Copy = Serializer.serialize(w1);
74  
75      assertEquals(w1, w1Copy);
76      assertEquals(w1.toString(), w1Copy.toString());
77    }
78  }