Skip to main content
summaryrefslogtreecommitdiffstats
blob: b726070f0ed07c2f0b06759f563013086425d332 (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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*******************************************************************************
 * 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.enums.StorageState;
import org.eclipse.osee.framework.core.model.test.mocks.ModelAsserts;
import org.eclipse.osee.framework.core.model.test.type.AbstractOseeTypeTest;
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 extends AbstractOseeTypeTest<Session> {

   private final int expectedId;
   private final String expectedClientAddress;
   private final String expectedClientMachine;
   private final String expectedClientVersion;
   private final int expectedClientPort;
   private final Date expectedCreationDate;
   private final String expectedUserId;
   private final Date expectedLastInteractionDate;
   private final String expectedLastInteraction;
   private final String exepectedManagedByServerId;

   public SessionTest(Session type, String guid, String name, int expectedId, String expectedClientAddress, String expectedClientMachine, String expectedClientVersion, int expectedClientPort, Date expectedCreationDate, String expectedUserId, Date expectedLastInteractionDate, String expectedLastInteraction, String exepectedManagedByServerId) {
      super(type, guid, name);
      this.expectedId = expectedId;
      this.expectedClientAddress = expectedClientAddress;
      this.expectedClientMachine = expectedClientMachine;
      this.expectedClientVersion = expectedClientVersion;
      this.expectedClientPort = expectedClientPort;
      this.expectedCreationDate = expectedCreationDate;
      this.expectedUserId = expectedUserId;
      this.expectedLastInteractionDate = expectedLastInteractionDate;
      this.expectedLastInteraction = expectedLastInteraction;
      this.exepectedManagedByServerId = exepectedManagedByServerId;
   }

   @Test
   public void testGuidAsInteger() {
      int actualId = Session.guidAsInteger(getType().getGuid());
      Assert.assertEquals(expectedId, actualId);
   }

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

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

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

   @Test
   public void testSetGetClientAddress() throws Exception {
      String newValue = GUID.create();
      ModelAsserts.assertTypeSetGet(getType(), Session.SESSION_CLIENT_ADDRESS, "getClientAddress", "setClientAddress",
         expectedClientAddress, newValue);
   }

   @Test
   public void testSetGetClientMachineName() throws Exception {
      String newValue = GUID.create();
      ModelAsserts.assertTypeSetGet(getType(), Session.SESSION_CLIENT_MACHINE_NAME, "getClientMachineName",
         "setClientMachineName", expectedClientMachine, newValue);
   }

   @Test
   public void testSetGetClientPort() throws Exception {
      int newValue = Integer.MAX_VALUE;
      ModelAsserts.assertTypeSetGet(getType(), Session.SESSION_CLIENT_PORT, "getClientPort", "setClientPort",
         expectedClientPort, newValue);
   }

   @Test
   public void testSetGetLastInteractionDate() throws Exception {
      Date newValue = new Date();
      ModelAsserts.assertTypeSetGet(getType(), Session.SESSION_LAST_INTERACTION_DATE, "getLastInteractionDate",
         "setLastInteractionDate", expectedLastInteractionDate, newValue);
   }

   @Test
   public void testSetGetLastInteractionDetails() throws Exception {
      String newValue = GUID.create();
      ModelAsserts.assertTypeSetGet(getType(), Session.SESSION_LAST_INTERACTION_DETAILS, "getLastInteractionDetails",
         "setLastInteractionDetails", expectedLastInteraction, newValue);
   }

   @Test
   public void testSetManagedByServerId() throws Exception {
      String newValue = GUID.create();
      ModelAsserts.assertTypeSetGet(getType(), Session.SESSION_MANAGED_BY_SERVER_ID, "getManagedByServerId",
         "setManagedByServerId", exepectedManagedByServerId, newValue);
   }

   @Parameters
   public static Collection<Object[]> getData() {
      Collection<Object[]> data = new ArrayList<Object[]>();
      for (int index = 1; index <= 3; index++) {
         String guid = "ABCD" + String.valueOf(index);
         int actualIndex = index - 1;
         int expectedId = 1946 + actualIndex * 20 + 4 * actualIndex;

         String name = "index-" + 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;
         Date lastInteractionDate = new Date();
         String lastInteraction = "lastInteraction-" + index;
         String managedByServerId = "serverId-" + index;

         Session session =
            new Session(guid, name, userId, creationDate, managedByServerId, clientVersion, clientMachine,
               clientAddress, clientPort, lastInteractionDate, lastInteraction);
         session.setStorageState(StorageState.LOADED);
         session.clearDirty();

         data.add(new Object[] {
            session,
            guid,
            name,
            expectedId,
            clientAddress,
            clientMachine,
            clientVersion,
            clientPort,
            creationDate,
            userId,
            lastInteractionDate,
            lastInteraction,
            managedByServerId});
      }
      return data;
   }
}

Back to the top