Java FreeStyleProjectMock Example

Introduction

The java freestyleprojectmock example is extracted from the most popular open source projects, you can refer to the following example for usage.

Programming language: Java

Namespace/package name: hudson.model

Example#1
File: BaseProjectPropertyTest.javaProject: srinivas-n4u/hudson

  /** Verify {@link BaseProjectProperty#getValue()} method. */
  @Test
  public void testGetValue() {
    Integer propertyValue = 10;
    property.setValue(propertyValue);
    // if value is not null - return it
    assertEquals(propertyValue, property.getValue());
    property.setValue(null);
    assertNull(property.getValue());

    BaseProjectProperty parentProperty = new BaseProjectProperty(parent);
    parentProperty.setKey(propertyKey);
    parentProperty.setValue(propertyValue);
    parent.putProjectProperty(propertyKey, parentProperty);

    project.setCascadingProject(parent);
    property = new BaseProjectProperty(project);
    property.setKey(propertyKey);
    // if current value is null and is not overridden value, take from cascading
    assertNull(property.getOriginalValue());
    assertEquals(propertyValue, property.getValue());

    property.setOverridden(true);
    // Property is overridden - return current value even if it is null.
    assertNull(property.getOriginalValue());
    assertNull(property.getValue());
  }

Example#2
File: BaseProjectPropertyTest.javaProject: srinivas-n4u/hudson

  /** Verify {@link BaseProjectProperty#setValue(Object)} method. */
  @Test
  public void testSetValue() {
    BaseProjectProperty property = new BaseProjectProperty(project);
    property.setKey(propertyKey);
    property.setValue(null);
    // If project doesn't have cascading - default boolean value is used for propertyOverridden flag
    assertFalse(property.isOverridden());
    assertNull(property.getOriginalValue());

    Object value = 12345;
    property.setValue(value);
    // If project doesn't have cascading - default boolean value is used for propertyOverridden flag
    assertFalse(property.isOverridden());
    assertEquals(value, property.getOriginalValue());

    String parentValue = "equalValue";
    BaseProjectProperty parentProperty = new BaseProjectProperty(parent);
    parentProperty.setKey(propertyKey);
    parentProperty.setValue(parentValue);
    parent.putProjectProperty(propertyKey, parentProperty);
    project.setCascadingProject(parent);

    // If value set to null, need to check whether default value is equals to cascading
    property.setValue(null);
    assertTrue(property.isOverridden());
    String overriddenValue = "newValue";
    property.setValue(overriddenValue);
    assertTrue(property.isOverridden());

    // Check whether current value is not null, after setting equal-to-cascading value current will
    // be null
    assertNotNull(property.getOriginalValue());
    assertTrue(property.isOverridden());
    property.setValue(parentValue);
    // Reset current property to null
    assertNull(property.getOriginalValue());
    // Cascading value is equal to current - reset flag to false.
    assertFalse(property.isOverridden());
  }

Example#3
File: BaseProjectPropertyTest.javaProject: srinivas-n4u/hudson

  /** Verify {@link BaseProjectProperty#getCascadingValue()} method. */
  @Test
  public void testGetCascadingValue() {
    String parentValue = "parentValue";
    // If project doesn't have cascading project - default value is used as cascading value.
    assertEquals(property.getDefaultValue(), property.getCascadingValue());

    project.setCascadingProject(parent);
    property = new BaseProjectProperty(project);
    property.setKey(propertyKey);
    // If project has cascading project and cascading value is not set - default value is used.
    assertEquals(property.getDefaultValue(), property.getCascadingValue());

    BaseProjectProperty parentProperty = new BaseProjectProperty(parent);
    parentProperty.setKey(propertyKey);
    parentProperty.setValue(parentValue);
    parent.putProjectProperty(propertyKey, parentProperty);
    project.setCascadingProject(parent);
    property = new BaseProjectProperty(project);
    property.setKey(propertyKey);
    property.setValue(parentValue);
    // If project has cascading project and cascading value is set - property value will be used.
    assertEquals(parentProperty.getOriginalValue(), property.getCascadingValue());
  }