Skip to main content
summaryrefslogtreecommitdiffstats
blob: f2c53d1906a71ee80850fe84353c43f9dfec60fd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.framework.core.server.test.internal.session;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import org.eclipse.osee.framework.core.server.internal.session.Session;
import org.eclipse.osee.framework.jdk.core.util.GUID;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

/**
 * Test Case for {@link Session}
 * 
 * @author Roberto E. Escobar
 */
@RunWith(Parameterized.class)
public class SessionTest {

   private final Session session;
   private final String expectedGuid;
   private final String expectedClientAddress;
   private final String expectedClientMachine;
   private final String expectedClientVersion;
   private final int expectedClientPort;
   private final Date expectedCreationDate;
   private final String expectedUserId;

   public SessionTest(Session session, String guid, String expectedClientAddress, String expectedClientMachine, String expectedClientVersion, int expectedClientPort, Date expectedCreationDate, String expectedUserId) {
      this.session = session;
      this.expectedGuid = guid;
      this.expectedClientAddress = expectedClientAddress;
      this.expectedClientMachine = expectedClientMachine;
      this.expectedClientVersion = expectedClientVersion;
      this.expectedClientPort = expectedClientPort;
      this.expectedCreationDate = expectedCreationDate;
      this.expectedUserId = expectedUserId;
   }

   @Test
   public void testGetGuid() {
      Assert.assertEquals(expectedGuid, session.getGuid());
   }

   @Test
   public void testGetClientVersion() {
      Assert.assertEquals(expectedClientVersion, session.getClientVersion());
   }

   @Test
   public void testGetCreationDate() {
      Assert.assertEquals(expectedCreationDate, session.getCreationDate());
   }

   @Test
   public void testGetUserId() {
      Assert.assertEquals(expectedUserId, session.getUserId());
   }

   @Test
   public void testSetGetClientAddress() throws Exception {
      String newValue = GUID.create();

      Assert.assertEquals(expectedClientAddress, session.getClientAddress());

      session.setClientAddress(newValue);
      Assert.assertEquals(newValue, session.getClientAddress());
   }

   @Test
   public void testSetGetClientMachineName() throws Exception {
      String newValue = GUID.create();

      Assert.assertEquals(expectedClientMachine, session.getClientMachineName());

      session.setClientMachineName(newValue);
      Assert.assertEquals(newValue, session.getClientMachineName());
   }

   @Test
   public void testSetGetClientPort() throws Exception {
      int newValue = Integer.MAX_VALUE;

      Assert.assertEquals(expectedClientPort, session.getClientPort());

      session.setClientPort(newValue);
      Assert.assertEquals(newValue, session.getClientPort());
   }

   @Parameters
   public static Collection<Object[]> getData() {
      Collection<Object[]> data = new ArrayList<>();
      for (int index = 1; index <= 3; index++) {
         String guid = "ABCD" + String.valueOf(index);
         String clientAddress = "addresss-" + index;
         String clientMachine = "machine-" + index;
         String clientVersion = "version-" + index;
         int clientPort = index * 345;
         Date creationDate = new Date();
         String userId = "userId-" + index;

         Session session =
            new Session(guid, userId, creationDate, clientVersion, clientMachine, clientAddress, clientPort);

         data.add(new Object[] {
            session,
            guid,
            clientAddress,
            clientMachine,
            clientVersion,
            clientPort,
            creationDate,
            userId

         });
      }
      return data;
   }
}

Back to the top