EmrHelperServiceImpl implements EmrHelperService { EmrClusterPreCreateDto emrPreCreateClusterStepsImpl(EmrClusterAlternateKeyDto emrClusterAlternateKeyDto, EmrClusterCreateRequest request) throws Exception { EmrClusterDefinitionEntity emrClusterDefinitionEntity = emrClusterDefinitionDaoHelper.getEmrClusterDefinitionEntity( new EmrClusterDefinitionKey(emrClusterAlternateKeyDto.getNamespace(), emrClusterAlternateKeyDto.getEmrClusterDefinitionName())); String originalClusterDefinitionXml = emrClusterDefinitionEntity.getConfiguration(); EmrClusterDefinition emrClusterDefinition = xmlHelper.unmarshallXmlToObject(EmrClusterDefinition.class, originalClusterDefinitionXml); overrideEmrClusterDefinition(emrClusterDefinition, request.getEmrClusterDefinitionOverride()); String accountId = emrClusterDefinition.getAccountId(); EmrParamsDto emrParamsDto = emrHelper.getEmrParamsDtoByAccountId(accountId); String overriddenEmrClusterDefinitionXml = xmlHelper.objectToXml(emrClusterDefinition); String replacedEmrClusterDefinitionXml = overriddenEmrClusterDefinitionXml .replaceAll(getS3ManagedReplaceString(), emrHelper.getS3StagingLocation(emrParamsDto.getTrustingAccountStagingBucketName())); emrClusterDefinition = xmlHelper.unmarshallXmlToObject(EmrClusterDefinition.class, replacedEmrClusterDefinitionXml); emrClusterDefinitionHelper.validateEmrClusterDefinitionConfiguration(emrClusterDefinition); namespaceIamRoleAuthorizationHelper.checkPermissions(emrClusterDefinitionEntity.getNamespace(), emrClusterDefinition.getServiceIamRole(), emrClusterDefinition.getEc2NodeIamProfileName()); return new EmrClusterPreCreateDto(emrClusterDefinition, emrParamsDto); }  @Override @Transactional(propagation = Propagation.NOT_SUPPORTED) EmrClusterCreateDto emrCreateClusterAwsSpecificSteps(EmrClusterCreateRequest emrClusterCreateRequest, EmrClusterDefinition emrClusterDefinition,
        EmrClusterAlternateKeyDto emrClusterAlternateKeyDto, EmrParamsDto emrParamsDto); @Override @Transactional(propagation = Propagation.REQUIRES_NEW) EmrClusterPreCreateDto emrPreCreateClusterSteps(EmrClusterAlternateKeyDto emrClusterAlternateKeyDto, EmrClusterCreateRequest emrClusterCreateRequest); @Override @Transactional(propagation = Propagation.REQUIRES_NEW) void logEmrClusterCreation(EmrClusterAlternateKeyDto emrClusterAlternateKeyDto, EmrClusterDefinition emrClusterDefinition, String clusterId);  }
