Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoberto E. Escobar2014-01-21 21:25:20 -0500
committerRyan D. Brooks2014-01-21 21:25:20 -0500
commit9ea8e0a944e9caee56b35b72a0d913a50394c3e4 (patch)
tree67077a71b076df437c6c87676475e6630dd30f44 /plugins/org.eclipse.osee.account.rest.test
parent1f33e0bf0a642c17b674bbeb791e88ea07c4726a (diff)
downloadorg.eclipse.osee-9ea8e0a944e9caee56b35b72a0d913a50394c3e4.tar.gz
org.eclipse.osee-9ea8e0a944e9caee56b35b72a0d913a50394c3e4.tar.xz
org.eclipse.osee-9ea8e0a944e9caee56b35b72a0d913a50394c3e4.zip
feature[ats_ATS8933]: Create Account REST API
Diffstat (limited to 'plugins/org.eclipse.osee.account.rest.test')
-rw-r--r--plugins/org.eclipse.osee.account.rest.test/.classpath7
-rw-r--r--plugins/org.eclipse.osee.account.rest.test/.project28
-rw-r--r--plugins/org.eclipse.osee.account.rest.test/META-INF/MANIFEST.MF18
-rw-r--r--plugins/org.eclipse.osee.account.rest.test/build.properties4
-rw-r--r--plugins/org.eclipse.osee.account.rest.test/pom.xml32
-rw-r--r--plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/AccountRestTestSuite.java24
-rw-r--r--plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountActiveResourceTest.java96
-rw-r--r--plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountInternalTestSuite.java31
-rw-r--r--plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountLoginResourceTest.java89
-rw-r--r--plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountLogoutResourceTest.java72
-rw-r--r--plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountOpsTest.java436
-rw-r--r--plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountPreferencesResourceTest.java93
-rw-r--r--plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountResourceTest.java123
-rw-r--r--plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountSessionsResourceTest.java56
-rw-r--r--plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountsResourceTest.java78
15 files changed, 1187 insertions, 0 deletions
diff --git a/plugins/org.eclipse.osee.account.rest.test/.classpath b/plugins/org.eclipse.osee.account.rest.test/.classpath
new file mode 100644
index 0000000000..ad32c83a78
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest.test/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/plugins/org.eclipse.osee.account.rest.test/.project b/plugins/org.eclipse.osee.account.rest.test/.project
new file mode 100644
index 0000000000..c38c42559e
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest.test/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.osee.account.rest.test</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/plugins/org.eclipse.osee.account.rest.test/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.account.rest.test/META-INF/MANIFEST.MF
new file mode 100644
index 0000000000..ac9e913b1c
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest.test/META-INF/MANIFEST.MF
@@ -0,0 +1,18 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: OSEE Account REST API Test (Incubation)
+Bundle-SymbolicName: org.eclipse.osee.account.rest.test
+Bundle-Version: 0.17.0.qualifier
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Bundle-Vendor: Eclipse Open System Engineering Environment
+Fragment-Host: org.eclipse.osee.account.rest;bundle-version="0.17.0"
+Import-Package: com.sun.ws.rs.ext,
+ org.apache.commons.lang.math,
+ org.hamcrest.core,
+ org.junit,
+ org.junit.rules,
+ org.junit.runner,
+ org.junit.runners,
+ org.junit.runners.model,
+ org.mockito,
+ org.mockito.stubbing
diff --git a/plugins/org.eclipse.osee.account.rest.test/build.properties b/plugins/org.eclipse.osee.account.rest.test/build.properties
new file mode 100644
index 0000000000..34d2e4d2da
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest.test/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
diff --git a/plugins/org.eclipse.osee.account.rest.test/pom.xml b/plugins/org.eclipse.osee.account.rest.test/pom.xml
new file mode 100644
index 0000000000..83ea40e454
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest.test/pom.xml
@@ -0,0 +1,32 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.eclipse.osee</groupId>
+ <artifactId>org.eclipse.osee.x.core.parent</artifactId>
+ <version>0.17.0-SNAPSHOT</version>
+ <relativePath>../../plugins/org.eclipse.osee.x.core.parent</relativePath>
+ </parent>
+
+ <artifactId>org.eclipse.osee.account.rest.test</artifactId>
+ <packaging>eclipse-test-plugin</packaging>
+ <name>OSEE Account REST API Test (Incubation)</name>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>tycho-surefire-plugin</artifactId>
+ <version>${tycho-version}</version>
+ <configuration>
+ <testSuite>org.eclipse.osee.account.rest.test</testSuite>
+ <testClass>org.eclipse.osee.account.rest.AccountRestTestSuite</testClass>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+
+</project>
diff --git a/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/AccountRestTestSuite.java b/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/AccountRestTestSuite.java
new file mode 100644
index 0000000000..130443febf
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/AccountRestTestSuite.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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.account.rest;
+
+import org.eclipse.osee.account.rest.internal.AccountInternalTestSuite;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * @author Roberto E. Escobar
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({AccountInternalTestSuite.class})
+public class AccountRestTestSuite {
+ // Test Suite
+}
diff --git a/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountActiveResourceTest.java b/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountActiveResourceTest.java
new file mode 100644
index 0000000000..0aabcf535e
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountActiveResourceTest.java
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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.account.rest.internal;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import org.eclipse.osee.account.rest.model.AccountActiveData;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+
+/**
+ * Test Case for {@link AccountActiveResource}
+ *
+ * @author Roberto E. Escobar
+ */
+public class AccountActiveResourceTest {
+
+ //@formatter:off
+ @Mock private AccountOps ops;
+ @Mock private AccountActiveData activeData;
+ //@formatter:on
+
+ private String accountId;
+ private AccountActiveResource resource;
+
+ @Before
+ public void setUp() {
+ initMocks(this);
+
+ resource = new AccountActiveResource(ops, accountId);
+ }
+
+ @Test
+ public void testIsActive() {
+ when(ops.isActive(accountId)).thenReturn(activeData);
+
+ AccountActiveData actual = resource.isActive();
+ assertEquals(activeData, actual);
+
+ verify(ops).isActive(accountId);
+ }
+
+ @Test
+ public void testSetActiveOk() {
+ when(ops.setAccountActive(accountId, true)).thenReturn(true);
+
+ Response response = resource.setActive();
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+
+ verify(ops).setAccountActive(accountId, true);
+ }
+
+ @Test
+ public void testSetActiveNotModified() {
+ when(ops.setAccountActive(accountId, true)).thenReturn(false);
+
+ Response response = resource.setActive();
+ assertEquals(Status.NOT_MODIFIED.getStatusCode(), response.getStatus());
+
+ verify(ops).setAccountActive(accountId, true);
+ }
+
+ @Test
+ public void testSetInactiveOk() {
+ when(ops.setAccountActive(accountId, false)).thenReturn(true);
+
+ Response response = resource.setInactive();
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+
+ verify(ops).setAccountActive(accountId, false);
+ }
+
+ @Test
+ public void testSetInactiveMotModified() {
+ when(ops.setAccountActive(accountId, false)).thenReturn(false);
+
+ Response response = resource.setInactive();
+ assertEquals(Status.NOT_MODIFIED.getStatusCode(), response.getStatus());
+
+ verify(ops).setAccountActive(accountId, false);
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountInternalTestSuite.java b/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountInternalTestSuite.java
new file mode 100644
index 0000000000..1a9dd21f22
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountInternalTestSuite.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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.account.rest.internal;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * @author Roberto E. Escobar
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ AccountActiveResourceTest.class,
+ AccountLoginResourceTest.class,
+ AccountLogoutResourceTest.class,
+ AccountOpsTest.class,
+ AccountPreferencesResourceTest.class,
+ AccountResourceTest.class,
+ AccountSessionsResourceTest.class,
+ AccountsResourceTest.class})
+public class AccountInternalTestSuite {
+ // Test Suite
+}
diff --git a/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountLoginResourceTest.java b/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountLoginResourceTest.java
new file mode 100644
index 0000000000..cf85cbe397
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountLoginResourceTest.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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.account.rest.internal;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import java.net.URI;
+import java.net.URISyntaxException;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.core.UriInfo;
+import org.eclipse.osee.account.rest.model.AccountLoginData;
+import org.eclipse.osee.account.rest.model.AccountSessionData;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+/**
+ * Test Case for {@link AccountLoginResource}
+ *
+ * @author Roberto E. Escobar
+ */
+public class AccountLoginResourceTest {
+
+ private static final long ACCOUNT_ID = 123413241244L;
+ private static final String ACCOUNT_BASE = "accounts";
+
+ //@formatter:off
+ @Mock private AccountOps ops;
+ @Mock private HttpServletRequest request;
+ @Mock private UriInfo uriInfo;
+ @Mock private AccountLoginData data;
+ @Mock private RequestInfo reqInfo;
+ @Mock private AccountSessionData session;
+ @Captor private ArgumentCaptor<RequestInfo> reqInfoCaptor;
+ //@formatter:on
+
+ private AccountLoginResource resource;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ resource = new AccountLoginResource(ops);
+ }
+
+ @Test
+ public void testLogin() throws URISyntaxException {
+ when(session.getAccountId()).thenReturn(ACCOUNT_ID);
+
+ when(ops.asRequestInfo(request)).thenReturn(reqInfo);
+ when(ops.doLogin(any(RequestInfo.class), eq(data))).thenReturn(session);
+ when(uriInfo.getBaseUri()).thenReturn(new URI(ACCOUNT_BASE));
+
+ Response response = resource.login(request, uriInfo, data);
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+
+ AccountSessionData actual = (AccountSessionData) response.getEntity();
+ assertEquals(session, actual);
+
+ URI location = (URI) response.getMetadata().getFirst(HttpHeaders.CONTENT_LOCATION);
+ assertNotNull(location);
+ assertEquals(ACCOUNT_BASE + "/" + ACCOUNT_ID, location.toASCIIString());
+
+ verify(ops).asRequestInfo(request);
+ verify(ops).doLogin(reqInfoCaptor.capture(), eq(data));
+ verify(uriInfo).getBaseUri();
+
+ assertEquals(reqInfo, reqInfoCaptor.getValue());
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountLogoutResourceTest.java b/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountLogoutResourceTest.java
new file mode 100644
index 0000000000..4bb455adb2
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountLogoutResourceTest.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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.account.rest.internal;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import org.eclipse.osee.account.rest.model.AccountSessionData;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+/**
+ * Test Case for {@link AccountLogoutResource}
+ *
+ * @author Roberto E. Escobar
+ */
+public class AccountLogoutResourceTest {
+
+ //@formatter:off
+ @Mock private AccountOps ops;
+
+ @Mock private AccountSessionData session;
+ //@formatter:on
+
+ private AccountLogoutResource resource;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ resource = new AccountLogoutResource(ops);
+ }
+
+ @Test
+ public void testLogout() {
+ String token = "dsfksa-kfsauiewa";
+
+ when(session.getToken()).thenReturn(token);
+ when(ops.doLogout(token)).thenReturn(true);
+
+ Response response = resource.logout(session);
+
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ verify(ops).doLogout(token);
+ }
+
+ @Test
+ public void testLogoutNotModified() {
+ String token = "dsfksa-kfsauiewa";
+
+ when(session.getToken()).thenReturn(token);
+ when(ops.doLogout(token)).thenReturn(false);
+
+ Response response = resource.logout(session);
+
+ assertEquals(Status.NOT_MODIFIED.getStatusCode(), response.getStatus());
+ verify(ops).doLogout(token);
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountOpsTest.java b/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountOpsTest.java
new file mode 100644
index 0000000000..ed3df9a333
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountOpsTest.java
@@ -0,0 +1,436 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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.account.rest.internal;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.HttpHeaders;
+import org.apache.commons.lang.math.RandomUtils;
+import org.eclipse.osee.account.admin.AccessDetails;
+import org.eclipse.osee.account.admin.Account;
+import org.eclipse.osee.account.admin.AccountAccess;
+import org.eclipse.osee.account.admin.AccountAdmin;
+import org.eclipse.osee.account.admin.AccountLoginRequest;
+import org.eclipse.osee.account.admin.AccountPreferences;
+import org.eclipse.osee.account.admin.CreateAccountRequest;
+import org.eclipse.osee.account.rest.model.AccountAccessData;
+import org.eclipse.osee.account.rest.model.AccountActiveData;
+import org.eclipse.osee.account.rest.model.AccountDetailsData;
+import org.eclipse.osee.account.rest.model.AccountInfoData;
+import org.eclipse.osee.account.rest.model.AccountInput;
+import org.eclipse.osee.account.rest.model.AccountLoginData;
+import org.eclipse.osee.account.rest.model.AccountPreferencesData;
+import org.eclipse.osee.account.rest.model.AccountPreferencesInput;
+import org.eclipse.osee.account.rest.model.AccountSessionData;
+import org.eclipse.osee.framework.jdk.core.type.Identifiable;
+import org.eclipse.osee.framework.jdk.core.type.ResultSet;
+import org.eclipse.osee.framework.jdk.core.type.ResultSets;
+import org.eclipse.osee.framework.jdk.core.util.GUID;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+
+/**
+ * Test Case for {@link AccountOps}
+ *
+ * @author Roberto E. Escobar
+ */
+public class AccountOpsTest {
+
+ private static final String ACCOUNT_UID = "hello@hello.com";
+
+ //@formatter:off
+ @Mock private AccountAdmin accountAdmin;
+ //@formatter:on
+
+ private AccountOps ops;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ ops = new AccountOps(accountAdmin);
+ }
+
+ @Test
+ public void testCreateAccount() {
+ String guid = GUID.create();
+ String username = "aUser";
+
+ String email = "hello@hello.com";
+ String name = "myName";
+ boolean active = true;
+
+ Map<String, String> map = new HashMap<String, String>();
+ map.put("a", "1");
+ map.put("b", "2");
+ map.put("c", "3");
+
+ AccountInput input = mock(AccountInput.class);
+ when(input.getEmail()).thenReturn(email);
+ when(input.getName()).thenReturn(name);
+ when(input.isActive()).thenReturn(active);
+ when(input.getPreferences()).thenReturn(map);
+
+ ArgumentCaptor<CreateAccountRequest> captor = ArgumentCaptor.forClass(CreateAccountRequest.class);
+
+ @SuppressWarnings("unchecked")
+ Identifiable<String> id = mock(Identifiable.class);
+ when(id.getGuid()).thenReturn(guid);
+
+ when(accountAdmin.createAccount(any(CreateAccountRequest.class))).thenReturn(id);
+
+ long accountId = 1982671L;
+ Account account = mockAccount(accountId, guid, name, email, username, active);
+ ResultSet<Account> result = ResultSets.singleton(account);
+ when(accountAdmin.getAccountByUuid(guid)).thenReturn(result);
+
+ AccountInfoData actual = ops.createAccount(username, input);
+
+ verify(accountAdmin).createAccount(captor.capture());
+ CreateAccountRequest request = captor.getValue();
+ assertNotNull(request);
+ assertAccount(actual, accountId, guid, name, email, username, active);
+ assertEquals(name, request.getDisplayName());
+ assertEquals(email, request.getEmail());
+ assertEquals(username, request.getUserName());
+ assertEquals(active, request.isActive());
+ assertEquals(map, request.getPreferences());
+ }
+
+ @Test
+ public void testDoLogin() {
+ String ipAddress = "192.168.100.199";
+ String userAgent = "my agent";
+
+ String scheme = "myscheme";
+ String username = "myuser";
+ String password = "mypass";
+
+ RequestInfo reqInfo = mock(RequestInfo.class);
+ when(reqInfo.getDetails()).thenReturn(userAgent);
+ when(reqInfo.getRemoteIpAddress()).thenReturn(ipAddress);
+
+ AccountLoginData login = mock(AccountLoginData.class);
+ when(login.getScheme()).thenReturn(scheme);
+ when(login.getUsername()).thenReturn(username);
+ when(login.getPassword()).thenReturn(password);
+
+ Date d1 = newRandomDate();
+ Date d2 = newRandomDate();
+ AccountAccess access = mockAccess(789L, "t3", d1, d2, ipAddress, userAgent);
+ ArgumentCaptor<AccountLoginRequest> captor = ArgumentCaptor.forClass(AccountLoginRequest.class);
+
+ when(accountAdmin.login(any(AccountLoginRequest.class))).thenReturn(access);
+
+ AccountSessionData actual = ops.doLogin(reqInfo, login);
+
+ verify(accountAdmin).login(captor.capture());
+ AccountLoginRequest request = captor.getValue();
+ AccessDetails details = request.getDetails();
+ assertNotNull(details);
+ assertEquals(789L, actual.getAccountId());
+ assertEquals("t3", actual.getToken());
+
+ assertEquals(scheme, request.getScheme());
+ assertEquals(username, request.getUserName());
+ assertEquals(password, request.getPassword());
+
+ assertEquals(userAgent, details.getAccessDetails());
+ assertEquals(ipAddress, details.getRemoteAddress());
+ }
+
+ @Test
+ public void testDoLogout() {
+ String token = "asdasa";
+
+ when(accountAdmin.logout(token)).thenReturn(true);
+
+ boolean actual = ops.doLogout(token);
+
+ assertEquals(true, actual);
+ verify(accountAdmin).logout(token);
+ }
+
+ @Test
+ public void testDeleteAccount() {
+ when(accountAdmin.deleteAccount(ACCOUNT_UID)).thenReturn(true);
+
+ boolean actual = ops.deleteAccount(ACCOUNT_UID);
+
+ assertEquals(true, actual);
+ verify(accountAdmin).deleteAccount(ACCOUNT_UID);
+ }
+
+ @Test
+ public void testAsRequestInfo() {
+ String ipAddress = "192.168.100.199";
+ String userAgent = "my agent";
+
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ when(request.getHeader(HttpHeaders.USER_AGENT)).thenReturn(userAgent);
+ when(request.getHeader("HTTP_X_FORWARDED_FOR")).thenReturn(ipAddress);
+
+ RequestInfo actual = ops.asRequestInfo(request);
+
+ assertEquals(userAgent, actual.getDetails());
+ assertEquals(ipAddress, actual.getRemoteIpAddress());
+ }
+
+ @Test
+ public void testAsAccountAccessData() {
+ Date d1 = newRandomDate();
+ Date d2 = newRandomDate();
+
+ AccountAccess access = mockAccess(789L, "t3", d1, d2, "f3", "d3");
+
+ AccountAccessData actual = ops.asAccountAccessData(access);
+
+ assertAccess(actual, 789L, d1, d2, "f3", "d3");
+ }
+
+ @Test
+ public void testAsSessionData() {
+ Date d1 = newRandomDate();
+ Date d2 = newRandomDate();
+ AccountAccess access = mockAccess(123L, "t1", d1, d2, "f1", "d1");
+
+ AccountSessionData actual = ops.asSessionData(access);
+
+ assertEquals(123L, actual.getAccountId());
+ assertEquals("t1", actual.getToken());
+ }
+
+ @Test
+ public void testGetAccountAccessById() {
+ Date d1 = newRandomDate();
+ Date d2 = newRandomDate();
+ Date d3 = newRandomDate();
+ Date d4 = newRandomDate();
+ Date d5 = newRandomDate();
+ Date d6 = newRandomDate();
+
+ AccountAccess access1 = mockAccess(123L, "t1", d1, d2, "f1", "d1");
+ AccountAccess access2 = mockAccess(456L, "t2", d3, d4, "f2", "d2");
+ AccountAccess access3 = mockAccess(789L, "t3", d5, d6, "f3", "d3");
+
+ ResultSet<AccountAccess> result = ResultSets.newResultSet(access1, access2, access3);
+ when(accountAdmin.getAccountAccessByUniqueField(ACCOUNT_UID)).thenReturn(result);
+
+ List<AccountAccessData> actual = ops.getAccountAccessById(ACCOUNT_UID);
+
+ assertEquals(3, actual.size());
+ Iterator<AccountAccessData> iterator = actual.iterator();
+ assertAccess(iterator.next(), 123L, d1, d2, "f1", "d1");
+ assertAccess(iterator.next(), 456L, d3, d4, "f2", "d2");
+ assertAccess(iterator.next(), 789L, d5, d6, "f3", "d3");
+
+ verify(accountAdmin).getAccountAccessByUniqueField(ACCOUNT_UID);
+ }
+
+ @Test
+ public void testGetAccountData() {
+ Account account = mockAccount(456L, "DEF", "acc2", "acc2@email.com", "u2", true);
+ ResultSet<Account> accounts = ResultSets.singleton(account);
+ when(accountAdmin.getAccountByUniqueField(ACCOUNT_UID)).thenReturn(accounts);
+
+ AccountInfoData actual = ops.getAccountData(ACCOUNT_UID);
+
+ assertAccount(actual, 456L, "DEF", "acc2", "acc2@email.com", "u2", true);
+ verify(accountAdmin).getAccountByUniqueField(ACCOUNT_UID);
+ }
+
+ @Test
+ public void testGetAccountDetailsData() {
+ Account account = mockAccount(789L, "GHI", "acc3", "acc3@email.com", "u3", true);
+ Map<String, String> map = new HashMap<String, String>();
+ map.put("a", "1");
+ map.put("b", "2");
+ map.put("c", "3");
+
+ AccountPreferences preferences = mock(AccountPreferences.class);
+ when(preferences.asMap()).thenReturn(map);
+ when(preferences.getId()).thenReturn(789L);
+ when(account.getPreferences()).thenReturn(preferences);
+
+ ResultSet<Account> accounts = ResultSets.singleton(account);
+ when(accountAdmin.getAccountByUniqueField(ACCOUNT_UID)).thenReturn(accounts);
+
+ AccountDetailsData actual = ops.getAccountDetailsData(ACCOUNT_UID);
+
+ assertAccount(actual, 789L, "GHI", "acc3", "acc3@email.com", "u3", true);
+ AccountPreferencesData actualPrefs = actual.getPreferences();
+ Map<String, String> actualMap = actualPrefs.getMap();
+
+ assertEquals(789L, actualPrefs.getId());
+ assertEquals(3, actualMap.size());
+ assertEquals("1", actualMap.get("a"));
+ assertEquals("2", actualMap.get("b"));
+ assertEquals("3", actualMap.get("c"));
+
+ verify(accountAdmin).getAccountByUniqueField(ACCOUNT_UID);
+ }
+
+ @Test
+ public void testGetAccountPreferencesData() {
+ Map<String, String> map = new HashMap<String, String>();
+ map.put("a", "1");
+ map.put("b", "2");
+ map.put("c", "3");
+
+ AccountPreferences preferences = mock(AccountPreferences.class);
+ when(preferences.asMap()).thenReturn(map);
+ when(preferences.getId()).thenReturn(123L);
+
+ Account account = mock(Account.class);
+ when(account.getPreferences()).thenReturn(preferences);
+
+ ResultSet<Account> accounts = ResultSets.singleton(account);
+ when(accountAdmin.getAccountByUniqueField(ACCOUNT_UID)).thenReturn(accounts);
+
+ AccountPreferencesData actual = ops.getAccountPreferencesData(ACCOUNT_UID);
+ assertEquals(123L, actual.getId());
+
+ Map<String, String> actualPrefs = actual.getMap();
+ assertEquals(3, actualPrefs.size());
+ assertEquals("1", actualPrefs.get("a"));
+ assertEquals("2", actualPrefs.get("b"));
+ assertEquals("3", actualPrefs.get("c"));
+
+ verify(accountAdmin).getAccountByUniqueField(ACCOUNT_UID);
+ }
+
+ @Test
+ public void testGetAllAccounts() {
+ Account account1 = mockAccount(123L, "ABC", "acc1", "acc1@email.com", "u1", true);
+ Account account2 = mockAccount(456L, "DEF", "acc2", "acc2@email.com", "u2", false);
+ Account account3 = mockAccount(789L, "GHI", "acc3", "acc3@email.com", "u3", true);
+
+ ResultSet<Account> accounts = ResultSets.newResultSet(account1, account2, account3);
+
+ when(accountAdmin.getAllAccounts()).thenReturn(accounts);
+
+ List<AccountInfoData> actual = ops.getAllAccounts();
+
+ assertEquals(3, actual.size());
+ Iterator<AccountInfoData> iterator = actual.iterator();
+
+ assertAccount(iterator.next(), 123L, "ABC", "acc1", "acc1@email.com", "u1", true);
+ assertAccount(iterator.next(), 456L, "DEF", "acc2", "acc2@email.com", "u2", false);
+ assertAccount(iterator.next(), 789L, "GHI", "acc3", "acc3@email.com", "u3", true);
+
+ verify(accountAdmin).getAllAccounts();
+ }
+
+ @Test
+ public void testIsActive() {
+ String guid = GUID.create();
+ long accountId = 23127916023214L;
+
+ Account account = mock(Account.class);
+ ResultSet<Account> result = ResultSets.singleton(account);
+
+ when(account.getGuid()).thenReturn(guid);
+ when(account.getId()).thenReturn(accountId);
+ when(account.isActive()).thenReturn(true);
+ when(accountAdmin.getAccountByUniqueField(ACCOUNT_UID)).thenReturn(result);
+
+ AccountActiveData actual = ops.isActive(ACCOUNT_UID);
+
+ assertEquals(accountId, actual.getAccountId());
+ assertEquals(guid, actual.getGuid());
+ assertEquals(true, actual.isActive());
+ verify(accountAdmin).getAccountByUniqueField(ACCOUNT_UID);
+ }
+
+ @Test
+ public void testSetAccountActive() {
+ when(accountAdmin.setActive(ACCOUNT_UID, true)).thenReturn(true);
+
+ boolean actual = ops.setAccountActive(ACCOUNT_UID, true);
+
+ assertEquals(true, actual);
+ verify(accountAdmin).setActive(ACCOUNT_UID, true);
+ }
+
+ @Test
+ public void testSetAccountPreferences() {
+ Map<String, String> map = new HashMap<String, String>();
+ map.put("a", "1");
+ map.put("b", "2");
+ map.put("c", "3");
+
+ AccountPreferencesInput input = mock(AccountPreferencesInput.class);
+ when(input.getMap()).thenReturn(map);
+ when(accountAdmin.setAccountPreferences(ACCOUNT_UID, map)).thenReturn(true);
+
+ boolean actual = ops.setAccountPreferences(ACCOUNT_UID, input);
+
+ assertEquals(true, actual);
+ verify(accountAdmin).setAccountPreferences(ACCOUNT_UID, map);
+ }
+
+ private static Date newRandomDate() {
+ return new Date(Math.abs(System.currentTimeMillis() - RandomUtils.nextLong()));
+ }
+
+ private static AccountAccess mockAccess(long id, String token, Date created, Date accessed, String accessFrom, String accessDetails) {
+ AccountAccess access = Mockito.mock(AccountAccess.class);
+ when(access.getAccountId()).thenReturn(id);
+ when(access.getAccessToken()).thenReturn(token);
+ when(access.getCreatedOn()).thenReturn(created);
+ when(access.getLastAccessedOn()).thenReturn(accessed);
+ when(access.getAccessedFrom()).thenReturn(accessFrom);
+ when(access.getAccessDetails()).thenReturn(accessDetails);
+ return access;
+ }
+
+ private static void assertAccess(AccountAccessData actual, long id, Date created, Date accessed, String accessFrom, String accessDetails) {
+ assertEquals(accessDetails, actual.getAccessDetails());
+ assertEquals(accessFrom, actual.getAccessedFrom());
+ assertEquals(id, actual.getAccountId());
+ assertEquals(created, actual.getCreatedOn());
+ assertEquals(accessed, actual.getLastAccessedOn());
+ }
+
+ private static Account mockAccount(long id, String uuid, String name, String email, String username, boolean active) {
+ Account account = Mockito.mock(Account.class);
+ when(account.getId()).thenReturn(id);
+ when(account.getGuid()).thenReturn(uuid);
+ when(account.getName()).thenReturn(name);
+ when(account.getEmail()).thenReturn(email);
+ when(account.getUserName()).thenReturn(username);
+ when(account.isActive()).thenReturn(active);
+ return account;
+ }
+
+ private static void assertAccount(AccountInfoData data, long id, String uuid, String name, String email, String username, boolean active) {
+ assertEquals(id, data.getAccountId());
+ assertEquals(uuid, data.getGuid());
+ assertEquals(name, data.getName());
+ assertEquals(email, data.getEmail());
+ assertEquals(username, data.getUserName());
+ assertEquals(active, data.isActive());
+ }
+}
diff --git a/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountPreferencesResourceTest.java b/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountPreferencesResourceTest.java
new file mode 100644
index 0000000000..3e1a7431fc
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountPreferencesResourceTest.java
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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.account.rest.internal;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+import java.util.HashMap;
+import java.util.Map;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import org.eclipse.osee.account.rest.model.AccountPreferencesData;
+import org.eclipse.osee.account.rest.model.AccountPreferencesInput;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+
+/**
+ * Test Case for {@link AccountPreferencesResource}
+ *
+ * @author Roberto E. Escobar
+ */
+public class AccountPreferencesResourceTest {
+
+ private static final String ACCOUNT_ID = "hello@hello.com";
+
+ //@formatter:off
+ @Mock private AccountOps accountOps;
+ @Mock private AccountPreferencesData preferences;
+ @Mock private AccountPreferencesInput input;
+ //@formatter:on
+
+ private AccountPreferencesResource resource;
+
+ @Before
+ public void setUp() {
+ initMocks(this);
+
+ resource = new AccountPreferencesResource(accountOps, ACCOUNT_ID);
+ }
+
+ @Test
+ public void testGetAccountPreferences() {
+ when(accountOps.getAccountPreferencesData(ACCOUNT_ID)).thenReturn(preferences);
+
+ AccountPreferencesData actual = resource.getAccountPreferences();
+
+ assertEquals(preferences, actual);
+ verify(accountOps).getAccountPreferencesData(ACCOUNT_ID);
+ }
+
+ @Test
+ public void testSetAccountPreferences() {
+ Map<String, String> map = new HashMap<String, String>();
+ map.put("a", "1");
+ map.put("b", "2");
+ map.put("c", "3");
+
+ when(input.getMap()).thenReturn(map);
+ when(accountOps.setAccountPreferences(ACCOUNT_ID, input)).thenReturn(true);
+
+ Response actual = resource.setAccountPreferences(input);
+
+ assertEquals(Status.OK.getStatusCode(), actual.getStatus());
+ verify(accountOps).setAccountPreferences(ACCOUNT_ID, input);
+ }
+
+ @Test
+ public void testSetAccountPreferencesNotModified() {
+ Map<String, String> map = new HashMap<String, String>();
+ map.put("a", "1");
+ map.put("b", "2");
+ map.put("c", "3");
+
+ when(input.getMap()).thenReturn(map);
+ when(accountOps.setAccountPreferences(ACCOUNT_ID, input)).thenReturn(false);
+
+ Response actual = resource.setAccountPreferences(input);
+
+ assertEquals(Status.NOT_MODIFIED.getStatusCode(), actual.getStatus());
+ verify(accountOps).setAccountPreferences(ACCOUNT_ID, input);
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountResourceTest.java b/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountResourceTest.java
new file mode 100644
index 0000000000..19cf47bfe4
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountResourceTest.java
@@ -0,0 +1,123 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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.account.rest.internal;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import org.eclipse.osee.account.rest.model.AccountDetailsData;
+import org.eclipse.osee.account.rest.model.AccountInfoData;
+import org.eclipse.osee.account.rest.model.AccountInput;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+
+/**
+ * Test Case for {@link AccountResource}
+ *
+ * @author Roberto E. Escobar
+ */
+public class AccountResourceTest {
+
+ private static final String ACCOUNT_ID = "hello@hello.com";
+
+ //@formatter:off
+ @Mock private AccountOps accountOps;
+
+ @Mock private AccountInput accountInput;
+ @Mock private AccountInfoData accountInfoData;
+ @Mock private AccountDetailsData details;
+ //@formatter:on
+
+ private AccountResource resource;
+
+ @Before
+ public void setUp() {
+ initMocks(this);
+
+ resource = new AccountResource(accountOps, ACCOUNT_ID);
+ }
+
+ @Test
+ public void testCreateAccount() {
+ when(accountOps.createAccount(ACCOUNT_ID, accountInput)).thenReturn(accountInfoData);
+
+ AccountInfoData actual = resource.createAccount(accountInput);
+ assertEquals(accountInfoData, actual);
+
+ verify(accountOps).createAccount(ACCOUNT_ID, accountInput);
+ }
+
+ @Test
+ public void testDeleteAccount() {
+ when(accountOps.deleteAccount(ACCOUNT_ID)).thenReturn(true);
+
+ Response actual = resource.deleteAccount();
+ assertEquals(Status.OK.getStatusCode(), actual.getStatus());
+
+ verify(accountOps).deleteAccount(ACCOUNT_ID);
+ }
+
+ @Test
+ public void testDeleteAccountNotModified() {
+ when(accountOps.deleteAccount(ACCOUNT_ID)).thenReturn(false);
+
+ Response actual = resource.deleteAccount();
+ assertEquals(Status.NOT_MODIFIED.getStatusCode(), actual.getStatus());
+
+ verify(accountOps).deleteAccount(ACCOUNT_ID);
+ }
+
+ @Test
+ public void testGetAccountDetailsData() {
+ when(accountOps.getAccountDetailsData(ACCOUNT_ID)).thenReturn(details);
+
+ AccountDetailsData actual = resource.getAccountDetailsData();
+ assertEquals(details, actual);
+
+ verify(accountOps).getAccountDetailsData(ACCOUNT_ID);
+ }
+
+ @Test
+ public void testAccountSettingsData() {
+ AccountPreferencesResource actual = resource.getAccountSettingsData();
+ assertNotNull(actual);
+
+ // Ensure resource constructed correctly;
+ actual.getAccountPreferences();
+ verify(accountOps).getAccountPreferencesData(ACCOUNT_ID);
+ }
+
+ @Test
+ public void testActive() {
+ AccountActiveResource actual = resource.active();
+ assertNotNull(actual);
+
+ // Ensure resource constructed correctly;
+ actual.isActive();
+ verify(accountOps).isActive(ACCOUNT_ID);
+ }
+
+ @Test
+ public void testGetSessions() {
+ AccountSessionsResource actual = resource.sessions();
+ assertNotNull(actual);
+
+ // Ensure resource constructed correctly;
+ actual.getAccountSessions();
+ verify(accountOps).getAccountAccessById(ACCOUNT_ID);
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountSessionsResourceTest.java b/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountSessionsResourceTest.java
new file mode 100644
index 0000000000..35706f8c6a
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountSessionsResourceTest.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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.account.rest.internal;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+import java.util.ArrayList;
+import java.util.List;
+import org.eclipse.osee.account.rest.model.AccountAccessData;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+
+/**
+ * Test Case for {@link AccountSessionsResource}
+ *
+ * @author Roberto E. Escobar
+ */
+public class AccountSessionsResourceTest {
+
+ private static final String ACCOUNT_ID = "hello@hello.com";
+
+ //@formatter:off
+ @Mock private AccountOps accountOps;
+ //@formatter:on
+
+ private AccountSessionsResource resource;
+
+ @Before
+ public void setUp() {
+ initMocks(this);
+
+ resource = new AccountSessionsResource(accountOps, ACCOUNT_ID);
+ }
+
+ @Test
+ public void testGetAccountSessions() {
+ List<AccountAccessData> accesses = new ArrayList<AccountAccessData>();
+ when(accountOps.getAccountAccessById(ACCOUNT_ID)).thenReturn(accesses);
+
+ List<AccountAccessData> actual = resource.getAccountSessions();
+
+ assertEquals(accesses, actual);
+ verify(accountOps).getAccountAccessById(ACCOUNT_ID);
+ }
+}
diff --git a/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountsResourceTest.java b/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountsResourceTest.java
new file mode 100644
index 0000000000..488c9752a2
--- /dev/null
+++ b/plugins/org.eclipse.osee.account.rest.test/src/org/eclipse/osee/account/rest/internal/AccountsResourceTest.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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.account.rest.internal;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+import java.util.ArrayList;
+import java.util.List;
+import org.eclipse.osee.account.rest.model.AccountInfoData;
+import org.eclipse.osee.account.rest.model.AccountInput;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+
+/**
+ * Test Case for {@link AccountsResource}
+ *
+ * @author Roberto E. Escobar
+ */
+public class AccountsResourceTest {
+
+ private static final String ACCOUNT_ID = "hello@hello.com";
+
+ //@formatter:off
+ @Mock private AccountOps accountOps;
+
+ @Mock private AccountInfoData account;
+ @Mock private AccountInput input;
+ //@formatter:on
+
+ private AccountsResource resource;
+
+ @Before
+ public void setUp() {
+ initMocks(this);
+
+ resource = new AccountsResource(accountOps);
+ }
+
+ @Test
+ public void testGetAccounts() {
+ List<AccountInfoData> accesses = new ArrayList<AccountInfoData>();
+ when(accountOps.getAllAccounts()).thenReturn(accesses);
+
+ List<AccountInfoData> actual = resource.getAccounts();
+
+ assertEquals(accesses, actual);
+ verify(accountOps).getAllAccounts();
+ }
+
+ @Test
+ public void testGetAccount() {
+ AccountResource actual = resource.getAccount(ACCOUNT_ID);
+ assertNotNull(actual);
+
+ // Ensure resource constructed correctly;
+ actual.createAccount(input);
+ verify(accountOps).createAccount(ACCOUNT_ID, input);
+ }
+
+ @Test
+ public void testGetLoginResource() {
+ AccountLoginResource actual = resource.getLoginResource();
+ assertNotNull(actual);
+ }
+
+}

Back to the top