use of com.viadee.sonarQuest.entities.Developer in project sonarQuest by viadee.
the class GratificationService method rewardDeveloperForSolvingAdventure.
private void rewardDeveloperForSolvingAdventure(final Developer developer, final Adventure adventure) {
final Developer rewardedDeveloper = developer;
rewardedDeveloper.addGold(adventure.getGold());
rewardedDeveloper.addXp(adventure.getXp());
rewardedDeveloper.setLevel(levelService.getLevelByDeveloperXp(developer.getXp()));
developerRepository.save(rewardedDeveloper);
}
use of com.viadee.sonarQuest.entities.Developer in project sonarQuest by viadee.
the class GratificationService method rewardParticipation.
private void rewardParticipation(final Participation participation) {
final Developer developer = participation.getDeveloper();
final Quest quest = participation.getQuest();
developer.addGold(quest.getGold());
developer.addXp(quest.getXp());
developer.setLevel(levelService.getLevelByDeveloperXp(developer.getXp()));
developerRepository.save(developer);
}
use of com.viadee.sonarQuest.entities.Developer in project sonarQuest by viadee.
the class GratificationService method addSkillReward.
private Developer addSkillReward(final Developer developer, final Task task) {
final Developer rewardedDeveloper = developer;
final List<Skill> avatarClassSkills = rewardedDeveloper.getAvatarClass().getSkills();
final List<Skill> artefactSkills = rewardedDeveloper.getArtefacts().stream().map(artefact -> artefact.getSkills()).flatMap(skills -> skills.stream()).collect(Collectors.toList());
final List<Skill> totalSkills = new ArrayList<>();
totalSkills.addAll(avatarClassSkills);
totalSkills.addAll(artefactSkills);
final Long extraGold = totalSkills.stream().filter(skill -> skill.getType().equals(SkillType.GOLD)).mapToLong(skill -> skill.getValue()).sum();
final Long extraXP = totalSkills.stream().filter(skill -> skill.getType().equals(SkillType.XP)).mapToLong(skill -> skill.getValue()).sum();
rewardedDeveloper.addGold(extraGold);
rewardedDeveloper.addXp(extraXP);
return rewardedDeveloper;
}
use of com.viadee.sonarQuest.entities.Developer in project sonarQuest by viadee.
the class UserManagementIT method testCreateDeleteDeveloper.
@Test
public void testCreateDeleteDeveloper() {
// Given
DeveloperDto developerDto = new DeveloperDto("testusername");
final long count = developerRepository.count();
// When
developerService.createDeveloper(developerDto);
// Then
Developer dev = developerRepository.findByUsername("testusername");
assertNotNull("developer could not be created", dev);
assertEquals("number of devs is inconsistent", developerRepository.count(), count + 1);
assertFalse(dev.isDeleted());
// When
developerService.deleteDeveloper(dev);
assertTrue("developer was not deleted", developerRepository.findByUsername("testusername").isDeleted());
// since deleting is logical deleting and not physical
assertEquals("number of devs is inconsistent", developerRepository.count(), count + 1);
assertTrue(dev.isDeleted());
}
use of com.viadee.sonarQuest.entities.Developer in project sonarQuest by viadee.
the class AdventureServiceTest method testGetAllAdventuresForWorldAndDeveloper.
@Test
public void testGetAllAdventuresForWorldAndDeveloper() {
// create mock developer
final Developer mockDeveloper1 = new Developer();
mockDeveloper1.setUsername("mockUserAdventureServiceTest1");
// create mock world
final World mockWorld = new World();
// create mock Adventure
final Adventure mockAdventure1 = new Adventure();
final Adventure mockAdventure2 = new Adventure();
final Adventure mockAdventure3 = new Adventure();
mockAdventure1.setTitle("mockAdventure1");
mockAdventure2.setTitle("mockAdventure2");
mockAdventure3.setTitle("mockAdventure3");
mockAdventure1.setWorld(mockWorld);
mockAdventure2.setWorld(mockWorld);
mockAdventure3.setWorld(mockWorld);
// a Adventure has a Developers
mockAdventure1.addDeveloper(mockDeveloper1);
mockAdventure2.addDeveloper(mockDeveloper1);
// init mock repos
final List<Adventure> adventuresByDeveloperAndWorld = new ArrayList<>();
adventuresByDeveloperAndWorld.add(mockAdventure1);
adventuresByDeveloperAndWorld.add(mockAdventure2);
final List<Adventure> adventuresByWorld = new ArrayList<>();
adventuresByWorld.add(mockAdventure1);
adventuresByWorld.add(mockAdventure2);
adventuresByWorld.add(mockAdventure3);
final List<Developer> developers = new ArrayList<>();
developers.add(mockDeveloper1);
when(adventureRepository.findByDevelopersAndWorld(developers, mockWorld)).thenReturn(adventuresByDeveloperAndWorld);
when(adventureRepository.findByWorld(mockWorld)).thenReturn(adventuresByWorld);
// call method to be tested
final List<Adventure> joinedAdventures = adventureService.getJoinedAdventuresForDeveloperInWorld(mockWorld, mockDeveloper1);
final List<Adventure> freeAdventures = adventureService.getFreeAdventuresForDeveloperInWorld(mockWorld, mockDeveloper1);
// verify result
assertTrue(joinedAdventures.contains(mockAdventure1));
assertTrue(joinedAdventures.contains(mockAdventure2));
assertTrue(freeAdventures.contains(mockAdventure3));
}
Aggregations