Search in sources :

Example 1 with DependencyFactory

use of jetbrains.buildServer.serverSide.dependency.DependencyFactory in project teamcity-rest by JetBrains.

the class BuildTypeRequestTest method testUpdatingSnapshotDependencies.

@Test
public void testUpdatingSnapshotDependencies() {
    BuildTypeImpl buildType1 = registerBuildType("buildType1", "projectName");
    BuildTypeImpl buildType2 = registerBuildType("buildType2", "projectName");
    BuildTypeImpl buildType3 = registerBuildType("buildType3", "projectName");
    BuildTypeImpl buildType4 = registerBuildType("buildType4", "projectName");
    BuildTypeImpl buildType5 = registerBuildType("buildType5", "projectName");
    DependencyFactory factory = myFixture.findSingletonService(DependencyFactory.class);
    assert factory != null;
    buildType1.addDependency(factory.createDependency(buildType2));
    buildType1.addDependency(factory.createDependency(buildType3));
    buildType1.addDependency(factory.createDependency(buildType4));
    final String btLocator = "id:" + buildType1.getExternalId();
    assertEquals(3, myBuildTypeRequest.getSnapshotDeps(btLocator, "$long,snapshot-dependencies($long)").propEntities.size());
    {
        PropEntitySnapshotDep submitted = new PropEntitySnapshotDep();
        submitted.type = "snapshot_dependency";
        submitted.sourceBuildType = new BuildType();
        submitted.sourceBuildType.setId(buildType5.getExternalId());
        String newId = myBuildTypeRequest.addSnapshotDep(btLocator, "$long", submitted).id;
        assertEquals(4, myBuildTypeRequest.getSnapshotDeps(btLocator, "$long,snapshot-dependencies($long)").propEntities.size());
        myBuildTypeRequest.deleteSnapshotDep(btLocator, newId);
        assertEquals(3, myBuildTypeRequest.getSnapshotDeps(btLocator, "$long,snapshot-dependencies($long)").propEntities.size());
    }
    {
        PropEntitiesSnapshotDep submitted = new PropEntitiesSnapshotDep();
        PropEntitySnapshotDep submitted1 = new PropEntitySnapshotDep();
        submitted1.type = "snapshot_dependency";
        submitted1.sourceBuildType = new BuildType();
        submitted1.sourceBuildType.setId(buildType1.getExternalId());
        submitted.propEntities = Arrays.asList(submitted1);
        checkException(BadRequestException.class, new Runnable() {

            public void run() {
                myBuildTypeRequest.replaceSnapshotDeps(btLocator, "$long", submitted);
            }
        }, null);
        assertNotNull(myBuildTypeRequest.getSnapshotDeps(btLocator, "$long,snapshot-dependencies($long)").propEntities);
        assertEquals(3, myBuildTypeRequest.getSnapshotDeps(btLocator, "$long,snapshot-dependencies($long)").propEntities.size());
        assertEquals(3, buildType1.getDependencies().size());
    }
    {
        PropEntitySnapshotDep submitted = new PropEntitySnapshotDep();
        submitted.type = "snapshot_dependency";
        submitted.sourceBuildType = new BuildType();
        submitted.sourceBuildType.setId(buildType1.getExternalId());
        checkException(BadRequestException.class, new Runnable() {

            public void run() {
                myBuildTypeRequest.addSnapshotDep(btLocator, "$long", submitted);
            }
        }, null);
        assertNotNull(myBuildTypeRequest.getSnapshotDeps(btLocator, "$long,snapshot-dependencies($long)").propEntities);
        assertEquals(3, myBuildTypeRequest.getSnapshotDeps(btLocator, "$long,snapshot-dependencies($long)").propEntities.size());
        assertEquals(3, buildType1.getDependencies().size());
    }
    myBuildTypeRequest.replaceSnapshotDeps(btLocator, "$long", new PropEntitiesSnapshotDep());
    assertEquals(0, buildType1.getDependencies().size());
}
Also used : DependencyFactory(jetbrains.buildServer.serverSide.dependency.DependencyFactory) BadRequestException(jetbrains.buildServer.server.rest.errors.BadRequestException) BuildTypeImpl(jetbrains.buildServer.serverSide.impl.BuildTypeImpl) Test(org.testng.annotations.Test) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest)

Aggregations

BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)1 BadRequestException (jetbrains.buildServer.server.rest.errors.BadRequestException)1 DependencyFactory (jetbrains.buildServer.serverSide.dependency.DependencyFactory)1 BuildTypeImpl (jetbrains.buildServer.serverSide.impl.BuildTypeImpl)1 Test (org.testng.annotations.Test)1