use of com.sequenceiq.cloudbreak.domain.Credential in project cloudbreak by hortonworks.
the class CredentialServiceTest method testRetrieveAccountCredentialsWhenUserIsNotAdmin.
@Test
public void testRetrieveAccountCredentialsWhenUserIsNotAdmin() {
IdentityUser user = mock(IdentityUser.class);
Set<String> platforms = Sets.newHashSet("AWS");
Credential credential = new Credential();
credential.setCloudPlatform("AWS");
when(user.getRoles()).thenReturn(Collections.singletonList(IdentityUserRole.fromString("USER")));
when(user.getAccount()).thenReturn("account");
when(user.getUserId()).thenReturn("userId");
when(accountPreferencesService.enabledPlatforms()).thenReturn(platforms);
when(credentialRepository.findPublicInAccountForUserFilterByPlatforms("userId", "account", platforms)).thenReturn(Sets.newHashSet(credential));
Set<Credential> actual = credentialService.retrieveAccountCredentials(user);
assertEquals("AWS", actual.stream().findFirst().get().cloudPlatform());
verify(credentialRepository, times(1)).findPublicInAccountForUserFilterByPlatforms("userId", "account", platforms);
}
use of com.sequenceiq.cloudbreak.domain.Credential in project cloudbreak by hortonworks.
the class CredentialServiceTest method testModifyMapAllField.
@Test
public void testModifyMapAllField() throws Exception {
Credential credential = new Credential();
credential.setCloudPlatform(PLATFORM);
credential.setTopology(new Topology());
credential.setAttributes(new Json("other"));
credential.setDescription("mod-desc");
Credential modify = credentialService.modify(user, credential);
assertEquals(credential.getTopology(), modify.getTopology());
assertEquals(credential.getAttributes(), modify.getAttributes());
assertEquals(credential.getDescription(), modify.getDescription());
assertNotEquals(originalTopology, modify.getTopology());
assertNotEquals(originalAttributes, modify.getAttributes());
assertNotEquals(originalAttributes, modify.getDescription());
assertEquals(credential.cloudPlatform(), modify.cloudPlatform());
}
use of com.sequenceiq.cloudbreak.domain.Credential in project cloudbreak by hortonworks.
the class CredentialServiceTest method testModifyMapNone.
@Test
public void testModifyMapNone() {
Credential credential = new Credential();
credential.setCloudPlatform(PLATFORM);
Credential modify = credentialService.modify(user, credential);
assertEquals(credentialToModify.getTopology(), modify.getTopology());
assertEquals(credentialToModify.getAttributes(), modify.getAttributes());
assertEquals(credentialToModify.getDescription(), modify.getDescription());
assertEquals(originalTopology, modify.getTopology());
assertEquals(originalAttributes, modify.getAttributes());
assertEquals(originalDescription, modify.getDescription());
assertEquals(credential.cloudPlatform(), modify.cloudPlatform());
}
use of com.sequenceiq.cloudbreak.domain.Credential in project cloudbreak by hortonworks.
the class TemplateDecoratorTest method testDecoratorWhenNoLocation.
@Test
public void testDecoratorWhenNoLocation() {
String region = "region";
String availibilityZone = "availabilityZone";
String variant = "variant";
String vmType = "vmType";
Template template = new Template();
Credential cloudCredential = mock(Credential.class);
CloudVmTypes cloudVmTypes = new CloudVmTypes(singletonMap(region, emptySet()), emptyMap());
when(cloudParameterService.getVmTypesV2(eq(cloudCredential), eq(region), eq(variant), anyMap())).thenReturn(cloudVmTypes);
when(locationService.location(region, availibilityZone)).thenReturn(null);
Template actual = underTest.decorate(cloudCredential, template, region, availibilityZone, variant);
Assert.assertNull(actual.getVolumeCount());
Assert.assertNull(actual.getVolumeSize());
}
use of com.sequenceiq.cloudbreak.domain.Credential in project cloudbreak by hortonworks.
the class TemplateDecoratorTest method testDecoratorWhenNoInstanceType.
@Test
public void testDecoratorWhenNoInstanceType() {
String vmType = "vmType";
String platform1 = "platform";
String volumeType = "volumeType";
String region = "region";
String availibilityZone = "availabilityZone";
String variant = "variant";
Credential cloudCredential = mock(Credential.class);
Template template = new Template();
template.setInstanceType("missingVmType");
template.setCloudPlatform(platform1);
template.setVolumeType(volumeType);
Platform platform = Platform.platform(platform1);
int minimumSize = 10;
int maximumSize = 100;
int minimumNumber = 1;
int maximumNumber = 5;
VolumeParameterConfig config = new VolumeParameterConfig(VolumeParameterType.MAGNETIC, minimumSize, maximumSize, minimumNumber, maximumNumber);
VmTypeMeta vmTypeMeta = new VmTypeMeta();
vmTypeMeta.setMagneticConfig(config);
Map<Platform, Map<String, VolumeParameterType>> diskMappings = newHashMap();
diskMappings.put(platform, singletonMap(volumeType, VolumeParameterType.MAGNETIC));
PlatformDisks platformDisk = new PlatformDisks(emptyMap(), emptyMap(), diskMappings, emptyMap());
CloudVmTypes cloudVmTypes = new CloudVmTypes();
Map<String, Set<VmType>> region1 = singletonMap(region, Collections.singleton(VmType.vmTypeWithMeta(vmType, vmTypeMeta, true)));
cloudVmTypes.setCloudVmResponses(region1);
when(cloudParameterService.getDiskTypes()).thenReturn(platformDisk);
when(cloudParameterService.getVmTypesV2(eq(cloudCredential), eq(region), eq(variant), anyMap())).thenReturn(cloudVmTypes);
when(locationService.location(region, availibilityZone)).thenReturn(region);
Template actual = underTest.decorate(cloudCredential, template, region, availibilityZone, variant);
Assert.assertNull(actual.getVolumeCount());
Assert.assertNull(actual.getVolumeSize());
}
Aggregations