Search in sources :

Example 1 with LogRotator

use of hudson.tasks.LogRotator in project hudson-2.x by hudson.

the class ProjectPropertyTest method testLogRotatorProjectPropertyGetOriginalValue.

@Test
public void testLogRotatorProjectPropertyGetOriginalValue() {
    LogRotator value = new LogRotator(1, 1, 1, 1);
    BaseProjectProperty property = new LogRotatorProjectProperty(project);
    property.setKey(propertyKey);
    property.setValue(value);
    assertEquals(value, property.getOriginalValue());
}
Also used : LogRotator(hudson.tasks.LogRotator) Test(org.junit.Test)

Example 2 with LogRotator

use of hudson.tasks.LogRotator in project hudson-2.x by hudson.

the class Job method submit.

/**
     * Derived class can override this to perform additional config submission
     * work.
     */
protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, FormException {
    JSONObject json = req.getSubmittedForm();
    description = req.getParameter("description");
    keepDependencies = req.getParameter("keepDependencies") != null;
    properties.clear();
    setCascadingProjectName(StringUtils.trimToNull(req.getParameter("cascadingProjectName")));
    CopyOnWriteList parameterDefinitionProperties = new CopyOnWriteList();
    int i = 0;
    for (JobPropertyDescriptor d : JobPropertyDescriptor.getPropertyDescriptors(Job.this.getClass())) {
        if (!CascadingUtil.isCascadableJobProperty(d)) {
            String name = "jobProperty" + i;
            JSONObject config = json.getJSONObject(name);
            JobProperty prop = d.newInstance(req, config);
            if (null != prop) {
                prop.setOwner(this);
                if (prop instanceof AuthorizationMatrixProperty) {
                    properties.add(prop);
                } else if (prop instanceof ParametersDefinitionProperty) {
                    parameterDefinitionProperties.add(prop);
                }
            }
        } else {
            BaseProjectProperty property = CascadingUtil.getBaseProjectProperty(this, d.getJsonSafeClassName());
            JobProperty prop = d.newInstance(req, json.getJSONObject(d.getJsonSafeClassName()));
            if (null != prop) {
                prop.setOwner(this);
            }
            property.setValue(prop);
            addCascadingJobProperty(property);
        }
        i++;
    }
    setParameterDefinitionProperties(parameterDefinitionProperties);
    LogRotator logRotator = null;
    if (null != req.getParameter("logrotate")) {
        logRotator = LogRotator.DESCRIPTOR.newInstance(req, json.getJSONObject("logrotate"));
    }
    setLogRotator(logRotator);
}
Also used : BaseProjectProperty(org.hudsonci.model.project.property.BaseProjectProperty) JSONObject(net.sf.json.JSONObject) LogRotator(hudson.tasks.LogRotator) CopyOnWriteList(hudson.util.CopyOnWriteList) AuthorizationMatrixProperty(hudson.security.AuthorizationMatrixProperty) ExtensionPoint(hudson.ExtensionPoint)

Example 3 with LogRotator

use of hudson.tasks.LogRotator in project hudson-2.x by hudson.

the class FreeStyleProjectTest method testSetLogRotatorValueEqualsWithParent.

@Test
public void testSetLogRotatorValueEqualsWithParent() {
    FreeStyleProject parentProject = new FreeStyleProjectMock("parent");
    parentProject.setLogRotator(new LogRotator(10, 11, 12, 13));
    FreeStyleProjectMock childProject1 = new FreeStyleProjectMock("child1");
    childProject1.setCascadingProject(parentProject);
    childProject1.setLogRotator(new LogRotator(10, 11, 12, 13));
    // else log rotator will be taken from parent
    childProject1.setCascadingProject(null);
    assertNull(childProject1.getLogRotator());
}
Also used : LogRotator(hudson.tasks.LogRotator) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with LogRotator

use of hudson.tasks.LogRotator in project hudson-2.x by hudson.

the class FreeStyleProjectTest method testGetLogRotatorFromParent.

@Test
public void testGetLogRotatorFromParent() {
    FreeStyleProject parentProject = new FreeStyleProjectMock("parent");
    parentProject.setLogRotator(new LogRotator(10, 11, 12, 13));
    FreeStyleProjectMock childProject1 = new FreeStyleProjectMock("child1");
    childProject1.setCascadingProject(parentProject);
    LogRotator result = childProject1.getLogRotator();
    assertNotNull(result);
    assertEquals(result.getDaysToKeep(), 10);
}
Also used : LogRotator(hudson.tasks.LogRotator) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with LogRotator

use of hudson.tasks.LogRotator in project hudson-2.x by hudson.

the class LegacyMatrixConfigurationTest method testLoadLegacyMatrixProject.

