Example #1
0
 private void checkValueCount(ConfigurationProperty p, List<String> values)
     throws InterpreterPropertyException {
   if (values.size() < p.getMinValueCount()) {
     throw new InterpreterPropertyException(
         "At least " + p.getMinValueCount() + " value(s) must be supplied for the property " + p);
   } else if (values.size() > p.getMaxValueCount()) {
     throw new InterpreterPropertyException(
         "At most " + p.getMaxValueCount() + " value(s) must be supplied for the property " + p);
   }
 }
 private void expectProperty(String propertyName, String propertyValue) {
   try {
     ConfigurationProperty configurationProperty =
         mock(ConfigurationProperty.class, propertyName + "config-property");
     when(mockPropertyOracle().getConfigurationProperty(propertyName))
         .thenReturn(configurationProperty);
     when(configurationProperty.getValues()).thenReturn(Arrays.asList(propertyValue));
   } catch (BadPropertyValueException e) {
   }
 }
Example #3
0
  public void testWritesTargetLibraryProperties() throws UnableToCompleteException {
    compilerContext = compilerContextBuilder.compileMonolithic(false).build();
    ModuleDef libraryOneModule =
        ModuleDefLoader.loadFromClassPath(
            TreeLogger.NULL,
            compilerContext,
            "com.google.gwt.dev.cfg.testdata.separate.libraryone.LibraryOne",
            false);

    // Library one sees all defined values for the "libraryTwoProperty" binding property and knows
    // which one was defined in this target library.
    for (BindingProperty bindingProperty :
        libraryOneModule.getProperties().getBindingProperties()) {
      if (!bindingProperty.getName().equals("libraryTwoProperty")) {
        continue;
      }
      assertEquals(
          Sets.newHashSet(bindingProperty.getDefinedValues()),
          Sets.newHashSet("yes", "no", "maybe"));
      assertEquals(
          Sets.newHashSet(bindingProperty.getTargetLibraryDefinedValues()),
          Sets.newHashSet("maybe"));
    }

    // Library one added a new defined value of "maybe" for the "libraryTwoProperty" binding
    // property.
    assertEquals(
        Sets.newHashSet(
            mockLibraryWriter.getNewBindingPropertyValuesByName().get("libraryTwoProperty")),
        Sets.newHashSet("maybe"));

    // Library one sees all defined values for the "libraryTwoConfigProperty" property and knows
    // which one was defined in this target library.
    for (ConfigurationProperty configurationProperty :
        libraryOneModule.getProperties().getConfigurationProperties()) {
      if (!configurationProperty.getName().equals("libraryTwoConfigProperty")) {
        continue;
      }
      assertEquals(Sets.newHashSet(configurationProperty.getValues()), Sets.newHashSet("false"));
      assertEquals(
          Sets.newHashSet(configurationProperty.getTargetLibraryValues()),
          Sets.newHashSet("false"));
    }

    // Library one added a new defined value of "maybe" for the "libraryTwoConfigProperty"
    // property.
    assertEquals(
        Sets.newHashSet(
            mockLibraryWriter
                .getNewConfigurationPropertyValuesByName()
                .get("libraryTwoConfigProperty")),
        Sets.newHashSet("false"));
  }
 @Test
 public void shouldNotCreatePackageRepositoryWhenRepositoryHasDuplicateConfigurationProperties()
     throws Exception {
   ConfigurationProperty property =
       new ConfigurationProperty(new ConfigurationKey("foo"), new ConfigurationValue("bar"));
   Configuration configuration = new Configuration(property, property);
   packageRepository.setConfiguration(configuration);
   CreatePackageRepositoryCommand command =
       new CreatePackageRepositoryCommand(
           goConfigService, packageRepositoryService, packageRepository, currentUser, result);
   assertFalse(command.isValid(cruiseConfig));
   assertThat(
       property.errors().firstError(), is("Duplicate key 'foo' found for Repository 'npmOrg'"));
 }
Example #5
0
 private void checkValues(ConfigurationProperty p, List<String> values)
     throws InterpreterPropertyException {
   Pattern pattern = Pattern.compile(p.getValidatingExpression());
   for (String value : values) {
     Matcher m = pattern.matcher(value);
     if (!m.matches()) {
       throw new InterpreterPropertyException(
           "Could not parse the value for interpreter property "
               + p
               + " expected to be in the form "
               + p.getExample());
     }
   }
 }
Example #6
0
 private void mergeValues(
     List<String> valuesFromSource, ConfigurationProperty p, List<String> vals) {
   switch (p.getPropertySourceMode()) {
     case APPEND:
       vals.addAll(valuesFromSource);
       break;
     case OVERRIDE:
       vals.clear();
       vals.addAll(valuesFromSource);
       break;
     default:
       throw new UnsupportedOperationException("Unknown source mode " + p.getPropertySourceMode());
   }
 }
Example #7
0
 private void checkIfMandatory(
     Map<ConfigurationProperty, List<String>> results, ConfigurationProperty p)
     throws InterpreterPropertyException {
   if (p.isMandatory() && !results.containsKey(p)) {
     throw new InterpreterPropertyException(
         "Mandatory property "
             + p
             + " was not set. "
             + "You can set this property with the -"
             + p.getSwitchName()
             + " switch, "
             + "the -"
             + p.getSwitchShortName()
             + " switch or the "
             + p.getSystemProperty()
             + " system property");
   }
 }
 private String getSystemPropertyName(VariantType type, ConfigurationProperty property) {
   return String.format("aerogear.%s.%s", type.getTypeName(), property.toString());
 }