ValidateElasticServiceValidator implements SetServiceInstancesValidator { @Override public void validate(final SetServiceInstancesValidationContext validationContext) throws RestErrorException { logger.info("Validating elastic service"); final ProcessingUnit pu = validationContext.getProcessingUnit(); final Properties contextProperties = pu.getBeanLevelProperties() .getContextProperties(); final String elasticProp = contextProperties .getProperty(CloudifyConstants.CONTEXT_PROPERTY_ELASTIC); if (elasticProp == null || !Boolean.parseBoolean(elasticProp)) { throw new RestErrorException(ResponseConstants.SERVICE_NOT_ELASTIC, validationContext.getServiceName()); } }  @Override void validate(final SetServiceInstancesValidationContext validationContext);  }
@Test public void testElasticPu() throws Exception { ValidateElasticServiceValidator fixture = new ValidateElasticServiceValidator(); SetServiceInstancesValidationContext validationContext = new SetServiceInstancesValidationContext(); validationContext.setApplicationName("default"); validationContext.setServiceName("simple"); validationContext.setCloud(null); ProcessingUnit mockedPu = Mockito.mock(ProcessingUnit.class); BeanLevelProperties mockedBlp = Mockito.mock(BeanLevelProperties.class); Properties props = new Properties(); props.setProperty(CloudifyConstants.CONTEXT_PROPERTY_ELASTIC, "true"); Mockito.when(mockedBlp.getContextProperties()).thenReturn(props); Mockito.when(mockedPu.getBeanLevelProperties()).thenReturn(mockedBlp); validationContext.setProcessingUnit(mockedPu); fixture.validate(validationContext); }
@Test(expected = RestErrorException.class) public void testNonElasticPu() throws Exception { ValidateElasticServiceValidator fixture = new ValidateElasticServiceValidator(); SetServiceInstancesValidationContext validationContext = new SetServiceInstancesValidationContext(); validationContext.setApplicationName("default"); validationContext.setServiceName("simple"); validationContext.setCloud(null); ProcessingUnit mockedPu = Mockito.mock(ProcessingUnit.class); BeanLevelProperties mockedBlp = Mockito.mock(BeanLevelProperties.class); Properties props = new Properties(); props.setProperty(CloudifyConstants.CONTEXT_PROPERTY_ELASTIC, "false"); Mockito.when(mockedBlp.getContextProperties()).thenReturn(props); Mockito.when(mockedPu.getBeanLevelProperties()).thenReturn(mockedBlp); validationContext.setProcessingUnit(mockedPu); fixture.validate(validationContext); }
@Test(expected = RestErrorException.class) public void testDefaultElasticValuePu() throws Exception { ValidateElasticServiceValidator fixture = new ValidateElasticServiceValidator(); SetServiceInstancesValidationContext validationContext = new SetServiceInstancesValidationContext(); validationContext.setApplicationName("default"); validationContext.setServiceName("simple"); validationContext.setCloud(null); ProcessingUnit mockedPu = Mockito.mock(ProcessingUnit.class); BeanLevelProperties mockedBlp = Mockito.mock(BeanLevelProperties.class); Properties props = new Properties(); Mockito.when(mockedBlp.getContextProperties()).thenReturn(props); Mockito.when(mockedPu.getBeanLevelProperties()).thenReturn(mockedBlp); validationContext.setProcessingUnit(mockedPu); fixture.validate(validationContext); }