@Test public void testEmrPreCreateClusterStepsImpl() throws Exception { EmrClusterDefinition emrClusterDefinitionOverride = new EmrClusterDefinition(); emrClusterDefinitionOverride.setAccountId(AWS_ACCOUNT_ID_2); emrClusterDefinitionOverride.setAdditionalInfo(STRING_VALUE_2); EmrClusterCreateRequest emrClusterCreateRequest = new EmrClusterCreateRequest(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME, EMR_CLUSTER_NAME, NO_DRY_RUN, emrClusterDefinitionOverride); EmrClusterAlternateKeyDto emrClusterAlternateKeyDto = new EmrClusterAlternateKeyDto(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME, EMR_CLUSTER_NAME); EmrClusterDefinitionKey emrClusterDefinitionKey = new EmrClusterDefinitionKey(NAMESPACE, EMR_CLUSTER_DEFINITION_NAME); NamespaceEntity namespaceEntity = new NamespaceEntity(); namespaceEntity.setCode(NAMESPACE); EmrClusterDefinitionEntity emrClusterDefinitionEntity = new EmrClusterDefinitionEntity(); emrClusterDefinitionEntity.setNamespace(namespaceEntity); emrClusterDefinitionEntity.setConfiguration(EMR_CLUSTER_CONFIGURATION_XML_1); EmrClusterDefinition originalEmrClusterDefinition = new EmrClusterDefinition(); originalEmrClusterDefinition.setAdditionalInfo(STRING_VALUE); originalEmrClusterDefinition.setAccountId(AWS_ACCOUNT_ID); EmrClusterDefinition finalEmrClusterDefinition = new EmrClusterDefinition(); finalEmrClusterDefinition.setServiceIamRole(SERVICE_IAM_ROLE); finalEmrClusterDefinition.setEc2NodeIamProfileName(EC2_NODE_IAM_PROFILE_NAME); EmrParamsDto emrParamsDto = new EmrParamsDto(NO_AWS_ACCESS_KEY, NO_AWS_SECRET_KEY, NO_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT, AWS_REGION_NAME_US_EAST_1, S3_TRUSTING_ACCOUNT_STAGING_BUCKET_NAME); when(emrClusterDefinitionDaoHelper.getEmrClusterDefinitionEntity(emrClusterDefinitionKey)).thenReturn(emrClusterDefinitionEntity); when(xmlHelper.unmarshallXmlToObject(EmrClusterDefinition.class, EMR_CLUSTER_CONFIGURATION_XML_1)).thenReturn(originalEmrClusterDefinition); when(emrHelper.getEmrParamsDtoByAccountId(AWS_ACCOUNT_ID_2)).thenReturn(emrParamsDto); when(xmlHelper.objectToXml(originalEmrClusterDefinition)).thenReturn(EMR_CLUSTER_CONFIGURATION_XML_2); when(configurationHelper.getProperty(ConfigurationValue.S3_STAGING_RESOURCE_LOCATION)) .thenReturn((String) ConfigurationValue.S3_STAGING_RESOURCE_LOCATION.getDefaultValue()); when(emrHelper.getS3StagingLocation(S3_TRUSTING_ACCOUNT_STAGING_BUCKET_NAME)).thenReturn(S3_STAGING_LOCATION); when(xmlHelper.unmarshallXmlToObject(EmrClusterDefinition.class, EMR_CLUSTER_CONFIGURATION_XML_2)).thenReturn(finalEmrClusterDefinition); emrHelperServiceImpl.emrPreCreateClusterSteps(emrClusterAlternateKeyDto, emrClusterCreateRequest); verify(emrClusterDefinitionDaoHelper).getEmrClusterDefinitionEntity(emrClusterDefinitionKey); verify(xmlHelper).unmarshallXmlToObject(EmrClusterDefinition.class, EMR_CLUSTER_CONFIGURATION_XML_1); verify(emrHelper).getEmrParamsDtoByAccountId(AWS_ACCOUNT_ID_2); verify(xmlHelper).objectToXml(originalEmrClusterDefinition); verify(configurationHelper).getProperty(ConfigurationValue.S3_STAGING_RESOURCE_LOCATION); verify(emrHelper).getS3StagingLocation(S3_TRUSTING_ACCOUNT_STAGING_BUCKET_NAME); verify(xmlHelper).unmarshallXmlToObject(EmrClusterDefinition.class, EMR_CLUSTER_CONFIGURATION_XML_2); verify(emrClusterDefinitionHelper).validateEmrClusterDefinitionConfiguration(finalEmrClusterDefinition); verify(namespaceIamRoleAuthorizationHelper).checkPermissions(namespaceEntity, SERVICE_IAM_ROLE, EC2_NODE_IAM_PROFILE_NAME); verifyNoMoreInteractionsHelper(); }