Search in sources :

Example 1 with UserProfile

use of com.sequenceiq.cloudbreak.domain.UserProfile in project cloudbreak by hortonworks.

the class ImageCatalogServiceDefaultTest method beforeTest.

@Before
public void beforeTest() throws Exception {
    MockitoAnnotations.initMocks(this);
    String catalogJson = FileReaderUtils.readFileFromClasspath(catalogFile);
    CloudbreakImageCatalogV2 catalog = JsonUtil.readValue(catalogJson, CloudbreakImageCatalogV2.class);
    when(imageCatalogProvider.getImageCatalogV2("")).thenReturn(catalog);
    IdentityUser user = getIdentityUser();
    when(authenticatedUserService.getCbUser()).thenReturn(user);
    when(userProfileService.get(user.getAccount(), user.getUserId(), user.getUsername())).thenReturn(new UserProfile());
}
Also used : IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) UserProfile(com.sequenceiq.cloudbreak.domain.UserProfile) CloudbreakImageCatalogV2(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2) Before(org.junit.Before)

Example 2 with UserProfile

use of com.sequenceiq.cloudbreak.domain.UserProfile in project cloudbreak by hortonworks.

the class ImageCatalogServiceTest method testDeleteImageCatalog.

@Test
public void testDeleteImageCatalog() {
    String name = "img-name";
    IdentityUser user = getIdentityUser();
    UserProfile userProfile = new UserProfile();
    ImageCatalog imageCatalog = new ImageCatalog();
    imageCatalog.setImageCatalogName(name);
    imageCatalog.setArchived(false);
    when(authenticatedUserService.getCbUser()).thenReturn(user);
    when(imageCatalogRepository.findByName(name, user.getUserId(), user.getAccount())).thenReturn(imageCatalog);
    when(userProfileService.get(user.getAccount(), user.getUserId(), user.getUsername())).thenReturn(userProfile);
    underTest.delete(name);
    verify(imageCatalogRepository, times(1)).save(imageCatalog);
    Assert.assertTrue(imageCatalog.isArchived());
    Assert.assertTrue(imageCatalog.getImageCatalogName().startsWith(name) && imageCatalog.getImageCatalogName().indexOf("_") == name.length());
}
Also used : IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) UserProfile(com.sequenceiq.cloudbreak.domain.UserProfile) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) Test(org.junit.Test)

Example 3 with UserProfile

use of com.sequenceiq.cloudbreak.domain.UserProfile in project cloudbreak by hortonworks.

the class UserProfileCredentialHandler method destroyProfilePreparation.

public void destroyProfilePreparation(Credential credential) {
    Set<UserProfile> userProfiles = userProfileService.findOneByCredentialId(credential.getId());
    for (UserProfile userProfile : userProfiles) {
        userProfile.setCredential(null);
        userProfileService.save(userProfile);
    }
}
Also used : UserProfile(com.sequenceiq.cloudbreak.domain.UserProfile)

Example 4 with UserProfile

use of com.sequenceiq.cloudbreak.domain.UserProfile in project cloudbreak by hortonworks.

the class UserProfileCredentialHandler method createProfilePreparation.

public void createProfilePreparation(Credential credential) {
    UserProfile userProfile = userProfileService.get(credential.getAccount(), credential.getOwner());
    if (userProfile != null && userProfile.getCredential() == null) {
        userProfile.setCredential(credential);
        userProfileService.save(userProfile);
    }
}
Also used : UserProfile(com.sequenceiq.cloudbreak.domain.UserProfile)

Example 5 with UserProfile

use of com.sequenceiq.cloudbreak.domain.UserProfile in project cloudbreak by hortonworks.

the class UserProfileServiceTest method getEmptyUserName.

@Test
public void getEmptyUserName() {
    String account = "account1";
    String owner = "123-123-123";
    UserProfile foundProfile = new UserProfile();
    foundProfile.setOwner(owner);
    foundProfile.setAccount(account);
    when(userProfileRepository.findOneByOwnerAndAccount(anyString(), anyString())).thenReturn(foundProfile);
    when(userProfileRepository.save(any(UserProfile.class))).thenReturn(new UserProfile());
    UserProfile returnedUserProfile = userProfileService.get(account, owner);
    verify(userProfileRepository, never()).save(any(UserProfile.class));
    assertEquals(account, returnedUserProfile.getAccount());
    assertEquals(owner, returnedUserProfile.getOwner());
    assertNotNull(returnedUserProfile);
    assertNull(returnedUserProfile.getUserName());
}
Also used : UserProfile(com.sequenceiq.cloudbreak.domain.UserProfile) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

UserProfile (com.sequenceiq.cloudbreak.domain.UserProfile)17 Test (org.junit.Test)7 Matchers.anyString (org.mockito.Matchers.anyString)6 IdentityUser (com.sequenceiq.cloudbreak.common.model.user.IdentityUser)4 CloudbreakImageCatalogV2 (com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2)2 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)2 Stack (com.sequenceiq.cloudbreak.domain.Stack)2 OperationDetails (com.sequenceiq.cloudbreak.structuredevent.event.OperationDetails)2 Before (org.junit.Before)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)1 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)1 Credential (com.sequenceiq.cloudbreak.domain.Credential)1 ImageCatalog (com.sequenceiq.cloudbreak.domain.ImageCatalog)1 Json (com.sequenceiq.cloudbreak.domain.json.Json)1 BlueprintDetails (com.sequenceiq.cloudbreak.structuredevent.event.BlueprintDetails)1 ClusterDetails (com.sequenceiq.cloudbreak.structuredevent.event.ClusterDetails)1 NotificationDetails (com.sequenceiq.cloudbreak.structuredevent.event.NotificationDetails)1 StackDetails (com.sequenceiq.cloudbreak.structuredevent.event.StackDetails)1 StructuredFlowErrorEvent (com.sequenceiq.cloudbreak.structuredevent.event.StructuredFlowErrorEvent)1