added missing tests (#48)
Reviewed-on: de.nclazz/codebuilder#48 Co-authored-by: Niclas Thobaben <nthobaben@nclazz.de> Co-committed-by: Niclas Thobaben <nthobaben@nclazz.de>master
parent
0aff4fca37
commit
973e927695
|
@ -35,9 +35,11 @@ pipeline {
|
|||
sh 'mvn verify -B -s settings.xml'
|
||||
jacoco(
|
||||
changeBuildStatus: true,
|
||||
exclusionPattern: '**/models/**',
|
||||
exclusionPattern: '**/models/**, **/resources/**/*Controller.class',
|
||||
minimumInstructionCoverage: '30',
|
||||
maximumInstructionCoverage: '50'
|
||||
maximumInstructionCoverage: '50',
|
||||
minimumClassCoverage: '60',
|
||||
maximumClassCoverage: '80'
|
||||
)
|
||||
recordIssues(
|
||||
enabledForFailure: true,
|
||||
|
|
|
@ -66,6 +66,10 @@ public class AuthenticationsService {
|
|||
}
|
||||
|
||||
public Optional<AuthenticationEntity> addAuthentication(@NonNull UserEntity user, AuthenticationType type, String value) {
|
||||
if(!this.usersService.userExists(user.getGuid())) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
AuthenticationEntity authentication = new AuthenticationEntity();
|
||||
authentication.setType(type);
|
||||
authentication.setValue(value);
|
||||
|
|
|
@ -18,7 +18,9 @@ import java.util.*;
|
|||
@Data
|
||||
@Table(name = "generators")
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@EqualsAndHashCode(
|
||||
callSuper = true,
|
||||
onlyExplicitlyIncluded = true)
|
||||
public class GeneratorEntity extends AbstractItem {
|
||||
|
||||
@Data
|
||||
|
@ -34,7 +36,10 @@ public class GeneratorEntity extends AbstractItem {
|
|||
}
|
||||
}
|
||||
|
||||
@EqualsAndHashCode.Include
|
||||
private String name;
|
||||
|
||||
@EqualsAndHashCode.Include
|
||||
@Column(name = "generator_key")
|
||||
private String key;
|
||||
private String description;
|
||||
|
|
|
@ -56,7 +56,7 @@ public class GeneratorsController {
|
|||
|
||||
@PostMapping
|
||||
public Generator createNewGenerator(@RequestBody GeneratorForm form) {
|
||||
return this.generatorsService.createGeneratorForOrganization(form.getOrganization(), form)
|
||||
return this.generatorsService.createGeneratorForOrganization(form)
|
||||
.map(this::mapGeneratorFromEntity)
|
||||
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND));
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@ public class GeneratorsService {
|
|||
|
||||
private final OrganizationService organizationService;
|
||||
private final GeneratorsRepository generatorsRepository;
|
||||
private final TypeMappingService typeMappingService;
|
||||
private final ApplicationEventPublisher publisher;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -64,9 +63,9 @@ public class GeneratorsService {
|
|||
return this.generatorsRepository.existsByKey(key);
|
||||
}
|
||||
|
||||
public Optional<GeneratorEntity> createGeneratorForOrganization(UUID organizationGuid, GeneratorForm form) {
|
||||
if(!this.organizationService.organizationExists(organizationGuid)) {
|
||||
log.warn("organization {} does not exist", organizationGuid);
|
||||
public Optional<GeneratorEntity> createGeneratorForOrganization(GeneratorForm form) {
|
||||
if(!this.organizationService.organizationExists(form.getOrganization())) {
|
||||
log.warn("organization {} does not exist", form.getOrganization());
|
||||
return Optional.empty();
|
||||
}
|
||||
String key = form.getKey() != null ? form.getKey() : CodebuilderUtils.createKeyForName(form.getName());
|
||||
|
@ -91,7 +90,7 @@ public class GeneratorsService {
|
|||
.collect(Collectors.toSet())
|
||||
);
|
||||
|
||||
generator.setOrganization(new OrganizationEntity(organizationGuid));
|
||||
generator.setOrganization(new OrganizationEntity(form.getOrganization()));
|
||||
|
||||
return Optional.of(this.generatorsRepository.save(generator));
|
||||
}
|
||||
|
@ -123,7 +122,12 @@ public class GeneratorsService {
|
|||
return result != 0;
|
||||
}
|
||||
|
||||
public void deleteByGuid(@NonNull UUID guid) {
|
||||
this.generatorsRepository.deleteById(guid);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("CollectionAddAllCanBeReplacedWithConstructor")
|
||||
private List<ValidationError> validateGenerator(GeneratorEntity generator, GeneratorEntity original) {
|
||||
List<ValidationError> errors = new ArrayList<>();
|
||||
|
||||
|
|
|
@ -1,20 +1,16 @@
|
|||
package de.nclazz.apps.codebuilder.resources.mappings;
|
||||
|
||||
import de.nclazz.codebuilder.v0.models.OrderBy;
|
||||
import de.nclazz.codebuilder.v0.models.TypeMapping;
|
||||
import de.nclazz.codebuilder.v0.models.TypeMappingForm;
|
||||
import de.nclazz.codebuilder.v0.models.TypeMappingUpdateForm;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.modelmapper.ModelMapper;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
|
@ -33,7 +29,7 @@ public class TypeMappingController {
|
|||
|
||||
@PostMapping
|
||||
public TypeMapping createMappingForOrganization(@RequestBody TypeMappingForm form) {
|
||||
return this.typeMappingService.createTypeMappingForOrganization(form.getOrganization(), form)
|
||||
return this.typeMappingService.createTypeMappingForOrganization(form)
|
||||
.map(this::mapTypeMappingFromEntity)
|
||||
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND));
|
||||
}
|
||||
|
@ -48,7 +44,7 @@ public class TypeMappingController {
|
|||
|
||||
@DeleteMapping("{guid}")
|
||||
public ResponseEntity<Void> deleteTypeMappingForOrganization(@PathVariable("guid")UUID guid) {
|
||||
return this.typeMappingService.markTypeMappingAsDeleted(guid)
|
||||
return this.typeMappingService.markDeletedByGuid(guid)
|
||||
? ResponseEntity.status(HttpStatus.NO_CONTENT).build()
|
||||
: ResponseEntity.status(HttpStatus.NOT_FOUND).build();
|
||||
}
|
||||
|
|
|
@ -28,6 +28,6 @@ interface TypeMappingRepository extends PagingAndSortingRepository<TypeMappingEn
|
|||
@Transactional
|
||||
@Modifying
|
||||
@Query("update TypeMappingEntity t set t.status = :status where t.guid = :guid")
|
||||
boolean updateTypeMappingStatus(@Param("guid") @NonNull UUID guid, @Param("status") @NonNull ItemStatus status);
|
||||
int updateTypeMappingStatus(@Param("guid") @NonNull UUID guid, @Param("status") @NonNull ItemStatus status);
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import de.nclazz.apps.codebuilder.common.Validations;
|
|||
import de.nclazz.apps.codebuilder.resources.organizations.OrganizationEntity;
|
||||
import de.nclazz.apps.codebuilder.resources.organizations.OrganizationService;
|
||||
import de.nclazz.codebuilder.v0.models.*;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.modelmapper.ModelMapper;
|
||||
|
@ -33,13 +34,13 @@ public class TypeMappingService {
|
|||
return this.typeMappingRepository.findById(guid);
|
||||
}
|
||||
|
||||
public Optional<TypeMappingEntity> createTypeMappingForOrganization(UUID organizationGuid, TypeMappingForm form) {
|
||||
if(!this.organizationService.organizationExists(organizationGuid)) {
|
||||
public Optional<TypeMappingEntity> createTypeMappingForOrganization(TypeMappingForm form) {
|
||||
if(!this.organizationService.organizationExists(form.getOrganization())) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
OrganizationEntity organization = new OrganizationEntity();
|
||||
organization.setGuid(organizationGuid);
|
||||
organization.setGuid(form.getOrganization());
|
||||
|
||||
TypeMappingEntity typeMapping = new TypeMappingEntity();
|
||||
typeMapping.setKey(form.getKey());
|
||||
|
@ -62,8 +63,12 @@ public class TypeMappingService {
|
|||
.map(this.typeMappingRepository::save);
|
||||
}
|
||||
|
||||
public boolean markTypeMappingAsDeleted(UUID mappingGuid) {
|
||||
return this.typeMappingRepository.updateTypeMappingStatus(mappingGuid, ItemStatus.DELETED);
|
||||
public boolean markDeletedByGuid(@NonNull UUID guid) {
|
||||
return this.typeMappingRepository.updateTypeMappingStatus(guid, ItemStatus.DELETED) != 0;
|
||||
}
|
||||
|
||||
public void deleteByGuid(@NonNull UUID guid) {
|
||||
this.typeMappingRepository.deleteById(guid);
|
||||
}
|
||||
|
||||
private List<ValidationError> validateTypeMapping(TypeMappingEntity mapping) {
|
||||
|
|
|
@ -29,13 +29,13 @@ import java.util.UUID;
|
|||
@EqualsAndHashCode(callSuper = true)
|
||||
public class MembershipEntity extends AbstractItem {
|
||||
|
||||
@OneToOne
|
||||
@ManyToOne
|
||||
private UserEntity member;
|
||||
|
||||
@OneToOne(orphanRemoval = true, cascade = CascadeType.REMOVE)
|
||||
@ManyToOne
|
||||
private OrganizationEntity organization;
|
||||
|
||||
@ElementCollection
|
||||
@ElementCollection(fetch = FetchType.EAGER)
|
||||
@Enumerated(EnumType.STRING)
|
||||
@CollectionTable(name = "membership_permissions")
|
||||
private Set<MemberPermission> permissions;
|
||||
|
|
|
@ -22,7 +22,6 @@ public abstract class MembershipEvent extends GenericEvent {
|
|||
private final UUID userGuid;
|
||||
|
||||
private final ItemStatus status;
|
||||
private final Set<MemberPermission> permissions;
|
||||
}
|
||||
|
||||
public MembershipEvent(String type, MembershipEntity membership, MembershipRef ref) {
|
||||
|
@ -44,8 +43,7 @@ public abstract class MembershipEvent extends GenericEvent {
|
|||
membership.getGuid(),
|
||||
membership.getOrganization().getGuid(),
|
||||
membership.getMember().getGuid(),
|
||||
membership.getStatus(),
|
||||
membership.getPermissions()
|
||||
membership.getStatus()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -61,8 +59,7 @@ public abstract class MembershipEvent extends GenericEvent {
|
|||
membership.getGuid(),
|
||||
membership.getOrganization().getGuid(),
|
||||
membership.getMember().getGuid(),
|
||||
membership.getStatus(),
|
||||
Collections.emptySet()
|
||||
membership.getStatus()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ interface MembershipRepository extends JpaRepository<MembershipEntity, UUID> {
|
|||
@Transactional
|
||||
@Modifying
|
||||
@Query("update MembershipEntity m set m.status = :status where m.guid = :guid")
|
||||
boolean updateMembershipStatus(@Param("guid") @NonNull UUID guid, @Param("status") @NonNull ItemStatus status);
|
||||
int updateMembershipStatus(@Param("guid") @NonNull UUID guid, @Param("status") @NonNull ItemStatus status);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ public class MembershipsController {
|
|||
private final MembershipsService membershipService;
|
||||
private final ModelMapper mapper;
|
||||
|
||||
@PreAuthorize("hasAnyAuthority('usser') and @membershipsService.userCanEditOrganization(#organizazionGuid, authentication)")
|
||||
@PreAuthorize("hasAnyAuthority('usser') and @membershipsService.userCanEditOrganization(#organizationGuid, authentication)")
|
||||
@GetMapping
|
||||
public List<MembershipSummary> findAll(@PathVariable("org_guid")UUID organizationGuid) {
|
||||
List<MembershipEntity> memberships = this.membershipService.findAll(organizationGuid)
|
||||
|
@ -34,25 +34,25 @@ public class MembershipsController {
|
|||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAnyAuthority('usser') and @membershipsService.userCanEditOrganization(#organizazionGuid, authentication)")
|
||||
@PreAuthorize("hasAnyAuthority('usser') and @membershipsService.userCanEditOrganization(#organizationGuid, authentication)")
|
||||
@GetMapping("{guid}")
|
||||
public Membership findByGuid(@PathVariable("org_guid")UUID organizationGuid,
|
||||
@PathVariable("guid")UUID guid) {
|
||||
return this.membershipService.findByGuid(organizationGuid, guid)
|
||||
return this.membershipService.findByGuid(guid)
|
||||
.map(this::mapMembershipFromEntity)
|
||||
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAnyAuthority('usser') and @membershipsService.userCanEditOrganization(#organizazionGuid, authentication)")
|
||||
@PreAuthorize("hasAnyAuthority('usser') and @membershipsService.userCanEditOrganization(#organizationGuid, authentication)")
|
||||
@PostMapping
|
||||
public Membership createNewMembership(@PathVariable("org_guid")UUID organizationGuid,
|
||||
@RequestBody MembershipForm form) {
|
||||
return this.membershipService.createMembershipForOrganization(organizationGuid, form)
|
||||
return this.membershipService.createMembershipForOrganization(form)
|
||||
.map(this::mapMembershipFromEntity)
|
||||
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAnyAuthority('usser') and @membershipsService.userCanEditOrganization(#organizazionGuid, authentication)")
|
||||
@PreAuthorize("hasAnyAuthority('usser') and @membershipsService.userCanEditOrganization(#organizationGuid, authentication)")
|
||||
@PutMapping("{guid}")
|
||||
public Membership updateMembership(@PathVariable("org_guid")UUID organizationGuid,
|
||||
@PathVariable("guid")UUID guid,
|
||||
|
@ -62,11 +62,11 @@ public class MembershipsController {
|
|||
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAnyAuthority('usser') and @membershipsService.userCanEditOrganization(#organizazionGuid, authentication)")
|
||||
@PreAuthorize("hasAnyAuthority('usser') and @membershipsService.userCanEditOrganization(#organizationGuid, authentication)")
|
||||
@DeleteMapping("{guid}")
|
||||
public ResponseEntity<Void> deleteMembership(@PathVariable("org_guid")UUID organizationGuid,
|
||||
@PathVariable("guid")UUID guid) {
|
||||
return this.membershipService.markMembershipAsDeleted(organizationGuid, guid)
|
||||
return this.membershipService.markMembershipAsDeleted(guid)
|
||||
? ResponseEntity.status(HttpStatus.NO_CONTENT).build()
|
||||
: ResponseEntity.status(HttpStatus.NOT_FOUND).build();
|
||||
}
|
||||
|
|
|
@ -32,17 +32,17 @@ public class MembershipsService {
|
|||
.map(OrganizationEntity::getMemberships);
|
||||
}
|
||||
|
||||
public Optional<MembershipEntity> findByGuid(UUID organizationGuid, UUID membershipGuid) {
|
||||
return this.organizationService.findByGuid(organizationGuid)
|
||||
.map(OrganizationEntity::getMemberships)
|
||||
.stream().flatMap(List::stream)
|
||||
.filter(membership -> Objects.equals(membership.getGuid(), membershipGuid))
|
||||
.findAny();
|
||||
public Optional<MembershipEntity> findByGuid(UUID guid) {
|
||||
return this.membershipRepository.findById(guid);
|
||||
}
|
||||
|
||||
public Optional<MembershipEntity> createMembershipForOrganization(UUID organizationGuid, MembershipForm form) {
|
||||
if(!this.organizationService.organizationExists(organizationGuid)) {
|
||||
log.warn("organization {} does not exist!", organizationGuid);
|
||||
public boolean existsByGuid(@NonNull UUID guid) {
|
||||
return this.membershipRepository.existsById(guid);
|
||||
}
|
||||
|
||||
public Optional<MembershipEntity> createMembershipForOrganization(MembershipForm form) {
|
||||
if(!this.organizationService.organizationExists(form.getOrganization())) {
|
||||
log.warn("organization {} does not exist!", form.getOrganization());
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ public class MembershipsService {
|
|||
}
|
||||
|
||||
OrganizationEntity organization = new OrganizationEntity();
|
||||
organization.setGuid(organizationGuid);
|
||||
organization.setGuid(form.getOrganization());
|
||||
|
||||
UserEntity user = new UserEntity();
|
||||
user.setGuid(form.getUser());
|
||||
|
@ -83,18 +83,15 @@ public class MembershipsService {
|
|||
membership = this.membershipRepository.save(membership);
|
||||
this.publisher.publishEvent(new MembershipEvent.Upserted(membership));
|
||||
|
||||
return Optional.of(membership);
|
||||
return findByGuid(membership.getGuid());
|
||||
}
|
||||
|
||||
public boolean markMembershipAsDeleted(@NonNull UUID organizationGuid, @NonNull UUID guid) {
|
||||
if(this.organizationService.findByGuid(organizationGuid).isPresent()) {
|
||||
return false;
|
||||
}
|
||||
public boolean markMembershipAsDeleted(@NonNull UUID guid) {
|
||||
Optional<MembershipEntity> membership = this.membershipRepository.findById(guid);
|
||||
if(membership.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
boolean success = this.membershipRepository.updateMembershipStatus(guid, ItemStatus.DELETED);
|
||||
boolean success = this.membershipRepository.updateMembershipStatus(guid, ItemStatus.DELETED) != 0;
|
||||
this.publisher.publishEvent(new MembershipEvent.Upserted(membership.get()));
|
||||
return success;
|
||||
}
|
||||
|
@ -131,8 +128,7 @@ public class MembershipsService {
|
|||
|| org.getMemberships().stream()
|
||||
.map(MembershipEntity::getMember)
|
||||
.map(UserEntity::getGuid)
|
||||
.filter(uid -> uid.equals(user))
|
||||
.findAny().isPresent();
|
||||
.anyMatch(uid -> uid.equals(user));
|
||||
}
|
||||
|
||||
private UUID fetchUserGuidFromAuthentication(Authentication authentication) {
|
||||
|
|
|
@ -25,12 +25,14 @@ import java.util.UUID;
|
|||
@Cacheable
|
||||
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = true, onlyExplicitlyIncluded = true)
|
||||
public class OrganizationEntity extends AbstractItem {
|
||||
|
||||
@EqualsAndHashCode.Include
|
||||
@Column(nullable = false)
|
||||
private String name;
|
||||
|
||||
@EqualsAndHashCode.Include
|
||||
@Column(name = "org_key", unique = true, nullable = false)
|
||||
private String key;
|
||||
|
||||
|
|
|
@ -75,6 +75,8 @@ public class OrganizationService {
|
|||
throw new ValidationException(errors);
|
||||
}
|
||||
|
||||
organization.setStatus(ItemStatus.ACTIVE);
|
||||
|
||||
this.organizationRepository.save(organization);
|
||||
this.publisher.publishEvent(new OrganizationEvent.Upserted(organization));
|
||||
return Optional.of(organization);
|
||||
|
|
|
@ -75,7 +75,6 @@ public class OrganizationsController {
|
|||
.orElseThrow(() -> new ResponseStatusException(HttpStatus.BAD_REQUEST));
|
||||
|
||||
this.membershipsService.createMembershipForOrganization(
|
||||
org.getGuid(),
|
||||
new MembershipForm(
|
||||
user.getGuid(),
|
||||
org.getGuid(),
|
||||
|
|
|
@ -21,7 +21,7 @@ public class TemplateEntity extends AbstractItem {
|
|||
|
||||
private boolean scaffolding = false;
|
||||
|
||||
@ManyToOne(cascade = CascadeType.REMOVE)
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "generator_guid")
|
||||
private GeneratorEntity generator;
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import de.nclazz.apps.codebuilder.common.Validations;
|
|||
import de.nclazz.apps.codebuilder.resources.generators.GeneratorEntity;
|
||||
import de.nclazz.apps.codebuilder.resources.generators.GeneratorsService;
|
||||
import de.nclazz.apps.codebuilder.resources.organizations.OrganizationService;
|
||||
import de.nclazz.codebuilder.v0.models.ItemStatus;
|
||||
import de.nclazz.codebuilder.v0.models.TemplateForm;
|
||||
import de.nclazz.codebuilder.v0.models.TemplateUpdateForm;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
@ -42,6 +43,7 @@ public class TemplatesService {
|
|||
template.setDirectory(form.getDirectory());
|
||||
template.setContent(form.getContent());
|
||||
template.setGenerator(new GeneratorEntity(form.getGenerator()));
|
||||
template.setStatus(ItemStatus.ACTIVE);
|
||||
|
||||
List<ValidationError> errors = validateTemplate(template, null);
|
||||
if(!errors.isEmpty()) {
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package de.nclazz.apps.codebuilder.resources.authentications;
|
||||
|
||||
import de.nclazz.apps.codebuilder.resources.users.UserEntity;
|
||||
import de.nclazz.codebuilder.v0.models.AuthenticationType;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class AuthenticationEntityTest {
|
||||
|
||||
@Test
|
||||
void InstancesOfAuthenticationShouldEqual() {
|
||||
UUID guid = UUID.randomUUID();
|
||||
UserEntity user = new UserEntity(UUID.randomUUID());
|
||||
|
||||
AuthenticationEntity a = new AuthenticationEntity();
|
||||
a.setGuid(guid);
|
||||
a.setUser(user);
|
||||
a.setType(AuthenticationType.PASSWORD);
|
||||
a.setValue("password");
|
||||
|
||||
AuthenticationEntity b = new AuthenticationEntity();
|
||||
b.setGuid(guid);
|
||||
b.setUser(user);
|
||||
b.setType(AuthenticationType.PASSWORD);
|
||||
b.setValue("password");
|
||||
|
||||
assertEquals(a, b);
|
||||
|
||||
b.setUser(new UserEntity(user.getGuid()));
|
||||
|
||||
assertEquals(a, b);
|
||||
}
|
||||
|
||||
}
|
|
@ -15,6 +15,7 @@ import org.springframework.test.context.ActiveProfiles;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
|
@ -118,7 +119,15 @@ class AuthenticationsServiceTest {
|
|||
assertFalse(result.isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void RequestingPasswordResetCreatesNewAuthentication() {
|
||||
Optional<AuthenticationEntity> result = this.authenticationsService.requestPasswordReset(this.user);
|
||||
assertTrue(result.isPresent());
|
||||
assertEquals(AuthenticationType.PASSWORD_RESET_TOKEN, result.get().getType());
|
||||
|
||||
result = this.authenticationsService.requestPasswordReset(new UserEntity(UUID.randomUUID()));
|
||||
assertTrue(result.isEmpty());
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package de.nclazz.apps.codebuilder.resources.generators;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class GeneratorEntityTest {
|
||||
|
||||
@Test
|
||||
void InstancesOfGeneratorShouldEqual() {
|
||||
UUID guid = UUID.randomUUID();
|
||||
String name = UUID.randomUUID().toString();
|
||||
|
||||
GeneratorEntity a = new GeneratorEntity();
|
||||
a.setGuid(guid);
|
||||
a.setKey(name);
|
||||
a.setName(name);
|
||||
|
||||
GeneratorEntity b = new GeneratorEntity();
|
||||
b.setGuid(guid);
|
||||
b.setKey(name);
|
||||
b.setName(name);
|
||||
|
||||
GeneratorEntity otherGuid = new GeneratorEntity();
|
||||
otherGuid.setGuid(UUID.randomUUID());
|
||||
otherGuid.setKey(name);
|
||||
otherGuid.setName(name);
|
||||
|
||||
GeneratorEntity otherKey = new GeneratorEntity();
|
||||
otherKey.setGuid(guid);
|
||||
otherKey.setKey("key");
|
||||
otherKey.setName(name);
|
||||
|
||||
GeneratorEntity otherName = new GeneratorEntity();
|
||||
otherKey.setGuid(guid);
|
||||
otherKey.setKey(name);
|
||||
otherKey.setName("name");
|
||||
|
||||
assertEquals(a, b);
|
||||
assertNotEquals(a, otherGuid);
|
||||
assertNotEquals(a, otherKey);
|
||||
assertNotEquals(a, otherName);
|
||||
assertNotEquals(otherGuid, otherKey);
|
||||
assertNotEquals(otherGuid, otherName);
|
||||
assertNotEquals(otherKey, otherName);
|
||||
|
||||
assertEquals(a.hashCode(), b.hashCode());
|
||||
assertNotEquals(a.hashCode(), otherKey.hashCode());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,135 @@
|
|||
package de.nclazz.apps.codebuilder.resources.generators;
|
||||
|
||||
import de.nclazz.apps.codebuilder.common.ValidationException;
|
||||
import de.nclazz.apps.codebuilder.resources.organizations.OrganizationEntity;
|
||||
import de.nclazz.apps.codebuilder.resources.organizations.OrganizationService;
|
||||
import de.nclazz.codebuilder.v0.models.GeneratorForm;
|
||||
import de.nclazz.codebuilder.v0.models.ItemStatus;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@SuppressWarnings("OptionalGetWithoutIsPresent")
|
||||
@SpringBootTest
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
@ActiveProfiles("test")
|
||||
class GeneratorsServiceTest {
|
||||
|
||||
@Autowired
|
||||
GeneratorsService service;
|
||||
|
||||
@Autowired
|
||||
OrganizationService organizationService;
|
||||
|
||||
OrganizationEntity organizationEntity;
|
||||
|
||||
@BeforeAll
|
||||
void setup() {
|
||||
OrganizationEntity org = new OrganizationEntity();
|
||||
org.setName("test-org");
|
||||
this.organizationEntity = this.organizationService.createNewOrganization(org).get();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
void tearDown() {
|
||||
this.organizationService.deleteByGuid(this.organizationEntity.getGuid());
|
||||
}
|
||||
|
||||
@Test
|
||||
void CreatingNewGeneratorShouldSucceed() {
|
||||
GeneratorForm form = new GeneratorForm();
|
||||
form.setName("generator");
|
||||
form.setOrganization(this.organizationEntity.getGuid());
|
||||
|
||||
Optional<GeneratorEntity> result = this.service.createGeneratorForOrganization(form);
|
||||
|
||||
assertTrue(result.isPresent());
|
||||
assertEquals(ItemStatus.ACTIVE, result.get().getStatus());
|
||||
assertEquals("generator", result.get().getName());
|
||||
assertEquals("generator", result.get().getKey());
|
||||
assertEquals(this.organizationEntity.getGuid(), result.get().getOrganization().getGuid());
|
||||
|
||||
assertTrue(this.service.findByGuid(result.get().getGuid()).isPresent());
|
||||
|
||||
this.service.deleteByGuid(result.get().getGuid());
|
||||
}
|
||||
|
||||
@Test
|
||||
void GeneratorCanNotBeCreatedOnIllegalKey() {
|
||||
GeneratorForm form = new GeneratorForm();
|
||||
form.setName("generator");
|
||||
form.setKey("-illegal key-");
|
||||
form.setOrganization(this.organizationEntity.getGuid());
|
||||
|
||||
assertThrows(ValidationException.class, () -> this.service.createGeneratorForOrganization(form));
|
||||
}
|
||||
|
||||
@Test
|
||||
void GeneratorCanBeDeleted() {
|
||||
GeneratorForm form = new GeneratorForm();
|
||||
form.setName("generator");
|
||||
form.setOrganization(this.organizationEntity.getGuid());
|
||||
|
||||
Optional<GeneratorEntity> result = this.service.createGeneratorForOrganization(form);
|
||||
|
||||
assertTrue(result.isPresent());
|
||||
assertEquals(ItemStatus.ACTIVE, result.get().getStatus());
|
||||
|
||||
assertTrue(this.service.markDeletedByGuid(result.get().getGuid()));
|
||||
|
||||
result = this.service.findByGuid(result.get().getGuid());
|
||||
|
||||
assertEquals(ItemStatus.DELETED, result.get().getStatus());
|
||||
|
||||
this.service.deleteByGuid(result.get().getGuid());
|
||||
|
||||
result = this.service.findByGuid(result.get().getGuid());
|
||||
|
||||
assertTrue(result.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void GeneratorCanNotBeDeletedIfNotExists() {
|
||||
assertFalse(this.service.markDeletedByGuid(UUID.randomUUID()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void GeneratorCanBeUpdatedSuccessfully() {
|
||||
GeneratorForm form = new GeneratorForm();
|
||||
form.setName("generator");
|
||||
form.setOrganization(this.organizationEntity.getGuid());
|
||||
|
||||
Optional<GeneratorEntity> result = this.service.createGeneratorForOrganization(form);
|
||||
|
||||
assertTrue(result.isPresent());
|
||||
assertEquals(ItemStatus.ACTIVE, result.get().getStatus());
|
||||
|
||||
GeneratorEntity original = result.get();
|
||||
original.setName("renamed");
|
||||
|
||||
this.service.updateGenerator(original);
|
||||
|
||||
result = this.service.findByGuid(result.get().getGuid());
|
||||
assertEquals("renamed", result.get().getName());
|
||||
|
||||
this.service.deleteByGuid(result.get().getGuid());
|
||||
}
|
||||
|
||||
@Test
|
||||
void GeneratorCanNotBeUpdatedIfNotExists() {
|
||||
GeneratorEntity generator = new GeneratorEntity(UUID.randomUUID());
|
||||
assertTrue(this.service.updateGenerator(generator).isEmpty());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package de.nclazz.apps.codebuilder.resources.mappings;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class TypeMappingEntityTest {
|
||||
|
||||
@Test
|
||||
void InstancesOfTypeMappingShouldEqual() {
|
||||
UUID guid = UUID.randomUUID();
|
||||
String key = "mapping";
|
||||
|
||||
TypeMappingEntity a = new TypeMappingEntity();
|
||||
a.setGuid(guid);
|
||||
a.setKey(key);
|
||||
|
||||
TypeMappingEntity b = new TypeMappingEntity();
|
||||
b.setGuid(guid);
|
||||
b.setKey(key);
|
||||
|
||||
TypeMappingEntity otherKey = new TypeMappingEntity();
|
||||
otherKey.setGuid(guid);
|
||||
otherKey.setKey("other");
|
||||
|
||||
TypeMappingEntity otherValue = new TypeMappingEntity();
|
||||
otherValue.setGuid(guid);
|
||||
otherValue.setKey(key);
|
||||
otherValue.setBooleanValue("customBoolean");
|
||||
|
||||
assertEquals(a, b);
|
||||
assertNotEquals(a, otherKey);
|
||||
assertNotEquals(a, otherValue);
|
||||
assertNotEquals(otherKey, otherValue);
|
||||
|
||||
assertEquals(a.hashCode(), b.hashCode());
|
||||
assertNotEquals(a.hashCode(), otherKey.hashCode());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
package de.nclazz.apps.codebuilder.resources.mappings;
|
||||
|
||||
import de.nclazz.apps.codebuilder.resources.organizations.OrganizationEntity;
|
||||
import de.nclazz.apps.codebuilder.resources.organizations.OrganizationService;
|
||||
import de.nclazz.codebuilder.v0.models.ItemStatus;
|
||||
import de.nclazz.codebuilder.v0.models.TypeMappingForm;
|
||||
import de.nclazz.codebuilder.v0.models.TypeMappingUpdateForm;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@SuppressWarnings("OptionalGetWithoutIsPresent")
|
||||
@SpringBootTest
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
@ActiveProfiles("test")
|
||||
class TypeMappingServiceTest {
|
||||
|
||||
@Autowired
|
||||
TypeMappingService service;
|
||||
|
||||
@Autowired
|
||||
OrganizationService organizationService;
|
||||
|
||||
OrganizationEntity organizationEntity;
|
||||
|
||||
|
||||
@BeforeAll
|
||||
void setup() {
|
||||
OrganizationEntity org = new OrganizationEntity();
|
||||
org.setName("test-org");
|
||||
this.organizationEntity = this.organizationService.createNewOrganization(org).get();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
void tearDown() {
|
||||
this.organizationService.deleteByGuid(this.organizationEntity.getGuid());
|
||||
}
|
||||
|
||||
@Test
|
||||
void CreatingNewTypeMappingShouldSucceed() {
|
||||
TypeMappingUpdateForm updateForm = new TypeMappingUpdateForm();
|
||||
updateForm.setBooleanValue("customBoolean");
|
||||
TypeMappingForm form = new TypeMappingForm(
|
||||
"mapping",
|
||||
this.organizationEntity.getGuid(),
|
||||
updateForm
|
||||
);
|
||||
Optional<TypeMappingEntity> result = this.service.createTypeMappingForOrganization(form);
|
||||
assertTrue(result.isPresent());
|
||||
assertEquals(ItemStatus.ACTIVE, result.get().getStatus());
|
||||
assertEquals("mapping", result.get().getKey());
|
||||
assertEquals(this.organizationEntity.getGuid(), result.get().getOrganization().getGuid());
|
||||
assertEquals("customBoolean", result.get().getBooleanValue());
|
||||
|
||||
assertTrue(this.service.findByGuid(result.get().getGuid()).isPresent());
|
||||
|
||||
this.service.deleteByGuid(result.get().getGuid());
|
||||
}
|
||||
|
||||
@Test
|
||||
void TypeMappingCanBeUpdatedSuccessfully() {
|
||||
TypeMappingUpdateForm updateForm = new TypeMappingUpdateForm();
|
||||
updateForm.setBooleanValue("customBoolean");
|
||||
updateForm.setString("customString");
|
||||
TypeMappingForm form = new TypeMappingForm(
|
||||
"mapping",
|
||||
this.organizationEntity.getGuid(),
|
||||
updateForm
|
||||
);
|
||||
Optional<TypeMappingEntity> result = this.service.createTypeMappingForOrganization(form);
|
||||
assertEquals("customBoolean", result.get().getBooleanValue());
|
||||
|
||||
updateForm = new TypeMappingUpdateForm();
|
||||
updateForm.setBooleanValue("renamedBoolean");
|
||||
|
||||
Optional<TypeMappingEntity> update = this.service.updateTypeMapping(result.get().getGuid(), updateForm);
|
||||
assertTrue(update.isPresent());
|
||||
assertEquals("renamedBoolean", update.get().getBooleanValue());
|
||||
assertNotEquals("customString", update.get().getString()); //Does not equal because not specified in form
|
||||
|
||||
this.service.deleteByGuid(result.get().getGuid());
|
||||
}
|
||||
|
||||
@Test
|
||||
void TypeMappingCanBeDeleted() {
|
||||
TypeMappingUpdateForm updateForm = new TypeMappingUpdateForm();
|
||||
updateForm.setBooleanValue("customBoolean");
|
||||
TypeMappingForm form = new TypeMappingForm(
|
||||
"mapping",
|
||||
this.organizationEntity.getGuid(),
|
||||
updateForm
|
||||
);
|
||||
Optional<TypeMappingEntity> result = this.service.createTypeMappingForOrganization(form);
|
||||
assertTrue(result.isPresent());
|
||||
assertEquals(ItemStatus.ACTIVE, result.get().getStatus());
|
||||
|
||||
assertTrue(this.service.markDeletedByGuid(result.get().getGuid()));
|
||||
|
||||
result = this.service.findByGuid(result.get().getGuid());
|
||||
|
||||
assertEquals(ItemStatus.DELETED, result.get().getStatus());
|
||||
|
||||
this.service.deleteByGuid(result.get().getGuid());
|
||||
|
||||
result = this.service.findByGuid(result.get().getGuid());
|
||||
|
||||
assertTrue(result.isEmpty());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package de.nclazz.apps.codebuilder.resources.memberships;
|
||||
|
||||
import de.nclazz.apps.codebuilder.resources.organizations.OrganizationEntity;
|
||||
import de.nclazz.apps.codebuilder.resources.users.UserEntity;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class MembershipEntityTest {
|
||||
|
||||
@Test
|
||||
void InstancesOfMembershipShouldEqual() {
|
||||
UUID guid = UUID.randomUUID();
|
||||
OrganizationEntity org = new OrganizationEntity(UUID.randomUUID());
|
||||
UserEntity user = new UserEntity(UUID.randomUUID());
|
||||
|
||||
MembershipEntity a = new MembershipEntity();
|
||||
a.setGuid(guid);
|
||||
a.setOrganization(org);
|
||||
a.setMember(user);
|
||||
|
||||
MembershipEntity b = new MembershipEntity();
|
||||
b.setGuid(guid);
|
||||
b.setOrganization(org);
|
||||
b.setMember(user);
|
||||
|
||||
MembershipEntity otherGuid = new MembershipEntity();
|
||||
otherGuid.setGuid(UUID.randomUUID());
|
||||
otherGuid.setOrganization(org);
|
||||
otherGuid.setMember(user);
|
||||
|
||||
assertEquals(a, b);
|
||||
assertNotEquals(a, otherGuid);
|
||||
assertNotEquals(b, otherGuid);
|
||||
|
||||
assertEquals(a.hashCode(), b.hashCode());
|
||||
assertNotEquals(a.hashCode(), otherGuid.hashCode());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,162 @@
|
|||
package de.nclazz.apps.codebuilder.resources.memberships;
|
||||
|
||||
import de.nclazz.apps.codebuilder.resources.organizations.OrganizationEntity;
|
||||
import de.nclazz.apps.codebuilder.resources.organizations.OrganizationService;
|
||||
import de.nclazz.apps.codebuilder.resources.users.UserEntity;
|
||||
import de.nclazz.apps.codebuilder.resources.users.UsersService;
|
||||
import de.nclazz.codebuilder.v0.models.*;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@SuppressWarnings("OptionalGetWithoutIsPresent")
|
||||
@SpringBootTest
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
@ActiveProfiles("test")
|
||||
class MembershipsServiceTest {
|
||||
|
||||
@Autowired
|
||||
MembershipsService service;
|
||||
|
||||
@Autowired
|
||||
OrganizationService organizationService;
|
||||
|
||||
@Autowired
|
||||
UsersService usersService;
|
||||
|
||||
OrganizationEntity organizationEntity;
|
||||
|
||||
@BeforeAll
|
||||
void setup() {
|
||||
OrganizationEntity org = new OrganizationEntity();
|
||||
org.setName("test-org");
|
||||
this.organizationEntity = this.organizationService.createNewOrganization(org).get();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
void tearDown() {
|
||||
this.organizationService.deleteByGuid(this.organizationEntity.getGuid());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
void CreatingNewMembershipShouldSucceed() {
|
||||
MembershipForm form = new MembershipForm();
|
||||
UserEntity user = createUser();
|
||||
|
||||
form.setOrganization(this.organizationEntity.getGuid());
|
||||
form.setUser(user.getGuid());
|
||||
form.setPermissions(Arrays.asList(MemberPermission.EDIT_ORGANIZATION));
|
||||
Optional<MembershipEntity> result = this.service.createMembershipForOrganization(form);
|
||||
|
||||
assertTrue(result.isPresent());
|
||||
assertEquals(ItemStatus.ACTIVE, result.get().getStatus());
|
||||
assertEquals(user.getGuid(), result.get().getMember().getGuid());
|
||||
assertTrue(result.get().getPermissions().contains(MemberPermission.EDIT_ORGANIZATION));
|
||||
assertFalse(result.get().getPermissions().contains(MemberPermission.EDIT_ITEMS));
|
||||
}
|
||||
|
||||
@Test
|
||||
void MembershipCanBeDeletedSuccessfully() {
|
||||
MembershipForm form = new MembershipForm();
|
||||
UserEntity user = createUser();
|
||||
|
||||
form.setOrganization(this.organizationEntity.getGuid());
|
||||
form.setUser(user.getGuid());
|
||||
form.setPermissions(Arrays.asList(MemberPermission.EDIT_ORGANIZATION));
|
||||
Optional<MembershipEntity> result = this.service.createMembershipForOrganization(form);
|
||||
|
||||
assertTrue(result.isPresent());
|
||||
assertEquals(ItemStatus.ACTIVE, result.get().getStatus());
|
||||
|
||||
assertTrue(this.service.markMembershipAsDeleted(result.get().getGuid()));
|
||||
|
||||
result = this.service.findByGuid(result.get().getGuid());
|
||||
|
||||
assertEquals(ItemStatus.DELETED, result.get().getStatus());
|
||||
|
||||
this.service.deleteMembership(result.get().getGuid());
|
||||
|
||||
assertTrue(this.service.findByGuid(result.get().getGuid()).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void MembershipCanNotBeDeletedIfNotExists() {
|
||||
assertFalse(this.service.markMembershipAsDeleted(UUID.randomUUID()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
void MembershipCanBeUpdatedSuccessfully() {
|
||||
MembershipForm form = new MembershipForm();
|
||||
UserEntity user = createUser();
|
||||
|
||||
form.setOrganization(this.organizationEntity.getGuid());
|
||||
form.setUser(user.getGuid());
|
||||
form.setPermissions(Arrays.asList(MemberPermission.EDIT_ORGANIZATION));
|
||||
Optional<MembershipEntity> result = this.service.createMembershipForOrganization(form);
|
||||
|
||||
assertTrue(result.isPresent());
|
||||
assertEquals(ItemStatus.ACTIVE, result.get().getStatus());
|
||||
|
||||
MembershipUpdateForm updateForm = new MembershipUpdateForm();
|
||||
updateForm.setPermissions(Collections.emptyList());
|
||||
updateForm.setPermissions(Arrays.asList(MemberPermission.EDIT_ITEMS, MemberPermission.VIEW_ITEMS));
|
||||
|
||||
result = this.service.updateMembershipForOrganization(form.getOrganization(), result.get().getGuid(), updateForm);
|
||||
|
||||
assertTrue(result.isPresent());
|
||||
assertTrue(result.get().getPermissions().contains(MemberPermission.EDIT_ITEMS));
|
||||
assertTrue(result.get().getPermissions().contains(MemberPermission.VIEW_ITEMS));
|
||||
assertFalse(result.get().getPermissions().contains(MemberPermission.EDIT_ORGANIZATION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void MembershipCanNotBeUpdatedIfNotExists() {
|
||||
MembershipUpdateForm form = new MembershipUpdateForm();
|
||||
|
||||
assertTrue(this.service.updateMembershipForOrganization(this.organizationEntity.getGuid(), UUID.randomUUID(), form).isEmpty());
|
||||
assertTrue(this.service.updateMembershipForOrganization(UUID.randomUUID(), UUID.randomUUID(), form).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void DeletingMembershipDoesNotDeleteOrganization() {
|
||||
MembershipForm form = new MembershipForm();
|
||||
UserEntity user = createUser();
|
||||
|
||||
form.setOrganization(this.organizationEntity.getGuid());
|
||||
form.setUser(user.getGuid());
|
||||
form.setPermissions(Arrays.asList(MemberPermission.EDIT_ORGANIZATION));
|
||||
Optional<MembershipEntity> result = this.service.createMembershipForOrganization(form);
|
||||
|
||||
assertTrue(result.isPresent());
|
||||
assertTrue(this.organizationService.organizationExists(this.organizationEntity.getGuid()));
|
||||
|
||||
this.service.deleteMembership(result.get().getGuid());
|
||||
|
||||
assertFalse(this.service.existsByGuid(result.get().getGuid()));
|
||||
|
||||
assertTrue(this.organizationService.organizationExists(this.organizationEntity.getGuid()));
|
||||
}
|
||||
|
||||
UserEntity createUser() {
|
||||
UserEntity user = new UserEntity();
|
||||
user.setEmail(UUID.randomUUID()+"@"+"test.tld");
|
||||
user.setName(UUID.randomUUID().toString().replaceAll("-", "_").substring(0, 32));
|
||||
|
||||
return this.usersService.createUser(user).get();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package de.nclazz.apps.codebuilder.resources.organizations;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class OrganizationEntityTest {
|
||||
|
||||
@Test
|
||||
void InstancesOfOrganizationShouldEqual() {
|
||||
UUID guid = UUID.randomUUID();
|
||||
String name = "organization";
|
||||
String key = "organization";
|
||||
|
||||
OrganizationEntity a = new OrganizationEntity();
|
||||
a.setGuid(guid);
|
||||
a.setName(name);
|
||||
a.setKey(key);
|
||||
|
||||
|
||||
OrganizationEntity b = new OrganizationEntity();
|
||||
b.setGuid(guid);
|
||||
b.setName(name);
|
||||
b.setKey(key);
|
||||
|
||||
assertEquals(a, b);
|
||||
assertEquals(a.hashCode(), b.hashCode());
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
package de.nclazz.apps.codebuilder.resources.organizations;
|
||||
|
||||
import de.nclazz.apps.codebuilder.common.ValidationException;
|
||||
import de.nclazz.codebuilder.v0.models.ItemStatus;
|
||||
import de.nclazz.codebuilder.v0.models.OrganizationForm;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@SpringBootTest
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
@ActiveProfiles("test")
|
||||
class OrganizationServiceTest {
|
||||
|
||||
@Autowired
|
||||
OrganizationService service;
|
||||
|
||||
@Test
|
||||
void OrganizationCanBeCreatedSuccessfully() {
|
||||
OrganizationEntity org = new OrganizationEntity();
|
||||
org.setName("organization");
|
||||
|
||||
Optional<OrganizationEntity> result = this.service.createNewOrganization(org);
|
||||
|
||||
assertTrue(result.isPresent());
|
||||
assertEquals(ItemStatus.ACTIVE, result.get().getStatus());
|
||||
assertEquals("organization", result.get().getName());
|
||||
assertEquals("organization", result.get().getKey());
|
||||
|
||||
this.service.deleteByGuid(result.get().getGuid());
|
||||
}
|
||||
|
||||
@Test
|
||||
void OrganizationCanNotBeCreatedWithValidationErrors() {
|
||||
OrganizationEntity org = new OrganizationEntity();
|
||||
org.setName("organization");
|
||||
org.setKey("- illegal key -");
|
||||
|
||||
assertThrows(ValidationException.class, () -> this.service.createNewOrganization(org));
|
||||
}
|
||||
|
||||
@Test
|
||||
void OrganizationCanBeUpdatedSuccessfully() {
|
||||
OrganizationEntity org = new OrganizationEntity();
|
||||
org.setName("organization");
|
||||
|
||||
Optional<OrganizationEntity> result = this.service.createNewOrganization(org);
|
||||
|
||||
assertTrue(result.isPresent());
|
||||
assertEquals(ItemStatus.ACTIVE, result.get().getStatus());
|
||||
|
||||
OrganizationEntity update = new OrganizationEntity();
|
||||
update.setGuid(result.get().getGuid());
|
||||
update.setName("renamed");
|
||||
update.setKey("renamed");
|
||||
|
||||
result = this.service.updateOrganization(update);
|
||||
assertTrue(result.isPresent());
|
||||
assertEquals(ItemStatus.ACTIVE, result.get().getStatus());
|
||||
assertEquals("renamed", result.get().getName());
|
||||
assertEquals("renamed", result.get().getKey());
|
||||
|
||||
this.service.deleteByGuid(result.get().getGuid());
|
||||
}
|
||||
|
||||
@Test
|
||||
void OrganizationCanNotBeUpdatedIfNotExists() {
|
||||
assertTrue(this.service.updateOrganization(new OrganizationEntity(UUID.randomUUID())).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void OrganizationCanBeDeletedSuccessfully() {
|
||||
OrganizationEntity org = new OrganizationEntity();
|
||||
org.setName("organization");
|
||||
|
||||
Optional<OrganizationEntity> result = this.service.createNewOrganization(org);
|
||||
|
||||
assertTrue(result.isPresent());
|
||||
assertEquals(ItemStatus.ACTIVE, result.get().getStatus());
|
||||
|
||||
assertTrue(this.service.markDeletedByGuid(result.get().getGuid()));
|
||||
|
||||
result = this.service.findByGuid(result.get().getGuid());
|
||||
assertTrue(result.isPresent());
|
||||
assertEquals(ItemStatus.DELETED, result.get().getStatus());
|
||||
|
||||
this.service.deleteByGuid(result.get().getGuid());
|
||||
|
||||
assertTrue(this.service.findByGuid(result.get().getGuid()).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void OrganizationCanNotBeDeletedIfNotExists() {
|
||||
assertFalse(this.service.markDeletedByGuid(UUID.randomUUID()));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package de.nclazz.apps.codebuilder.resources.templates;
|
||||
|
||||
import de.nclazz.codebuilder.v0.models.TemplateTarget;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class TemplateEntityTest {
|
||||
|
||||
@Test
|
||||
void InstancesShouldEqual() {
|
||||
UUID guid = UUID.randomUUID();
|
||||
String name = "template";
|
||||
TemplateTarget target = TemplateTarget.MODEL;
|
||||
|
||||
TemplateEntity a = new TemplateEntity();
|
||||
a.setGuid(guid);
|
||||
a.setName(name);
|
||||
a.setTarget(target);
|
||||
|
||||
TemplateEntity b = new TemplateEntity();
|
||||
b.setGuid(guid);
|
||||
b.setName(name);
|
||||
b.setTarget(target);
|
||||
|
||||
assertEquals(a, b);
|
||||
assertEquals(a.hashCode(), b.hashCode());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,171 @@
|
|||
package de.nclazz.apps.codebuilder.resources.templates;
|
||||
|
||||
import de.nclazz.apps.codebuilder.common.ValidationException;
|
||||
import de.nclazz.apps.codebuilder.resources.generators.GeneratorEntity;
|
||||
import de.nclazz.apps.codebuilder.resources.generators.GeneratorsService;
|
||||
import de.nclazz.apps.codebuilder.resources.organizations.OrganizationEntity;
|
||||
import de.nclazz.apps.codebuilder.resources.organizations.OrganizationService;
|
||||
import de.nclazz.codebuilder.v0.models.*;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@SuppressWarnings("OptionalGetWithoutIsPresent")
|
||||
@SpringBootTest
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
@ActiveProfiles("test")
|
||||
class TemplatesServiceTest {
|
||||
|
||||
@Autowired
|
||||
TemplatesService service;
|
||||
|
||||
@Autowired
|
||||
GeneratorsService generatorsService;
|
||||
|
||||
@Autowired
|
||||
OrganizationService organizationService;
|
||||
|
||||
OrganizationEntity organization;
|
||||
GeneratorEntity generator;
|
||||
|
||||
@BeforeAll
|
||||
void setup() {
|
||||
OrganizationEntity org = new OrganizationEntity();
|
||||
org.setName("organization");
|
||||
this.organization = this.organizationService.createNewOrganization(org).get();
|
||||
|
||||
GeneratorForm form = new GeneratorForm();
|
||||
form.setName("generator");
|
||||
form.setOrganization(this.organization.getGuid());
|
||||
this.generator = this.generatorsService.createGeneratorForOrganization(form).get();
|
||||
}
|
||||
|
||||
@Test
|
||||
void TemplateCanBeCreatedSuccessfully() {
|
||||
TemplateForm form = new TemplateForm();
|
||||
form.setName("template");
|
||||
form.setTarget(TemplateTarget.MODEL);
|
||||
form.setContent("content");
|
||||
form.setDirectory("dir");
|
||||
form.setFilename("filename");
|
||||
form.setScaffolding(false);
|
||||
form.setGenerator(this.generator.getGuid());
|
||||
|
||||
Optional<TemplateEntity> result = this.service.createNewTemplate(form);
|
||||
|
||||
assertTrue(result.isPresent());
|
||||
assertEquals(ItemStatus.ACTIVE, result.get().getStatus());
|
||||
assertEquals(TemplateTarget.MODEL, result.get().getTarget());
|
||||
assertEquals("content", result.get().getContent());
|
||||
assertEquals("filename", result.get().getFilename());
|
||||
assertEquals("dir", result.get().getDirectory());
|
||||
|
||||
this.service.deleteByGuid(result.get().getGuid());
|
||||
}
|
||||
|
||||
@Test
|
||||
void TemplateCanNotBeCreatedOnValidationErrors() {
|
||||
TemplateForm formIllegalName = new TemplateForm();
|
||||
formIllegalName.setName(UUID.randomUUID().toString());
|
||||
formIllegalName.setTarget(TemplateTarget.MODEL);
|
||||
formIllegalName.setContent("content");
|
||||
formIllegalName.setDirectory("dir");
|
||||
formIllegalName.setFilename("filename");
|
||||
formIllegalName.setScaffolding(false);
|
||||
formIllegalName.setGenerator(this.generator.getGuid());
|
||||
|
||||
assertThrows(ValidationException.class, () -> this.service.createNewTemplate(formIllegalName));
|
||||
}
|
||||
|
||||
@Test
|
||||
void TemplateCanBeUpdatedSuccessfully() {
|
||||
TemplateForm form = new TemplateForm();
|
||||
form.setName("template");
|
||||
form.setTarget(TemplateTarget.MODEL);
|
||||
form.setContent("content");
|
||||
form.setDirectory("dir");
|
||||
form.setFilename("filename");
|
||||
form.setScaffolding(false);
|
||||
form.setGenerator(this.generator.getGuid());
|
||||
|
||||
Optional<TemplateEntity> result = this.service.createNewTemplate(form);
|
||||
|
||||
assertTrue(result.isPresent());
|
||||
assertEquals(ItemStatus.ACTIVE, result.get().getStatus());
|
||||
|
||||
TemplateUpdateForm updateForm = new TemplateUpdateForm();
|
||||
updateForm.setName("renamed");
|
||||
updateForm.setTarget(TemplateTarget.MODEL);
|
||||
updateForm.setContent("content");
|
||||
updateForm.setDirectory("dir");
|
||||
updateForm.setFilename("filename");
|
||||
updateForm.setScaffolding(false);
|
||||
|
||||
result = this.service.updateTemplate(result.get().getGuid(), updateForm);
|
||||
assertEquals("renamed", result.get().getName());
|
||||
|
||||
this.service.deleteByGuid(result.get().getGuid());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void TemplateCanNotBeUpdatedIfNotExists() {
|
||||
TemplateUpdateForm form = new TemplateUpdateForm();
|
||||
assertTrue(this.service.updateTemplate(UUID.randomUUID(), form).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void TemplateCanBeDeleted() {
|
||||
TemplateForm form = new TemplateForm();
|
||||
form.setName("template");
|
||||
form.setTarget(TemplateTarget.MODEL);
|
||||
form.setContent("content");
|
||||
form.setDirectory("dir");
|
||||
form.setFilename("filename");
|
||||
form.setScaffolding(false);
|
||||
form.setGenerator(this.generator.getGuid());
|
||||
|
||||
Optional<TemplateEntity> result = this.service.createNewTemplate(form);
|
||||
|
||||
assertTrue(result.isPresent());
|
||||
assertEquals(ItemStatus.ACTIVE, result.get().getStatus());
|
||||
|
||||
assertTrue(this.service.findByGuid(result.get().getGuid()).isPresent());
|
||||
|
||||
this.service.deleteByGuid(result.get().getGuid());
|
||||
|
||||
assertTrue(this.service.findByGuid(result.get().getGuid()).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void DeletingTemplateDoesNotDeleteGenerator() {
|
||||
TemplateForm form = new TemplateForm();
|
||||
form.setName("template");
|
||||
form.setTarget(TemplateTarget.MODEL);
|
||||
form.setContent("content");
|
||||
form.setDirectory("dir");
|
||||
form.setFilename("filename");
|
||||
form.setScaffolding(false);
|
||||
form.setGenerator(this.generator.getGuid());
|
||||
|
||||
Optional<TemplateEntity> result = this.service.createNewTemplate(form);
|
||||
|
||||
assertTrue(this.service.findByGuid(result.get().getGuid()).isPresent());
|
||||
assertTrue(this.generatorsService.findByGuid(this.generator.getGuid()).isPresent());
|
||||
|
||||
this.service.deleteByGuid(result.get().getGuid());
|
||||
|
||||
assertTrue(this.service.findByGuid(result.get().getGuid()).isEmpty());
|
||||
assertTrue(this.generatorsService.findByGuid(this.generator.getGuid()).isPresent());
|
||||
}
|
||||
|
||||
}
|
|
@ -9,18 +9,27 @@ import static org.junit.jupiter.api.Assertions.*;
|
|||
class UserEntityTest {
|
||||
|
||||
@Test
|
||||
void UserEntityForSameUserShouldEqual() {
|
||||
UserEntity entity = new UserEntity();
|
||||
entity.setGuid(UUID.randomUUID());
|
||||
entity.setName("test");
|
||||
entity.setEmail("test@test.tld");
|
||||
void InstancesOfUserShouldEqual() {
|
||||
UserEntity a = new UserEntity();
|
||||
a.setGuid(UUID.randomUUID());
|
||||
a.setName("test");
|
||||
a.setEmail("test@test.tld");
|
||||
|
||||
UserEntity entityB = new UserEntity();
|
||||
entityB.setGuid(entity.getGuid());
|
||||
entityB.setName("test");
|
||||
entityB.setEmail("test@test.tld");
|
||||
UserEntity b = new UserEntity();
|
||||
b.setGuid(a.getGuid());
|
||||
b.setName("test");
|
||||
b.setEmail("test@test.tld");
|
||||
|
||||
assertEquals(entity, entityB);
|
||||
UserEntity otherName = new UserEntity();
|
||||
otherName.setGuid(a.getGuid());
|
||||
otherName.setName("other");
|
||||
otherName.setEmail("test@test.tld");
|
||||
|
||||
assertEquals(a, b);
|
||||
assertNotEquals(a, otherName);
|
||||
|
||||
assertEquals(a.hashCode(), b.hashCode());
|
||||
assertNotEquals(a.hashCode(), otherName.hashCode());
|
||||
}
|
||||
|
||||
}
|
|
@ -4,8 +4,10 @@ import de.nclazz.apps.codebuilder.common.ValidationException;
|
|||
import de.nclazz.codebuilder.v0.models.ItemStatus;
|
||||
import de.nclazz.codebuilder.v0.models.UserRole;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
import java.util.Optional;
|
||||
|
|
|
@ -12,5 +12,7 @@ spring:
|
|||
main:
|
||||
banner-mode: off
|
||||
logging.level.org.springframework: OFF
|
||||
logging.level.root: OFF
|
||||
logging.level.root: WARN
|
||||
logging.level.ch.qos.logback: WARN
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<include resource="org/springframework/boot/logging/logback/base.xml" />
|
||||
<logger name="org.springframework" level="ERROR"/>
|
||||
<logger name="ch.qos" level="ERROR"/>
|
||||
|
||||
<root level="OFF">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
</root>
|
||||
<statusListener class="ch.qos.logback.core.status.NopStatusListener" />
|
||||
</configuration>
|
|
@ -1,5 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<include resource="org/springframework/boot/logging/logback/base.xml" />
|
||||
<logger name="org.springframework" level="ERROR"/>
|
||||
</configuration>
|
Loading…
Reference in New Issue