Search in sources :

Example 16 with SmartSenseSubscription

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

the class SmartSenseSubscriptionServiceTest method getDefaultForUserWhenDefaultSmartSenseIdIsSpecifiedButAndItsEqualsToTheSubscriptionId.

@Test
public void getDefaultForUserWhenDefaultSmartSenseIdIsSpecifiedButAndItsEqualsToTheSubscriptionId() {
    ReflectionTestUtils.setField(underTest, "defaultSmartsenseId", DEPLOYMENT_SMARTSENSE_ID);
    SmartSenseSubscription subscription = createSmartSenseSubscription();
    subscription.setSubscriptionId(DEPLOYMENT_SMARTSENSE_ID);
    when(repository.findByAccountAndOwner(user.getAccount(), user.getUserId())).thenReturn(subscription);
    doNothing().when(authorizationService).hasReadPermission(subscription);
    SmartSenseSubscription result = underTest.getDefaultForUser(user);
    Assert.assertEquals("The given SmartSenseSubscription instance has got a unexpected update", subscription, result);
    verify(authorizationService, times(1)).hasReadPermission(Matchers.<SmartSenseSubscription>any());
}
Also used : SmartSenseSubscription(com.sequenceiq.cloudbreak.domain.SmartSenseSubscription) Test(org.junit.Test)

Example 17 with SmartSenseSubscription

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

the class SmartSenseSubscriptionServiceTest method testGetDefaultForUserWhenDefaultSmartSenseIdIsNotSpecifiedAndDefaultSubscriptionCouldBeFoundButNotAuthorized.

@Test
public void testGetDefaultForUserWhenDefaultSmartSenseIdIsNotSpecifiedAndDefaultSubscriptionCouldBeFoundButNotAuthorized() {
    SmartSenseSubscription smartSenseSubscription = createSmartSenseSubscription();
    String exceptionMessage = "Unable to identify SmartSense subscription for the user.";
    when(repository.findByAccountAndOwner(user.getAccount(), user.getUserId())).thenReturn(smartSenseSubscription);
    doThrow(new AccessDeniedException(exceptionMessage)).when(authorizationService).hasReadPermission(smartSenseSubscription);
    thrown.expect(SmartSenseSubscriptionAccessDeniedException.class);
    thrown.expectMessage(exceptionMessage);
    underTest.getDefaultForUser(user);
    verify(authorizationService, times(1)).hasReadPermission(Matchers.<SmartSenseSubscription>any());
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) SmartSenseSubscription(com.sequenceiq.cloudbreak.domain.SmartSenseSubscription) Test(org.junit.Test)

Example 18 with SmartSenseSubscription

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

the class AmbariSmartSenseCapturerTest method testCaptureWheTriggerNeedsToBeDoneAndNoExceptionOccured.

@Test
public void testCaptureWheTriggerNeedsToBeDoneAndNoExceptionOccured() {
    Optional<SmartSenseSubscription> smartSenseSubscription = Optional.empty();
    AmbariClient ambariClient = Mockito.mock(AmbariClient.class);
    when(ambariClient.smartSenseCapture(1)).thenReturn(1);
    when(smartSenseSubscriptionService.getDefault()).thenReturn(smartSenseSubscription);
    when(smartsenseConfigurationLocator.smartsenseConfigurable(smartSenseSubscription)).thenReturn(true);
    underTest.capture(1, ambariClient);
    verify(ambariClient, times(1)).smartSenseCapture(anyInt());
}
Also used : SmartSenseSubscription(com.sequenceiq.cloudbreak.domain.SmartSenseSubscription) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) Test(org.junit.Test)

Example 19 with SmartSenseSubscription

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

the class AmbariSmartSenseCapturerTest method testCaptureWheTriggerNeedsToBeDoneAndExceptionOccured.

@Test
public void testCaptureWheTriggerNeedsToBeDoneAndExceptionOccured() {
    Optional<SmartSenseSubscription> smartSenseSubscription = Optional.empty();
    AmbariClient ambariClient = Mockito.mock(AmbariClient.class);
    when(ambariClient.smartSenseCapture(1)).thenThrow(new AmbariServiceException("failed"));
    when(smartSenseSubscriptionService.getDefault()).thenReturn(smartSenseSubscription);
    when(smartsenseConfigurationLocator.smartsenseConfigurable(smartSenseSubscription)).thenReturn(true);
    underTest.capture(1, ambariClient);
    verify(ambariClient, times(1)).smartSenseCapture(anyInt());
}
Also used : SmartSenseSubscription(com.sequenceiq.cloudbreak.domain.SmartSenseSubscription) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) Test(org.junit.Test)

Example 20 with SmartSenseSubscription

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

the class FlexSubscriptionServiceTest method getFlexSubscription.

private FlexSubscription getFlexSubscription(String name, String subscriptionId, boolean usedForController, boolean usedAsDefault) {
    FlexSubscription subscription = new FlexSubscription();
    subscription.setName(name);
    subscription.setSubscriptionId(subscriptionId);
    subscription.setAccount("BIGACCOUNT");
    subscription.setOwner("MINE");
    subscription.setUsedForController(usedForController);
    subscription.setDefault(usedAsDefault);
    SmartSenseSubscription sSSubscription = new SmartSenseSubscription();
    subscription.setSmartSenseSubscription(sSSubscription);
    return subscription;
}
Also used : FlexSubscription(com.sequenceiq.cloudbreak.domain.FlexSubscription) SmartSenseSubscription(com.sequenceiq.cloudbreak.domain.SmartSenseSubscription)

Aggregations

SmartSenseSubscription (com.sequenceiq.cloudbreak.domain.SmartSenseSubscription)24 Test (org.junit.Test)10 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)3 IdentityUser (com.sequenceiq.cloudbreak.common.model.user.IdentityUser)3 SmartSenseSubscriptionJson (com.sequenceiq.cloudbreak.api.model.SmartSenseSubscriptionJson)2 FlexSubscription (com.sequenceiq.cloudbreak.domain.FlexSubscription)2 FlexUsageControllerJson (com.sequenceiq.cloudbreak.api.model.flex.FlexUsageControllerJson)1 BlueprintProcessingException (com.sequenceiq.cloudbreak.blueprint.BlueprintProcessingException)1 HdfConfigs (com.sequenceiq.cloudbreak.blueprint.nifi.HdfConfigs)1 BlueprintView (com.sequenceiq.cloudbreak.blueprint.template.views.BlueprintView)1 FileSystemConfigurationView (com.sequenceiq.cloudbreak.blueprint.template.views.FileSystemConfigurationView)1 BlueprintStackInfo (com.sequenceiq.cloudbreak.blueprint.templates.BlueprintStackInfo)1 StackRepoDetails (com.sequenceiq.cloudbreak.cloud.model.component.StackRepoDetails)1 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)1 NotFoundException (com.sequenceiq.cloudbreak.controller.NotFoundException)1 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)1 FileSystem (com.sequenceiq.cloudbreak.domain.FileSystem)1 LdapConfig (com.sequenceiq.cloudbreak.domain.LdapConfig)1 CloudbreakServiceException (com.sequenceiq.cloudbreak.service.CloudbreakServiceException)1 IOException (java.io.IOException)1