Skip to content

Commit

Permalink
first draft
Browse files Browse the repository at this point in the history
  • Loading branch information
jpkrohling committed Dec 4, 2015
1 parent 87aa27c commit 80ca32d
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import javax.annotation.security.PermitAll;
import javax.ejb.Stateless;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;

import org.hawkular.accounts.api.CurrentUser;
Expand Down Expand Up @@ -66,6 +68,31 @@ public Response getPersonas() {
return Response.ok().entity(personas).build();
}

/**
* Retrieves all personas to which this {@link org.hawkular.accounts.api.model.HawkularUser} has access to.
*
* @return a {@link javax.ws.rs.core.Response} whose entity is a {@link java.util.List} of
* {@link org.hawkular.accounts.api.model.Persona}
*/
@GET
@Path("/{id:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}}")
public Response getPersonas(@PathParam("id") String personaId) {
HawkularUser user = userInstance.get();
// here, we purposely get the personas for the *user*, not for the current persona
Persona persona = organizationService
.getOrganizationsForPersona(user)
.stream()
.filter(p -> p.getIdAsUUID().equals(UUID.fromString(personaId)))
.findFirst()
.get();

if (persona == null) {
return Response.status(Response.Status.NOT_FOUND).build();
} else {
return Response.ok().entity(persona).build();
}
}

/**
* Retrieves all personas to which this {@link org.hawkular.accounts.api.model.HawkularUser} has access to.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright 2015 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hawkular.accounts.itest.smoke

import groovyx.net.http.HttpResponseException
import org.jboss.arquillian.junit.Arquillian
import org.junit.Test
import org.junit.runner.RunWith

import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertNotNull

/**
* @author Juraci Paixão Kröhling
*/
@RunWith(Arquillian.class)
class PersonaITest extends BaseSmokeTest {

@Test
void canGetCurrentPersona() {
// just a sanity test before we start for real
def response = client.get(path: "/hawkular/accounts/personas/current")
assertEquals(200, response.status)
assertNotNull(response.data.id)
}

@Test
void canGetPreferredPersona() {
def orgName = UUID.randomUUID().toString()
def response = client.post(
path: '/hawkular/accounts/organizations',
body: [name: orgName]
)

assertEquals(200, response.status)
assertNotNull(response.data.id)
assertEquals('The company name should have been persisted', orgName, response.data.name)

def preferredPersonaId = response.data.id;

response = client.get(path: "/hawkular/accounts/personas/${preferredPersonaId}")
assertEquals(200, response.status)
assertEquals(response.data.id, preferredPersonaId)
assertNotNull(response.data.id)
}

@Test
void preferredPersonaCannotBeFound() {
// just a sanity test before we start for real
try {
client.get(path: "/hawkular/accounts/personas/some-non-sense")
} catch (HttpResponseException exception) {
assertEquals(404, exception.response.status)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@ import static org.junit.Assert.assertTrue
@RunWith(Arquillian.class)
class SecretStoreITest extends BaseSmokeTest {

@Test
void canGetCurrentPersona() {
// just a sanity test before we start for real
def response = client.get(path: "/hawkular/accounts/personas/current")
assertEquals(200, response.status)
assertNotNull(response.data.id)
assertTrue(true)
}

@Test
void createTokenBasedOnCurrentPersonaCredentials() {
def response = client.post(path: "/hawkular/secret-store/v1/tokens/create")
Expand Down

0 comments on commit 80ca32d

Please sign in to comment.