diff --git a/backend/pom.xml b/backend/pom.xml index 508859f..84a0292 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -17,7 +17,8 @@ limitations under the License. --> - + 4.0.0 diff --git a/backend/src/main/java/org/hawkular/accounts/backend/boundary/PermissionChecker.java b/backend/src/main/java/org/hawkular/accounts/backend/boundary/PermissionChecker.java index 29d0fd9..a2fe597 100644 --- a/backend/src/main/java/org/hawkular/accounts/backend/boundary/PermissionChecker.java +++ b/backend/src/main/java/org/hawkular/accounts/backend/boundary/PermissionChecker.java @@ -16,16 +16,16 @@ */ package org.hawkular.accounts.backend.boundary; -import javax.ejb.Stateless; -import javax.inject.Inject; import org.hawkular.accounts.backend.entity.HawkularUser; import org.hawkular.accounts.backend.entity.Organization; import org.hawkular.accounts.backend.entity.Owner; import org.hawkular.accounts.backend.entity.Resource; import org.keycloak.KeycloakPrincipal; +import javax.ejb.Stateless; +import javax.inject.Inject; + /** - * * @author Juraci Paixão Kröhling */ @Stateless @@ -38,7 +38,7 @@ public class PermissionChecker { * Determines whether the current {@link HawkularUser} has access to the {@link Resource} * * @param currentUser the user to be checked - * @param resource the resource to be checked + * @param resource the resource to be checked * @return true if the user is the owner or if the user belongs to an organization that owns the resource */ public boolean hasAccessTo(HawkularUser currentUser, Resource resource) { @@ -49,7 +49,7 @@ public boolean hasAccessTo(HawkularUser currentUser, Resource resource) { * Determines whether the current {@KeycloakPrincipal} has access to the {@link Resource}. * * @param principal the {@link KeycloakPrincipal} representing the current user - * @param resource the resource to be checked + * @param resource the resource to be checked * @return true if the user is the owner or if the user belongs to an organization that owns the resource * @see PermissionChecker#hasAccessTo(org.keycloak.KeycloakPrincipal, org.hawkular.accounts.backend.entity.Owner) */ @@ -61,7 +61,7 @@ public boolean hasAccessTo(KeycloakPrincipal principal, Resource resource) { * Determines whether the current {@link HawkularUser} has access to the resource owned by {@link Owner} * * @param currentUser the user to be checked - * @param owner the owner of the resource + * @param owner the owner of the resource * @return true if the user is the owner or if the user belongs to an organization that owns the resource */ public boolean hasAccessTo(HawkularUser currentUser, Owner owner) { @@ -82,10 +82,10 @@ public boolean hasAccessTo(HawkularUser currentUser, Owner owner) { * Determines whether the current {@link KeycloakPrincipal} has access to the resources owned by {@link Owner}. * * @param principal the {@link KeycloakPrincipal} representing the current user - * @param owner the owner of the resource + * @param owner the owner of the resource * @return true if the user is the owner or if the user belongs to an organization that owns the resource * @see PermissionChecker#hasAccessTo( - * org.hawkular.accounts.backend.entity.User, org.hawkular.accounts.backend.entity.Owner) + *org.hawkular.accounts.backend.entity.User, org.hawkular.accounts.backend.entity.Owner) */ public boolean hasAccessTo(KeycloakPrincipal principal, Owner owner) { // Here's a bit of explanation: judging by the name of this class, we wouldn't expect any record to be created. @@ -97,13 +97,13 @@ public boolean hasAccessTo(KeycloakPrincipal principal, Owner owner) { /** * Recursively checks whether an user is a member or owner of an organization. Examples: - * + *

* jdoe is owner of acme -> true * jdoe is member of acme -> true * jdoe is member of emca which is member of acme -> true * emca is member of acme -> true * - * @param member the member to be checked + * @param member the member to be checked * @param organization the organization that might contain the user * @return true if the user belongs to the organization recursively */ @@ -146,7 +146,7 @@ public boolean isMemberOf(Owner member, Organization organization) { * Recursively checks if the specified owner is a direct or indirect owner of the given organization. For instance, * if jdoe is the owner of acme, and acme owns emca, then jdoe owns emca indirectly. * - * @param owner the {@link Owner} to check. In our example above, it would be jdoe or acme. + * @param owner the {@link Owner} to check. In our example above, it would be jdoe or acme. * @param organization the {@link Organization} to verify ownership of. In our example above, it would be emca. * @return whether or not the specified owner is directly or indirectly the owner of the given organization. */ diff --git a/backend/src/main/java/org/hawkular/accounts/backend/boundary/ResourceService.java b/backend/src/main/java/org/hawkular/accounts/backend/boundary/ResourceService.java index 75de3ef..d84d217 100644 --- a/backend/src/main/java/org/hawkular/accounts/backend/boundary/ResourceService.java +++ b/backend/src/main/java/org/hawkular/accounts/backend/boundary/ResourceService.java @@ -16,81 +16,81 @@ */ package org.hawkular.accounts.backend.boundary; -import java.util.List; +import org.hawkular.accounts.backend.entity.Owner; +import org.hawkular.accounts.backend.entity.Resource; +import org.hawkular.accounts.backend.entity.Resource_; +import org.keycloak.KeycloakPrincipal; + import javax.ejb.Stateless; import javax.inject.Inject; import javax.persistence.EntityManager; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Root; -import org.hawkular.accounts.backend.entity.Owner; -import org.hawkular.accounts.backend.entity.Resource; -import org.hawkular.accounts.backend.entity.Resource_; -import org.keycloak.KeycloakPrincipal; +import java.util.List; /** - * * @author Juraci Paixão Kröhling */ @Stateless public class ResourceService { - @Inject - EntityManager em; + @Inject + EntityManager em; - @Inject - UserService userService; + @Inject + UserService userService; - /** - * Retrieves a {@link Resource} based on its ID. - * - * @param id the resource's ID - * @return the existing {@link Resource} or null if the resource doesn't exists. - */ - public Resource getById(String id) { - CriteriaBuilder builder = em.getCriteriaBuilder(); - CriteriaQuery query = builder.createQuery(Resource.class); - Root root = query.from(Resource.class); - query.select(root); - query.where(builder.equal(root.get(Resource_.id), id)); + /** + * Retrieves a {@link Resource} based on its ID. + * + * @param id the resource's ID + * @return the existing {@link Resource} or null if the resource doesn't exists. + */ + public Resource getById(String id) { + CriteriaBuilder builder = em.getCriteriaBuilder(); + CriteriaQuery query = builder.createQuery(Resource.class); + Root root = query.from(Resource.class); + query.select(root); + query.where(builder.equal(root.get(Resource_.id), id)); - List results = em.createQuery(query).getResultList(); - if (results.size() == 1) { - return results.get(0); - } + List results = em.createQuery(query).getResultList(); + if (results.size() == 1) { + return results.get(0); + } + + if (results.size() > 1) { + throw new IllegalStateException("More than one resource found for ID " + id); + } - if (results.size() > 1) { - throw new IllegalStateException("More than one resource found for ID " + id); + return null; } - return null; - } + /** + * Retrieves a {@link Resource} based on its ID or creates a new {@link Resource} if it doesn't exists. + * + * @param id the resource's ID + * @param owner if the resource doesn't exists, a new one is created with the specified owner + * @return the existing {@link Resource} or a new one if it doesn't exists yet. + */ + public Resource getOrCreateById(String id, Owner owner) { + Resource resource = getById(id); + if (null == resource) { + resource = new Resource(id, owner); + em.persist(resource); + } - /** - * Retrieves a {@link Resource} based on its ID or creates a new {@link Resource} if it doesn't exists. - * - * @param id the resource's ID - * @param owner if the resource doesn't exists, a new one is created with the specified owner - * @return the existing {@link Resource} or a new one if it doesn't exists yet. - */ - public Resource getOrCreateById(String id, Owner owner) { - Resource resource = getById(id); - if (null == resource) { - resource = new Resource(id, owner); - em.persist(resource); + return resource; } - return resource; - } - - /** - * Retrieves a {@link Resource} based on its ID or creates a new {@link Resource} if it doesn't exists. - * - * @param id the resource's ID - * @param principal if the resource doesn't exists, a new one is created with the specified principal - * @return the existing {@link Resource} or a new one if it doesn't exists yet. - * @see ResourceService#getOrCreateById(java.lang.String, org.hawkular.accounts.backend.entity.Owner) - */ - public Resource getOrCreateById(String id, KeycloakPrincipal principal) { - return getOrCreateById(id, userService.getByPrincipal(principal)); - } + /** + * Retrieves a {@link Resource} based on its ID or creates a new {@link Resource} if it doesn't exists. + * + * @param id the resource's ID + * @param principal if the resource doesn't exists, a new one is created with the specified principal + * @return the existing {@link Resource} or a new one if it doesn't exists yet. + * @see ResourceService#getOrCreateById(java.lang.String, org.hawkular.accounts.backend.entity.Owner) + */ + public Resource getOrCreateById(String id, KeycloakPrincipal principal) { + return getOrCreateById(id, userService.getByPrincipal(principal)); + } } diff --git a/backend/src/main/java/org/hawkular/accounts/backend/boundary/UserService.java b/backend/src/main/java/org/hawkular/accounts/backend/boundary/UserService.java index 4bba8b3..5764149 100644 --- a/backend/src/main/java/org/hawkular/accounts/backend/boundary/UserService.java +++ b/backend/src/main/java/org/hawkular/accounts/backend/boundary/UserService.java @@ -16,72 +16,75 @@ */ package org.hawkular.accounts.backend.boundary; -import java.util.List; +import org.hawkular.accounts.backend.entity.HawkularUser; +import org.hawkular.accounts.backend.entity.HawkularUser_; +import org.keycloak.KeycloakPrincipal; + import javax.ejb.Stateless; import javax.inject.Inject; import javax.persistence.EntityManager; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Root; -import org.hawkular.accounts.backend.entity.HawkularUser; -import org.hawkular.accounts.backend.entity.HawkularUser_; -import org.keycloak.KeycloakPrincipal; +import java.util.List; /** - * * @author Juraci Paixão Kröhling */ @Stateless public class UserService { - @Inject - EntityManager em; + @Inject + EntityManager em; - /** - * Retrieves an {@link HawkularUser} based in its ID. - * @param id the user ID - * @return the existing user with the given ID or null if the user is not found. - */ - public HawkularUser getById(String id) { - CriteriaBuilder builder = em.getCriteriaBuilder(); - CriteriaQuery query = builder.createQuery(HawkularUser.class); - Root root = query.from(HawkularUser.class); - query.select(root); - query.where(builder.equal(root.get(HawkularUser_.id), id)); + /** + * Retrieves an {@link HawkularUser} based in its ID. + * + * @param id the user ID + * @return the existing user with the given ID or null if the user is not found. + */ + public HawkularUser getById(String id) { + CriteriaBuilder builder = em.getCriteriaBuilder(); + CriteriaQuery query = builder.createQuery(HawkularUser.class); + Root root = query.from(HawkularUser.class); + query.select(root); + query.where(builder.equal(root.get(HawkularUser_.id), id)); - List results = em.createQuery(query).getResultList(); - if (results.size() == 1) { - return results.get(0); - } + List results = em.createQuery(query).getResultList(); + if (results.size() == 1) { + return results.get(0); + } - if (results.size() > 1) { - throw new IllegalStateException("More than one user found for ID " + id); + if (results.size() > 1) { + throw new IllegalStateException("More than one user found for ID " + id); + } + + return null; } - return null; - } + /** + * Retrieves an {@link HawkularUser} based on the {@link KeycloakPrincipal}. + * + * @param principal the {@link KeycloakPrincipal} + * @return an {@link HawkularUser} instance representing the user for the {@link KeycloakPrincipal}.It's never null. + */ + public HawkularUser getByPrincipal(KeycloakPrincipal principal) { + return getOrCreateById(principal.getName()); + } - /** - * Retrieves an {@link HawkularUser} based on the {@link KeycloakPrincipal}. - * @param principal the {@link KeycloakPrincipal} - * @return an {@link HawkularUser} instance representing the user for the {@link KeycloakPrincipal}. It's never null. - */ - public HawkularUser getByPrincipal(KeycloakPrincipal principal) { - return getOrCreateById(principal.getName()); - } + /** + * Retrieves an {@link HawkularUser} based on its ID. If no user is found, a new one is created and returned. + * + * @param id the user ID + * @return an {@link HawkularUser} instance representing the user with the given ID. It's never null. + */ + public HawkularUser getOrCreateById(String id) { + HawkularUser user = getById(id); + if (null == user) { + user = new HawkularUser(id); + em.persist(user); + } - /** - * Retrieves an {@link HawkularUser} based on its ID. If no user is found, a new one is created and returned. - * @param id the user ID - * @return an {@link HawkularUser} instance representing the user with the given ID. It's never null. - */ - public HawkularUser getOrCreateById(String id) { - HawkularUser user = getById(id); - if (null == user) { - user = new HawkularUser(id); - em.persist(user); + return user; } - - return user; - } } diff --git a/backend/src/main/java/org/hawkular/accounts/backend/control/ApplicationResources.java b/backend/src/main/java/org/hawkular/accounts/backend/control/ApplicationResources.java index c65dacd..8b89fcf 100644 --- a/backend/src/main/java/org/hawkular/accounts/backend/control/ApplicationResources.java +++ b/backend/src/main/java/org/hawkular/accounts/backend/control/ApplicationResources.java @@ -21,13 +21,12 @@ import javax.persistence.PersistenceContext; /** - * * @author Juraci Paixão Kröhling */ @ApplicationScoped public class ApplicationResources { - @Produces - @PersistenceContext - private static javax.persistence.EntityManager em; + @Produces + @PersistenceContext + private static javax.persistence.EntityManager em; } diff --git a/backend/src/main/java/org/hawkular/accounts/backend/control/HawkularAccountsMessageLogger.java b/backend/src/main/java/org/hawkular/accounts/backend/control/HawkularAccountsMessageLogger.java index 160c727..b5d7a32 100644 --- a/backend/src/main/java/org/hawkular/accounts/backend/control/HawkularAccountsMessageLogger.java +++ b/backend/src/main/java/org/hawkular/accounts/backend/control/HawkularAccountsMessageLogger.java @@ -21,13 +21,12 @@ import org.jboss.logging.annotations.ValidIdRange; /** - * * @author Juraci Paixão Kröhling */ @MessageLogger(projectCode = "HAWKACC") @ValidIdRange(min = 100000, max = 109999) public interface HawkularAccountsMessageLogger { - HawkularAccountsMessageLogger LOGGER = Logger.getMessageLogger - (HawkularAccountsMessageLogger.class, HawkularAccountsMessageLogger.class.getPackage().getName()); + HawkularAccountsMessageLogger LOGGER = Logger.getMessageLogger + (HawkularAccountsMessageLogger.class, HawkularAccountsMessageLogger.class.getPackage().getName()); } diff --git a/backend/src/main/java/org/hawkular/accounts/backend/entity/BaseEntity.java b/backend/src/main/java/org/hawkular/accounts/backend/entity/BaseEntity.java index f2b3499..14a52a2 100644 --- a/backend/src/main/java/org/hawkular/accounts/backend/entity/BaseEntity.java +++ b/backend/src/main/java/org/hawkular/accounts/backend/entity/BaseEntity.java @@ -16,74 +16,73 @@ */ package org.hawkular.accounts.backend.entity; +import javax.persistence.Id; +import javax.persistence.MappedSuperclass; +import javax.persistence.PreUpdate; import java.io.Serializable; import java.time.ZonedDateTime; import java.util.Objects; import java.util.UUID; -import javax.persistence.Id; -import javax.persistence.MappedSuperclass; -import javax.persistence.PreUpdate; /** - * * @author Juraci Paixão Kröhling */ @MappedSuperclass public class BaseEntity implements Serializable { - @Id - private String id = UUID.randomUUID().toString(); - - private final ZonedDateTime createdAt = ZonedDateTime.now(); - private ZonedDateTime updatedAt = ZonedDateTime.now(); + @Id + private String id = UUID.randomUUID().toString(); - protected BaseEntity() { - } + private final ZonedDateTime createdAt = ZonedDateTime.now(); + private ZonedDateTime updatedAt = ZonedDateTime.now(); - public BaseEntity(String id) { - this.id = id; - } + protected BaseEntity() { + } - public String getId() { - return id; - } + public BaseEntity(String id) { + this.id = id; + } - public ZonedDateTime getCreatedAt() { - return createdAt; - } + public String getId() { + return id; + } - public ZonedDateTime getUpdatedAt() { - return updatedAt; - } + public ZonedDateTime getCreatedAt() { + return createdAt; + } - @PreUpdate - public void setUpdatedAt() { - this.updatedAt = ZonedDateTime.now(); - } + public ZonedDateTime getUpdatedAt() { + return updatedAt; + } - @Override - public String toString() { - return "BaseEntity{" + "id=" + id + ", createdAt=" + createdAt + ", updatedAt=" + updatedAt + '}'; - } + @PreUpdate + public void setUpdatedAt() { + this.updatedAt = ZonedDateTime.now(); + } - @Override - public int hashCode() { - int hash = 5; - hash = 71 * hash + Objects.hashCode(this.id); - return hash; - } + @Override + public String toString() { + return "BaseEntity{" + "id=" + id + ", createdAt=" + createdAt + ", updatedAt=" + updatedAt + '}'; + } - @Override - public boolean equals(Object obj) { - if (obj == null) { - return false; + @Override + public int hashCode() { + int hash = 5; + hash = 71 * hash + Objects.hashCode(this.id); + return hash; } - if (getClass() != obj.getClass()) { - return false; + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final BaseEntity other = (BaseEntity) obj; + return Objects.equals(this.id, other.id); } - final BaseEntity other = (BaseEntity) obj; - return Objects.equals(this.id, other.id); - } } diff --git a/backend/src/main/java/org/hawkular/accounts/backend/entity/HawkularUser.java b/backend/src/main/java/org/hawkular/accounts/backend/entity/HawkularUser.java index 82e044c..f509aa4 100644 --- a/backend/src/main/java/org/hawkular/accounts/backend/entity/HawkularUser.java +++ b/backend/src/main/java/org/hawkular/accounts/backend/entity/HawkularUser.java @@ -27,10 +27,10 @@ @Entity public class HawkularUser extends Owner { - protected HawkularUser() { // JPA happy - } + protected HawkularUser() { // JPA happy + } - public HawkularUser(String id) { - super(id); - } + public HawkularUser(String id) { + super(id); + } } diff --git a/backend/src/main/java/org/hawkular/accounts/backend/entity/Organization.java b/backend/src/main/java/org/hawkular/accounts/backend/entity/Organization.java index 589e609..e9fe658 100644 --- a/backend/src/main/java/org/hawkular/accounts/backend/entity/Organization.java +++ b/backend/src/main/java/org/hawkular/accounts/backend/entity/Organization.java @@ -16,12 +16,12 @@ */ package org.hawkular.accounts.backend.entity; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; import javax.persistence.Entity; import javax.persistence.ManyToMany; import javax.persistence.ManyToOne; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; /** * Represents an non-user entity that can own resources. It has itself an owner. @@ -31,42 +31,42 @@ @Entity public class Organization extends Owner { - @ManyToOne - private Owner owner; + @ManyToOne + private Owner owner; - @ManyToMany - private final List members = new ArrayList<>(); + @ManyToMany + private final List members = new ArrayList<>(); - protected Organization() { // jpa happy - super(); - } - - public Organization(String id, Owner owner) { - super(id); - this.owner = owner; - } + protected Organization() { // jpa happy + super(); + } - public Owner getOwner() { - return owner; - } + public Organization(String id, Owner owner) { + super(id); + this.owner = owner; + } - public List getMembers() { - return Collections.unmodifiableList(members); - } + public Owner getOwner() { + return owner; + } - public void addMember(Owner member) { - if (members.contains(member)) { - return; + public List getMembers() { + return Collections.unmodifiableList(members); } - members.add(member); - } + public void addMember(Owner member) { + if (members.contains(member)) { + return; + } - public void removeMember(Owner member) { - if (!members.contains(member)) { - return; + members.add(member); } - members.remove(member); - } + public void removeMember(Owner member) { + if (!members.contains(member)) { + return; + } + + members.remove(member); + } } diff --git a/backend/src/main/java/org/hawkular/accounts/backend/entity/Owner.java b/backend/src/main/java/org/hawkular/accounts/backend/entity/Owner.java index 0acc64a..690ff16 100644 --- a/backend/src/main/java/org/hawkular/accounts/backend/entity/Owner.java +++ b/backend/src/main/java/org/hawkular/accounts/backend/entity/Owner.java @@ -28,10 +28,10 @@ @Entity @Inheritance(strategy = InheritanceType.JOINED) public class Owner extends BaseEntity { - protected Owner() { // JPA happy - } + protected Owner() { // JPA happy + } - public Owner(String id) { - super(id); - } + public Owner(String id) { + super(id); + } } diff --git a/backend/src/main/java/org/hawkular/accounts/backend/entity/Resource.java b/backend/src/main/java/org/hawkular/accounts/backend/entity/Resource.java index da0bdd8..1bbaa16 100644 --- a/backend/src/main/java/org/hawkular/accounts/backend/entity/Resource.java +++ b/backend/src/main/java/org/hawkular/accounts/backend/entity/Resource.java @@ -20,28 +20,27 @@ import javax.persistence.ManyToOne; /** - * * @author Juraci Paixão Kröhling */ @Entity public class Resource extends BaseEntity { - @ManyToOne - private Owner owner; + @ManyToOne + private Owner owner; - protected Resource() { // JPA happy - } + protected Resource() { // JPA happy + } - public Resource(Owner owner) { - this.owner = owner; - } + public Resource(Owner owner) { + this.owner = owner; + } - public Resource(String id, Owner owner) { - super(id); - this.owner = owner; - } + public Resource(String id, Owner owner) { + super(id); + this.owner = owner; + } - public Owner getOwner() { - return owner; - } + public Owner getOwner() { + return owner; + } } diff --git a/backend/src/main/java/org/hawkular/accounts/backend/entity/adapter/ZonedDateTimeAdapter.java b/backend/src/main/java/org/hawkular/accounts/backend/entity/adapter/ZonedDateTimeAdapter.java index 5547136..d6d1a72 100644 --- a/backend/src/main/java/org/hawkular/accounts/backend/entity/adapter/ZonedDateTimeAdapter.java +++ b/backend/src/main/java/org/hawkular/accounts/backend/entity/adapter/ZonedDateTimeAdapter.java @@ -16,14 +16,13 @@ */ package org.hawkular.accounts.backend.entity.adapter; +import javax.persistence.AttributeConverter; +import javax.persistence.Converter; import java.sql.Timestamp; import java.time.ZoneOffset; import java.time.ZonedDateTime; -import javax.persistence.AttributeConverter; -import javax.persistence.Converter; /** - * * @author Juraci Paixão Kröhling */ @Converter(autoApply = true) diff --git a/backend/src/main/webapp/WEB-INF/beans.xml b/backend/src/main/webapp/WEB-INF/beans.xml index f437bae..5d7ddff 100644 --- a/backend/src/main/webapp/WEB-INF/beans.xml +++ b/backend/src/main/webapp/WEB-INF/beans.xml @@ -18,9 +18,9 @@ --> diff --git a/backend/src/test/java/org/hawkular/accounts/backend/boundary/BaseEntityManagerEnabledTest.java b/backend/src/test/java/org/hawkular/accounts/backend/boundary/BaseEntityManagerEnabledTest.java index e80f29d..436f89d 100644 --- a/backend/src/test/java/org/hawkular/accounts/backend/boundary/BaseEntityManagerEnabledTest.java +++ b/backend/src/test/java/org/hawkular/accounts/backend/boundary/BaseEntityManagerEnabledTest.java @@ -16,21 +16,21 @@ */ package org.hawkular.accounts.backend.boundary; +import org.junit.Before; + import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.Persistence; -import org.junit.Before; /** - * * @author Juraci Paixão Kröhling */ public class BaseEntityManagerEnabledTest { - EntityManager entityManager; + EntityManager entityManager; - @Before - public void initializeEntityManager() { - EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("backend-unittest-pu"); - this.entityManager = entityManagerFactory.createEntityManager(); - } + @Before + public void initializeEntityManager() { + EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("backend-unittest-pu"); + this.entityManager = entityManagerFactory.createEntityManager(); + } } diff --git a/backend/src/test/java/org/hawkular/accounts/backend/boundary/PermissionCheckerTest.java b/backend/src/test/java/org/hawkular/accounts/backend/boundary/PermissionCheckerTest.java index eeaa980..850d7ea 100644 --- a/backend/src/test/java/org/hawkular/accounts/backend/boundary/PermissionCheckerTest.java +++ b/backend/src/test/java/org/hawkular/accounts/backend/boundary/PermissionCheckerTest.java @@ -16,16 +16,17 @@ */ package org.hawkular.accounts.backend.boundary; -import java.util.UUID; import org.hawkular.accounts.backend.entity.HawkularUser; import org.hawkular.accounts.backend.entity.Organization; import org.hawkular.accounts.backend.entity.Resource; -import static org.junit.Assert.assertTrue; import org.junit.Test; import org.keycloak.KeycloakPrincipal; +import java.util.UUID; + +import static org.junit.Assert.assertTrue; + /** - * * @author Juraci Paixão Kröhling */ public class PermissionCheckerTest extends BaseEntityManagerEnabledTest { diff --git a/backend/src/test/java/org/hawkular/accounts/backend/boundary/ResourceServiceTest.java b/backend/src/test/java/org/hawkular/accounts/backend/boundary/ResourceServiceTest.java index a371145..86745e2 100644 --- a/backend/src/test/java/org/hawkular/accounts/backend/boundary/ResourceServiceTest.java +++ b/backend/src/test/java/org/hawkular/accounts/backend/boundary/ResourceServiceTest.java @@ -16,59 +16,60 @@ */ package org.hawkular.accounts.backend.boundary; -import java.util.UUID; import org.hawkular.accounts.backend.entity.HawkularUser; import org.hawkular.accounts.backend.entity.Owner; import org.hawkular.accounts.backend.entity.Resource; -import static org.junit.Assert.assertNotNull; import org.junit.Before; import org.junit.Test; +import java.util.UUID; + +import static org.junit.Assert.assertNotNull; + /** - * * @author Juraci Paixão Kröhling */ public class ResourceServiceTest extends BaseEntityManagerEnabledTest { - private ResourceService resourceService; - private UserService userService; + private ResourceService resourceService; + private UserService userService; - @Before - public void prepareServices() { - this.resourceService = new ResourceService(); - this.userService = new UserService(); - this.userService.em = entityManager; - this.resourceService.em = entityManager; - this.resourceService.userService = this.userService; - } + @Before + public void prepareServices() { + this.resourceService = new ResourceService(); + this.userService = new UserService(); + this.userService.em = entityManager; + this.resourceService.em = entityManager; + this.resourceService.userService = this.userService; + } - @Test - public void existingResourceIsRetrieved() { - entityManager.getTransaction().begin(); - Owner user = new HawkularUser(UUID.randomUUID().toString()); - String resourceId = UUID.randomUUID().toString(); - Resource resource = new Resource(resourceId, user); - entityManager.persist(user); - entityManager.persist(resource); - entityManager.getTransaction().commit(); + @Test + public void existingResourceIsRetrieved() { + entityManager.getTransaction().begin(); + Owner user = new HawkularUser(UUID.randomUUID().toString()); + String resourceId = UUID.randomUUID().toString(); + Resource resource = new Resource(resourceId, user); + entityManager.persist(user); + entityManager.persist(resource); + entityManager.getTransaction().commit(); - entityManager.getTransaction().begin(); - assertNotNull(resourceService.getById(resourceId)); - entityManager.getTransaction().commit(); - } + entityManager.getTransaction().begin(); + assertNotNull(resourceService.getById(resourceId)); + entityManager.getTransaction().commit(); + } - @Test - public void nonExistingResourceIsCreated() { - entityManager.getTransaction().begin(); - Owner user = new HawkularUser(UUID.randomUUID().toString()); - entityManager.persist(user); - entityManager.getTransaction().commit(); + @Test + public void nonExistingResourceIsCreated() { + entityManager.getTransaction().begin(); + Owner user = new HawkularUser(UUID.randomUUID().toString()); + entityManager.persist(user); + entityManager.getTransaction().commit(); - entityManager.getTransaction().begin(); - Resource resource = resourceService.getOrCreateById(UUID.randomUUID().toString(), user); - entityManager.getTransaction().commit(); + entityManager.getTransaction().begin(); + Resource resource = resourceService.getOrCreateById(UUID.randomUUID().toString(), user); + entityManager.getTransaction().commit(); - entityManager.getTransaction().begin(); - assertNotNull(resourceService.getById(resource.getId())); - entityManager.getTransaction().commit(); - } + entityManager.getTransaction().begin(); + assertNotNull(resourceService.getById(resource.getId())); + entityManager.getTransaction().commit(); + } } diff --git a/backend/src/test/java/org/hawkular/accounts/backend/entity/BasicPersistenceUnitTest.java b/backend/src/test/java/org/hawkular/accounts/backend/entity/BasicPersistenceUnitTest.java index 539820b..96a9990 100644 --- a/backend/src/test/java/org/hawkular/accounts/backend/entity/BasicPersistenceUnitTest.java +++ b/backend/src/test/java/org/hawkular/accounts/backend/entity/BasicPersistenceUnitTest.java @@ -16,53 +16,54 @@ */ package org.hawkular.accounts.backend.entity; +import org.junit.Before; +import org.junit.Test; + import javax.persistence.Entity; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.Persistence; + import static org.junit.Assert.assertEquals; -import org.junit.Before; -import org.junit.Test; /** - * * @author Juraci Paixão Kröhling */ public class BasicPersistenceUnitTest { - private EntityManager entityManager; + private EntityManager entityManager; - @Before - public void setup() { - EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("backend-unittest-pu"); - this.entityManager = entityManagerFactory.createEntityManager(); - } + @Before + public void setup() { + EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("backend-unittest-pu"); + this.entityManager = entityManagerFactory.createEntityManager(); + } - @Test - public void testIsAbleToPersist() { - BaseEntityTest baseEntityTest = new BaseEntityTest(); + @Test + public void testIsAbleToPersist() { + BaseEntityTest baseEntityTest = new BaseEntityTest(); - entityManager.getTransaction().begin(); - entityManager.persist(baseEntityTest); - entityManager.getTransaction().commit(); - } + entityManager.getTransaction().begin(); + entityManager.persist(baseEntityTest); + entityManager.getTransaction().commit(); + } - @Test - public void createdAtIsConsistent() { - BaseEntityTest baseEntityTest = new BaseEntityTest(); + @Test + public void createdAtIsConsistent() { + BaseEntityTest baseEntityTest = new BaseEntityTest(); - entityManager.getTransaction().begin(); - entityManager.persist(baseEntityTest); - entityManager.getTransaction().commit(); + entityManager.getTransaction().begin(); + entityManager.persist(baseEntityTest); + entityManager.getTransaction().commit(); - entityManager.getTransaction().begin(); - BaseEntityTest fromDatabase = entityManager.find(BaseEntityTest.class, baseEntityTest.getId()); - entityManager.getTransaction().commit(); + entityManager.getTransaction().begin(); + BaseEntityTest fromDatabase = entityManager.find(BaseEntityTest.class, baseEntityTest.getId()); + entityManager.getTransaction().commit(); - assertEquals("Timezone should be kept", fromDatabase.getCreatedAt(), baseEntityTest.getCreatedAt()); - } + assertEquals("Timezone should be kept", fromDatabase.getCreatedAt(), baseEntityTest.getCreatedAt()); + } - @Entity - public class BaseEntityTest extends BaseEntity { - } + @Entity + public class BaseEntityTest extends BaseEntity { + } } diff --git a/distribution/pom.xml b/distribution/pom.xml index 67a331d..e4bb10d 100644 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -17,7 +17,8 @@ limitations under the License. --> - + 4.0.0 diff --git a/example/backend/pom.xml b/example/backend/pom.xml index ab9228e..8be78c2 100644 --- a/example/backend/pom.xml +++ b/example/backend/pom.xml @@ -17,7 +17,8 @@ limitations under the License. --> - + 4.0.0 diff --git a/example/pom.xml b/example/pom.xml index ead5db3..debb213 100644 --- a/example/pom.xml +++ b/example/pom.xml @@ -17,7 +17,8 @@ limitations under the License. --> - + 4.0.0 diff --git a/example/ui/pom.xml b/example/ui/pom.xml index 5c291f0..7946465 100644 --- a/example/ui/pom.xml +++ b/example/ui/pom.xml @@ -17,7 +17,8 @@ limitations under the License. --> - + 4.0.0 diff --git a/ui/pom.xml b/ui/pom.xml index 6643e65..0bf3de8 100644 --- a/ui/pom.xml +++ b/ui/pom.xml @@ -17,7 +17,8 @@ limitations under the License. --> - + 4.0.0