/**
     * Tests unmarshalls MatrixProject configuration and checks whether properties are loaded correctly.
     *
     * @throws Exception if any.
     */
@Test
@Ignore
public void testLoadLegacyMatrixProject() throws Exception {
    Hudson hudson = createMock(Hudson.class);
    expect(hudson.getNodes()).andReturn(Lists.<Node>newArrayList()).anyTimes();
    expect(hudson.getInitLevel()).andReturn(InitMilestone.STARTED).anyTimes();
    expect(hudson.getRootDir()).andReturn(new File("./target/matrix")).anyTimes();
    ExtensionList<TransientProjectActionFactory> actionList = ExtensionList.create(hudson, TransientProjectActionFactory.class);
    expect(hudson.getExtensionList(TransientProjectActionFactory.class)).andReturn(actionList).anyTimes();
    ExtensionList<SaveableListener> saveableListenerList = ExtensionList.create(hudson, SaveableListener.class);
    expect(hudson.getExtensionList(SaveableListener.class)).andReturn(saveableListenerList).anyTimes();
    expect(hudson.getAllItems(MatrixConfiguration.class)).andReturn(Lists.<MatrixConfiguration>newArrayList()).anyTimes();
    mockStatic(Hudson.class);
    expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
    replayAll();
    MatrixProject project = (MatrixProject) Items.getConfigFile(config).read();
    project.setAllowSave(false);
    project.initProjectProperties();
    project.buildProjectProperties();
    verifyAll();
    assertEquals("/tmp/1", project.getProperty(AbstractProject.CUSTOM_WORKSPACE_PROPERTY_NAME).getValue());
    assertEquals(new Integer(7), CascadingUtil.getIntegerProjectProperty(project, AbstractProject.QUIET_PERIOD_PROPERTY_NAME).getValue());
    assertTrue(CascadingUtil.getBooleanProjectProperty(project, MatrixProject.RUN_SEQUENTIALLY_PROPERTY_NAME).getValue());
    assertEquals("!(label==\"win\" && DB==\"oracle\")", project.getProperty(MatrixProject.COMBINATION_FILTER_PROPERTY_NAME).getValue());
    assertEquals("label==\"unix\" && DB==\"mysql\"", project.getProperty(MatrixProject.TOUCH_STONE_COMBINATION_FILTER_PROPERTY_NAME).getValue());
    assertEquals(Result.SUCCESS, CascadingUtil.getResultProjectProperty(project, MatrixProject.TOUCH_STONE_RESULT_CONDITION_PROPERTY_NAME).getValue());
    assertEquals(new LogRotator(7, 7, 7, 7), CascadingUtil.getLogRotatorProjectProperty(project, MatrixProject.LOG_ROTATOR_PROPERTY_NAME).getValue());
    AxisList axes = CascadingUtil.getAxesListProjectProperty(project, MatrixProject.AXES_PROPERTY_NAME).getValue();
    assertEquals(2, axes.size());
    assertEquals("DB", axes.get(0).getName());
    assertEquals(2, axes.get(0).getValues().size());
    assertEquals("oracle", axes.get(0).getValues().get(0));
    assertEquals("mysql", axes.get(0).getValues().get(1));
    assertEquals("label", axes.get(1).getName());
    assertEquals(2, axes.get(1).getValues().size());
    assertEquals("unix", axes.get(1).getValues().get(0));
    assertEquals("win", axes.get(1).getValues().get(1));
    assertEquals(3, project.getActiveConfigurations().size());
    assertEquals(2, project.getActiveConfigurations().iterator().next().getCombination().size());
}
Also used : SaveableListener(hudson.model.listeners.SaveableListener) LogRotator(hudson.tasks.LogRotator) Hudson(hudson.model.Hudson) Node(hudson.model.Node) File(java.io.File) TransientProjectActionFactory(hudson.model.TransientProjectActionFactory) Ignore(org.junit.Ignore) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

LogRotator (hudson.tasks.LogRotator)8 Test (org.junit.Test)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 ExtensionPoint (hudson.ExtensionPoint)1 Hudson (hudson.model.Hudson)1 Node (hudson.model.Node)1 TransientProjectActionFactory (hudson.model.TransientProjectActionFactory)1 SaveableListener (hudson.model.listeners.SaveableListener)1 AuthorizationMatrixProperty (hudson.security.AuthorizationMatrixProperty)1 CopyOnWriteList (hudson.util.CopyOnWriteList)1 File (java.io.File)1 JSONObject (net.sf.json.JSONObject)1 BaseProjectProperty (org.hudsonci.model.project.property.BaseProjectProperty)1 Ignore (org.junit.Ignore)1